Setting Up CUDA and cuDNN on Ubuntu 20.04

Nvidia
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Setting Up CUDA and cuDNN on Ubuntu 20.04 with NVIDIA 535 Driver


Hello there, fellow tech enthusiasts! If you’re a machine learning or data science professional, you’re likely familiar with CUDA and cuDNN, two vital software libraries from NVIDIA. They supercharge computing by harnessing the power of NVIDIA graphics processing units (GPUs). Today, we will walk through the process of setting up CUDA and cuDNN on an Ubuntu 20.04 system. In our case, we are using the NVIDIA 535 driver, which we installed from the Software & Updates Center in Ubuntu.

Before we dive in, let’s understand a bit about these libraries. CUDA, or Compute Unified Device Architecture, is a parallel computing platform and API that allows software developers to use a CUDA-enabled GPU for general-purpose computing. CuDNN, on the other hand, stands for CUDA Deep Neural Network Library. It’s a GPU-accelerated library for deep neural networks that provides highly optimized primitive functions, such as activation functions and forward and backward convolutional operations.

Without further ado, let’s delve into the setup process. Remind yourself that we use the Linux distribution Ubuntu here.

Step 1: System Update

First and foremost, ensure your system is up-to-date by running the following commands:

sudo apt update
sudo apt upgrade -y


Step 2: Verify NVIDIA Driver Installation

As we’re using the NVIDIA 535 driver, it should already be installed. However, you can verify this by running the command nvidia-smi in the terminal. This will display the installed NVIDIA driver version along with other GPU details.

Step 3: Download and Install CUDA Toolkit

We are installing CUDA version 11.8.0. You can download it from the NVIDIA developer website using the wget command. After downloading, we install the toolkit with superuser privileges.

wget  https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run --toolkit --silent --override


The –toolkit flag is used to install the CUDA Toolkit, and the –silent –override is for non-interactive installation.

Step 4: Configure Environment Variables

After installing CUDA, you must set up the environment variables. Add the following lines to the end of your ~/.bashrc file:

export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}


Now update your ~/.bashrc file to reflect the changes.

source ~/.bashrc


Step 5: Verify CUDA Installation

You can verify your CUDA installation by running the nvcc -V command. It should display the CUDA Compiler (nvcc) version.

Step 6: Download and Install cuDNN

We’re installing CuDNN version 8.6.0. You can download it from the NVIDIA developer website, just like CUDA from this link. You must log in before trying to download.

sudo dpkg -i cudnn-local-repo-ubuntu2004-8.6.0.163_1.0-1_amd64.deb
sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/


Here, dpkg installs the downloaded package, and the cp command copies the GPG key to the appropriate directory.

Step 7: Update the APT Repository

Update your APT repository before installing the cuDNN packages.

sudo apt-get update


Step 8: Install cuDNN Libraries

We’ll now install the cuDNN runtime library, the developer library, and the code samples library.

sudo apt-get install libcudnn8=8.6.0.163-1+cuda11.8
sudo apt-get install libcudnn8-dev=8.6.0.163-1+cuda11.8
sudo apt-get install libcudnn8-samples=8.6.0.163-1+cuda11.8


Step 9: Verify cuDNN Installation

You can verify the cuDNN installation by compiling and running the cuDNN sample code, located in the usr/src/cudnn_samples_v8 directory.

That’s it! You’ve successfully installed CUDA and cuDNN on your Ubuntu 20.04 system. This setup allows you to leverage the power of your NVIDIA GPU to accelerate machine learning and other computational workloads. Enjoy your enhanced computing capabilities!

This git repository may be useful to you. You can find all the installation scripts here: cuda-cudnn-install-automation-script, and the official guidelines from NVIDIA are here: Installation Guide

Share The Blog With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Leave a Reply

Your email address will not be published. Required fields are marked *

Advanced topics are covered in our ebooks with many examples.

Recent Posts

pexels-abet-llacer-919734
What is Linux and what does it do?