avatarRahul Bhadani

Summary

The website provides a comprehensive guide to installing the CUDA Toolkit 11.3 and cuDNN on Ubuntu 20.04 for machine learning tasks, specifically tailored for systems with an NVIDIA GPU.

Abstract

The article outlines the process of installing the CUDA Toolkit and cuDNN on Ubuntu 20.04, which is crucial for leveraging NVIDIA GPUs for machine learning tasks. It details the necessary steps, including setting up repository preferences, installing the CUDA toolkit via a .deb file, and verifying the installation with system checks. The guide also covers the download and installation of cuDNN libraries, samples, and documentation from NVIDIA's official website, ensuring compatibility with the installed CUDA version. Additionally, it provides troubleshooting tips for common issues such as secure boot conflicts and offers a method to test the successful installation of cuDNN using sample applications.

Opinions

  • The author suggests that installing CUDA and cuDNN can be challenging but is rewarding for the performance gains in machine learning applications.
  • The use of an NVIDIA GPU, when properly set up with CUDA and cuDNN, is presented as a powerful tool for developing fast machine learning applications.
  • The article implies that maintaining an up-to-date NVIDIA developer account is beneficial for accessing the latest software and resources.
  • The author emphasizes the importance of following the provided instructions carefully to ensure a smooth installation process.
  • The inclusion of troubleshooting steps indicates that the author expects some users may encounter common issues and provides guidance to resolve them.
  • The successful installation is validated through practical examples, suggesting the author's commitment to providing a reliable and tested installation method.

Installing cuDNN and CUDA Toolkit on Ubuntu 20.04 for Machine Learning Tasks

Image by the author. Z = Y⁶— X⁶

It is always convoluted and challenging to install a CUDA toolkit and library that needs to interact with your NVIDIA GPU on an Ubuntu machine. However, if done right, the CUDA toolkit with your NVIDIA GPU can be a great tool that can harness the power of GPU to produce fast applications.

Basic Requirements

The basic requirement for following instructions in this article is a computer with Ubuntu 20.04 installed with an NVIDIA GPU. In my case, it was NVIDIA GeForce GTX 1650 Ti.

Further, at the time of writing this article, I installed the latest version of the CUDA toolkit which was CUDA Toolkit 11.3.

The other requirement is the NVIDIA developer account that can be obtained at https://developer.nvidia.com/login free of charge.

CUDA Toolkit Installation

I decided to install a .deb file of the CUDA toolkit following the instruction I reproduced below:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600

wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda-repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.deb

sudo apt-key add /var/cuda-repo-ubuntu2004-11-3-local/7fa2af80.pub
sudo apt-get update

sudo apt-get -y install cuda
export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

A few checks can be performed once the CUDA toolkit is installed:

systemctl status nvidia-persistenced

From its documentation, nvidia-persistenced is intended to be run as a daemon from system initialization and is generally designed as a tool for compute-only platforms where the NVIDIA device is not used to display a graphical user interface. If the daemon is not running, you can start/restart the daemon as follows

sudo systemctl enable nvidia-persistenced

To get the version of the NVIDIA driver, type

cat /proc/driver/nvidia/version

which, in my case, gave output as

NVRM version: NVIDIA UNIX x86_64 Kernel Module  465.19.01  Fri Mar 19 07:44:41 UTC 2021
GCC version:  gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

Now, we move to download cuDNN, a deep-learning library for writing applications for ML task using NVIDIA GPU:

Installing cuDNN

In order to download cuDNN libraries, you need to go to https://developer.nvidia.com/cudnn and click on the Download cuDNN button. The webpage will ask you to login into the NVIDIA developer account. After logging in and accepting their terms and conditions, you should click on the following three links:

cuDNN Runtime Library for Ubuntu20.04 x86_64 (Deb)

cuDNN Developer Library for Ubuntu20.04 x86_64 (Deb)

cuDNN Code Samples and User Guide for Ubuntu20.04 x86_64 (Deb)

which is relevant to Ubuntu 20.04 LTS. After downloading, you should have the following three .deb files:

  1. libcudnn8-samples_8.2.0.53–1+cuda11.3_amd64.deb
  2. libcudnn8-dev_8.2.0.53–1+cuda11.3_amd64.deb
  3. libcudnn8_8.2.0.53–1+cuda11.3_amd64.deb

that you can install using dpkg commands:

sudo dpkg -i  libcudnn8_8.2.0.53-1+cuda11.3_amd64.deb
sudo dpkg -i libcudnn8-dev_8.2.0.53-1+cuda11.3_amd64.deb
sudo dpkg -i libcudnn8-samples_8.2.0.53-1+cuda11.3_amd64.deb

Next, you should type the following to see if your cuDNN communicates with the NVIDIA driver:

nvidia-smi

If you get an error and a message saying unable to communicate, you probably have secure boot enabled that can be turned off by typing:

sudo mokutil --disable-validation

Typing the above command will ask you to enter a password. Reboot. Then enter the password. And note down the password. Usually, the system will ask you to enter specific letters of your password. Once you successfully verify your password, the secure boot will be disabled. Now, reboot your computer and in the terminal, type as follows

nvidia-smi

and you should see the following output:

Fri Apr 30 21:19:53 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.19.01    Driver Version: 465.19.01    CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   41C    P8     3W /  N/A |    825MiB /  3914MiB |      7%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                            
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1084      G   /usr/lib/xorg/Xorg                133MiB |
|    0   N/A  N/A      1720      G   /usr/lib/xorg/Xorg                339MiB |
|    0   N/A  N/A      1892      G   /usr/bin/gnome-shell               68MiB |
|    0   N/A  N/A      3439    C+G   ...R2021a/bin/glnxa64/MATLAB      226MiB |
|    0   N/A  N/A      3720      G   ...1531959360FF99E4245683A9B        5MiB |
|    0   N/A  N/A      4966      G   ...AAAAAAAAA= --shared-files       33MiB |
+-----------------------------------------------------------------------------+

Testing the installation of cuDNN

To test the installation of cuDNN, copy cuDNN samples into your home directory,

cp -r /usr/src/cudnn_samples_v8/ $HOME

Change directory to mnist example, compile the code, and run.

cd $HOME/cudnn_samples_v8/mnistCUDNN/
make
./mnistCUDNN

You should some outputs with some texts at the end stating Tests passed.

You are now ready to write deep learning applications using NVIDIA and cuDNN.

Reference

  1. https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&=Ubuntu&target_version=20.04&target_type=deb_local
  2. https://developer.nvidia.com/cudnn
  3. https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
Deep Learning
Nvidia
Cudnn
Artificial Intelligence
Machine Learning
Recommended from ReadMedium