Establishing CUDA & cuDNN for Machine Studying could be an awesome course of. On this information, I’ll stroll you thru the steps to put in CUDA and cuDNN in your system, guaranteeing your machine is accurately arrange for machine studying duties.
Whether or not you’re an skilled developer or a newbie on this planet of machine studying, this tutorial will provide help to get began with ease.
System Configuration:
Replace & Improve
Firstly, test for updates in your OS.
sudo apt replace && sudo apt improve
Take away earlier NVIDIA set up
Uninstall the earlier NVIDIA and CUDA set up to keep away from messing up the brand new set up.
sudo apt-get take away --purge -y '*nvidia*' '*cuda*' 'libcudnn*' 'libnccl*' '*cudnn*' '*nccl*'
sudo apt-get autoremove --purge -y
sudo apt-get clear
Examine if there are any remaining packages or recordsdata.
dpkg -l | grep -E 'nvidia|cuda|cudnn|nccl'
Detecting and Managing Drivers on Ubuntu
ubuntu-drivers gadgets
We are going to set up the NVIDIA driver tagged beneficial — Which signifies which drivers are beneficial for each bit of {hardware} primarily based on compatibility and efficiency.
Set up Ubuntu drivers
sudo ubuntu-drivers autoinstall
Set up NVIDIA drivers
My beneficial model is 555, change “XYZ” within the following command to your beneficial driver.
sudo apt set up nvidia-driver-XZY
Reboot the system for these modifications to take impact.
reboot
Examine Set up
After reboot confirm that the next command works:
nvidia-smi
Replace & Improve
Once more, test for updates in your OS.
sudo apt replace && sudo apt improve
Set up CUDA Toolkit
In the meanwhile of scripting this textual content, the most recent CUDA model supported by Pytorch is 12.1.
Yow will discover older variations within the CUDA Toolkit Archive. In my case, I can be persevering with with CUDA Toolkit 12.1.1 (April 2023).
You will want to pick out your working system (Linux in my case). Afterwards, you may be prompted to pick out the Structure. If you’re unsure what’s the Structure of your PC you should utilize the command under (in my case the Structure is x86_64).
uname -m
Subsequent, we have to choose the distribution and model of our working system, in my case Ubuntu 22.04. Lastly, I’m utilizing the deb (native) installer sort.
These are the instructions for putting in CUDA Toolkit 12.1:
wget https://developer.obtain.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /and so on/apt/preferences.d/cuda-repository-pin-600
wget https://developer.obtain.nvidia.com/compute/cuda/12.1.1/local_installers/cuda-repo-ubuntu2204-12-1-local_12.1.1-530.30.02-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-1-local_12.1.1-530.30.02-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get replace
sudo apt-get -y set up cuda-12-1
⚠️ NOTE: The final command differs from the one on the CUDA set up web page. I added “-12–1” to specify the CUDA model to put in.
Examine CUDA set up
nvcc --version