ARM-software / ComputeLibrary

The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
MIT License
2.84k stars 776 forks source link

WOA native building error (Exception 0xC0000005 with CpuElementwiseUnaryKernel.cpp) #1137

Open xengpro opened 2 months ago

xengpro commented 2 months ago

Output of 'strings libarm_compute.so | grep arm_compute_version':

Platform: Snapdragon 8cx Gen 3/ X Elite X1E78100

Operating System: Windows 11 (23h2/24h2)

Problem description: I've tried to build by following the guide from: https://arm-software.github.io/ComputeLibrary/latest/how_to_build.xhtml#S1_6_windows_host, but failed with error like:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang-cl @C:\\Users\\xeng\\AppData\\Local\\Temp\\tmpdeamyx7s.lnk
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'src\cpu\kernels\CpuElementwiseUnaryKernel.cpp'.
4.      Running pass 'AArch64 Instruction Selection' on function '@"?validate@CpuElementwiseUnaryKernel@kernels@cpu@arm_compute@@SA?AVStatus@4@W4ElementWiseUnary@4@AEBVITensorInfo@4@1@Z"'
Exception Code: 0xC0000005
#0 0x00007ff7aadc9f14 (C:\Program Files\LLVM\bin\clang-cl.exe+0x1829f14)
#1 0x00007ff7aadc88a0 (C:\Program Files\LLVM\bin\clang-cl.exe+0x18288a0)
#2 0x00007ff7aadc6a54 (C:\Program Files\LLVM\bin\clang-cl.exe+0x1826a54)
clang-cl: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 18.1.8
Target: aarch64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang-cl: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-cl: note: diagnostic msg: C:\Users\xeng\AppData\Local\Temp\CpuElementwiseUnaryKernel-33a8dd.cpp
clang-cl: note: diagnostic msg: C:\Users\xeng\AppData\Local\Temp\CpuElementwiseUnaryKernel-33a8dd.sh
clang-cl: note: diagnostic msg:

********************
scons: *** [build\src\cpu\kernels\CpuElementwiseUnaryKernel.obj] Error 1
^C^C^C^C
scons: *** [build\src\core\utils\FormatUtils.obj] Error 3221225786
scons: *** [build\src\runtime\Utils.obj] Error 3221225786
scons: *** [build\src\core\Utils.obj] Error 3221225786
^Cscons: *** [build\src\runtime\NEON\functions\NEDetectionPostProcessLayer.obj] Error 3221225786
scons: *** [build\src\cpu\operators\CpuGemmLowpMatrixMultiplyCore.obj] Error 3221225786
scons: Build interrupted.
scons: building terminated because of errors.
scons: writing .sconsign file.

I've tried code base v23.x and v24.07/08, all failed. The toolchain I used:

logs attached: v24.08_xelite.zip

morgolock commented 2 months ago

Hi @xengpro

This seems to be a toolchain problem, could you please try with Clang 16 and let us know if that works?

Hope this helps.

xengpro commented 2 months ago

Hi @xengpro

This seems to be a toolchain problem, could you please try with Clang 16 and let us know if that works?

Hope this helps.

Hi @morgolock , I tried clang15 earlier, but vs2022 requires clang 17+: "Unexpected compiler version, expected Clang 17.0.0 or newer."

morgolock commented 2 months ago

Hi @xengpro

There seems to be a problem with the Clang toolchain in VS. In order to compile ACL you have to download the external Clang toolchain I mentioned above. Try downloading https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.6 and building ACL with it. That's what we use in the team to build ACL natively on Windows.

Hope this helps.

xengpro commented 2 months ago

Hi @morgolock, Thanks for you help. But I've tried llvmorg-16.0.6 a few minutes earlier, and get same error.

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h(898,1): error:
      static assertion failed: error STL1000: Unexpected compiler version, expected Clang 17.0.0 or newer.
_EMIT_STL_ERROR(STL1000, "Unexpected compiler version, expected Clang 17.0.0 or newer.");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h(519,44): note:
      expanded from macro '_EMIT_STL_ERROR'
#define _EMIT_STL_ERROR(NUMBER, MESSAGE)   static_assert(false, "error " #NUMBER ": " MESSAGE)
                                           ^             ~~~~~
1 error generated.
scons: *** [build\src\common\cpuinfo\CpuInfo.obj] Error 1
scons: building terminated because of errors.

C:\xeng\ACL>clang-cl -v
clang version 16.0.6
Target: aarch64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

So it seems still not possible for ACL to build completely natively (with Visual Studio 2022 Arm64 build, which is 17.4 and newer ) on windows at the moment?

morgolock commented 2 months ago

Hi @xengpro

It's possible to build ACL natively using the toolchain I mentioned above, we have jobs building ACL every day natively on Windows. The problem with VS22 is that it does not support inline assembly for arm64 targets.

From what I see in the logs you shared there is a problem with your environment. In the error you shared above I see mention to Clang 17.0.0. It's likely your devenv is not properly setup. If you use the standalone Clang 16 toolchain you should see no references to Clang 17.

xengpro commented 2 months ago

Hi @morgolock ,

I'm using standalone clang.

In the error you shared above I see mention to Clang 17.0.0.

It mentions Clang 17 because it detects that Clang 16.0.6 doesn't meet its expectations. So I tried standalone version Clang 18.1.8 and 17.0.6 which can build but get stuck in CpuElementwiseUnaryKernel.cpp. Comments out a few lines in it can let the build proceed, but still stuck somewhere else like framework.cpp.

The problem with VS22 is that it does not support inline assembly for arm64 targets.

That's true. And the Clang (17.0.3) that comes with vs2022 also fails anyway. So on a X Elite Laptop, I'm using the following setup :

It's possible to build ACL natively using the toolchain I mentioned above

Could you share the version of your vs2022 and msvc/winsdk workloads?

morgolock commented 2 months ago

Hi @xengpro

image

Snapdragon (TM) 8cx Gen 2 @ 3.15 GHz 3.15 GHz Windows 11 Enterprise Microsoft Visual Studio Community 2022 (ARM 64-bit) - Current Version 17.9.0

That's true. And the Clang (17.0.3) that comes with vs2022 also fails anyway.

It sounds like there is a problem with development environment and it is not properly setup.

xengpro commented 2 months ago

Hi @morgolock ,

It sounds like there is a problem with development environment and it is not properly setup.

The setup is supposed to be very straight forward, so I couldn't mess it up:

then for my setup, llvm fails be like:

But thanks to you information, I changed the VS2022 to 17.9.7 and compilation succeeded with 'standalone=0'.

However, when build with with 'standalone=1', the arm_compute.dll is linked but arm_compute.lib not produced:

LINK : fatal error LNK1181: cannot open input file 'arm_compute.lib'
scons: *** [build\arm_compute_graph.dll] Error 1181
morgolock commented 2 months ago

Hi @xengpro

If you want to build a program that uses ACL you will have to link statically against arm_compute-static-lib.

However, when build with with 'standalone=1', the arm_compute.dll is linked but arm_compute.lib not produced:

Could you please share you full build command? It should build without errors with standalone=1. I'm building with VS22 version 17.9.0 + Clang 16.0.6

Hope this helps,

xengpro commented 1 month ago

However, when build with with 'standalone=1', the arm_compute.dll is linked but arm_compute.lib not produced:

Could you please share you full build command? It should build without errors with standalone=1. I'm building with VS22 version 17.9.0 + Clang 16.0.6

Really sorry for the typo. I was using 'standalone=0' when I was trying to get .dll files.

scons opencl=0 neon=1 os=windows examples=0 validation_tests=0 benchmark_examples=0 build=native Werror=0 exceptions=1 standalone=0 -j8 arch=arm64-v8.2-a
morgolock commented 1 month ago

Hi @xengpro

That's right, we only support building with standalone=1. This means that arm_compute_validation will link statically with arm_compute-static-lib. If you want to write a program that uses ACL you will have to also link statically with arm_compute-static-lib

Hope this helps.

morgolock commented 1 month ago

Hi @xengpro

I tried to compile ACL with clang 17 or later and I got the same error you reported. This is a problem in the compiler crashing. I've raised a bug in LLVM as the see: https://github.com/llvm/llvm-project/issues/108976

xengpro commented 1 month ago

I tried to compile ACL with clang 17 or later and I got the same error you reported. This is a problem in the compiler crashing. I've raised a bug in LLVM as the see: llvm/llvm-project#108976

Cool, thanks~!

That's right, we only support building with standalone=1.

Any plan to add standalone=0 support? Some program, such as onnx runtime, needs to change a lot to use static load.

morgolock commented 3 weeks ago

Hi @xengpro

Any plan to add standalone=0 support? Some program, such as onnx runtime, needs to change a lot to use static load.

No plans in the short term, we have more important things like multi_isa support for Windows. I'll have a look into it and see how much effort will be require to produce the DLLs that can be used from a standalone program.

The following patch will fix the problems you had when you tried to build ACL with clang17 and the latest version of VS22. I had to disable optimizations when building with clang 17 or later because the compilers would crash otherwise. We'll enable this again once the toolchain gets fixed.

Hope this helps