Crosscompilation for arm64

Peter_Peter: <p>I’m looking for a way to compile (install) pytorch for arm64 platform and as of now I’m not interesting of optimized (GPU-like) version of pytorch, it’s good enough to have CPU version able to run on ARM device. Please can you advice how can I either compile or install such a version of pytorch?<br>
In my case I do not have CUDA available on device but instead I have OpenCL 1.2 FP.</p>

SimonW: <p>I think you can just compile with <code>NO_CUDA=1</code>. Could you try it and see if there is any error?</p>

Peter_Peter: <p>I would love too, but is there install dependencies ? Since my platfrom ti’s kind of minimal on packages …</p>

SimonW: <p>Yes, you would need <code>numpy pyyaml mkl setuptools cmake cffi</code></p>

Peter_Peter: <aside class="quote no-group" data-username="SimonW" data-post="4" data-topic="9885">
<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/simonw/48/1702_2.png" class="avatar"> SimonW:</div>
<blockquote>
<p>mkl</p>
</blockquote>
</aside>
<p>Is it mkl library for arm architecture? Isn’t Intel lib?</p>

SimonW: <p>Right, you can skip that. Sorry I just copied + pasted from Github install page without checking. <img src="//discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=5" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

NikhilKanda: <p>I’m wondering to know if there’s a way to cross compile Pytorch on Allwinner platform (AArch64 processor). Leads are greatly appreciated.</p>
<p>Also <a class="mention" href="/u/peter_peter">@Peter_Peter</a>, I presume that you’ve compiled or installed pytorch on arm64 by now. Could you please post the steps you have followed for the same?</p>
<p>TIA</p>

smth: <p><a class="mention" href="/u/nikhilkanda">@NikhilKanda</a> this is the script I used to compile on AGX Xavier which is an ARM64 platform: <a href="https://gist.github.com/soumith/45f61db3379db67414814ad9d5f2a427" rel="nofollow noopener">https://gist.github.com/soumith/45f61db3379db67414814ad9d5f2a427</a></p>

NikhilKanda: <p>Hi <a class="mention" href="/u/smth">@smth</a>. Thanks for the info, but I hope that is not cross compilation. Correct me if I’m wrong</p>

smth: <p>oh, sorry yes this is not cross-compilation.</p>
<p>I dont think all parts of our build system are even ready for cross-compilation</p>

dinesh_mareedu: <p>Can you give me any information about cross compilation of pytorch …</p>

solvingPuzzles: <p>I haven’t tried this, but the following tutorial looks relevant:</p>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://lightning.svbtle.com/cargo/favicon-5ed3591b57f6a4f0d5cb82c6680b33bb1058fe757c71ccb094952824e7e00b17.ico" class="site-icon" width="15" height="15">
      <a href="https://nmilosev.svbtle.com/compling-arm-stuff-without-an-arm-board-build-pytorch-for-the-raspberry-pi" target="_blank" rel="nofollow noopener">nmilosev on Svbtle</a>
  </header>
  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:124/108;"><img src="https://svbtleusercontent.com/9C6eBNC9wovR79WL9augjj0xspap.png" class="thumbnail"></div>

<h3><a href="https://nmilosev.svbtle.com/compling-arm-stuff-without-an-arm-board-build-pytorch-for-the-raspberry-pi" target="_blank" rel="nofollow noopener">Compling ARM stuff without an ARM board / Build PyTorch for the Raspberry Pi...</a></h3>

<p>I am in the process of building a self-driving RC car. It’s a fun process full of discovery (I hate it already). Once it is finished I hope to write a longer article here about what I learned so stay tuned! While the electronics stuff was... |...</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


Tumb1eweed: <p>met the same problem, need to cross compile libtorch for arm64 in x86-64 platform, is there any resources about this?</p>

Tchamp: <p>To build libtorch you can follow these instructions:</p><aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/master/docs/libtorch.rst</a></h4>


      <pre><code class="lang-rst">libtorch (C++-only)
===================

The core of pytorch does not depend on Python. A
CMake-based build system compiles the C++ source code into a shared
object, libtorch.so.

Building libtorch using Python
------------------------------

You can use a python script/module located in tools package to build libtorch
::
   cd &lt;pytorch_root&gt;

   # Make a new folder to build in to avoid polluting the source directories
   mkdir build_libtorch &amp;&amp; cd build_libtorch

   # You might need to export some required environment variables here.
   Normally setup.py sets good default env variables, but you'll have to do
   that manually.
</code></pre>



  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Personally, I only use CMake for cross-compiling and add a -DCMAKE_TOOLCHAIN_FILE=&lt;path to your cmake toolchain&gt; argument</p>
<p>If you have problems with binaries like mkrename mkdisp mkalias or addSuffix, you will have to compile sleef with your x86_64 compiler and then add for libtorch the cmake argument : -DNATIVE_BUILD_DIR=&lt;path to native sleef build&gt;.</p>

Jesse_Stone: <p>full build step cross compile on arm64</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://fatalfeel.blogspot.com/2013/12/libtorch-cross-compile-on-aarch64-linux.html">
  <header class="source">
      <img src="https://fatalfeel.blogspot.com/favicon.ico" class="site-icon" width="32" height="32">

      <a href="https://fatalfeel.blogspot.com/2013/12/libtorch-cross-compile-on-aarch64-linux.html" target="_blank" rel="noopener nofollow ugc">fatalfeel.blogspot.com</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://fatalfeel.blogspot.com/2013/12/libtorch-cross-compile-on-aarch64-linux.html" target="_blank" rel="noopener nofollow ugc">libtorch cross compile on aarch64-linux-gnu-gcc include backward</a></h3>

  <p> Refer to: https://github.com/pytorch/pytorch#get-the-pytorch-source https://github.com/pytorch/pytorch/blob/master/docs/libtorch.rst https:...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


mavs: <p>Hi, i wonder if the build system is ready for cross-compilation now, and my terget is Jetson TX2, i’d like to cross compiling libtorch, thx.</p>

mavs: <p>Hi, i followed the steps but always encounter the cmake warning ’ Could Not find CUDA(missing:CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY)'. Then the USE_CUDA was forced to be OFF, and the output of cross compilation was just libtorch_cpu.so and so on, but no libtorch_cuda.so. Could you give more cross compilation information, thx.</p>