248

I have searched many places but ALL I get is HOW to install it, not how to verify that it is installed. I can verify my NVIDIA driver is installed, and that CUDA is installed, but I don't know how to verify CuDNN is installed. Help will be much appreciated, thanks!

PS.
This is for a caffe implementation. Currently everything is working without CuDNN enabled.

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
alfredox
  • 4,082
  • 6
  • 21
  • 29

13 Answers13

239

The installation of CuDNN is just copying some files. Hence to check if CuDNN is installed (and which version you have), you only need to check those files.

Install CuDNN

Step 1: Register an nvidia developer account and download cudnn here (about 80 MB). You might need nvcc --version to get your cuda version.

Step 2: Check where your cuda installation is. For most people, it will be /usr/local/cuda/. You can check it with which nvcc.

Step 3: Copy the files:

$ cd folder/extracted/contents
$ sudo cp include/cudnn.h /usr/local/cuda/include
$ sudo cp lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Check version

You might have to adjust the path. See step 2 of the installation.

$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

edit: In later versions this might be the following (credits to Aris)

$ cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

Notes

When you get an error like

F tensorflow/stream_executor/cuda/cuda_dnn.cc:427] could not set cudnn filter descriptor: CUDNN_STATUS_BAD_PARAM

with TensorFlow, you might consider using CuDNN v4 instead of v5.

Ubuntu users who installed it via apt: https://askubuntu.com/a/767270/10425

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • 2
    These steps for CuDNN are good. Would you say they can be ever so slightly improved if the copies were symlink-preserving (-av flags)? – auro Jun 04 '16 at 18:36
  • 13
    modifying the path slightly worked for my install `cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2` – Micah Stubbs Oct 04 '17 at 06:33
  • I had to change my path to `/usr/local/cuda/**/*.h` – bwest87 Feb 13 '18 at 00:24
  • The link you posted to download cudnn links to the deb files. Here's where you can download the tar files: https://developer.nvidia.com/rdp/cudnn-archive – BourbonCreams May 30 '18 at 14:24
  • 1
    More recently, to get version, the following works. cat /usr/include/x86_64-linux-gnu/cudnn_v7.h | grep CUDNN_MAJOR -A 2 – auro Jan 23 '19 at 01:42
  • @BourbonCreams the link for **cudnn 7.1.4** has three versions: runtime, developer and code samples for **CUDA 8.0**. Which one of them should I install? All? – bit_scientist Feb 08 '19 at 01:52
  • Well that depends on your preference. Check this answer for an explanation: https://stackoverflow.com/q/48784645/4834745 To be able to access the code, you would want the developer version. – BourbonCreams Feb 08 '19 at 07:12
  • 4
    For me, the `CUDNN_MAJOR` variable is contained in /usr/local/cuda/include/cudnn_version.h I'm using CuDNN 8.0.5 – spurra Dec 09 '20 at 14:31
  • When I try to download on Linux using wget I get `ERROR 403: Forbidden` – mikey Feb 18 '21 at 19:07
  • 2
    I second @spurra 's comment the newer versions of cudnn have a `cudnn_version.h` file. Hence the whole command would look something like : `cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2` – Ari Jan 19 '22 at 12:58
  • `sudo cp -P` https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#installlinux-tar – skytree Feb 07 '22 at 03:10
  • cat: /usr/local/cuda/include/cudnn.h: No such file or directory – Furkan Gözükara Jun 13 '23 at 13:59
159

My answer shows how to check the version of CuDNN installed, which is usually something that you also want to verify. You first need to find the installed cudnn file and then parse this file. To find the file, you can use:

whereis cudnn.h
CUDNN_H_PATH=$(whereis cudnn.h)

If that doesn't work, see "Redhat distributions" below.

Once you find this location you can then do the following (replacing ${CUDNN_H_PATH} with the path):

cat ${CUDNN_H_PATH} | grep CUDNN_MAJOR -A 2

The result should look something like this:

#define CUDNN_MAJOR 7
#define CUDNN_MINOR 5
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

Which means the version is 7.5.0.

Ubuntu 18.04 (via sudo apt install nvidia-cuda-toolkit)

This method of installation installs cuda in /usr/include and /usr/lib/cuda/lib64, hence the file you need to look at is in /usr/include/cudnn.h.

CUDNN_H_PATH=/usr/include/cudnn.h
cat ${CUDNN_H_PATH} | grep CUDNN_MAJOR -A 2

Debian and Ubuntu

From CuDNN v5 onwards (at least when you install via sudo dpkg -i <library_name>.deb packages), it looks like you might need to use the following:

cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2

For example:

$ cat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2                                                         
#define CUDNN_MAJOR      6
#define CUDNN_MINOR      0
#define CUDNN_PATCHLEVEL 21
--
#define CUDNN_VERSION    (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

#include "driver_types.h"
                      

indicates that CuDNN version 6.0.21 is installed.

Redhat distributions

On CentOS, I found the location of CUDA with:

$ whereis cuda
cuda: /usr/local/cuda

I then used the procedure about on the cudnn.h file that I found from this location:

$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
Jonathan
  • 4,847
  • 3
  • 32
  • 37
58

To check installation of CUDA, run below command, if it’s installed properly then below command will not throw any error and will print correct version of library.

function lib_installed() { /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep $1; }
function check() { lib_installed $1 && echo "$1 is installed" || echo "ERROR: $1 is NOT installed"; }
check libcuda
check libcudart

To check installation of CuDNN, run below command, if CuDNN is installed properly then you will not get any error.

function lib_installed() { /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep $1; }
function check() { lib_installed $1 && echo "$1 is installed" || echo "ERROR: $1 is NOT installed"; }
check libcudnn 

OR

you can run below command from any directory

nvcc -V

it should give output something like this

 nvcc: NVIDIA (R) Cuda compiler driver
 Copyright (c) 2005-2016 NVIDIA Corporation
 Built on Tue_Jan_10_13:22:03_CST_2017
 Cuda compilation tools, release 8.0, V8.0.61
Sherlock
  • 993
  • 1
  • 10
  • 22
  • I run the nvcc -V command and it threw error. such command not found. – Infinite Loops Nov 29 '18 at 13:11
  • @InfiniteLoops do you have nvidia cuda toolkit installed ? – Sherlock Nov 29 '18 at 14:54
  • @Sherlock i directly run the cmd from the installation guide of TensorFlow, that i assume installing Cuda n cudnn. It says it add Nvidia package repo and Install cuda and tools. But the function you stated earlier works. It displays something like libcudnn.so.7 -> libcudnn.so.7.2.1 – Infinite Loops Nov 29 '18 at 15:29
  • @InfiniteLoops if you are getting error that "such command not found" that means nvidia tool kit is not installed. try command `nvcc` and check your output. check below link also https://devtalk.nvidia.com/default/topic/457664/nvcc-quot-no-command-39-nvcc-39-found-quot-/ – Sherlock Nov 30 '18 at 13:30
  • 3
    What does running `nvcc -V` has to do with cudnn? As in your example, it does not appear to show the cudnn version... – Redoman Mar 11 '22 at 17:36
50

Installing CuDNN just involves placing the files in the CUDA directory. If you have specified the routes and the CuDNN option correctly while installing caffe it will be compiled with CuDNN.

You can check that using cmake. Create a directory caffe/build and run cmake .. from there. If the configuration is correct you will see these lines:

-- Found cuDNN (include: /usr/local/cuda-7.0/include, library: /usr/local/cuda-7.0/lib64/libcudnn.so)

-- NVIDIA CUDA:
--   Target GPU(s)     :   Auto
--   GPU arch(s)       :   sm_30
--   cuDNN             :   Yes

If everything is correct just run the make orders to install caffe from there.

cesans
  • 869
  • 7
  • 5
  • Awesome, thank you for the answer. I did have cuDNN enabled after enabling it in the make file and recompiling it worked :D. – alfredox Jul 16 '15 at 04:33
  • 91
    Is there a way to find if cuDNN is installed without using Caffe. Something like the examples you get with CUDA? – gokul_uf Feb 28 '16 at 18:41
  • 7
    @gokul_uf per martin's answer below, you can use the following (assuming you've symlinked /usr/local/cuda to /usr/local/cuda-#.#): `cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2` – matt Oct 25 '17 at 03:11
  • 2
    @Boooooooooms He's simply taking the contents of a "header file" for the programming language C, and using the program "grep" to read out a specific variable for us – Greg Hilston Jun 15 '19 at 06:10
  • I don't have Caffe. – rjurney Aug 24 '19 at 21:22
  • 1
    the grep doesn't work any more, as version has been taken out of the cudnn.h and put in cudnn_version.h . But you can still verify the file exists with the cat command, just leave out everything from the | grep pipe onwards. – DragonLord Aug 14 '21 at 01:31
42

Getting cuDNN Version [Linux]

Use following to find path for cuDNN:

cat $(whereis cudnn.h) | grep CUDNN_MAJOR -A 2

If above doesn't work try this:

cat $(whereis cuda)/include/cudnn.h | grep CUDNN_MAJOR -A 2

Getting cuDNN Version [Windows]

Use following to find path for cuDNN:

C:\>where cudnn*
C:\Program Files\cuDNN6\cuda\bin\cudnn64_6.dll

Then use this to dump version from header file,

type "%PROGRAMFILES%\cuDNN6\cuda\include\cudnn.h" | findstr "CUDNN_MAJOR CUDNN_MINOR CUDNN_PATCHLEVEL"

Getting CUDA Version

This works on Linux as well as Windows:

nvcc --version
Shital Shah
  • 63,284
  • 17
  • 238
  • 185
  • 1
    Just to add a user case: I cannot find the `cudnn.h` file in my cuda installation and I thought I did not have cudnn installed. But I later run the cuda sample code downloaded from the official website, and it passed... – yuqli Nov 27 '18 at 01:52
  • 3
    The full command I used to find the full version number was: `type "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\cudnn.h" | findstr "CUDNN_MAJOR CUDNN_MINOR CUDNN_PATCHLEVEL"` – Taran Dec 07 '18 at 13:36
  • Cool! I updated answer so now it prints these details. – Shital Shah Dec 07 '18 at 23:54
23

When installing on ubuntu via .deb you can use sudo apt search cudnn | grep installed

Vladimirs
  • 910
  • 11
  • 17
  • It shows that I installed the [first one](https://i.stack.imgur.com/LTrJX.jpg), so did I install it successfully? – yode Dec 14 '21 at 19:42
18

I have cuDNN 8.0 and none of the suggestions above worked for me. The desired information was in /usr/include/cudnn_version.h, so

cat /usr/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

did the trick.

Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
  • 1
    For me the path in Ubuntu 20.04.1 LTS with cuDNN 8 was like this.. `/usr/local/cuda/include/cudnn_version.h` hope it may helps anyone. – b00r00x0 Sep 11 '20 at 15:28
17

On Ubuntu 20.04LTS:

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR

returned the expected results

Soran Ghaderi
  • 207
  • 2
  • 5
13
torch.backends.cudnn.version()

should do the trick

  • 7
    Keep in mind that this might show the cudnn version included in pytorch, rather than the system-wide cudnn you might have manually installed following the nvidia guide. The fact that you can either install cuda/cudnn included in pytorch or the standalone versions of cuda/cudnn provided by nvidia originates a lot of confusion, but this answer makes it all clear: https://superuser.com/a/1572762/105024 – Redoman Mar 11 '22 at 20:49
  • Good point @redoman - this answer is safe only for PyTorch: `torch` cuDNN bindings are no indication for, say `tensorflow` users (or indeed `caffe` users as OP), because the python `torch` package can ship with its own cuDNN library, as one can see by running `$ cd / && find | grep site-packages | grep libcudnn` – mirekphd Jun 03 '23 at 16:55
8

How about checking with python code:

from tensorflow.python.platform import build_info as tf_build_info

print(tf_build_info.cudnn_version_number)
# 7 in v1.10.0
Scott
  • 4,974
  • 6
  • 35
  • 62
6

Run ./mnistCUDNN in /usr/src/cudnn_samples_v7/mnistCUDNN

Here is an example:

cudnnGetVersion() : 7005 , CUDNN_VERSION from cudnn.h : 7005 (7.0.5)
Host compiler version : GCC 5.4.0
There are 1 CUDA capable devices on your machine :
device 0 : sms 30  Capabilities 6.1, SmClock 1645.0 Mhz, MemSize (Mb) 24446, MemClock 4513.0 Mhz, Ecc=0,    boardGroupID=0
Using device 0
Ripi2
  • 7,031
  • 1
  • 17
  • 33
jeff wang
  • 149
  • 1
  • 3
  • 4
    This is actually not bad advice, except where it is wrong. `mnistCUDNN` should not be in that directory since that is not supposed to be a writable directory. Rather the samples should have been copied as a sub-directory to the users home directory and built there. So if it was properly installed and built according to the instructions on the Nvidia site, `mnistCUDNN ` will be in `~/cudnn_samples_v7` – Mike Wise Mar 07 '18 at 12:53
  • Just to add you can get the code sample from the official NVIDIA website, following instructions here(https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#verify) for how to install and verify. – yuqli Nov 27 '18 at 01:51
  • 1
    I see. My `cudnn.h` was installed at `/usr/include/cudnn.h`, not sure why but this happened before when I install CUDA with `apt-get` as well. This time I was using `dpkg` and did not change anything... – yuqli Nov 27 '18 at 02:00
4

For CUDnn 8.1 and above use the following command:

cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

enter image description here

MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22
3
torch.backends.cudnn.m.is_available()
yode
  • 483
  • 7
  • 16
  • 1
    Welcome to StackOverflow. Please edit your answer to include a description of what your code does. – Sean Sep 10 '22 at 21:48