Install CUDA&&cudnn on Ubuntu20.04 (detailed graphic tutorial for beginners)

Preparation

Note: The local system is Ubuntu20.04

1. Install the graphics card driver
Open 'Software and Updates, click Additional Drivers to install the graphics card driver.
insert image description here
2. gcc installation
If the system is Ubuntu22.04, it needs to be installed.
Enter the command in the terminal to see if there is gcc.

gcc --version

insert image description here
3. gcc installation
The native version of ubuntu20.04 gcc is 9.4.0
insert image description here
to install gcc-7, command:

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

After installing gcc-7, there are two versions of gcc in the system, so to set the default gcc, the command is as follows:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 1

This command can set the priority of each version of gcc through update-alternatives. The highest priority is the system default version. You can use the following command to display its priority:

sudo update-alternatives --display gcc

insert image description here

CUDA installation

Install CUDA 11.7, select runfile(local), and use the generated instructions to download and install.
insert image description here
Select the corresponding version, and then you can install the command below:

woet httos://developer.donnload,nvidia.com/compute/cuda/11,7.0/local installers/cuda 11,7.0 515,43.04 linux.rurs 
sudo sh cuda 11.7.0 51543.04 linux.run

Execute the above generation command in the terminal, as shown in the figure below.
insert image description here
If step 1 prompts Existing package manager installation of the driver found. It is strongly recommended that you remove this before continuing., select continue , remove the driver item in the next step , and then select install :
insert image description here
After the installation is complete, the display is as follows:
insert image description here
in ~/ Add the following environment variables to the .bashrc file:

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}}

If other versions have been installed before, delete the previous environment variables and import the environment variables of this installation.
Note: For vim operation, enter i to insert and then esc to enter: wq to save
View vim instructions and click: link .
insert image description here
Use the following command to update the system environment variables

source ~/.bashrc
sudo ldconfig

At this point, the cuda installation is complete, enter the nvcc -V command to view the cuda information

nvcc -V

insert image description here

cudnn installation

Download link: https://developer.nvidia.com/rdp/cudnn-download
insert image description here Note: The red box version in the picture

Change the permissions of the include and lib64 folders under the usr/local/cuda/ folder.
Commonly used commands to modify permissions

sudo chmod 600 ××× (只有所有者有读和写的权限)
sudo chmod 644 ××× (所有者有读和写的权限,组用户只有读的权限)
sudo chmod 700 ××× (只有所有者有读和写以及执行的权限)
sudo chmod 666 ××× (每个人都有读和写的权限)
sudo chmod 777 ××× (每个人都有读和写以及执行的权限)

Execute the command to modify the permissions of the folder:

cd /usr/local/cuda
sudo chmod 666 include
sudo chmod 666 lib64

insert image description here

Then extract the cudnn-linux-x86_64-8.6.0.163_cuda11-archive.tar.xz file. After waiting for the decompression to complete, right-click in the download folder to open the terminal. Execute the following command:

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*

See NVIDIA official installation guide 1.3.1 ( Installation Guide : Step-by-step instructions for installation and upgrade)
insert image description here
to verify whether the installation is successful, execute the command:

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

insert image description here
At this point cudnn is also installed.

Guess you like

Origin blog.csdn.net/weixin_45080292/article/details/129338338