(推荐一个我自己做的普法公众号,大可说法律,有法律方面咨询的可以关注)
Ubuntu20.04系统显卡2080 Ti 安装cuda和cudnn
历经千辛万苦,终于完成第一步,先晒一下结果图:
CUDA 10.2.89
cudnn 版本:7.6.5
本机器配置:
显卡为:GeForce RTX 2080 Ti Rev. A,其它如下:
安装流程
Ubuntu系统的安装选择最小安装,Ubuntu安装记得设置密码,否则可能导致驱动安装后无法进入桌面。开始安装之前需安装必要的依赖,并更改好源,一般使用清华源。
安装依赖可能使用的命令:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
安装流程大致包括:
- 禁用nouveau
- Nvidia驱动安装
- Cuda安装
- cudnn安装
第一步:禁用nouveau
这步操作是为了禁用系统自带的显卡驱动:
sudo gedit /etc/modprobe.d/blacklist.conf
最后一行添加:
blacklist nouveau
options nouveau modeset=0
保存关闭,执行:
sudo update-initramfs -u
然后重启(切忌不要使用reboot,要使用sudo reboot,否则无效,别问我是怎么知道的,鬼知道我重启了多少次):
sudo reboot
重启,执行,如果没有输出说明禁用成功了,否则解决这一步的问题:
lsmod | grep nouveau
第二步 Nvidia驱动安装
查看机器显卡型号
lshw -numeric -C display
在官网下载程序https://www.geforce.cn/drivers 搜索相应的驱动程序下载,随后开始安装,然后安装时确保自己没有胡乱安装过别的版本的,包括在软件和更新图形界面的操作,总之确保显卡驱动未安装(没错,就是我胡乱安装了别的版本又安装这个版本导致无法开机,重新装了系统)
下载好驱动后,进入所在文件夹后,授权并安装:
sudo chmod a+x NVIDIA-Linux-x86_64-450.57.run
sudo ./NVIDIA-Linux-x86_64-450.57.run --no-opengl-files --no-x-check --no-nouveau-check
–no-opengl-files 只安装驱动文件,不安装OpenGL文件。这个参数最重要
–no-x-check 安装驱动时不检查X服务
–no-nouveau-check 安装驱动时不检查nouveau
至此,驱动安装成功,可执行下面命令检查:
nvidia-smi
执行后有如下显示:
第三步Cuda安装
从 https://developer.nvidia.com/cuda-toolkit-archive 下载对应版本的cuda,选择10.2的版本即可。
由于Ubuntu20.04自带gcc版本为9.7.0,而Cuda10.2需要添加并切换为gcc7。
(之前安装依赖也是为了这一步,如果只安装gcc7,系统会找不到,可能是我安装的问题吧)
安装gcc7
sudo apt install gcc-7 g++-7
查看gcc版本,可以看到目前系统中存在7和9两个版本
ls /usr/bin/gcc*
使用update-alternatives进行版本切换,输入以下命令:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
输入以下命令:
sudo update-alternatives --config gcc
命令查看gcc的默认版本,可以看到当前默认gcc版本为7,即切换成功。
安装cuda
sudo sh ./cuda_10.2.89_440.33.01_linux.run
点击continue 输入 accept,cuda安装包自带的显卡驱动点掉,因为已经安装过了。然后选择install,
配置环境变量:
gedit ~/.bashrc
在打开的文件最后添加以下语句并保存:
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
更新环境变量配置
source ~/.bashrc
至此,cuda安装完成,输入nvcc -V
命令查看cuda信息。
第四步cudnn安装
从 https://developer.nvidia.com/cudnn 下载cuDNN,需要注册登陆,也可以从我的网盘下载, 链接: https://pan.baidu.com/s/1CVFc6GWicpf7hYI9VqcBsw 密码: j927
下载解压:
tar -xvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
将cuda/include/cudnn.h文件复制到usr/local/cuda/include文件夹,将cuda/lib64/下所有文件复制到/usr/local/cuda/lib64文件夹中,并添加读取权限:
sudo cp ./cuda/lib64/* /usr/local/cuda/lib64
sudo cp ./cuda/include/cudnn.h /usr/local/cuda/include
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
好了,大功告成,输入命令检验:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
验证
找到cuda-install-samples-10.2.sh文件,后面/home/archy是你自己的路径。
/usr/local/cuda-10.2/bin/cuda-install-samples-10.2.sh /home/archy/
结果显示如下:
Copying samples to /home/archy/NVIDIA_CUDA-10.2_Samples now...
Finished copying samples.
在home主目录下,找到/NVIDIA_CUDA-10.2_Samples/1_Utilities/deviceQuery,执行命令make &&./deviceQuery
cd NVIDIA_CUDA-10.2_Samples/1_Utilities/deviceQuery
make &&./deviceQuery
显示以下结果:
Detected 1 CUDA Capable device(s)
Device 0: "GeForce RTX 2080 Ti"
CUDA Driver Version / Runtime Version 11.0 / 10.2
CUDA Capability Major/Minor version number: 7.5
Total amount of global memory: 11011 MBytes (11546329088 bytes)
(68) Multiprocessors, ( 64) CUDA Cores/MP: 4352 CUDA Cores
GPU Max Clock rate: 1635 MHz (1.63 GHz)
Memory Clock rate: 7000 Mhz
Memory Bus Width: 352-bit
L2 Cache Size: 5767168 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: 1024
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 3 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 / 101 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.0, CUDA Runtime Version = 10.2, NumDevs = 1
Result = PASS
验证其他例子的时候发现会提示:
#error -- unsupported GNU version! gcc versions later than 8 are not supported!
输入命令查看
ls /usr/local/cuda/bin/
是否包括gcc 和g++两个文件夹。
bin2c cuobjdump nvdisasm
computeprof fatbinary nvlink
crt nsight nv-nsight-cu
cudafe++ nsight_ee_plugins_manage.sh nv-nsight-cu-cli
cuda-gdb nsight-sys nvprof
cuda-gdbserver nsys nvprune
cuda-install-samples-10.2.sh nsys-exporter nvvp
cuda-memcheck nvcc ptxas
cuda-uninstaller nvcc.profile
如果向上面一样没有gcc和g++,建立软链接,如下操作:
sudo ln -s /usr/bin/gcc-7 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-7 /usr/local/cuda/bin/g++
操作后显示有g++ 和gcc了,如图:
bin2c fatbinary nvdisasm
computeprof g++ nvlink
crt gcc nv-nsight-cu
cudafe++ nsight nv-nsight-cu-cli
cuda-gdb nsight_ee_plugins_manage.sh nvprof
cuda-gdbserver nsight-sys nvprune
cuda-install-samples-10.2.sh nsys nvvp
cuda-memcheck nsys-exporter ptxas
cuda-uninstaller nvcc
cuobjdump nvcc.profile
若操作失误,建立错误gcc或g++,使用sudo rm g++
删除重新执行上述命令即可。