Problems with LAPACK on iOS

kulikovv: <p>Hello!<br>
I’m trying to run my model on <strong>iOS</strong> and encounter a problem with <strong>LibTorch</strong>. The problem is in the call of <strong>SVD</strong> function.</p>
<p>The following code:</p>
<pre><code class="lang-auto">#import &lt;torch/script.h&gt;
#import &lt;ATen/Functions.h&gt;
at::Tensor tensor = torch::ones({3,3});
auto result = at::svd(tensor);
</code></pre>
<p>crushes with error as execution time:</p>
<pre><code class="lang-auto">svd: LAPACK library not found in compilation (apply_svd at /Users/distiller/project/aten/src/ATen/native/BatchLinearAlgebra.cpp:935)
(no backtrace available)
</code></pre>
<p>Any thoughts would be appreciated!</p>

albanD: <p>Hi,</p>
<p>I am not very familiar with the iOS build system. Did you built libtorch from source yourself?</p>
<p>The error comes from the fact that there were no linear algebra library found at compile time and so linear algebra functions (svd, eig, etc) are not available.</p>

kulikovv: <aside class="quote no-group" data-username="albanD" data-post="2" data-topic="69240">
<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/alband/48/215_2.png" class="avatar"> albanD:</div>
<blockquote>
<p>The error comes from the fact that there were no linear algebra library found at compile time and so linear algebra functions (svd, eig, etc) are not available.</p>
</blockquote>
</aside>
<p>Thanks for your reply! No, I’ve followed the tutorial <a href="https://pytorch.org/mobile/ios/" class="inline-onebox" rel="noopener nofollow ugc">iOS | PyTorch</a></p>

albanD: <p>Interesting. I don’t see any good reason why the official binary was not compiled with Lapack…<br>
Let’s wait for some mobile people to shed some light.</p>
<p>In the meantime. If you want, you can try to compile from source using the instructions from that link. And double check that during the compilation, your lapack library (the native apple one should be good) is properly detected and used.</p>

xta0: <p>Hi <a class="mention" href="/u/kulikovv">@kulikovv</a>,</p>
<p>We didn’t compile LAPACK into our binary. However, since LAPCK is supported by the Accelerate.framework on iOS. You can manually enable it by following the steps below</p>
<ol>
<li>Add a compiler flag - <code>CMAKE_ARGS+=("-DUSE_LAPACK=ON")</code> in <code>build_ios.sh</code> to tell cmake to compile LAPACK.</li>
<li>Follow the tutorial to run the build script and setup your project</li>
<li>Link Accelerate.framework to your project</li>
</ol>
<p>Let me know if it works for you. Thanks.</p>

kulikovv: <p>Thanks! It solved my problem!</p>

Jonson: <p>Hi, I got the same problem in android platfrom, do you have any suggestions? really thanks!</p>

onlyliucat: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/4/34354ff18220a34b9fc87ad1756bde9fd5ccd940.png" data-download-href="https://discuss.pytorch.org/uploads/default/34354ff18220a34b9fc87ad1756bde9fd5ccd940" title="WeChat5518849ccb92b8a036a0c3b96421a6ac"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/4/34354ff18220a34b9fc87ad1756bde9fd5ccd940_2_690x446.png" alt="WeChat5518849ccb92b8a036a0c3b96421a6ac" data-base62-sha1="7rR34fOOUTQUJDtp74yBlIww43S" width="690" height="446" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/4/34354ff18220a34b9fc87ad1756bde9fd5ccd940_2_690x446.png, https://discuss.pytorch.org/uploads/default/optimized/3X/3/4/34354ff18220a34b9fc87ad1756bde9fd5ccd940_2_1035x669.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/3/4/34354ff18220a34b9fc87ad1756bde9fd5ccd940.png 2x" data-dominant-color="4C4C4C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">WeChat5518849ccb92b8a036a0c3b96421a6ac</span><span class="informations">1152×745 139 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div>   , I.ve add the flag<br>
CMAKE_ARGS+=(“-DUSE_LAPACK=ON”) , but I get the error like in the picture , it.s likes lack of LAPACK  lib’s error.  How I fix this error ? thanks ! <img src="https://discuss.pytorch.org/images/emoji/apple/nauseated_face.png?v=12" title=":nauseated_face:" class="emoji" alt=":nauseated_face:" loading="lazy" width="20" height="20">  I want to build IOS Pytorch lib , use the command : BUILD_PYTORCH_MOBILE=1 IOS_ARCH=arm64 ./scripts/build_ios.sh</p>

yingbo: <p>I got the similar error when I built for the android with LAPACK, PyTorch version 1.9.</p>

cccclai: <p><a class="mention" href="/u/ivankobzarev">@IvanKobzarev</a> do you know the solution in Android?</p>