Libtorch for raspberry pi

Hi everyone do you have ever compile libtorch for raspberry pi 3 ?. Do you mind share it?

This should help -> PyTorch 1.3 wheels for Raspberry Pi (Python 3.7)

You’ll find the dynamic library in something like /home/pi/.local/lib/python3.7/site-packages/torch/lib, and the header files in /home/pi/.local/lib/python3.7/site-packages/torch/include/torch/csrc/api/include or / and /home/pi/.local/lib/python3.7/site-packages/torch/include.

@LeviViana Thankyou this is really helpful

1 Like

Hi,

Thanks for the locations. So on my pi, I have the header files installed in /Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch. I am using pytorch in a python environment. These are the following header files:
all.h data jit.h optim.h serialize.h arg.h data.h nn ordered_dict.h torch.h autograd.h detail nn.h python.h types.h cuda.h expanding_array.h optim serialize utils.h

So I ran the code here with the location to torch set to the location mentioned above. But I got the following error:

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!
See also "/home/pi/Desktop/sarvagya/cpp/dcgan/build/CMakeFiles/CMakeOutput.log".

What do you suggest I should do?

There should be a directory with cmake in torch/share or a subdir a few directories upthe hierarchy.

Best regards

Thomas

Hi,

According to this, I have set Torch_DIR to /python3.7/site-packages/torch/share/cmake/Torch which contains TorchConfig.cmake TorchConfigVersion.cmake.

But when I run cmake to /env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch, I get the error:

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!
See also "/home/pi/Desktop/sarvagya/cpp/dcgan/build/CMakeFiles/CMakeOutput.log".

It would look to me that the first path would put you more on the path (ha!) to success than the second. How are you invoking cmake?

Like this:
cmake -DCMAKE_PREFIX_PATH=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch ..

Yeah, that is the wrong prefix path.
I always use
Torch_DIR=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/share/cmake cmake ..
and that seems to work for me (well, I have a different path to python3.7, but the general idea).

1 Like

So, after this,

should I add
-DCMAKE_PREFIX_PATH=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch ..?

I don’t, but you do as you prefer.

I am asking because if I run this

I get this:

cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>
  cmake [options] -S <path-to-source> -B <path-to-build>

Specify a source directory to (re-)generate a build system for it in the
current working directory.  Specify an existing build directory to
re-generate its build system.

Run 'cmake --help' for more information.

And when I run

Torch_DIR=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/share/cmake cmake -DCMAKE_PREFIX_PATH=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch ..
I get this:

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!
See also "/home/pi/Desktop/sarvagya/cpp/dcgan/build/CMakeFiles/CMakeOutput.log".

Ah, right, the .. (where your CMakeLists.txt lies), needs to stay. And you might want to delete CMakeCache.txt and CMakeFiles.

What do you mean by “needs to stay”? Which command are you referring to?

CMake expects you to pass the directory of where the CMakeLists.txt lies as a parameter. I originally forgot to add that in my reply. This is the error message Specify a source directory you are seeing from CMake when you don’t do it.

So I tried to run cmake both the ways I mentioned above (after deleting CMakeCache.txt and CMakeFiles) and I got the same Torch_DIR error:

Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

So for me it works with the torch-dir as given (I did try before writing it), but you could also add the Torch subdir.

I was doing the clumsiest mistake out there. I was not putting the ~ before /Desktop in Torch_DIR. So it wasn’t able to get the full location. What a mistake.