CuDNN not found while compiling PyTorch C++ extension

artbataev: <p>I’m trying to build C++ Extension with CMake using libtorch or using installed Pytorch package.<br>
It’s ok when I use CPU-only build, but when using GPU-build there is a problem with Caffe2 - no CuDNN</p>
<p>So there is a question - is it possible somehow to detect automatically if Cudnn is installed (there were no problems with pytorch installation itself)?<br>
Is it possible to simplify the process (I want to install the package using pip)?</p>
<pre><code class="lang-auto">&gt;&gt; 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".

</code></pre>

aaronlelevier: <p>Hi, did you solve this error? If so, can you post the solution? I’m currently getting the same error. Thanks</p>

InnovArul: <aside class="quote no-group quote-modified" data-username="artbataev" data-post="1" data-topic="31789">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/artbataev/48/6966_2.png" class="avatar"> artbataev:</div>
<blockquote>
<p>– Could NOT find CUDNN (missing: CUDNN_INCLUDE_DIR CUDNN_LIBRARY</p>
</blockquote>
</aside>
<p>just to get dditional info,  have you set these environment variables to correct folder locations?</p>

artbataev: <p>For now I have no good solution, except installing cuda and cudnn, following official guide <a href="https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html:" rel="nofollow noopener">https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html:</a></p>
<pre><code class="lang-auto">$ 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*
</code></pre>
<p>or setting CUDNN_INCLUDE_DIR directly.</p>
<p>Maybe you can use one from anaconda environment, but I’m not sure.</p>

aaronlelevier: <p>Thank you both!</p>
<p>It’s now working. For me, this is super n00b mistake <img src="https://discuss.pytorch.org/images/emoji/apple/blush.png?v=6" title=":blush:" class="emoji" alt=":blush:">  I had the Nvidia drivers and Cuda installed, but I’ve never done C++ development, so I didn’t have Nvidia’s <code>cudnn</code> installed.</p>
<p>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 <code>cudnn</code> was installed.</p>
<p><a href="https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installlinux" class="onebox" target="_blank" rel="nofollow noopener">https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#installlinux</a></p>

Tangeni_M_Shikomba: <p><strong>ASSUMING THAT YOU ARE USING UBUNTU 18.04</strong></p>
<ul>
<li>Download cuDNN Debian files (runtime, dev, and docs) from here: <strong><a href="https://developer.nvidia.com/rdp/cudnn-download" rel="nofollow noopener">https://developer.nvidia.com/rdp/cudnn-download</a></strong>
</li>
</ul>
<pre><code class="lang-auto">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
</code></pre>
<ul>
<li>Verify installation</li>
</ul>
<pre><code class="lang-auto">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 &amp;&amp; make

Run the mnistCUDNN sample.
$ ./mnistCUDNN
</code></pre>

Lin_Jia: <p>I am on ubuntu 20.04,  <a class="mention" href="/u/tangeni_m_shikomba">@Tangeni_M_Shikomba</a> 's solution also works. Nvidia official website does not have deb download for 20.04, I downloaded older versions, and they work fine.</p>