20. Ubuntu22.04 + RTX2080 configuration graphics driver + CUDA + cuDNN

Twenty, Ubuntu22.04 + RTX2080 configuration graphics driver + CUDA + cuDNN

    • 1. According to the NVIDIA graphics card model, download the corresponding graphics card driver
    • 2. According to the graphics card driver, download the corresponding CUDA
    • 3. According to the CUDA version, download the corresponding cuDNN library

1. According to the NVIDIA graphics card model, download the corresponding graphics card driver

  • First determine your graphics card model
lspci | grep -i vga

You can see that the graphics card model is GeForce RTX 2080

  • Then go to NVIDIA official website to download the corresponding graphics card driver

Graphics card driver download address

Then put the downloaded driver into an English folder (otherwise the Chinese characters may be garbled when entering the non-graphical interface). For example, I created a new driver here.

  • Install required dependencies
sudo apt-get update
sudo apt-get install g++
sudo apt-get install gcc
sudo apt-get install make
  • Uninstall the original NVIDIA driver
sudo apt-get remove --purge nvidia*
  • Disable nouveau (nouveau is a universal driver)
sudo gedit /etc/modprobe.d/blacklist.conf

Add the following two lines at the end of blacklist.conf and close the text after saving

blacklist nouveau

options nouveau modeset=0

Enter the following update in the terminal and restart the computer after the update is completed (required)

sudo update-initramfs -u

After restarting, enter the following command. If there is no output, nouveau has been closed.

lsmod | grep nouveau
  • Turn off Secure Boot

Restart and press F2 to enter your computer’s BIOS settings.

Close Secure Boot, clear the secure boot key, save and exit and restart

  • The installation process needs to be carried out in a non-graphical interface. Enter the following command to enter the non-graphical interface.
#Enter the text interface
sudo telinit 3

# If you need to return to the graphical interface, use this command
sudo telinit 5
  • Enter username and password
  • Turn off display service
sudo service gdm3 stop
  • Give permissions to the driver and run the installation
cd /home/yao/driver/NVIDIA-Linux-x86_64-535.113.01.run

sudo chmod 777 NVIDIA-Linux-x86_64-535.113.01.run

#Installation: –no-opengl-files only installs driver files, not OpenGL files
sudo ./NVIDIA-Linux-x86_64-535.113.01.run --no-opengl-files

There are some options during installation

  1. Select continue installation
  2. Install Nvidia’s 32-bit compatibility libraries? Select No
  3. Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? Select No
  4. Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. Select No There may be problems if you select yes
  • After installation is complete, restart the display service
sudo service gdm3 start
  • After the driver installation is complete, check
nvidia-smi

You can see that the graphics card driver version is 535.113.01
The highest supported CUDA version is 12.2

  • Bring up the NVIDIA settings interface, indicating that there is no problem
nvidia-settings

2. Download the corresponding CUDA according to the graphics card driver

  • CUDA is a parallel computing platform and application programming interface (API) developed by NVIDIA

CUDA is a low-level platform that provides direct access and control of the GPU. Developers can use CUDA to write GPU kernel functions and call these kernel functions on the host (CPU) to implement parallel computing. CUDA improves a set of APIs to manage GPU memory, thread scheduling, data transfer and other operations, allowing developers to more conveniently utilize the GPU’s parallel computing capabilities.

  • CUDA needs to correspond to the graphics card driver you installed above

Adaptation relationship between graphics card driver and CUDA

The graphics card driver I installed: NVIDIA-Linux-x86_64-535.113.01.run
The highest supported CUDA version is 12.2
However, I am going to install CUDA 11.7 here, because this version is basically installed on the Internet.

  • Install CUDA

CUDA download

Choose your own operating system, chip architecture, Linux distribution, and installation method

The official website provides installation instructions
I am using the deb(local) method to install it here! ! ! Note: Never install in this way! ! ! I keep it here to avoid pitfalls! ! !
If after installing it like this, the extended screen will not be recognized after restarting, I guess it uninstalled the graphics card driver I installed before.
I solved it later by reinstalling the graphics card driver as above! ! !

I have created a new CUDA folder here and run these instructions in this directory

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda-repo-ubuntu2204-11-7-local_11.7.0-515.43.04-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-11-7-local_11.7.0-515.43.04-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-11-7-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda

An error will be reported in the last step, because this method of installation will automatically install the graphics card driver, which is not the same version as the graphics card driver we installed before! !
If we have requirements for the graphics card version, it is recommended not to install it this way.

Now switch to the runfile(loacl) installation method, and no error will be reported.

wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run
sudo sh cuda_11.7.0_515.43.04_linux.run

Select Continue

Enter accept

Select what needs to be installed ([X] means to install, [ ] means not to install)
Press Spacebar to cancel the driver installation because it has been installed before.
Then select install

This means the installation is successful

  • Configure environment variables
sudo gedit ~/.bashrc

Add the CUDA environment variables to the end

export PATH=/usr/local/cuda-11.7/bin${<!-- -->PATH: + :${<!-- -->PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64${LD_LIBRARY_PATH: + :${LD_LIBRARY_PATH}}


Save and close file
Reload the current user’s bash configuration file ~/.bashrc
View the version information of the CUDA compiler (nvcc)

source ~/.bashrc
nvcc -V

3. According to the CUDA version, download the corresponding cuDNN library

  • cuDNN is an acceleration library developed by NVIDIA specifically for deep learning tasks.

cuDNN provides a series of high-performance implementations of basic deep learning operations, such as convolution, pooling, normalization, etc. cuDNN is based on CUDA, which takes advantage of the parallel computing capabilities and related APIs provided by CUDA. By using cuDNN, developers can build and train deep learning models more easily and achieve better performance on GPUs. cuDNN has become a widely used library in the field of deep learning, and many deep learning frameworks (such as TensorFlow, PyTorch) have integrated support for cuDNN to obtain higher computing performance.

  • cuDNN needs to correspond to the CUDA version installed above

cuDNN is just a plug-and-play library. You don’t need to worry about accidentally installing it wrong, because you just place the library file in the cuda directory.
If the wrong version is installed, just delete and install the new version.
There are more cuDNN versions corresponding to CUDA 11.7. The one I installed here is cuDNN 8.6.0

  • Install cuDNN

Downloading from the official website requires registering an account

cuDNN Download


Unzip the cuDNN file

tar -xvf cudnn-linux-x86_64-8.6.0.163_cuda11-archive.tar.xz

Copy the following files to the CUDA directory (include and lib64 under the /usr/local/cuda/ folder)

cd /home/yao/cuDNN
sudo cp cudnn-*-archive/include/cudnn*.h /usr/local/cuda/include
sudo cp cudnn-*-archive/lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a + r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

Verify successful installation

sudo cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

This means it’s installed

Installing cuDNN is essentially simple, just move the files in the include and lib you downloaded to the directory corresponding to CUDA.