in ,

How To Install Ubuntu Nvidia Driver With CUDA And cuDNN

Ubuntu Nvidia Driver With Cuda And Cudnn

In this lab, we will install the Ubuntu Nvidia Driver with CUDA Toolkit and cuDNN library to make our Ubuntu 20.04 LTS ready for GPU-Accelerated apps development and deep learning processing.

Step1: Update Ubuntu Linux

# apt update
# apt upgrade

Step2: Install And Check Prerequests

Now we need to make sure that all Linux required headers are installed.

# apt install linux-headers-$(uname -r) -y

Install GCC and other required build tools

# apt install build-essential

Check your GPU Graphic Card for the CUDA Enabled feature, the compute capability listed here for Nvidia CUDA GPUs Graphic Cards.

# lspci | grep -i nvidia

If (you found your GPU Card is CUDA Supported) { continue applying the following steps } else { Skip CUDA and cuDNN Installation Step }.

Step3: Install Ubuntu Nvidia Driver Repositories

Adding the Nvidia Official Repositories

Downloading and adding the official NVIDIA CUDA repository Pin file from the NVIDIA website for Ubuntu 20.04 and adding the GPG key of the official NVIDIA package repository
The list of CUDA repo packages for Ubuntu 20.04 is listed here.

# wget -O /etc/apt/preferences.d/cuda-repository-pin-600 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
# apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
# add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
# apt update
# apt upgrade

Step4: Install Nvidia CUDA

Installing the latest version of CUDA from the Official Ubuntu NVIDIA Driver Package Repository and GDS package the GPUDirectStorage (GDS), currently at the article published date Nvidia Driver nvidia-driver-510, cuda-drivers-510, cuda-11-6, and other requirement packages will be installed during the next running command.

# apt install cuda
# apt install nvidia-gds
# echo 'export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}' >> ~/.bashrc

To confirm whether CUDA is working, reboot the system, then run the following command:

# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0

Step5: Install cuDNN

# apt install libcudnn8 libcudnn8-dev

Step6: Set The Active Nvidia CUDA Version

Currently, we installed the Nvidia CUDA Driver version 11.6 and Driver version 510 from the ubuntu Nvidia Driver official Repository of Ubuntu 20.04.

But what if we need to install CUDA 11.5, for example, need to run the CUDA 11.5 based cuDNN library libcudnn8 8.3.3.40-1+cuda11.5

So we will install the previous CUDA Version

# apt install cuda-11-5

And to display all CUDA  Alternatives

# update-alternatives --display cuda
cuda - auto mode
link best version is /usr/local/cuda-11.6
link currently points to /usr/local/cuda-11.6
link cuda is /usr/local/cuda
/usr/local/cuda-11.5 - priority 115
/usr/local/cuda-11.6 - priority 116

And To make the CUDA-11.5 is the active version

# update-alternatives --config cuda
There are 2 choices for the alternative cuda (providing /usr/local/cuda).

  Selection    Path                  Priority   Status
------------------------------------------------------------
* 0            /usr/local/cuda-11.6   116       auto mode
  1            /usr/local/cuda-11.5   115       manual mode
  2            /usr/local/cuda-11.6   116       manual mode

Press  to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/local/cuda-11.5 to provide /usr/local/cuda (cuda) in manual mode

Extra Step: Install Python PIP And Tools

Install Python And PIP

# apt install python-is-python pip

Install Third-Party Libraries For More Features With CUDA

# apt install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev libfreeimage-dev

Get Information About Your GPU

# apt install hwinfo
# hwinfo --gfxcard --short

# lshw -C display

# nvidia-smi

Note That: If you are not the root user while using nvcc or CUDA tools, you will need to sudo commands to be run as the superuser, and we need to append the CUDA tools bin directory /usr/local/cuda/bin to the secure_path value at the /etc/sudoers file.

# visudo /etc/sudoers
~~~~
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/cuda/bin"

# Host alias specification
~~~~

What do you think?

Leave a Reply

Your email address will not be published.

Install Tensorflow 2.8.0 On Ubuntu 20.04 Lts

How To Install Python TensorFlow 2.8.0 GPU On Ubuntu 20.04 LTS

How Do I Buy Ethereum

How Do I Buy Ethereum?