How to Install cuDNN and CUDA for Windows and Linux

CUDA Deep Neural Network (cuDNN) is a GPU library for deep neural networks, while CUDA is library to access and command the GPU. Here’s how to download them.

Written by Zubair Zahid
Published on Jun. 14, 2024
How to Install cuDNN and CUDA for Windows and Linux
Image: Shutterstock / Built In
Brand Studio Logo

CUDA is a computing platform and library from NVIDIA that utilizes parallel computing to make it faster and easier for users to access and command the graphical processing unit for general use. CUDA deep neural network (cuDNN) is a GPU library designed for deep neural network use.

What is CUDA Deep Neural Network (cuDNN)? 

CUDA deep neural network (cuDNN) is a GPU library offered by NVIDIA that is explicitly designed for deep neural network use. It can be downloaded on both Windows and Linux.    

Here’s how to download both for Windows and Linux

 

CUDA and cuDNN Download for Windows

Download CUDA for Windows

Go to NVIDIA’s site to download the latest CUDA Toolkit. You can also download previous versions from the Archive of Previous CUDA Releases under the “Resources” section on the same page .

For this tutorial, I will download and install CUDA 11.0. You can use the latest CUDA toolkit and its corresponding cuDNN file. This is just for demonstration. 

Go to Archive of Previous CUDA Releases and click on CUDA Toolkit 11.0 Update1.

On the next page, first, choose your operating system as Windows.

Next, choose your Architecture and version. For my system, the architecture is x86_64, as I have a 64-bit system, and the version of Windows is 10. To find your system’s architecture in Windows, go to Control Panel -> System and Security -> System. It will be mentioned as system type.

Next, choose any installer type to download. I have downloaded the exe (local) type installer.

You will then see the installation instructions using the base installer which is 2.7 GB in size. Once downloaded, click on the exe file and follow on-screen prompts.

CUDA download screen on NVIDIA
Download screen for CUDA on NVIDIA. | Screenshot: Zubair Zahir
NVIDIA installer page.
NVIDIA installer screen. | Screenshot: Zubair Zahir

When the setup starts, select a location to extract the installer. Once that is done the CUDA installer will start. In the CUDA installer, choose Express installation and click on “Next.” This will install the “CUDA Toolkit” on your system in the location C:\Program Files\NVIDIA GPU Computing Toolkit.

Environment variable path
Environment variable path and system variables. | Screenshot: Zubair Zahir

Next, make sure to check if your environment variables have the path to CUDA as shown in the image. It should automatically add the second path. If it doesn’t, then manually add them to the system variables.

  • CUDA_PATH → C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0
  • CUDA_PATH_V11_0C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0

More on AICUDA Error: Device-Side Assert Triggered in Pytorch

 

Download CUDNN for Windows

Go to NVIDIA’s cuDNN page to download the latest version of cuDNN for the latest CUDA toolkit version. Or go to the archive to download a previous version of cuDNN that is compatible with your CUDA toolkit.

You have to be signed in using your NVIDIA account to download cuDNN. If you don’t have an account, create one.

Since I have CUDA 11.0.1, I will download cuDNN 8.0.5 for CUDA 11.0

Click on “cuDNN 8.0.5” and select “cuDNN Library for Windows (x86).”

cuDNN library page to download on NVIDIA
CuDNN library page on NVIDIA. | Screenshot: Zubair Zahir

Next, it will ask you to log in. Create an Nvidia account or sign in using Google or Facebook. Once logged in you can download the cuDNN. Download and extract it.

Copy the contents of the CUDA folder inside the cuDNN folder to the path where we installed CUDA in the first step above. We need the contents of the “bin,” “include” and “lib” folders from cuDNN to be inside the “bin,” “include” and “lib” folders of the CUDA directory.

Copy contents from the folder below:

Folder contents for cuDNN download
Folder contents bin, include and lib need to be copied to the CUDA folder. | Screenshot: Zubair Zahir

To this folder:

Folder contents for CUDA with cuDNN files.
CUDA folder with the cuDNN contents copied inside. | Screenshot: Zubair Zahir

Finally, just like we did for CUDA, we have to set the environment variable for cuDNN as well.

CuDNN environment variables set
CuDNN environment variables and system variable set. | Screenshot: Zubair Zahir

Set the system variable with the name cuDNN to point to the “bin,” “include” and “lib folders,” which we copied into the CUDA directory. Also, add these same paths to the Path System variable.

The paths to add are mentioned below:

Paths to add into cuDNN system variable
Paths to add for cuDNN. | Screenshot: Zubair Zahir
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include
  • C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\lib

Make sure to add these paths to both the cuDNN and path system variables.

That’s it. We have successfully set up CUDA and cuDNN on our Windows System.

 

CUDA and cuDNN Download for Linux

Download CUDA for Linux

Go to NVIDIA’s website to download the latest CUDA toolkit. You can also download previous versions from the “Archive of Previous CUDA Releases under the “Resources” section on the same page given above.

Once again, I will download and install CUDA 11.0 for this demonstration. If you’d like to follow along, go to the archive page and click on CUDA Toolkit 11.0 Update1.

First, choose your operating system as Linux.

Next, choose your architecture, distribution and version. For my system, the architecture is x86_64 as I have a 64-bit Ubuntu system, and the version of Ubuntu is 18.04.

Next, choose any installer type to download. I have downloaded the “runfile (local) type” installer.

You will then see a few commands in the installation instructions for the base installer.

CUDA download for Linux
CUDA installer page for Linux. | Screenshot: Zubair Zahir

Then, open a terminal and run the following commands to update and upgrade all the packages on your Ubuntu.

  • sudo apt-get update
  • sudo apt-get upgrade

Next, install all the necessary dependencies.

sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install build-essential cmake unzip pkg-config
sudo apt-get install gcc-6 g++-6 
sudo apt-get install libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libopenblas-dev libatlas-base-dev liblapack-dev gfortran
sudo apt-get install libhdf5-serial-dev
sudo apt-get install python3-dev python3-tk python-imaging-tk
sudo apt-get install libgtk-3-dev

Next, add the ppa:graphics-drivers/ppa repository into your system.

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update

Install the NVIDIA driver compatible with your CUDA version. For CUDA 11.0 the minimum driver version for Linux is “>= 450.36.06.”

CUDA driver requirements
CUDA driver requirements for Linux. | Screenshot: Zubair Zahir
sudo apt-get install nvidia-driver-450

You can read about the minimum driver versions required.

Create a folder and run the commands from the installation instructions for the base installer.

cd ~
mkdir installers
cd installers/
wget https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run
sudo sh cuda_11.0.3_450.51.06_linux.run
CUDA set up code
CUDA set up code for Linux. | Screenshot: Zubair Zahir

When the setup starts, accept the EULA agreement. Then on the next screen uncheck the NVIDIA driver option since we have already installed it manually earlier. Finally, press Enter to install CUDA.

CUDA installer code for Linux
CUDA installer code for Linux. | Screenshot: Zubair Zahir

You’ll see a summary at the end of the CUDA installation as shown below.

Summary of CUDA installation for Linux
Summary of CUDA installation. | Screenshot: Zubair Zahir

Next, open the bashrc script file using the following command.

nano ~/.bashrc

Add the following lines at the end of the bashrc file.

# NVIDIA CUDA TOOLKIT
export PATH=/usr/local/cuda-11.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
CUDA toolkit bashrc file
NVIDIA CUDA toolkit. | Screenshot: Zubair Zahir

The bashrc file looks like below:

CUDA bashrc file
CUDA bashrc file for Linux. | Screenshot: Zubair Zahir

Press “Ctrl + x, y”, and “Enter” to save changes.

Run the source command to update your current shell environment.

source ~/.bashrc

That’s it! We have successfully installed CUDA on our system. Run sudo reboot to restart your system for the new changes to take effect. After Ubuntu restarts, you can confirm your CUDA installation by running nvcc -V and nvidia-smi commands.

CUDA installation confirmation for Linux.
CUDA installation confirmation for Linux. | Screenshot: Zubair Zahir
A tutorial on how to download cuDNN and CUDA. | Video: Life2Coding

More on AIAI Chips: What Are They?

 

How to Download CUDNN in Linux

Once again, go to NVIDIA’s site and download the latest version of cuDNN for the latest CUDA toolkit version or visit the archive page to download a previous version of cuDNN that is compatible with your CUDA toolkit.

You have to be signed in using your NVIDIA account to download cuDNN. Since I have CUDA 11.0.1, I will download cuDNN 8.0.5 for CUDA 11.0.

Click on cuDNN 8.0.5 and select cuDNN Library for Linux (x86_64).

cuDNN download file for Linux on NVIDIA
CuDNN library for Linux on NVIDIA. | Screenshot: Zubair Zahir
How to check Linux architecture.
How to check Linux architecture. | Screenshot: Zubair Zahir

You can check your architecture using the command uname -m in a terminal.

Next, it will ask you to log in. Create an Nvidia account or sign in using Google or Facebook. Once logged in you can download the cuDNN file.

Copy the downloaded cuDNN zip file to the “installers” folder.

cuDNN package in CUDA folder
Download cuDNN file in the installers folder. | Screenshot: Zubair Zahir

Unzip the cuDNN zip file using the following command. You will see a folder named “cuda” with “include” and “lib64” sub-folders in it after unzipping this.

tar -zxf cudnn-11.0-linux-x64-v8.0.5.39.tgz
Unzipped cuDNN files
Unzipped cuDNN files. | Screenshot: Zubair Zahir

Next, we have to copy the contents of these sub-folders to the path where we installed CUDA in the first step above.

Copy content from the CUDA folder unzipped from cuDNN to the main CUDA directory. 

Copy contents from cuDNN into CUDA folder
Contents in the cuDNN folder to be copied to CUDA. | Screenshot: Zubair Zahir

We need the contents of the “include” and “lib64” folders from cuDNN to be inside the include and “lib64” folders of the CUDA directory, where we installed CUDA shown in the first step. Run the following commands:

cd cuda
sudo cp -P lib64/* /usr/local/cuda/lib64/
sudo cp -P include/* /usr/local/cuda/include/
CuDNN confirmation code on Linux
Confirmation code that cuDNN has been installed on Linux. | Screenshot: Zubair Zahir

That’s it. We have successfully set up CUDA and cuDNN on our Linux Ubuntu 18.04 system.

Frequently Asked Questions

  1. Install the latest version of cuDNN that matches your version of CUDA for Windows.
  2. Copy the contents of the CUDA folder inside the cuDNN folder to the path where we installed CUDA.
  3. Set environment variable to cuDNN.
  4. Set the system variable with the name cuDNN to point to the bin, include and lib folders.
  5. Add these same paths to both the cuDNN and Path System variables.
  1. Select the version of cuDNN that matches your version of CUDA for Linux.
  2. Copy the downloaded cuDNN zip file to the installers folder.
  3. Unzip the cuDNN zip file using the following command: tar -zxf cudnn-11.0-linux-x64-v8.0.5.39.tgz
  4. Copy the contents of the bin, include and lib folders to the CUDA path.
  5. Copy the content from the CUDA folder unzipped from cuDNN to the main CUDA directory.
  6. Run the following commands: cd cuda; sudo cp -P lib64/* /usr/local/cuda/lib64/;sudo cp -P include/* /usr/local/cuda/include/
Hiring Now
FluentStream
Cloud • Mobile • Software • Utilities
SHARE