ubuntu20 configure cuda environment

1. Download the driver
1. Use the following command to find the driver your computer needs.

ubuntu-drivers devices

2. The above command may also return empty and nothing will be displayed. Add the source of the official ppa and just update the following.

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

3. Install the graphics card with the specified version, the
installation fails, and the corresponding version of the graphics card is not found. I can only try other methods.
4. Let it automatically install the graphics card

sudo ubuntu-drivers autoinstall

5. After the installation is complete, the graphics card model cannot be found through nvdia-smi. Restart it and check that there is nvdia-455 graphics card in Settings->Software Update->Additional Drivers. I installed it by default and continue to configure the following environment.
6. After installing the driver, you must downgrade the gcc g++ version, otherwise it is easy to fail the cuda installation.
7. This is also an installation tutorial, there are many pictures, you can refer to it.

2. Download cuda and install cuda
1. How to make sure that the graphics card model of your computer matches the cuda version. You can check it yourself on the cuda official website, and all the online ones are updated according to the above.

From the picture above, you can see that the corresponding cuda can be installed as long as the above version of the graphics card version does not have to be the same. My graphics card model is 455, and cuda 11.1 can be installed, but I installed 10.2.
2. The link I downloaded is cuda10.2 

It can be seen from the above figure that we downloaded the ubuntu18 version of cuda, and then we need to install it on ubuntu20. Although the version does not correspond to it, it is ok. I think maybe the version difference is not particularly big, it should be adaptable or upward compatible. I didn't try so I just guessed.
Downloading using wget was interrupted, so I started the Thunder download speed lever.
Three, download cudnn install cudnn
1. execute the command
 

sudo sh cuda_10.2.89_440.33.01_linux.run

Then cuda is installed successfully. The next step is to configure the environment variables of cuda.
1. First you need to open the file through gedit ~/.bashrc

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

2. Write the above file into it and save it. Of course you need to source ~/.bashrc to activate your newly added environment. If the activation is successful, continue to the next step. If it fails, see if your path is wrong. Use which or whereis to find it. Eliminate errors.
3. Judge whether cuda is installed successfully through nvcc -V, if the version information is returned, it is successful.
4.export PATH=$PATH:/usr/local/cuda-10.2/bin This command means to add an environment variable /usr/local/cuda-10.2/bin based on the original PATH environment variable. For details, please refer to the following link Environment Variable Principle
5. After installing cuda, consider how to install cudnn. This thing needs to match your cuda version. I downloaded the deb version directly. And you need to have an nvdia account to be able to download.
Install through the following three commands.
 

sudo dpkg -i libcudnn8_8.0.0.180-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn8-dev_8.0.0.180-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn8-doc_8.0.0.180-1+cuda10.2_amd64.deb

Use the following command to test whether your cudnn is installed successfully.

# 将cuDNN示例复制到可写路径
cp -r /usr/src/cudnn_samples_v8/ $HOME
# 进入到可写路径
cd  $HOME/cudnn_samples_v8/mnistCUDNN
# 编译mnistCUDNN示例
make clean && make
# 运行mnistCUDNN示例
./mnistCUDNN

The first sentence of the above command means to copy the file cudnn_samples_v8 to /home/username. Why should this be done? Only by moving to this file, your cudnn_samples_v8 can be read and written at will. In src, the read and write execution may be restricted. . Then enter the corresponding file to compile, if the gcc version is wrong, the compilation will fail.
Here my gcc version is 8 and the compilation failed. I passed apt install gcc-7 g++7. Then set up the soft link to gcc and g++ and then compile it successfully. The setting of the soft connection
fails after the setting is completed by the following command
 

sudo ln -s gcc-7.8 gcc
sudo ln -s g++-7.8 g++

So I found the following:

sudo ln -s /usr/bin/gcc-7.8 /usr/bin/gcc
sudo ln -s /usr/bin/gcc-7.8 /usr/bin/gcc

The compilation is successful, so there are pitfalls in setting up the soft link.
The last execution command, if you compile successfully and cuda and cudnn are okay, you will be successful. If there is a problem, quickly troubleshoot where the problem is.

V. Configure torch
1. Go to the pytorch official website and choose the corresponding version of torch. Downloading the network through pip is too unstable, so I used Thunder again. Go to the torch version to find the corresponding torch version to download. After the download is successful, pass pip *.whl. You can install it.
Six, test torch
 

import torch
torch.cuda.is_available()

 

Guess you like

Origin blog.csdn.net/nyist_yangguang/article/details/114950033