Install CUDA and CUDNN on Windows & Linux

Install CUDA and CUDNN on Windows & Linux

CONTENTS

( But first ✅Subscribe to my YouTube channel 👉🏻 https://bit.ly/3Ap3sdi 😁😜)

CUDA & CUDNN FOR WINDOWS

STEP 1) Download and install CUDA Toolkit

● Go to https://developer.nvidia.com/cuda-downloads to download the latest CUDA Toolkit.

You can also download previous versions from Archive of Previous CUDA Releases OR under the Resources section at the cuda-downloads link given above.

( For this Tutorial, I will download and install CUDA 11.0. You can 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 know 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.

When the setup starts, select a location to extract the installer. Once that is done the CUDA installer will start. Over there, 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.

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_0 —-> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0


STEP 2) Download and setup CUDNN

Go to https://developer.nvidia.com/cudnn to download the latest version of CUDNN for the latest CUDA toolkit version OR go to https://developer.nvidia.com/rdp/cudnn-archive to download a previous version of CUDNN that is compatible with your CUDA toolkit.

NOTE: You have to be signed in using your Nvidia account to download CUDNN. If you do not 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).

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 archive. Download and extract it.

Copy the contents of the cuda folder inside the cuDNN folder to the path where we installed CUDA in step 1 above. (We need the contents of the bin, include & lib folders from cuDNN to be inside the bin, include and lib folders of the CUDA directory)

COPY CONTENTS FROM THIS FOLDER

TO THIS FOLDER

Finally, just like we did for CUDA, we have to set Environment variables for cuDNN as well. See pic below.

Set 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:

  • –> 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\x64;

NOTE: Make sure to add these paths to both the CUDNN and Path System variables.

● Finally, reboot the system. You can verify your CUDA installation through command prompt by running the following 2 commands:

nvidia-smi
nvcc -V

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


CUDA & CUDNN FOR LINUX

STEP 1) Download and install CUDA Toolkit

Go to https://developer.nvidia.com/cuda-downloads to download the latest CUDA Toolkit.

You can also download previous versions from Archive of Previous CUDA Releases OR under the Resources section at the cuda-downloads link given above.

(For this Tutorial, I will download and install CUDA 11.0. You can 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 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.

LET’S BEGIN

  • Open a terminal.
  • Firstly, 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 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
  • Next, install the NVidia driver compatible with your CUDA version. For CUDA 11.0 the minimum driver version for Linux is >= 450.36.06.

NOTE: You can either do the following step to manually install any specific NVidia driver version you want or you can skip this step and simply install the NVidia driver that is bundled with the CUDA software.

sudo apt-get install nvidia-driver-450

(You can read about the minimum driver versions required here on the links given below.)

https://docs.nvidia.com/deploy/cuda-compatibility/index.html

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

  • Next, 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
  • 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 and finally press Enter to install CUDA. ( You can leave the Driver option checked if you have not manually installed a specific version NVidia driver above. This installs the driver version 450.51.06 which comes bundled with the CUDA installer.)

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

  • Next, open the bashrc script file using the following command.
nano ~/.bashrc
  • Add the following lines at the end of the bashrc file. ( I have Cuda 11.0. Change this according to your version)
# 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}}

The bashrc file looks like below:

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

  • Next, 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.


STEP 2) Download and setup CUDNN

Go to https://developer.nvidia.com/cudnn to download the latest version of CUDNN for the latest CUDA toolkit version OR go to https://developer.nvidia.com/rdp/cudnn-archive to download a previous version of CUDNN that is compatible with your CUDA toolkit.

NOTE: You have to be signed in using your Nvidia account to download CUDNN. If you do not 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 Linux (x86_64).

NOTE: 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.
  • 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
  • Next, we have to copy the contents of these sub-folders to the path where we installed CUDA in step 1 above.

COPY CONTENTS FROM THE CUDA FOLDER UNZIPPED FROM CUDNN TO THE MAIN CUDA DIRECTORY

  • We need the contents of the include & lib64 folders from cuDNN to be inside the include and lib64 folders of CUDA directory (where we installed CUDA shown in step 1 above). Run the following commands:
cd cuda
sudo cp -P lib64/* /usr/local/cuda/lib64/
sudo cp -P include/* /usr/local/cuda/include/

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


References

https://developer.nvidia.com/

One thought on “Install CUDA and CUDNN on Windows & Linux

  1. When open “nano ~/.bashrc” to add the env vars, if you install another version of cuda, you must to edit the path.

    I have installed 11.7, I edit my file this way:

    # NVIDIA CUDA TOOLKIT
    export PATH=/usr/local/cuda-11.7/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Leave a Reply

en_USEnglish