Detailed explanation of Ubuntu16.04 installation of nvidia driver + CUDA+cuDNN tutorial
- 2021-07-03 01:05:05
- OfStack
Preparatory work
1. Check whether GPU supports CUDA
lspci | grep -i nvidia
2. View the Linux version
uname -m && cat /etc/*release
nvidia driver
1. Uninstall the original N card driver first
#for case1: original driver installed by apt-get:
sudo apt-get remove --purge nvidia*
#for case2: original driver installed by runfile:
sudo chmod +x *.run
sudo ./NVIDIA-Linux-x86_64-384.59.run --uninstall
2. Disable the nouveau driver
sudo gedit /etc/modprobe.d/blacklist.conf
At the end of the text, add:
blacklist nouveau
options nouveau modeset=0
Then execute:
sudo update-initramfs -u
After restarting, you can see if nouveau is running:
lsmod | grep nouveau # 没输出代表禁用生效
3. Disable the X-Window service
sudo service lightdm stop # This closes the graphical interface
Press Ctrl-Alt+F1 to enter the command line interface and enter the user name and password to log in.
4. Install the driver from the command line
Driver website https://www.nvidia.cn/Download/index.aspx? lang = cn
# Give drive run File gives execute permission:
sudo chmod +x NVIDIA-Linux-x86_64-384.59.run
# The following parameters are very important and cannot be omitted:
sudo ./NVIDIA-Linux-x86_64-384.59.run In fact, in fact, the no-opengl-files
5. Driver test:
nvidia-smi # If the information list of GPU is listed, the driver installation is successful
nvidia-settings # If the setting dialog box pops up, it also means that the driver is successfully installed
CUDA Installation
1. Download the CUDA for the corresponding system
Website http://developer.nvidia.com/cuda-downloads Select runfile Installation
Step 2 Install
sudo sh cuda_<version>_linux.run
After starting the installation, you need to read the instructions. You can read them directly using Ctrl + C, or you can read them slowly using the space bar. The following are the installation options:
(If you agree to the terms, you must agree to continue the installation)
accept/decline/quit: accept
(Do not install the driver here, because the latest driver has been installed, otherwise the old version of the graphics card driver may be installed, resulting in repeated login.)
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n
Install the CUDA 10.0 Toolkit? (Is it installed CUDA 10 , which must be installed here)
(y)es/(n)o/(q)uit: y
Enter Toolkit Location (Installation path, use default, just enter directly)
[ default is /usr/local/cuda-10.0 ]:
Do you want to install a symbolic link at /usr/local/cuda? (Agree to create soft link)
(y)es/(n)o/(q)uit: y
Install the CUDA 10.0 Samples? (You don't need to install the test, you have it yourself.)
(y)es/(n)o/(q)uit: n
Installing the CUDA Toolkit in /usr/local/cuda-10.0 ... (Start installation)
3. Configure environment variables
sudo gedit ~/.bashrc
Add at the end
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Update
source ~/.bashrc
4. Verify the installation
View cuda version
nvcc -V
CUDA Sample Test:
# Compile and test equipment deviceQuery :
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
make
./deviceQuery
# Compile and test bandwidth bandwidthTest :
cd ../bandwidthTest
make
./bandwidthTest
If the final result of both tests is Result = PASS, CUDA is installed successfully.
* 5. CUDA Uninstall
Enter on the command line
sudo apt-get remove cuda
sudo apt-get autoclean
sudo apt-get remove cuda*
Then switch to usr/local/in the directory
cd /usr/local/
sudo rm -r cuda-9.1
cuDNN Installation
Download the corresponding version cuDNN https://developer.nvidia.com/cudnn
tar xvzf cudnn-9.2-linux-x64-v7.1
sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
sudo ldconfig
Reference
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions
Summarize