Libtorch for raspberry pi

username: Kiki_Rizki_Arpiandi
cooked: <p>Hi everyone do you have ever compile libtorch for raspberry pi 3 ?. Do you mind share it?</p>

username: LeviViana
cooked: <p>This should help -&gt; <a href="https://discuss.pytorch.org/t/pytorch-1-3-wheels-for-raspberry-pi-python-3-7/58580" class="inline-onebox">PyTorch 1.3 wheels for Raspberry Pi (Python 3.7)</a></p>
<p>You’ll find the dynamic library in something like <code>/home/pi/.local/lib/python3.7/site-packages/torch/lib</code>, and the header files in <code>/home/pi/.local/lib/python3.7/site-packages/torch/include/torch/csrc/api/include</code> or / and <code>/home/pi/.local/lib/python3.7/site-packages/torch/include</code>.</p>

username: Kiki_Rizki_Arpiandi
cooked: <p><a class="mention" href="/u/leviviana">@LeviViana</a> Thankyou this is really helpful</p>

username: Flock1
cooked: <p>Hi,</p>
<p>Thanks for the locations. So on my pi, I have the header files installed in <code>/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch</code>. I am using pytorch in a python environment. These are the following header files:<br>
<code>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</code></p>
<p>So I ran the code <a href="https://pytorch.org/tutorials/advanced/cpp_frontend.html" rel="noopener nofollow ugc">here</a> with the location to torch set to the location mentioned above. But I got the following error:</p>
<pre><code class="lang-auto">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".
</code></pre>
<p>What do you suggest I should do?</p>

username: tom
cooked: <p>There should be a directory with cmake in torch/share or a subdir a few directories upthe hierarchy.</p>
<p>Best regards</p>
<p>Thomas</p>

username: Flock1
cooked: <p>Hi,</p>
<p>According to <a href="https://github.com/pytorch/pytorch/issues/12449#issuecomment-623581992" rel="noopener nofollow ugc">this</a>, I have set <code>Torch_DIR</code> to <code>/python3.7/site-packages/torch/share/cmake/Torch</code> which contains <code>TorchConfig.cmake  TorchConfigVersion.cmake</code>.</p>
<p>But when I run cmake to <code>/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch</code>, I get the error:</p>
<pre><code class="lang-auto">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".
</code></pre>

username: tom
cooked: <aside class="quote no-group" data-username="Flock1" data-post="8" data-topic="63107">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/flock1/48/12220_2.png" class="avatar"> Flock1:</div>
<blockquote>
<p>According to <a href="https://github.com/pytorch/pytorch/issues/12449#issuecomment-623581992" rel="noopener nofollow ugc">this</a>, I have set <code>Torch_DIR</code> to <code>/python3.7/site-packages/torch/share/cmake/Torch</code> which contains <code>TorchConfig.cmake  TorchConfigVersion.cmake</code> .</p>
<p>But when I run cmake to <code>/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch</code> , I get the error:</p>
</blockquote>
</aside>
<p>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?</p>

username: Flock1
cooked: <p>Like this:<br>
<code>cmake -DCMAKE_PREFIX_PATH=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch ..</code></p>

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

username: Flock1
cooked: <p>So, after this,</p>
<aside class="quote no-group" data-username="tom" data-post="11" data-topic="63107">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/48/3162_2.png" class="avatar"> tom:</div>
<blockquote>
<p>Torch_DIR=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/share/cmake cmake</p>
</blockquote>
</aside>
<p>should I add<br>
<code>-DCMAKE_PREFIX_PATH=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/include/torch/csrc/api/include/torch ..</code>?</p>

username: tom
cooked: <p>I don’t, but you do as you prefer.</p>

username: Flock1
cooked: <p>I am asking because if I run this</p>
<aside class="quote no-group" data-username="tom" data-post="11" data-topic="63107">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/48/3162_2.png" class="avatar"> tom:</div>
<blockquote>
<p>Torch_DIR=/Desktop/sarvagya/project_folder/env/lib/python3.7/site-packages/torch/share/cmake cmake</p>
</blockquote>
</aside>
<p>I get this:</p>
<pre><code class="lang-auto">cmake [options] &lt;path-to-source&gt;
  cmake [options] &lt;path-to-existing-build&gt;
  cmake [options] -S &lt;path-to-source&gt; -B &lt;path-to-build&gt;

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.
</code></pre>
<p>And when I run</p>
<p><code>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 ..</code><br>
I get this:</p>
<pre><code class="lang-auto">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".
</code></pre>

username: tom
cooked: <p>Ah, right, the <code>..</code> (where your CMakeLists.txt lies), needs to stay. And you might want to delete CMakeCache.txt and CMakeFiles.</p>

username: Flock1
cooked: <p>What do you mean by “needs to stay”? Which command are you referring to?</p>

username: tom
cooked: <p>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 <code>Specify a source directory</code> you are seeing from CMake when you don’t do it.</p>

username: Flock1
cooked: <p>So I tried to run <code>cmake</code> both the ways I mentioned above (after deleting <code>CMakeCache.txt</code> and <code>CMakeFiles</code>) and I got the same <code>Torch_DIR</code> error:</p>
<pre><code class="lang-auto">Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake
</code></pre>

username: tom
cooked: <p>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.</p>

username: Flock1
cooked: <p>I was doing the clumsiest mistake out there. I was not putting the <code>~</code> before <code>/Desktop</code> in <code>Torch_DIR</code>. So it wasn’t able to get the full location. What a mistake.</p>