Skip to content

Instantly share code, notes, and snippets.

@eliazonta
Forked from denguir/cuda_install.md
Last active April 20, 2024 06:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliazonta/e98a470c09655d7f276da258984e3e5a to your computer and use it in GitHub Desktop.
Save eliazonta/e98a470c09655d7f276da258984e3e5a to your computer and use it in GitHub Desktop.
Installation procedure for CUDA & cuDNN

How to install CUDA & cuDNN on Ubuntu 23.10

Install NVIDIA drivers

Update & upgrade

sudo apt update && sudo apt upgrade

Remove previous NVIDIA installation

sudo apt autoremove nvidia* --purge

Check Ubuntu devices

ubuntu-drivers devices

You will install the NVIDIA driver whose version is tagged with recommended

Install Ubuntu drivers

sudo ubuntu-drivers autoinstall

Install NVIDIA drivers

My recommended version is 525, adapt to yours

sudo apt install nvidia-driver-525

Reboot & Check

reboot

after restart verify that the following command works

nvidia-smi

Install CUDA drivers

Update & upgrade

sudo apt update && sudo apt upgrade

Install CUDA toolkit

sudo apt install nvidia-cuda-toolkit

Check CUDA install

nvcc --version

Install cuDNN

Download cuDNN .deb file

You can download cuDNN file here. You will need an Nvidia account. Select the cuDNN version for the appropriate CUDA version, which is the version that appears when you run:

nvcc -V | grep cuda_

Install cuDNN

sudo apt install ./<filename.deb>
sudo cp /var/cudnn-local-repo-ubuntuXXXX.../cudnn-<something>.gpg /usr/share/keyrings/

My cuDNN version is 8, adapt the following to your version:

sudo apt update
sudo apt install libcudnn8
sudo apt install libcudnn8-dev
sudo apt install libcudnn8-samples

Test CUDA on PyTorch

Create a virtualenv and activate it

sudo apt-get install python3-pip
sudo pip3 install virtualenv 
python3 -m venv venv
source venv/bin/activate

Install PyTorch

pip3 install torch torchvision torchaudio

Open Python and execute a test

import torch
print(torch.cuda.is_available()) # should be True

t = torch.rand(10, 10).cuda()
print(t.device) # should be CUDA
@janpfeifer
Copy link

hi @eliazonta , not sure you are maintaining it, but unfortunately this installs nvida-cuda-toolkit 12.0.

Any hints on how to get nvidia-cuda-toolkit 12.3 installed ?

cheers

@eliazonta
Copy link
Author

hi @janpfeifer thanks for reaching out, apologise for the late reply.
You are right, unfortunately I don't have access to a ubuntu machine rn to test it out.

Based on Nvidia docs with
sudo apt-get -y install cuda-toolkit-12-3 you should be able to get it done

let me know if I was able to help

cheers

@janpfeifer
Copy link

I don't think that is available by default in Ubuntu 23.10:

#  apt search cuda-toolkit
Sorting... Done
Full Text Search... Done
cuda-toolkit-11-config-common/now 11.8.89-1 all [installed,local]
  Common config package for CUDA Toolkit 11.

cuda-toolkit-12-3-config-common/now 12.3.52-1 all [residual-config]
  (none)

nvidia-cuda-toolkit/mantic,now 12.0.140~12.0.1-2 amd64 [installed]
  NVIDIA CUDA development toolkit

nvidia-cuda-toolkit-doc/mantic,mantic,now 12.0.1-2 all [installed,automatic]
  NVIDIA CUDA and OpenCL documentation

nvidia-cuda-toolkit-gcc/mantic,now 12.0.1-2 amd64 [installed]
  NVIDIA CUDA development toolkit (GCC compatibility)

Do you have any different source configured under /etc/apt/sources.list.d ?

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