Detailed steps of installing CUDA and cudnn on Ubuntu 22.04

In the Ubuntu system, you can use nvidia-smithe command to see the current GPU information, and you can see the CUDA Version in the upper right corner, which means the maximum supported CUDA version number.
In the previous article , the graphics card driver has been installed. This time, continue to install CUDA and cudnn.
insert image description here
To be installed:
cuda 11.7
cuDNN v8.9.0 (for CUDA 11.x)

Install CUDA

Open the official website: https://developer.nvidia.com/cuda-toolkit-archive
Select CUDA 11.7, select "Lunix" and the corresponding architecture, system, version and installation form as shown in the figure below:
insert image description here

Choose the form of runfile (local), and the website will give us the command to install:
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

Enter in the terminal in sequence.

First command:
insert image description here

Second command:
Attention! Since we have installed the driver before, don't install the driver again this time.

Enter accept
insert image description here

Press ENTER to tick off the Driver!
Then select Install
insert image description here

insert image description here

Finally, open the terminal and configure environment variables:

vim ~/.bashrc

Finally add:

export PATH=$PATH:/usr/local/cuda-11.7/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.7/lib64

Enter :wqto exit.
Open a terminal and type:

source ~/.bashrc

Finish!


Finally, enter the terminal nvcc -Vto view the CUDA version:
insert image description here

install cudnn

Download the installation file

Open and log in to https://developer.nvidia.com/rdp/cudnn-download
and choose to download cuDNN v8.9.0 (for CUDA 11.x),
then choose Local Installer for Ubuntu22.04 x86_64 (Deb), and
the download will start. After downloading, it is recommended to move the deb file to the home directory.

insert image description here


Install

Open the Installation Guide above to view the installation method.
Among them we have installed the graphics driver and CUDA.
If the system has not installed the zlib package, you can sudo apt-get install zlib1ginstall it first.

insert image description here

Installation steps:
1. Open the directory where the deb file is stored, right-click to open the terminal, and enter (the name of the deb file is the same as the one you downloaded):
sudo dpkg -i cudnn-local-repo-ubuntu2204-8.9.0.131_1.0-1_amd64.deb

2.Import the CUDA GPG key.
insert image description here

enter:
sudo cp /var/cudnn-local-repo-ubuntu2204-8.9.0.131/cudnn-local-2063C34E-keyring.gpg /usr/share/keyrings/

3. Refresh the library:
sudo apt-get update

4.Install the runtime library.

Note that the pairing of libcudnn8 and cuda version here is specified and can be apt-cache policy libcudnn8viewed through the command.
I should use libcudnn8=8.9.0.131-1+cuda11.8 here

enter:
sudo apt-get install libcudnn8=8.9.0.131-1+cuda11.8

5.Install the developer library.

sudo apt-get install libcudnn8-dev=8.9.0.131-1+cuda11.8

6.Install the code samples and the cuDNN library documentation.

sudo apt-get install libcudnn8-samples=8.9.0.131-1+cuda11.8

Verify that the installation was successful

insert image description here

cp -r /usr/src/cudnn_samples_v8/ $HOME
cd $HOME/cudnn_samples_v8/mnistCUDNN
make clean && make
./mnistCUDNN

Note: If the above make command prompts that FreeImage.h is missing, run:sudo apt-get install libfreeimage3 libfreeimage-dev

success:
insert image description here

Guess you like

Origin blog.csdn.net/takedachia/article/details/130375718