Ubuntu 20.04 安装NVIDIA+CUDA+CuDnn

如果之前安装过其他版本的驱动,需要先去除

# removing ALL nvidia software
$ sudo apt-get purge nvidia* 

# Checking what's left:
$ dpkg -l | grep nvidia
# Then I deleted the ones that showed up (mostly libnvidia-* but also xserver-xorg-video-nvidia-xxx`)
$ sudo apt-get purge libnvidia* xserver-xorg-video-nvidia-440 
$ sudo apt autoremove # clean it up

安装新驱动

# now reinstall everything including nvidia-common
$ sudo apt-get install nvidia-common

# find the right driver again
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ ubuntu-drivers devices
$ sudo apt-get install nvidia-driver-440 # the recommended one by ubuntu-drivers
$ update-initramfs -u # needed to do this so rebooting wouldn't lose configuration I think

$ sudo reboot 

重启之后检测:

nvidia-smi

安装Cuda

首先获取密钥

sudo apt-key del 7fa2af80

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin

sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600

我们安装的是CUDA Toolkit 11.6.2

export XX=11
export Y=6
export Z=2

下载debian文件

wget https://developer.download.nvidia.com/compute/cuda/${XX}.${Y}.${Z}/
local_installers/cuda-repo-wsl-ubuntu-${XX}-${Y}-local_${XX}.${Y}.${Z}-1_amd64.deb

更改配置使之可以被安装

sudo dpkg -i cuda-repo-wsl-ubuntu-${XX}-${Y}-local_${XX}.${Y}.${Z}-1_amd64.deb

安装CUDA

sudo apt update
sudo apt install cuda=${XX}.${Y}.${Z}-1 -y

export PATH=/usr/local/cuda/bin:${PATH}
source ~/.bashrc

nvcc --version

cuDNN

export CUDA_VERSION=11.6

从CUDA Deep Neural Network (cuDNN) | NVIDIA Developer 官网下载cuDNN

配置文件使之可被安装

sudo dpkg -i cudnn-local-repo-ubuntu2004-*_1.0-1_amd64.deb

安装cuDNN

sudo apt install libcudnn8=*-1+cuda${CUDA_VERSION}
sudo apt-get install libcudnn8-dev=*-1+cuda${CUDA_VERSION}
sudo apt-get install libcudnn8-samples=*-1+cuda${CUDA_VERSION}

验证安装

cp /usr/src/cudnn_samples_v8/ $HOME -rfv
cd ~/cudnn_samples_v8/conv_sample
make clean
make -sj
./conv_sample

你可能感兴趣的:(小白也会玩,ubuntu,linux,运维)