Error in cmake while setting up libtorch

Hello all,
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 -

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)

However, I run into the following error -


-- 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".

I have just started developing in c++ so this might be a very basic question…
What could I be doing wrong,
TIA

You might need to change these lines in cmake/public/cuda.cmake (or the C2 equivalent):

-  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()

Sorry for the late reply @ptrblck… 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 -

-- 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".

My cuddn.h is in /usr/local/cuda/include and
My cudnn.so and .a files are in /usr/local/cuda/lib64…

Do we need to provide any other option while running CMake ?
TIA

I have cuda properly placed now, had wiped it out and reinstalled it again.
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.
However running make throws the error fatal error: torch/torch.h: No such file or directory #include <torch/torch.h>
What could be going wrong??.
CMakeLists.txt is -

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")

and cmake output is -

-- 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++

TIA

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.

1 Like