Ubuntu 18.04 installing Anaconda, CUDA, cudnn, PyTorch(GPU)

Anaconda3 + CUDA + cudnn + PyTorch(GPU) installation record under Ubuntu 18.04 (non virtual machine) 1. Anaconda3 instal...
2.1 uninstall NVIDIA graphics card driver
2.2 disable the built-in nouveau drive
2.3 reinstall NVIDIA driver
  2.4 CUDA installation

Anaconda3 + CUDA + cudnn + PyTorch(GPU) installation record under Ubuntu 18.04 (non virtual machine)

1. Anaconda3 installation

Official website download address: https://developer.nvidia.com/cuda-toolkit-archive.

Download address of open source software mirror station of Tsinghua University: Index of /anaconda/archive / | Tsinghua University open source mirror | Tsinghua Open Source Mirror

sh Anaconda3-2019.10-Linux-x86_64.sh
2. Installing cuda

Before installation, you'd better uninstall the NVIDIA graphics card driver, disable the Ubuntu built-in driver, and then manually install the NVIDIA graphics card driver, not because it's the best, but because it's successful.

2.1 uninstall NVIDIA graphics card driver

You can try any of the following. Just uninstall it

sudo apt-get purge --remove nvidia* sudo ./usr/bin/nvidia-uninstall sudo apt-get install autoremove --purge nvidia*

If you have CUDA before, you'd better uninstall it

sudo ./usr/local/cuda-11.4/bin/cuda-uninstaller

2.2 disable the built-in nouveau drive

sudo gedit /etc/modprobe.d/blacklist_nouveau.conf

Restart the computer and run

lsmod | grep nouveau

, if there's nothing, it means OK.

2.3 reinstall NVIDIA driver

Terminal input

ubuntu-drivers devices

Check the recommended version of the system. Mine is 470. (there is one recommended)


Then directly execute the terminal

sudo apt-get install nvidia-driver-470-server

That's right. Different devices have different driver versions installed. Please be optimistic. My own desktop is 470.
Finally, test the terminal input

nvidia-smi

, you can see that my graphics card driver is 470.57.02, and the recommended CUDA version is 11.4.

  2.4 CUDA installation

Go directly to the official website, CUDA Toolkit 11.5 Downloads | NVIDIA Developer , find your corresponding version and you'll be OK. Then download a run file, and then directly execute sudo sh xxxxx.run on the terminal. If the driver has been installed before, the new version of CUDA may prompt something like "your computer has installed a version of graphics card driver, you choose to uninstall or continue first", and then choose to continue. Then an option will pop up below, asking us which module s we need, the first of which is driver. Just don't select this.

  Enter the directory of the run file, open the terminal, and execute

sudo sh xxx.run

Check whether the graphics card driver is installed

nvidia-smi

  If the graphics card driver is not installed, it does not need to be installed separately. Check the graphics card driver during CUDA installation (it is selected by default)

  If the graphics card driver has been installed, do not check the graphics card driver during CUDA installation

Configure environment variables sudo gedit ~/.bashrc export PATH=$PATH:/usr/local/cuda-11.4/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.4/lib64 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-11.4/lib64 Update environment variables >>> source ~/.bashrc see cuda Is the installation successful nvcc -V If the output content is similar to that below OK. nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Sun_Aug_15_21:14:11_PDT_2021 Cuda compilation tools, release 11.4, V11.4.120 Build cuda_11.4.r11.4/compiler.30300941_0

Test 2

Compile and run sample, and enter the installation directory: / usr/local/cuda-11.4/samples/0_Simple/vectorAdd. This is just one example. We can select any one and execute it

sudo make

, then run

./vectorAdd

.
A lot of things will be output in the terminal. If the last line is like Pass and Test Pass, it is successful.

3. Install cudnn

cudnn corresponding to CUDA version can be found on the official website, https://developer.nvidia.com/rdp/cudnn-download.

cuda11.4 corresponds to cudnn v8.22

Bypass the registration, copy the link and download with Xunlei

4. Install pytorch

2 November 2021, 03:44 | Views: 9664

Add new comment

For adding a comment, please log in
or create account

0 comments