I’ve successfully installed PyTorch v1.10.0 on my Nvidia Jetson but I would like to use the C++ / Libtorch portion of the install.
The “wheels” specifically for the Nvidia Jetsons are here
On my Jetson (AGX Xavier) I believe Libtorch is installed in this path
~/.local/lib/python3.6/site-packages/torch/lib
But I don’t know how to make use of anything in this path. I would like to use it to run a Libtorch script in C++. This is a list of all the files in that path.
libbackend_with_compiler.so, libcaffe2_detectron_ops_gpu.so, libcaffe2_observers.so, libtorchbind_test.so, libtorch_global_deps.so, libc10_cuda.so, libcaffe2_module_test_dynamic.so, libjitbackend_test.so, libtorch_cpu.so libtorch_python.so, libc10.so, libcaffe2_nvrtc.so, libshm.so, libtorch_cuda.so, libtorch.so
Could I specifically use the libtorch.so
to compile my LibTorch script somehow?
Below: I’m simply trying to compile the example script for Libtorch from the official site
I am following the instructions on the page exactly and for /absolute/path/to/libtorch I put the path I mentioned above, ~/.local/lib/python3.6/site-packages/torch/lib.
I need to build the Libtorch script with cmake and I’m getting the error…
$ cmake -DCMAKE_PREFIX_PATH=/home/jet/.local/lib/python3.6/site-packages/torch/lib ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:4 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
Could not find a package configuration file provided by "Torch" with any of
the following names:
TorchConfig.cmake
torch-config.cmake
Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
"Torch_DIR" to a directory containing one of the above files. If "Torch"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
This is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example-app)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET example-app
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:example-app>)
endif (MSVC)