Missing CUDA path

hello,

I wanted to try the C++ module of PyTorch and I started with the very introduction of the module.

I installed cxx11 ABI and ran the code as mentioned. However, I got this error:

CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) 
CMake Warning at /home/sarvagya/Desktop/libtorch/share/cmake/Caffe2/public/cuda.cmake:31 (message):
  Caffe2: CUDA cannot be found.  Depending on whether you are building Caffe2
  or a Caffe2 dependent library, the next warning / error will give you more
  info.
Call Stack (most recent call first):
  /home/sarvagya/Desktop/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /home/sarvagya/Desktop/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:4 (find_package)


CMake Error at /home/sarvagya/Desktop/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:90 (message):
  Your installed Caffe2 version uses CUDA but I cannot find the CUDA
  libraries.  Please set the proper CUDA prefixes and / or install CUDA.
Call Stack (most recent call first):
  /home/sarvagya/Desktop/libtorch/share/cmake/Torch/TorchConfig.cmake:40 (find_package)
  CMakeLists.txt:4 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/sarvagya/Desktop/cpp/dcgan/build/CMakeFiles/CMakeOutput.log".
See also "/home/sarvagya/Desktop/cpp/dcgan/build/CMakeFiles/CMakeError.log".

So I wanted to know how do I set CUDA variable.

I also wanted to ask one more thing. I have installed the cuda toolkit through anaconda for PyTorch. So if I set the environment variable to that CUDA, will it work?

You can try my module:


It will download libtorch automatically.
All you have to do is to change https://github.com/QuantScientist/PngTorch/blob/master/cmake_find/download_libtorch.cmake:
set(CUDA_V "cpu")
set(LIBTORCH_DEVICE "cpu")

#set(CUDA_V "10.2")
#set(LIBTORCH_DEVICE "cu102")

This is based on code from https://github.com/prabhuomkar/pytorch-cpp/

Best,

Hi,

Thanks for the reply. So if I mention "10.2", how does it find CUDA? Because as I mentioned, I don’t have raw CUDA installed but when I installed pytorch through anaconda, it installed cuda toolkit for that version. So can you clear this part for me?

I am not sure I follow:
Do you have a GPU or only a CPU?
Did you install CUDA + cuDNN from NVIDIA?

I have a GPU. But I haven’t installed CUDA from nvidia directly. I installed cuda through anaconda for PyTorch 1.6. Like this

I was able to solve this. I had to install raw CUDA ad cudnn from NVIDIA and follow the step. One extra step I did was to add cudnn_version.h to /usr/local/cuda/include/. Then run the cmake and it’ll work