XNNPACK icon indicating copy to clipboard operation
XNNPACK copied to clipboard

How to build XNNPACK by Bazel 6.5 in windows, but without avx

Open dicotom opened this issue 10 months ago • 5 comments

I am trying to build tensorflow 2.18.0 with bazel 6.5, in config I put all the noavx flags, and in bazel build I used --define=tflite_with_xnnpack=false, but still fails with:

ERROR: C:/users/user/_bazel_user/yopxtjri/external/XNNPACK/BUILD.bazel:803:36: Compiling external/XNNPACK/avx512vnni_prod_microkernels.c failed: (Exit 1): clang-cl.exe failed: error executing command (from target @XNNPACK//:avx512vnni_prod_microkernels)

The error message clearly indicates that even though I'm trying to build without AVX, the build system is still trying to compile code using AVX-512 instructions (specifically avx512vnni_prod_microkernels.c). This is happening within the XNNPACK library, which TensorFlow uses for optimized operations.

dicotom avatar Feb 06 '25 15:02 dicotom

Hi, thanks for the report. I think you just want avx512 disabled, not avx2 etc? Is that error showing something more specific, like a header or intrinsic that fails? If the issue is your compiler does not support vnni

  1. with cmake it should detect the compiler and disable instructions based on version
  2. with bazel there are flags for each isa to disable it. sofor this one it is --define xnn_enable_avx512vnni=false

fbarchard avatar Feb 07 '25 01:02 fbarchard

what other avx xnnpack uses? I have an old cpu which does not support any avx instructions.

dicotom avatar Feb 07 '25 10:02 dicotom

xnnpack supports SSE and x86 32 bit. In practice its getting hard to test on anything less than SSE4.2 The lowest end cpu I've tested on recently is Intel Silvermont, which is in Asus Yoga, which is both windows and android.

I'm having a bit of trouble testing Windows myself. On Windows 11 with VC2023 and default builds, if I use Intel SDE to emulate a westmere, which is sse4, I get an error

TID 0 SDE-ERROR: Executed instruction not valid for specified chip (WESTMERE): 0x7ffedadc8080: vinsertf128 ymm0, ymm0, xmm0, 0x1
Image: C:\Windows\System32\msvcrt.dll+0x78080
Function: memset
Instruction bytes are: c4 e3 7d 18 c0 01

That probably doesnt happen if you build on Windows 10 or earlier? with bazel you can try --features=fully_static_link to avoid DLLs

and then its the compiler having default avx that may get in the way. so you can try --copt=-mno-avx and --copt=-mno-avx2 with clang, or /arch:SSE2 with Visual C

fbarchard avatar Feb 08 '25 01:02 fbarchard

bazel on linux is currently broken, and likely would occur on all x86 platforms

XNNPACK/BUILD.bazel:640:8: declared output 'testdata/cmake/gen/avx512bf16_microkernels.cmake' was not created by genrule.

normally the flag --define xnn_enable_avx512bf16=false would work around it, but its not working and will need a fix

bazel build -c opt --define xnn_enable_avx512bf16=false :all

I was able to test Westmere (SSE4) on Windows 11 with SDE using an sde flag -chip_check_exe_only What CPU do you have?

fbarchard avatar Feb 13 '25 04:02 fbarchard

FWIW we now have tests running using Intel SDE that ensure XNNPack runs on Intel Silvermont (Atom) which has SSE4.1 but not AVX. The tests pass on both Windows and Linux.

fbarchard avatar Feb 17 '25 23:02 fbarchard