最正确的方法安装NVIDIA驱动+CUDA10+cuDNN7.6
话不多说直接开始
平台:
Ubuntu18.04
显卡 GTX1080TI**2+Quadro P6000*2
如果以前已经装有NVIDIA驱动,先卸载
sudo apt-get remove --purge nvidia*
一、禁用nouveau
sudo vim /etc/modprobe.d/blacklist.conf
加入下列代码
blacklist nouveau
options nouveau modeset=0
blacklist lbm-nouveau
alias nouveau off
alias lbm-nouveau off
应用更改
sudo update-initramfs -u
sudo reboot
验证nouveau是否禁用
lsmod | grep nouveau
# 没有输出说明禁用成功
二、 下载安装包
下载CUDA10.run安装包
对于Ubuntu18.04的,直接运行以下命令
wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
下载cuDNN7.6安装包,需要注册nvidia账号才能下载,而且要和CUDA版本对应
修改权限+安装必要组件
sudo chmod 755 cuda_10.0.130_410.48_linux.run
sudo apt-get install gcc make freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev -y
三、 安装
sudo ./cuda_10.0.130_410.48_linux.run
一直按f,输入accept
Do you accept the previously read EULA?
accept/decline/quit: accept
安装NVIDIA显示驱动
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: y
安装OpenGL库
Do you want to install the OpenGL libraries?
(y)es/(n)o/(q)uit [ default is yes ]: y
安装NVIDIA-xconfig
Do you want to run nvidia-xconfig?
This will update the system X configuration file so that the NVIDIA X driver
is used. The pre-existing X configuration file will be backed up.
This option should not be used on systems that require a custom
X configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit [ default is no ]: y
安装CUDA10 toolkit
Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y
选择CUDA安装位置,直接按回车采用默认位置
Enter Toolkit Location[ default is /usr/local/cuda-10.0 ]:
接下来一路y
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: yInstall the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: y
CUDA Samples位置采用默认即可
Enter CUDA Samples Location[ default is /home/$USER ]:
输出如下信息说明安装完成
===========
= Summary =
===========Driver: Installed
Toolkit: Installed in /usr/local/cuda-10.0
Samples: Installed in /home/$USERPlease 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 rootTo uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-10.0/bin
To uninstall the NVIDIA Driver, run nvidia-uninstallPlease see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-10.0/doc/pdf for detailed information on setting up CUDA.Logfile is /tmp/cuda_install_2493.log
检查驱动是否安装成功,输入以下命令
nvidia-smi
类似以下输出说明驱动安装成功
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48 Driver Version: 410.48 |
|-------------------------------+----------------------+----------------------+
| 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 GTX 108... Off | 00000000:04:00.0 Off | N/A |
| 21% 34C P0 60W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX 108... Off | 00000000:08:00.0 Off | N/A |
| 20% 32C P0 59W / 250W | 0MiB / 11178MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 2 Quadro P6000 Off | 00000000:85:00.0 Off | Off |
| 21% 36C P0 62W / 250W | 0MiB / 24449MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 3 Quadro P6000 Off | 00000000:89:00.0 Off | Off |
| 21% 25C P0 59W / 250W | 0MiB / 24449MiB | 2% Default |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
设置环境变量
vi ~/.bashrc
在最后加入以下两行代码
export PATH=$PATH:/usr/local/cuda-10.0/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
使环境变量生效
source ~/.bashrc
输入以下命令测试CUDA是否安装成功
nvcc -V
会输出以下信息
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
安装cuDNN,进入cuDNN下载目录,然后解压
sudo tar -zxvf cudnn-10.0-linux-x64-v7.6.0.64.tgz
依次执行以下命令
sudo cp cuda/include/* /usr/local/cuda/include/
sudo cp cuda/lib64/* /usr/local/cuda/lib64/
#修改cudnn.h权限
sudo chmod 644 /usr/local/cuda/include/cudnn.h## 编辑cuDNN动态链接库的软链接关系
cd /usr/local/cuda/lib64/
# ll查看其它链接库关系,类似的编辑cuDNN动态链接库
ll
sudo ln -sf libcudnn.so.7.6.0 libcudnn.so.7
sudo ln -sf libcudnn.so.7 libcudnn.so
#更新链接库
sudo ldconfig
source ~/.bashrc
简单测试
cd ~/NVIDIA_CUDA-10.0_Samples/2_Graphics/volumeRender
make -j$(nproc)
./volumeRender