ubuntu16.4安装cuda10.2 + nvidia驱动 + cudnn7.6.5
转载及小幅修改:https://www.jianshu.com/p/e5589c9a5eb6
1、检查系统版本及显卡型号支持版本,这里不做赘述,可进上述连接看看官网说明,下载自己电脑支持的cuda版本及cudnn版本。本人是用RTX2070显卡。
2、屏蔽开源驱动nouveau,不然安装nvidia驱动会出现失败情况。
sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
sudo update-initramfs -u
3、cd进入CUDA的run文件所在文件夹,然后关闭图像界面。
sudo service lightdm stop
4、再次要注意!
(1)如果电脑只有独显,可使用以下命令安装CUDA+Nvidia驱动,一路选择默认参数即可
sudo sh ./cuda_10.2.89_440.33.01_linux.run
(2)如果电脑有集显+独显(也就是没有装Nvidia驱动的情况下直接可驱动显示器),必须使用以下命令安装,也就是不装OpenGL,如果不加 - -no-opengl-libs,询问是否安装OpenGL时又选了yes的话,待会开机就会循环登录进不去桌面!血泪教训!
sudo sh ./cuda_10.2.89_440.33.01_linux.run --no-opengl-libs
5、如果没有意外,就是安装完成了,显示如下,别着急关闭终端,记住下面提示的安装地址:PATH includes /usr/local/cuda-10.2/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-10.2/lib64,有用!
===========
= Summary =
===========
Driver: Installed
Toolkit: Installed in /usr/local/cuda-10.2/
Samples: Installed in /home/rst/, but missing recommended libraries
Please make sure that
- PATH includes /usr/local/cuda-10.2/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-10.2/lib64, or, add /usr/local/cuda-10.2/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-10.2/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall
Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.2/doc/pdf for detailed information on setting up CUDA.
Logfile is /var/log/cuda-installer.log
6、安装成功后可重启图像界面
sudo service lightdm start
7、然后就是配置环境了。查看第5步,代码提示编辑~/.bashrc文件,添加环境变量,并保存退出
sudo vim ~/.bashrc
8、在环境变量中加入第5步记住的地址
export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64:$LD_LIBRARY_PATH
9、然后重新加载环境
source ~/.bashrc
10、可再检查安装版本及是否成功
nvidia-smi
显示如下:
Tue Jul 5 14:57:08 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.33.01 Driver Version: 440.33.01 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 2070 Off | 00000000:01:00.0 Off | N/A |
| 17% 31C P8 15W / 175W | 268MiB / 7981MiB | 1% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 26224 G /usr/lib/xorg/Xorg 165MiB |
| 0 26725 G compiz 101MiB |
+-----------------------------------------------------------------------------+
11、解压cudnn文件
sudo tar -zxvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
12、复制文件并给权限
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*