Preparation before installation
The main purpose of CUDA is deep learning, and the current mainstream deep learning framework Tensorflow2 supports up to CUDA 10.1, so this article explains the main process of installing CUDA 10.1 on the Ubuntu 20.04 system.
First, check if your NVIDIA graphics driver supports cuda10.1 version.
Execute the following commands in the terminal:
nvidia-smi
If CUDA Version:… The version number here is greater than or equal to 10.1 (mine is 10.2), you can install cuda10.1.
Key point: gcc downgrade
Because the gcc version that comes with Ubuntu20.04 is 9.3, and cuda10.1 does not support gcc-9, you need to install gcc-7 manually. The command is as follows:
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-79
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-91
This command can set the priority of each version of gcc through update-alternatives, the highest priority is the system default version, and the priority can be displayed with the following command:
sudo update-alternatives --display gcc
The same goes for setting the default g++:
sudo update-alternatives --install /usr/bin/g++ g++/usr/bin/g++-79
sudo update-alternatives --install /usr/bin/g++ g++/usr/bin/g++-91
Display g++ priority:
sudo update-alternatives --display g++
Follow the installation steps on the official website to download and install CUDA 10.1
CUDA Toolkit 10.1 update2 Archive
As shown in the figure above, it is recommended to choose the run file to install, which is more concise.
Move to the Install option, press Enter, and wait for the installation to complete.
Configure executable file and library path
After the installation is complete, you need to configure the environment for CUDA 10.1.
First open the .bashrc file in the home directory: gedit ~/.bashrc
Add the following at the end of the file:
export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Save and close the file to complete the configuration.
Update environment: source ~/.bashrc
Install cuDNN
Download cuDNN
Download cuDNN
After opening the link, the website will ask you to log in. If you do not have an NVIDIA account, log in after registering.
Select the version (7.6.5) corresponding to CUDA 10.1, click to open, select cuDNN Library for Linux, and click to download. (It is better to choose the file format of cuDNN Library for Linux for easier installation)
Install cuDNN
Switch to the directory where the downloaded file is located, and decompress the downloaded cuDNN compressed file to the current directory:
tar zxvf ./cudnn-10.1-linux-x64-v7.6.5.32.tgz -C ./
Will unzip
Copy the cuda/include/cudnn.h file to the /usr/local/cuda/include folder
Copy all files under cuda/lib64/ to the /usr/local/cuda/lib64 folder
Add read and execute permissions for the above files:
sudo chmod 755/usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
Installed
Reference article:
Ubuntu 20.04 CUDA&cuDNN installation method
Ubuntu: install cuda10.1 driver
Recommended Posts