Ubuntu 20.04 installs the latest version of cuda 11.7 and cudnn

1. Install the graphics card driver

 Refer to another article: Tutorial on installing Nvidia graphics card driver in Ubuntu20.04_ytusdc's blog-CSDN blog

2. Install CUDA

NVIDIA official website (latest version): CUDA Toolkit 12.2 Update 1 Downloads | NVIDIA Developer

CUDA historical version download address: CUDA Toolkit Archive | NVIDIA Developer

Here is the official installation guide given by nvidia (you can refer to it if you encounter problems):

NVIDIA CUDA Installation Guide for Linux

2.1. Select runfile and execute the installation according to the code entered into the terminal as prompted by the official website:

 2.2. Installation process option selection

 gcc, if an error is reported, just install gcc and g++.

sudo apt-get install gcc
sudo apt-get install g++

2.3. Then continue and enter accept.

 2.4. Then continue, select the first driver and press Enter to cancel, because we already have a driver.

2.5. Configure environment variables in .bashrc

Then just install it directly. After waiting for a while, the installation will be completed, and then configure the environment variables in .bashrc.

sudo gedit ~/.bashrc

 Add: to the last line of the opened file:

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

Ok, the cuda configuration is completed. The normal test is to use the script in the sample to test. It may be the latest version of cuda. ​​If there is no sample, just assume that it is installed. Use nvcc -V to test whether there is cuda below.

Then 

source ~/.bashrc

3. Install CUDNN

Download the corresponding version of cudnn.
The latest version download address: Log in | NVIDIA Developer
cudnn historical version:  cuDNN Archive | NVIDIA Developer

Official Installation Guide:  Installation Guide - NVIDIA Docs

Download the cudnn version corresponding to CUDA

 3.1. Download the Deb version and install it.

After downloading, it is a Deb type file and needs to be decompressed.

sudo dpkg -i cudnn*.deb

3.2. There will be a prompt after decompression. Import the CUDA GPG Key according to the prompts.

  Write according to instructions

sudo cp /var/cudnn-local-repo-ubuntu2004-8.5.0.96/cudnn-local-0579404E-keyring.gpg /usr/share/keyrings/

Notice! ! ! Most tutorials on the Internet, including the official website, will let you download 3 packages, but they are actually out. In the latest version, after decompression, these 3 packages are already in /var. You can see these 3 Deb packages in the cudnn package. , just need to decompress in sequence

 3.3. Refresh the repository metadata. (required, otherwise the following commands cannot be used)

sudo apt-get update

3.4、Install the runtime library.

sudo apt-get install libcudnn8=8.x.x.x-1+cudaX.Y

3.5、Install the developer library.

sudo apt-get install libcudnn8-dev=8.x.x.x-1+cudaX.Y

3.6、Install the code samples.

sudo apt-get install libcudnn8-samples=8.x.x.x-1+cudaX.Y

above  X.Y and 8.x.x.x 换成 /var/cudnn-local-repo-ubuntu2004-8.5.0.96 中文件中的相应版本号

4. Test whether the installation is successful

Because the structure of the new version seems to have changed, just follow the steps below

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

If the following results appear, cudnn is fully installed.

 

Errors encountered during testing:

 As shown in the picture above, it is because the corresponding library is indeed installed. Just install the corresponding library and retest.

sudo apt-get install libfreeimage3 libfreeimage-dev

Guess you like

Origin blog.csdn.net/ytusdc/article/details/132404002