Pytorch Build "almost" succeeds but fails | Undefined symbols for architecture x86_64 __cvtu32_mask16

username: Stevers
cooked: <p>I am also getting this from a clean git clone.  I am using MacOS (Mojave 10.14.6) and I just updated xcode to the latest version.</p>
<p>I did a fresh git clone of pytorch repostiory and started following the README directions. This is what I got:</p>
<pre><code class="lang-auto">Undefined symbols for architecture x86_64: "__cvtu32_mask16", referenced from: _xnn_f32_clamp_ukernel__avx512f in libXNNPACK.a(avx512f.c.o) _xnn_f32_dwconv_ukernel_up16x25__avx512f in libXNNPACK.a(up16x25-avx512f.c.o) _xnn_f32_dwconv_ukernel_up16x4__avx512f in libXNNPACK.a(up16x4-avx512f.c.o) _xnn_f32_dwconv_ukernel_up16x9__avx512f in libXNNPACK.a(up16x9-avx512f.c.o)
</code></pre>
<p>Here’s the exact order of what I did following the fresh <code>git clone</code>.</p>
<pre><code class="lang-auto">conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi
	# Omitted `typing` because I’m on Python 3.7
git submodule sync
git submodule update --init —recursive
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../“}
USE_CUDA=0 MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ python setup.py install
</code></pre>
<p>Clang</p>
<pre><code class="lang-auto">clang --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
</code></pre>
<p>GCC (same as clang)</p>
<pre><code class="lang-auto">gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
</code></pre>

username: albanD
cooked: <p>Can you try disabling the xnnpack build by setting <code>USE_XNNPACK=0</code> ?</p>

username: Stevers
cooked: <p>Thanks for the reply!</p>
<p>That did not fix it.</p>
<p>I stumbled upon this <a href="https://clang.llvm.org/doxygen/avx512fintrin_8h.html#ad07632aafd0a306bb4151e3a17b8313b" rel="nofollow noopener">documenation</a> from Doxygen, which I’m aware Pytorch uses per <strong>CONTRIBUTING.md</strong></p>
<p>You can see the <code>_cvtu32_mask16</code> function is specified there.</p>
<p>This is definitely beyond my realm of expertise &gt;&lt;.  I commented on an issue on the github project but I wasn’t sure if that was the right place. It appears someone else is getting the same issue and it happened very recently.</p>

username: zw19906
cooked: <p>Could you share the link to the issue where you have commented. I have the same issue when building on macOS 10.13 but it looks fine on macOS 10.15.</p>

username: zw19906
cooked: <p>I believe I have figured out why.</p>
<p>The documentation where you found <code>_cvtu32_mask16</code> indicates that <code>_cvtu32_mask16</code> is an llvm(clang) function. And the error message indicates it was XNNPACK that is linking this function.</p>
<p>So I dive into the XNNPACK source code and found this line: <a href="https://github.com/google/XNNPACK/blob/master/src/xnnpack/intrinsics-polyfill.h#L36" rel="nofollow noopener">https://github.com/google/XNNPACK/blob/master/src/xnnpack/intrinsics-polyfill.h#L36</a></p>
<p>When I checkout pytorch tags/v1.5.0, the same line says Apple Clang pre-<strong>10</strong> so the judgement is <code>(__apple_build_version__ &lt; 10000000)</code>. In this way, XNNPACK does not define its own <code>_cvtu32_mask16</code> implementation but refer it to clang, tries to link it finally and failed because the clang installed on macOS 10.13/10.14 does not have <code>_cvtu32_mask16</code> implemented in its libraries.</p>
<p>That also explains why macOS 10.15 works because the clang version on macOS 10.15 is 11.</p>

username: llv22
cooked: <aside class="quote no-group" data-username="zw19906" data-post="5" data-topic="73000">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/z/ea666f/48.png" class="avatar"> zw19906:</div>
<blockquote>
<p>_cvtu32_mask16</p>
</blockquote>
</aside>
<p>so can we compile clang 11 on macOSX 10.13.6, then use this for compilation?<br>
From my point of view, this can be a simple approach to avoid side effect. Any other suggestion?<br>
Because I really want to strive out on 10.13.6 with portable GPU.</p>

username: llv22
cooked: <p><a class="mention" href="/u/zw19906">@zw19906</a> <a class="mention" href="/u/stevers">@Stevers</a>  sorry for late response, I figured out how to build torch on macOS 10.13.6 + CUDA 10.1(update 2) + cudnn 7.6.5.<br>
Just summarize in <a href="https://github.com/pytorch/pytorch/issues/46803" rel="noopener nofollow ugc">pytorch/pytorch#46803</a> and <a href="https://github.com/google/XNNPACK/issues/1081" rel="noopener nofollow ugc">google/XNNPACK#1081</a> for your reference. But,  honestly speaking, I thought XNNPACK might have more potential bugs for code generation template. Anyway make torch building for avx passing…</p>