Install CUDA and CUDNN on ubuntu, simple version

1. Preparation

For the installation of the Nvidia driver, please see my other article ubuntu18.04 Three ways to install the Nvidia driver (must read)_Miao Yin Smile-CSDN Blog

Open the terminal and enter

nvidia-smi

The following information comes out:

 If this message comes out, it means the driver is correct. Check the CUDA version displayed by the driver. The installed version should be as close to this as possible. The driver can be backward compatible, that is, a version lower than the CUDA version displayed can be installed. as the picture shows

2. Install CUDA

1. Download the corresponding version from the official website, and you need to consider the nvidia driver: CUDA Toolkit Archive | NVIDIA Developer

2. Download cuda according to the nvidia driver version. Note that there is a wget URL option below. If the wget download is slow, you can open the link to download directly.

 3. Install cuda

Go to the downloaded folder and enter

sudo sh cuda_10.0.130_410.48_linux.run

Note that the new version of cuda installation is a small window. You need to press Enter to choose which one not to install. The old version is through asking questions.

Choose accept for the first option

Except for the option to install the driver, select yes for everything else.

4. Configure environment variables

Enter the following command to open bashrc

sudo vi ~/.bashrc
或者
sudo gedit ~/.bashrc

Add the following content at the bottom. Note that the cuda-10.0 inside needs to be replaced with your own version. You can go to /usr/local/ to take a look.

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

Restart configuration file

source ~/.bashrc

3. Install CUDNN

Log in to cuDNN Archive | NVIDIA Developer , you need to register an account in advance

Find the corresponding cudnn version according to the cuda version, and download the tar package in linux

If you don’t know the cuda version, use nvcc -V to query it. If you can’t find it, it means that there may be a problem with the cuda environment variable. Go back to the previous step

 unzip files

// 注意自己下载文件的路径和名称
tar -xvf cudnn-linux-x86_64-*.tar.xz

Copy the file of cudnn, pay attention to the decompressed name of cudnn

# 进入cudnn的路径
cd cudnn-linux-x86_64-8.8.0.121_cuda11-archive/
# 查看自己的cuda版本,我的是11.4
ls /usr/local
# 复制文件
sudo cp include/cudnn.h /usr/local/cuda-11.4/include
sudo cp lib/libcudnn* /usr/local/cuda-11.4/lib64
sudo chmod a+r /usr/local/cuda-11.4/include/cudnn.h
sudo chmod a+r /usr/local/cuda-11.4/lib64/libcudnn*

Note: cudnn8.0 and above will update the version information to the cudnn_version.h file. You also need to copy this file, otherwise there will be no response during verification.

sudo cp include/cudnn_version.h    /usr/local/cuda-11.4/include/

Verification successful

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

 The above message appears, indicating success.

Guess you like

Origin blog.csdn.net/qq_37424778/article/details/123402661