Ubuntu 18.04安装CUDA 10.0笔记

1. 下载

在CUDA官网上下载CUDA 10.0的Ubuntu 18.04安装包:
https://developer.nvidia.com/cuda-10.0-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal




2. 确保系统中安装了NVIDIA的显卡驱动

可以参照这篇文章进行驱动安装:https://blog.csdn.net/discoverer100/article/details/101753039




3. 安装CUDA

S1. 打开终端,cd到CUDA 10.0安装包所在的目录。

S2. 首先运行命如下命令,赋予可执行权限:

chmod 777 cuda_10.0.130_410.48_linux.run

S3. 接下来运行如下命令进行安装:

sudo ./cuda_10.0.130_410.48_linux.run

S4. 在终端中根据提示一步一步操作,如下所示,这里面特别要留意:不要安装显卡驱动

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n

Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-10.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/test ]: 

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...

S5. 安装结束,终端中会显示如下信息:

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/test ...
Copying samples to /home/test/NVIDIA_CUDA-10.0_Samples now...
Finished copying samples.

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-10.0
Samples:  Installed in /home/test, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-10.0/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-10.0/lib64, or, add /usr/local/cuda-10.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-10.0/bin

Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for detailed information on setting up CUDA.

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 10.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_8442.log

S6. 运行如下命令补充安装缺失的包:

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev 



4. 配置环境变量

S1. 在终端中运行如下命令:

sudo gedit ~/.bashrc

S2. 在打开的gedit文本编辑区的末尾加上如下内容并保存(如果安装CUDA时自行选择了路径,那么下面的HOME路径要结合实际来写):

# for CUDA 10.0
export CUDA_10_0_HOME=/usr/local/cuda-10.0
export PATH=$PATH:$CUDA_10_0_HOME/bin 
export LD_LIBRARY_PATH=CUDA_10_0_HOME/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

S3. 关闭gedit窗口,在终端中运行如下命令,使环境变量立即生效:

source ~/.bashrc



5. 验证安装

S1. 在终端中分别执行如下三条命令:

cd /usr/local/cuda/samples/1_Utilities/deviceQuery 
sudo make
./deviceQuery

S2. 运行后终端中会输出如下内容:

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1070"
  CUDA Driver Version / Runtime Version          10.1 / 10.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8112 MBytes (8505524224 bytes)
  (15) Multiprocessors, (128) CUDA Cores/MP:     1920 CUDA Cores
  GPU Max Clock rate:                            1759 MHz (1.76 GHz)
  Memory Clock rate:                             4004 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.1, CUDA Runtime Version = 10.0, NumDevs = 1
Result = PASS

上面的结果给出的是PASS,说明CUDA安装成功。至此,Ubuntu 18.04下的CUDA 10.0安装就完成了。

你可能感兴趣的:(CUDA,环境搭建,Ubuntu)