How to build libtorch for aarch64?

heethesh: <p>What is the right way to cross-compile libtorch for aarch64 target on an amd64 Linux host?</p>
<p>I’m currently using <code>tools/build_libtorch.py</code>, however, when I try to use this library to build my C++ code using, <code>cmake -DCMAKE_PREFIX_PATH=/path/to/build_libtorch ..</code>, I get errors regarding missing header files and <code>libcaffe2_gpu.so</code>.</p>
<p>Is there a script or a tutorial that would help organize the libtorch library similar to the structure released on the downloads page?</p>
<pre><code class="lang-auto">libtorch/
  bin/
  include/
  lib/
  share/
</code></pre>

tom: <p>You might try to follow the route android takes, providing a CMAKE_TOOLCHAIN_FILE and you might need a host protobuf, see scripts/build_android.sh for inspiration.<br>
I will admit that I did not try but build natively on aarch64 for the time being…</p>
<p>Best regards</p>
<p>Thomas</p>

Kiki_Rizki_Arpiandi: <p>Any update on this I tray to built it myself too, I got an error when I try simple c++ example from the official website</p>

tom: <p>So this has two parts:</p>
<ol>
<li>Build libtorch on aarch64,</li>
<li>build libtorch on Android.</li>
</ol>
<p>Which one are you most interested in?</p>
<p>For 1) you can build PyTorch natively on the largest Raspberry Pi 4 or NVidia Jetsons pretty much by running setup.py. The caveat is that the build may (will) crash with out of memory if you run with -j4. My solution to that has been to then build the large C++ with -j1 and afterwards continue with -j4. More fancy things like distcc probably get better results yet.</p>
<p>For 2) check out the <a href="https://pytorch.org/mobile/android/#building-pytorch-android-from-source" rel="nofollow noopener">Pytorch mobile build instructions</a>.</p>
<p>Best regards</p>
<p>Thomas</p>

Kiki_Rizki_Arpiandi: <p>Thanks for your response Tom, Finally I make it work on Jetson Nano, by just using <code>python3 setup.py install</code> . The problem was I built libtorch without cxx 11 abi activated. I reinstall it with cxx 11 abi = 1, run <code>/usr/bin/jetson_clock</code> and I used 1G swap file. <strong>works like charm</strong>, no crash, it took about 12 hours to complete</p>

Alio: <p>Would it be possible for you to leave a few more breadcrumbs about how you did this?<br>
There is very written about how to get LibTorch on a Jetson.</p>
<p>You wrote</p>
<blockquote>
<p>using <code>python3 setup.py install</code> . The problem was I built libtorch without cxx 11 abi activated</p>
</blockquote>
<p>Would it be possible for you to post the contents if you still have these files with your modifications?</p>

Jesse_Stone: <p>here are full build steps using cross compile tool aarch64 g++<br>
<a href="https://fatalfeel.blogspot.com/2013/12/libtorch-cross-compile-on-aarch64-linux.html" rel="noopener nofollow ugc">https://fatalfeel.blogspot.com/2013/12/libtorch-cross-compile-on-aarch64-linux.html</a></p>
<p>Demo:<br>
<a href="https://www.mediafire.com/view/1zgp44v08n7tpj6/libtorch_build_ok.png" rel="noopener nofollow ugc">https://www.mediafire.com/view/1zgp44v08n7tpj6/libtorch_build_ok.png</a><br>
<a href="https://www.mediafire.com/view/fdwap6ldb8zl6w0/torchvision.png" rel="noopener nofollow ugc">https://www.mediafire.com/view/fdwap6ldb8zl6w0/torchvision.png</a></p>

mavs: <p>Hi, I follow your blog and tried to cross compile to aarch64, then i could not achieve the same result:</p>
<ol>
<li>i could not get libtorch_cuda.so after following your instruction to cross compile pytorch source code, just got lictorch_cpu.so and other so files.</li>
<li>after then i changed USE_CUDA=ON &amp; USE_CUDNN=ON, i met some cmake errors.<br>
could you provide more help, and my target is Jetson TX2, thx.</li>
</ol>

Jesse_Stone: <p>I use ubuntu 16.04, root login<br>
cuda_10.2.89_440.33.01_linux ,<br>
cuda_10.2.1_linux,<br>
cuda_10.2.2_linux<br>
libcudnn8_8.0.5.39-1+cuda10.2_amd64<br>
libcudnn8-dev_8.0.5.39-1+cuda10.2_amd64<br>
libcudnn8-samples_8.0.5.39-1+cuda10.2_amd64</p>
<p>driver use data center version:<br>
NVIDIA-Linux-x86_64-440.118.02</p>
<p>cmake 3.20.5</p>

ptrblck: <p>CUDA 10 is not supported in recent PyTorch releases anymore so you might need to update to 11.4 or newer if you want to build from source.</p>