Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vitorcalvi/39c72a6f7d74a55d01f2b0df0bdfcfb4 to your computer and use it in GitHub Desktop.
Save vitorcalvi/39c72a6f7d74a55d01f2b0df0bdfcfb4 to your computer and use it in GitHub Desktop.
Instructions for CUDA v11.8 and cuDNN 8.7 installation on Ubuntu 22.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
###
# Function to print messages
print_message() {
echo -e "\n"
echo "###############################################"
echo "# \$1"
echo "###############################################"
echo -e "\n"
}
print_message "Verifying if the system has a CUDA-capable GPU"
lspci | grep -i nvidia
print_message "Removing previous NVIDIA installations"
sudo apt purge -y nvidia*
sudo apt remove -y nvidia-*
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt autoremove -y && sudo apt autoclean -y
sudo rm -rf /usr/local/cuda*
print_message "Updating the system"
sudo apt update && sudo apt upgrade -y
print_message "Installing essential packages"
sudo apt install -y g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
print_message "Adding PPA repository for graphics drivers"
sudo add-apt-repository -y ppa:graphics-drivers/ppa
sudo apt update
print_message "Finding recommended driver versions"
ubuntu-drivers devices
print_message "Installing NVIDIA driver with dependencies"
sudo apt install -y nvidia-driver-535 nvidia-kernel-source-535
print_message "Reboot the system to load the new NVIDIA driver"
sudo reboot now
# After reboot, continue the installation
print_message "Verifying NVIDIA driver installation"
nvidia-smi
print_message "Downloading and setting up CUDA repository"
sudo wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"
print_message "Updating the system again"
sudo apt update && sudo apt upgrade -y
print_message "Installing CUDA 11.8"
sudo apt install -y cuda-11-8
print_message "Setting up environment variables for CUDA"
echo 'export PATH=/usr/local/cuda-11.8/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
print_message "Downloading and installing cuDNN v8.7.0 for CUDA 11.8"
CUDNN_TAR_FILE="cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz"
wget https://developer.download.nvidia.com/compute/redist/cudnn/v8.7.0/local_installers/11.8/${CUDNN_TAR_FILE}
tar -xvf ${CUDNN_TAR_FILE}
sudo cp -P cudnn-linux-x86_64-8.7.0.84_cuda11-archive/include/cudnn*.h /usr/local/cuda-11.8/include
sudo cp -P cudnn-linux-x86_64-8.7.0.84_cuda11-archive/lib/libcudnn* /usr/local/cuda-11.8/lib64/
sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn*
print_message "Installing NVIDIA CUDA Toolkit"
sudo apt install -y nvidia-cuda-toolkit
print_message "Verifying the installation"
nvidia-smi
nvcc -V
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
print_message "Setting up NVIDIA Docker repository and installing NVIDIA Docker"
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
print_message "Updating the system again"
sudo apt-get update
print_message "Installing NVIDIA Docker"
sudo apt-get install -y nvidia-docker2
print_message "Restarting Docker"
sudo systemctl restart docker
@vitorcalvi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment