Hi all,
I followed the tutorial of libtorch https://pytorch.org/cppdocs/installing.html 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:
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
My CMakeLists:
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)
The PC’s driver version: 550.127.08 and CUDA Version: 12.4.
I am new to c++ and libtorch and have no idea how to fix it. Any suggestions are appreciated! Thank you!