Unable to build CUDA libtorch

BBBBBBob: <p>Hi all,</p>
<p>I followed the tutorial of libtorch <a href="https://pytorch.org/cppdocs/installing.html" rel="noopener nofollow ugc">https://pytorch.org/cppdocs/installing.html</a> but using a CUDA 12.4 version libtorch instead of CPU. However I failed to build the code using the CMakeLists provided by the tutorial and here is the error:</p>
<pre><code class="lang-auto">cmake -DCMAKE_PREFIX_PATH=/usr/include/libtorch ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found CUDA: /usr/local/cuda (found version "12.6") 
-- The CUDA compiler identification is NVIDIA 12.6.77
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Found CUDAToolkit: /usr/local/cuda/include (found version "12.6.77") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- 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  
-- Caffe2: CUDA detected: 12.6
-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
-- Caffe2: CUDA toolkit directory: /usr/local/cuda
-- Caffe2: Header version is: 12.6
-- Found Python: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
CMake Warning at /usr/include/libtorch/share/cmake/Caffe2/public/cuda.cmake:140 (message):
  Failed to compute shorthash for libnvrtc.so
Call Stack (most recent call first):
  /usr/include/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
  /usr/include/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:5 (find_package)


-- Could NOT find nvtx3 (missing: nvtx3_dir) 
CMake Warning at /usr/include/libtorch/share/cmake/Caffe2/public/cuda.cmake:180 (message):
  Cannot find NVTX3, find old NVTX instead
Call Stack (most recent call first):
  /usr/include/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:86 (include)
  /usr/include/libtorch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:5 (find_package)


-- USE_CUDNN is set to 0. Compiling without cuDNN support
-- USE_CUSPARSELT is set to 0. Compiling without cuSPARSELt support
-- USE_CUDSS is set to 0. Compiling without cuDSS support
-- USE_CUFILE is set to 0. Compiling without cuFile support
-- Autodetected CUDA architecture(s):  7.5 7.5
-- Added CUDA NVCC flags for: -gencode;arch=compute_75,code=sm_75
-- Found Torch: /usr/include/libtorch/lib/libtorch.so  
-- Configuring done
-- Generating done
</code></pre>
<p>My CMakeLists:</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

project(libtorch_example)

find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

add_executable(example example.cpp)
target_link_libraries(example "${TORCH_LIBRARIES}")
set_property(TARGET example PROPERTY CXX_STANDARD 17)
</code></pre>
<p>The PC’s driver version: 550.127.08 and CUDA Version: 12.4.</p>
<p>I am new to c++ and libtorch and have no idea how to fix it. Any suggestions are appreciated! Thank you!</p>

ptrblck: <p>What’s the error? It seems the config step was done so did you try to build it afterwards?</p>

BBBBBBob: <aside class="quote no-group" data-username="BBBBBBob" data-post="1" data-topic="213850">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/b/439d5e/48.png" class="avatar"> BBBBBBob:</div>
<blockquote>
<p><code> Failed to compute shorthash for libnvrtc.so</code></p>
</blockquote>
</aside>
<p>Hi, the errors seem to be <code>Failed to compute shorthash for libnvrtc.so</code> and <code>Cannot find NVTX3, find old NVTX instead</code>, how can I fix them? But as you said I build it afterwards and it successed. Thank you!</p>

weitaoliu: <p>Hey,</p>
<blockquote>
<p><code>Failed to compute shorthash for libnvrtc.so</code></p>
</blockquote>
<p>this should not affect the compiling and it is that CMake does not recognize “Python::Interpreter”.</p>
<p>Regarding the “NVTX3”, you can find the solution at <a href="https://discuss.pytorch.org/t/libtorch-cannot-find-nvtx3-find-old-nvtx-instead/213641/2" class="inline-onebox">Libtorch, Cannot find NVTX3, find old NVTX instead - #2 by weitaoliu</a>.</p>
<p>Also, according to your log, the CUDA version is 12.6 not 12.4.</p>
<p>Best, Weitao.</p>

BBBBBBob: <p>Thank you Weitao. I thought it was an error but turned out to be fine. Anyway thank you for your help!</p>