CuDNN not found while compiling PyTorch C++ extension

I’m trying to build C++ Extension with CMake using libtorch or using installed Pytorch package.
It’s ok when I use CPU-only build, but when using GPU-build there is a problem with Caffe2 - no CuDNN

So there is a question - is it possible somehow to detect automatically if Cudnn is installed (there were no problems with pytorch installation itself)?
Is it possible to simplify the process (I want to install the package using pip)?

>> CXX=g++-5 cmake -DCMAKE_PREFIX_PATH=/home/artbataev/Documents/libraries/libtorch ..
-- The CXX compiler identification is GNU 5.5.0
-- Check for working CXX compiler: /usr/bin/g++-5
-- Check for working CXX compiler: /usr/bin/g++-5 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda (found suitable version "9.0", minimum required is "7.0") 
-- Caffe2: CUDA detected: 9.0
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 9.0
-- Could NOT find CUDNN (missing: CUDNN_INCLUDE_DIR CUDNN_LIBRARY) 
CMake Warning at /home/artbataev/Documents/libraries/libtorch/share/cmake/Caffe2/public/cuda.cmake:101 (message):
  Caffe2: Cannot find cuDNN library.  Turning the option off
Call Stack (most recent call first):
  /home/artbataev/Documents/libraries/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /home/artbataev/Documents/libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:39 (find_package)
  CMakeLists.txt:11 (find_package)


-- Autodetected CUDA architecture(s): 6.1;6.1
-- Added CUDA NVCC flags for: -gencode;arch=compute_61,code=sm_61
CMake Error at /home/artbataev/Documents/libraries/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:96 (message):
  Your installed Caffe2 version uses cuDNN but I cannot find the cuDNN
  libraries.  Please set the proper cuDNN prefixes and / or install cuDNN.
Call Stack (most recent call first):
  /home/artbataev/Documents/libraries/libtorch/share/cmake/Torch/TorchConfig.cmake:39 (find_package)
  CMakeLists.txt:11 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/artbataev/Documents/ML/end2end/build/CMakeFiles/CMakeOutput.log".
See also "/home/artbataev/Documents/ML/end2end/build/CMakeFiles/CMakeError.log".

1 Like

Hi, did you solve this error? If so, can you post the solution? I’m currently getting the same error. Thanks

just to get dditional info, have you set these environment variables to correct folder locations?

For now I have no good solution, except installing cuda and cudnn, following official guide https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html:

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

or setting CUDNN_INCLUDE_DIR directly.

Maybe you can use one from anaconda environment, but I’m not sure.

3 Likes

Thank you both!

It’s now working. For me, this is super n00b mistake :blush: I had the Nvidia drivers and Cuda installed, but I’ve never done C++ development, so I didn’t have Nvidia’s cudnn installed.

I followed the installation instructions here for the “runtime library” and it linked the paths for me. I did see some notes about linking paths, but I didn’t have to once cudnn was installed.

https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installlinux

ASSUMING THAT YOU ARE USING UBUNTU 18.04

1. Install the runtime library, for example:
$ sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb

2. Install the developer library, for example:
$ sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb

3. Install the code samples and the cuDNN Library User Guide, for example:
$ sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb
  • Verify installation
Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME

Go to the writable path.
$ cd  $HOME/cudnn_samples_v7/mnistCUDNN

Compile the mnistCUDNN sample.
$make clean && make

Run the mnistCUDNN sample.
$ ./mnistCUDNN

I am on ubuntu 20.04, @Tangeni_M_Shikomba 's solution also works. Nvidia official website does not have deb download for 20.04, I downloaded older versions, and they work fine.