Missing CUDA path

username: Flock1
cooked: <p>hello,</p>
<p>I wanted to try the C++ module of PyTorch and I started with the very introduction of the <a href="https://pytorch.org/tutorials/advanced/cpp_frontend.html" rel="nofollow noopener">module</a>.</p>
<p>I installed <code>cxx11 ABI</code> and ran the code as mentioned. However, I got this error:</p>
<pre><code class="lang-auto">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".
</code></pre>
<p>So I wanted to know how do I set CUDA variable.</p>
<p>I also wanted to ask one more thing. I have installed the <code>cuda toolkit</code> through anaconda for PyTorch. So if I set the environment variable to that CUDA, will it work?</p>

username: dambo
cooked: <p>You can try my module:<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="16" height="16">
      <a href="https://github.com/QuantScientist/PngTorch" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars1.githubusercontent.com/u/18743986?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/QuantScientist/PngTorch" target="_blank" rel="nofollow noopener">QuantScientist/PngTorch</a></h3>

<p>An integration of the libpng /png++ libraries with the Libtorch C++ Deep Learning Library.  - QuantScientist/PngTorch</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
It will download libtorch automatically.<br>
All you have to do is to change <a href="https://github.com/QuantScientist/PngTorch/blob/master/cmake_find/download_libtorch.cmake:" rel="nofollow noopener">https://github.com/QuantScientist/PngTorch/blob/master/cmake_find/download_libtorch.cmake:</a>
<pre><code class="lang-auto">set(CUDA_V "cpu")
set(LIBTORCH_DEVICE "cpu")

#set(CUDA_V "10.2")
#set(LIBTORCH_DEVICE "cu102")
</code></pre>
<p>This is based on code from <a href="https://github.com/prabhuomkar/pytorch-cpp/" rel="nofollow noopener">https://github.com/prabhuomkar/pytorch-cpp/</a></p>
<p>Best,</p>

username: Flock1
cooked: <p>Hi,</p>
<p>Thanks for the reply. So if I mention <code>"10.2"</code>, 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?</p>

username: dambo
cooked: <p>I am not sure I follow:<br>
Do you have a GPU or only a CPU?<br>
Did you install CUDA + cuDNN from NVIDIA?</p>

username: Flock1
cooked: <p>I have a GPU.  But I haven’t installed CUDA from nvidia directly. I installed cuda through anaconda for PyTorch 1.6. Like <a href="https://pytorch.org/get-started/locally/#start-locally" rel="nofollow noopener">this</a></p>

username: Flock1
cooked: <p>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 <code>cudnn_version.h</code> to <code>/usr/local/cuda/include/</code>. Then run the <code>cmake</code> and it’ll work</p>