Error in cmake while setting up libtorch

username: a_d
cooked: <p>Hello  all,<br>
I have been trying to set up libtorch on centos8 as instructed on the installation guide provided by Pytorch. I have cuDNN 8 with 440.33 drivers and my cmake( version 3.1) looks like -</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(TorchTest)

set(CMAKE_PREFIX_PATH "/home/atharva/libtorch/libtorch/share/cmake/")
find_package(Torch REQUIRED)

add_executable(TorchTest main.cpp)
target_link_libraries(TorchTest /home/atharva/libtorch/libtorch/lib)
</code></pre>
<p>However, I run into the following error -</p>
<pre><code class="lang-auto">
-- Caffe2: CUDA detected: 10.2
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 10.2
-- Found cuDNN: v?  (include: /usr/include, library: /usr/lib64/libcudnn.so)
CMake Error at /home/atharva/libtorch/libtorch/share/cmake/Caffe2/public/cuda.cmake:170 (message):
  PyTorch requires cuDNN 7 and above.
Call Stack (most recent call first):
  /home/atharva/libtorch/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /home/atharva/libtorch/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/atharva/CLionProjects/TorchTest/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/home/atharva/CLionProjects/TorchTest/cmake-build-debug/CMakeFiles/CMakeError.log".
</code></pre>
<p>I have just started developing in c++ so this might be a very basic question…<br>
What could I be doing wrong,<br>
TIA</p>

username: ptrblck
cooked: <p>You might need to change these lines in <code>cmake/public/cuda.cmake</code> (or the C2 equivalent):</p>
<pre><code class="lang-auto">-  file(READ ${CUDNN_INCLUDE_PATH}/cudnn_version.h CUDNN_HEADER_CONTENTS)
+  if(EXISTS ${CUDNN_INCLUDE_PATH}/cudnn_version.h)
+    file(READ ${CUDNN_INCLUDE_PATH}/cudnn_version.h CUDNN_HEADER_CONTENTS)
+  else()
+    file(READ ${CUDNN_INCLUDE_PATH}/cudnn.h CUDNN_HEADER_CONTENTS)
+  endif()
</code></pre>

username: a_d
cooked: <p>Sorry for the late reply <a class="mention" href="/u/ptrblck">@ptrblck</a>… just saw the reply today, I replaced my stable downloads with the nightly and the CMake file contains exactly what you suggested. However, I get an error saying  -</p>
<pre><code class="lang-auto">-- Caffe2: CUDA detected: 10.2
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 10.2
-- Could NOT find CUDNN (missing: CUDNN_LIBRARY_PATH) 
CMake Warning at /home/atharva/libtorch/libtorch/share/cmake/Caffe2/public/cuda.cmake:109 (message):
  Caffe2: Cannot find cuDNN library.  Turning the option off
Call Stack (most recent call first):
  /home/atharva/libtorch/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /home/atharva/libtorch/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:5 (find_package)


-- Autodetected CUDA architecture(s):  7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
CMake Error at /home/atharva/libtorch/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/atharva/libtorch/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/atharva/CLionProjects/TorchTest/CMakeFiles/CMakeOutput.log".
See also "/home/atharva/CLionProjects/TorchTest/CMakeFiles/CMakeError.log".
</code></pre>
<p>My cuddn.h is in /usr/local/cuda/include and<br>
My cudnn.so and .a files are in /usr/local/cuda/lib64…</p>
<p>Do we need to provide any other option while running CMake ?<br>
TIA</p>

username: a_d
cooked: <p>I have cuda properly placed now, had wiped it out and reinstalled it again.<br>
So during Cmake compilation it detects libcudnn.so and says libcudnn7 or above required even though I have both libcudnn.so and libcudnn.so.8 in /cuda/lib64. To circumvent this I  changed this from a fatal error to a warning in cuda.cmake and cmake runs fine.<br>
However running make throws the error <code>fatal error: torch/torch.h: No such file or directory  #include &lt;torch/torch.h&gt;</code><br>
What could be going wrong??.<br>
CMakeLists.txt is -</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.16)
project(Pytorch_c__)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_PREFIX_PATH "/home/atharva/torch/torch/")
find_package(Torch REQUIRED)
add_executable(Pytorch_c__ main.cpp)
target_link_libraries(Pytorch_c__ "$(TORCH_LIBRARIES")
</code></pre>
<p>and cmake output is -</p>
<pre><code class="lang-auto">-- Caffe2: CUDA detected: 10.2
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 10.2
-- Found cuDNN: v?  (include: /usr/local/cuda/include, library: /usr/local/cuda/lib64/libcudnn.so)
-- PyTorch requires cuDNN 7 and above.
-- Autodetected CUDA architecture(s):  7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Configuring done
-- Generating done
-- Build files have been written to: /home/atharva/CLionProjects/Pytorch-c++
</code></pre>
<p>TIA</p>

username: a_d
cooked: <p>cudnn version might not be found in cudnn.h. In the cuda.cmake change cudnn.h to cudnn_version.h and caffe2 is able to find the cudnn version.</p>