Table of contents
2-3--Download and install CUDA Toolkit
2-4--Configure environment variables
2-5--Test whether the installation is successful:
4--Test whether pytorch can use Cuda
1--Install the Nvidia driver
① View the installable Nvidia driver version:
ubuntu-drivers devices
② Install the corresponding version of Nvidia driver:
The blogger chooses the first one here, and the recommended version can also be installed
sudo apt-get install nvidia-driver-515
During the installation process, it is generally necessary to set a password, which will be used later to restart the system!
③ After the installation is complete, you need to restart the computer:
reboot
After restarting the computer, the following Perform MDK management interface will pop up:
Select the second option Eroll MDK, enter the password set in step ②, you will find that there are only three options left, choose the first boot option to complete the installation of the Nvidia driver;
④ Verify installation:
nvidia-smi
When the above interface appears, the installation is successful!
2--Install CUDA
2-1-- Disable nouveau
① Check the blacklist
sudo gedit /etc/modprobe.d/blacklist.conf
② Add a blacklist at the end of the pop-up text
blacklist nouveau
③ Save and restart
sudo update-initramfs -u
reboot
④ Test whether it is disabled successfully
lsmod | grep nouveau
Disable nouveau with no output Success!
2-2--Select CUDA Toolkit
NVIDIA CUDA driver version download address: https://developer.nvidia.com/cuda-toolkit-archive
Note: Select the appropriate version to install, make sure that the version of CUDA Toolkit is lower than the version of Nvidia driver! (The CUDA Toolkit version of the blogger here is 465.19.01, which is lower than the installed Nvidia driver version 515.86.01, which can be compatible and adapted)
2-3--Download and install CUDA Toolkit
① Install according to the two commands in the 2-2 screenshot (the first command will download CUDA Toolkit, and the second command will install CUDA Toolkit):
wget https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.19.01_linux.run
sudo sh cuda_11.3.1_465.19.01_linux.run
When executing the installation command, you may need to execute the following command first:
sudo chmod +x cuda_11.3.1_465.19.01_linux.run
Then execute the installation command:
sudo sh cuda_11.3.1_465.19.01_linux.run
After accept, don't install the driver, because we have already installed the Nvidia driver before!
2-4--Configure environment variables
sudo gedit ~/.bashrc
Add the following two paths at the end: (Since the blogger installed Cuda11.3, the path is cuda-11.3, which needs to be set according to the actual installation version and path)
export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Update system variables:
source ~/.bashrc
2-5--Test whether the installation is successful:
nvcc -V
3-- Install CUDA CuDNN
CUDA CuDNN download address: https://developer.nvidia.com/rdp/cudnn-archive
① Download the appropriate CUDA CuDNN version: (select the second item x86 64 to download)
② Unzip the installation package:
tar -xzvf cudnn-11.3-linux-x64-v8.2.1.32.tgz
③ Copy the file to the cuda installation directory, and give execution permission:
sudo cp -d cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp -d cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
④ Test whether the installation is successful:
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
Outputting the corresponding version number means the installation is successful!
4-- Test whether pytorch can use Cuda
pytorch download address: https://pytorch.org/
① Download the appropriate version of pytorch (here the blogger chooses the v1.12.0 version based on Cuda11.3);
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch
② Verify the availability of Cuda:
python
import torch
print(torch.cuda.is_available())
When the output is True , it means that pytorch is installed successfully, pytorch can use Cuda to accelerate, Nvidia driver, CUDA Toolkit and CUDA CuDNN are all installed successfully! ! ! !