Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vejvarm/0283c1bb8d913e82b24daba4de3f4c6a to your computer and use it in GitHub Desktop.
Save vejvarm/0283c1bb8d913e82b24daba4de3f4c6a to your computer and use it in GitHub Desktop.
Instructions for CUDA v12.2 and cuDNN 8.7 installation on Ubuntu 20.04 for PyTorch 2.0.0
#!/bin/bash
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
###
### to verify your gpu is cuda enable check
lspci | grep -i nvidia
### If you have previous installation remove it first.
#### alternative 1
sudo apt purge nvidia* -y
sudo apt remove nvidia-* -y
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt autoremove -y && sudo apt autoclean -y
sudo rm -rf /usr/local/cuda*
#### alternative 2 (if installed via runfile):
sudo /usr/local/cuda-11.8/bin/cuda-uninstaller
# system update
sudo apt update && sudo apt upgrade -y
# install other import packages
sudo apt install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
# first get the PPA repository driver
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
# find recommended driver versions for you
ubuntu-drivers devices
# install nvidia driver with dependencies
sudo apt install libnvidia-common-535 libnvidia-gl-535 nvidia-driver-535 -y
# reboot
sudo reboot now
# verify that the following command works
nvidia-smi
# download and prepare the cuda repository
(follow this page: https://developer.nvidia.com/cuda-12-2-2-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=runfile_local)
## install using runfile:
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run
sudo sh cuda_12.2.2_535.104.05_linux.run
# setup your paths
echo 'export PATH="/usr/local/cuda-12.2/bin${PATH:+:${PATH}}"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
# install cuDNN v 9.0.0
# First register here: https://developer.nvidia.com/developer-program/signup
wget https://developer.download.nvidia.com/compute/cudnn/9.0.0/local_installers/cudnn-local-repo-ubuntu2004-9.0.0_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2004-9.0.0_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-ubuntu2004-9.0.0/cudnn-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cudnn-cuda-12
## legacy (manual cudnn installation)
CUDNN_TAR_FILE="cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz"
sudo wget https://developer.download.nvidia.com/compute/redist/cudnn/v8.7.0/local_installers/11.8/cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz
sudo tar -xvf ${CUDNN_TAR_FILE}
sudo mv cudnn-linux-x86_64-8.7.0.84_cuda11-archive cuda
### copy the following files into the cuda toolkit directory.
sudo cp -P cuda/include/cudnn.h /usr/local/cuda-11.8/include
sudo cp -P cuda/lib/libcudnn* /usr/local/cuda-11.8/lib64/
sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn*
# Finally, to verify the installation, check
nvidia-smi
nvcc -V
cat /usr/include/x86_64-linux-gnu/cudnn_version_v9.h
# install Pytorch (an open source machine learning framework)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment