1. Install the graphics driver
Confirm the required cuda version, take cuda10.1 as an example
1. View version correspondence
In the cuda documentation , check the required cuda corresponding graphics card driver version
cuda10.1 . The graphics card driver version is required under linux>=418.39
2. Install the graphics driver online
- Add ppa source
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
- View the driver version that supports the current graphics card in the added source
ubuntu-drivers devices
- Install the required graphics driver, take nvidia-430 as an example,
sudo apt install nvidia-430
Pay attention to the driver name, which should be consistent with the version required in the above picture
- View graphics card driver information
nvidia-smi
Two, install cuda
1. Download
Go to the cuda toolkit archive to download the required cuda version
- Choose the first runfile (local) method (other methods are also available)
- You can download the installation package by entering the wget command through the terminal
wget https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_418.87.00_linux.run
- You can also copy the link selected in the above picture and download the installation package manually
2. Installation
- Run the download and hit the .run file to install
sudo sh cuda_10.1.243_418.87.00_linux.run
Select continue to continue
Enter accept below to continue
Remove the X in front of Driver, Don’t install Driver, because it’s installed before and, choose install to start installation
3. Add environment variables
- Open .banshrc file
sudo gedit ~/.bashrc
- Add the following three lines at the end of the opened document,The last line is modified to its own version of cuda
export CUDA_HOME=/usr/local/cuda
export PATH=$PATH:$CUDA_HOME/bin
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- Save the file and exit, terminal input
source ~/.bashrc
4. Test whether the installation is successful
- There are two ways to view the cuda version,Pay attention to spaces and uppercase V
nvcc -V
cat /usr/local/cuda/version.txt
Show successful installation of cuda10.1.243
- You can also use the following method to test
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
Three, install cudnn
1. Install via cuDNN Library for Linux
- Download the required cudnn on the cudnn official website ,Registration required
Choose cuDNN Library for Linux (x86) - Unzip the downloaded file,Downloaded file name
tar -xzvf cudnn-10.1-linux-x64-v8.0.5.39.tgz
- Copy files
sudo cp -r cuda/include/ /usr/local/cuda/include/
sudo cp -r cuda/lib64/ /usr/local/cuda/lib64/
- Grant permissions
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
- View cudnn version
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
or
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
Depending on the version of cudnn, the commands used are different, refer to the link