I’ve been trying to get Libtorch to run on my Jetson Nano, but with no success so far. I have a docker container built from l4t-pytorch:r32.4.4-pth1.6-py3 (which matches the jetpack version on my nano).
When I try compiling my C++ code (with catkin as I’m using it for a ROS melodic package), I get an error that Torch cannot be found:
Could not find a package configuration file provided by "Torch" with any of
the following names:
CMake Error at /usr/local/lib/python3.6/dist-packages/torch/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.
On my desktop version I had the same problem and I solved it by installing libtorch C++ API directly and adding its path to the CMAKE_PATH. How can I solve this on the Jetson?
Could the reason be that ROS melodic requires python 2 while I’m adding the python3 pytorch path to CMAKE?
EDIT: I tried building a mock ROS example (while using --runtime nvidia in the same container) but that does not depend on torch and it compiled successfully.
It seems more likely now that the problem is in the interaction between ROS melodic and pytorch. On my desktop I’ve successfully compiled the package by installing the libtorch C++ API directly and linking to it. However, as the Jetson is using an ARM64 architecture I cannot find a precompiled libtorch C++ for it (only the python wheels).
@vassil17 libtorch is included with the PyTorch wheel (e.g. under /usr/local/lib/python3.8/dist-packages/torch/lib)
Yea, my guess it’s having trouble finding it given that Melodic uses Python 2 whereas libtorch is installed under a Python 3 path. I’m not sure how to fix that, but presumably you could manually add the libtorch path to CMake.
It’s probably also worth mentioning that ROS Melodic is EOL, and should you be able to use Noetic, you could use dustynv/ros:noetic-pytorch-l4t-r32.7.1 from jetson-containers which already has PyTorch installed on top of ROS Noetic.
I wonder if when you add the libtorch path, it is overwriting other paths that ROS environment may have set, as opposed to appending it? Although from this post, it appears that you are pre-pending it. Honestly I’m not sure why that happens, and I don’t personally use PyTorch with Melodic due to the aforementioned Python incompatibility.
I believe it’s with the CXX11 ABI version (at least on my system with JetPack 4.6 and PyTorch 4.6 it was)
You can check this by checking the torch/share/cmake/Torch/TorchConfig.cmake file under the directory in which your PyTorch wheel was installed to: