How to verify CuDNN installation?
Asked Answered
I

15

263

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.

Imf answered 9/7, 2015 at 18:58 Comment(4)
did you try run some example with and without USE_CUDNN enabled?Rennes
how do you verify that your NVIDIA and CUDA driver is installed?Birecree
@CharlieParker To verify CUDA just type nvcc -VDolora
They asked for CUDNN folks :)) READ carefully !!!Edd
W
52

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.

Welltodo answered 10/7, 2015 at 19:56 Comment(6)
Awesome, thank you for the answer. I did have cuDNN enabled after enabling it in the make file and recompiling it worked :D.Imf
Is there a way to find if cuDNN is installed without using Caffe. Something like the examples you get with CUDA?Woo
@Woo 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 2Antedate
@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 usBottoms
I don't have Caffe.Toothy
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.Fonzie
R
247

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

Rael answered 2/5, 2016 at 8:56 Comment(12)
These steps for CuDNN are good. Would you say they can be ever so slightly improved if the copies were symlink-preserving (-av flags)?Petersburg
modifying the path slightly worked for my install cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2Carry
I had to change my path to /usr/local/cuda/**/*.hEmbryotomy
The link you posted to download cudnn links to the deb files. Here's where you can download the tar files: developer.nvidia.com/rdp/cudnn-archiveResident
More recently, to get version, the following works. cat /usr/include/x86_64-linux-gnu/cudnn_v7.h | grep CUDNN_MAJOR -A 2Petersburg
@Resident 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?Uzzia
Well that depends on your preference. Check this answer for an explanation: https://mcmap.net/q/55894/-which-nvidia-cudnn-release-type-for-tensorflow-on-ubuntu-16-04-closed/4834745 To be able to access the code, you would want the developer version.Resident
For me, the CUDNN_MAJOR variable is contained in /usr/local/cuda/include/cudnn_version.h I'm using CuDNN 8.0.5Rag
When I try to download on Linux using wget I get ERROR 403: ForbiddenPreclinical
I second @Rag '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 2Costermansville
sudo cp -P docs.nvidia.com/deeplearning/cudnn/install-guide/…Phlox
cat: /usr/local/cuda/include/cudnn.h: No such file or directoryDuke
M
168

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
Mess answered 13/9, 2017 at 14:20 Comment(1)
no longer; now found in cudnn_version.h .Fonzie
R
61

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
Rejuvenate answered 22/11, 2017 at 14:12 Comment(5)
I run the nvcc -V command and it threw error. such command not found.Sunil
@InfiniteLoops do you have nvidia cuda toolkit installed ?Rejuvenate
@Rejuvenate 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.1Sunil
@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 devtalk.nvidia.com/default/topic/457664/…Rejuvenate
What does running nvcc -V has to do with cudnn? As in your example, it does not appear to show the cudnn version...Ashien
W
52

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.

Welltodo answered 10/7, 2015 at 19:56 Comment(6)
Awesome, thank you for the answer. I did have cuDNN enabled after enabling it in the make file and recompiling it worked :D.Imf
Is there a way to find if cuDNN is installed without using Caffe. Something like the examples you get with CUDA?Woo
@Woo 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 2Antedate
@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 usBottoms
I don't have Caffe.Toothy
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.Fonzie
T
45

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
Tophole answered 6/7, 2018 at 3:48 Comment(3)
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...Ebony
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"Dulla
Cool! I updated answer so now it prints these details.Tophole
U
26

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

Udo answered 31/3, 2018 at 18:20 Comment(1)
It shows that I installed the first one, so did I install it successfully?Tweak
S
21

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.

Stigmatism answered 24/8, 2020 at 20:19 Comment(2)
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.Ciaracibber
Comment worked for me!Impotence
G
19

On Ubuntu 20.04LTS:

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

returned the expected results

Ginsberg answered 20/12, 2020 at 18:15 Comment(3)
Amazing answer. This is the easiest way to test CuDNNGambeson
Works for Ubuntu 18.04 LTSNowadays
for cuDNN 8.3 this is the answer, as somewhere down the line Nvidia changed the content on cudnn.h as to remove the CUDNN_MAJOR string we're looking after.Esme
F
14
torch.backends.cudnn.version()

should do the trick

Fruitage answered 17/2, 2022 at 0:9 Comment(2)
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: superuser.com/a/1572762/105024Ashien
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 libcudnnWeirdo
B
10

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
Beaudoin answered 10/8, 2020 at 5:25 Comment(2)
Probably it is print(tf_build_info.build_info)Otilia
print(tf_build_info.build_info['cudnn_version'])Ellamaeellan
T
7

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
Trippet answered 22/2, 2018 at 13:41 Comment(3)
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_v7Yaw
Just to add you can get the code sample from the official NVIDIA website, following instructions here(docs.nvidia.com/deeplearning/sdk/cudnn-install/…) for how to install and verify.Ebony
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...Ebony
C
6

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

Chavey answered 1/9, 2021 at 18:6 Comment(0)
T
5
torch.backends.cudnn.m.is_available()
Tweak answered 10/9, 2022 at 19:4 Comment(1)
Welcome to StackOverflow. Please edit your answer to include a description of what your code does.Lionhearted
R
2

Its really easy to check for cudnn installation in Python using Pytorch:

import torch
print(torch.backends.cudnn.enabled)
print(torch.backends.cudnn.version())
Rufford answered 9/2 at 15:18 Comment(0)
S
1

This should work across different Linux distributions and different versions of CUDA:

grep -Rw --include 'cudnn*.h' '#define\s\+CUDNN_\(MAJOR\|MINOR\|PATCHLEVEL\)' /usr
Sateen answered 13/12, 2023 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.