Bazel can't cross-compile the XNNPACK tests
Using Bazel 8.1.1 (also broken under Bazel 7.6.1)
Build command is:
bazel build -c opt --config=android_arm64 test:all
Example output is:
Compiling kai/ukernels/matmul/matmul_clamp_f32_qai8dxp_qsi4c32p/kai_matmul_clamp_f32_qai8dxp4x8_qsi4c32p4x8_8x4x32_neon_i8mm.c failed: (Exit 1): gcc failed: error executing CppCompile command (from target @@+_repo_rules+KleidiAI//kai/ukernels/matmul:i8mm_impl_asm) /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 34 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
cc1: error: bad value 'armv8.2-a+i8mm' for '-march=' switch
cc1: note: valid arguments to '-march=' switch are: nocona core2 nehalem corei7 westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell skylake skylake-avx512 cannonlake icelake-client rocketlake icelake-server cascadelake tigerlake cooperlake sapphirerapids emeraldrapids alderlake raptorlake meteorlake graniterapids graniterapids-d arrowlake arrowlake-s lunarlake pantherlake bonnell atom silvermont slm goldmont goldmont-plus tremont gracemont sierraforest grandridge clearwaterforest knl knm x86-64 x86-64-v2 x86-64-v3 x86-64-v4 eden-x2 nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 lujiazui yongfeng k8 k8-sse3 opteron opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3 bdver4 znver1 znver2 znver3 znver4 znver5 btver1 btver2 native
Use --verbose_failures to see the command lines of failed build steps.
Host is Linux x64. Shouldn't be using GCC - should be using the Android NDK for this. Does anybody use this flow regularly?
bazel build -c opt --config=android_arm64 //... and bazel build -c opt --config=android_arm64 :all don't work either.
Hi @Sentimentron,
I think most of our users use cmake for Android builds, and this path is also covered in our GitHub workflows.
You likely need to set up the bazel cross-platform build for Android as described here: https://bazel.build/docs/android-ndk. If you do get this to work, we'd be very interested in a PR adding this ability to our BUILD files!
Cheers, Pedro
This could be a couple things
i8mm is relatively new and your compiler version may be too old.
with cmake the compiler version is checked and i8mm disabled if it wont work.
with bazel there is no auto detect but there are build flags to disable advanced instruction sets. Try adding:
--define=xnn_enable_arm_i8mm=true
In the CMakeLists.txt you can see the compilers/versions needed for I8MM, but it doesnt include GCC and Visual C, so it could use an update.
SET(XNNPACK_ENABLE_ARM_I8MM OFF)
SET(XNNPACK_ENABLE_ARM_SME OFF)
SET(XNNPACK_ENABLE_ARM_SME2 OFF)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "11")
SET(XNNPACK_ENABLE_ARM_I8MM OFF)
SET(XNNPACK_ENABLE_ARM_SME OFF)
SET(XNNPACK_ENABLE_ARM_SME2 OFF)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "18")
SET(XNNPACK_ENABLE_ARM_SME OFF)
SET(XNNPACK_ENABLE_ARM_SME2 OFF)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "10")
SET(XNNPACK_ENABLE_ARM_SME OFF)
SET(XNNPACK_ENABLE_ARM_SME2 OFF)
ENDIF()
The godbolt website is a handy way to try different compilers and options like -march=armv8.2-a+i8mm to see which version of compiler is required to at least accept the command line
The error 'armv8.2-a+i8mm' indicates bad build flags for gcc. I only find the one set of flags that includes i8mm: build_params.bzl: copts = ["-march=armv8.2-a+i8mm+fp16"], it could be gcc does accept that combination gcc 10 documentation https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/AArch64-Options.html indicates i8mm is an option for armv8.6
it could also be a gcc 10 bug, because I've seen sve/sme that are armv9, require you to specifiy armv8.6 for gcc.
it was fixed in gcc 11.
Try changing build_params.bzl to
-march=armv8.6-a+i8mm
or try not specifying 8.2 -march=armv8-a+dotprod+i8mm"
i8mm is an option of armv8.5 and gcc may be picky and not allow you to specify it as an option for armv8.2
there is also a bug in gcc 10 for sve and arm recommended these flags march=armv8.5-a+i8mm+sve2 instead of -march=armv9-a+sve2
XNNPack is better tested with clang and would support all features with version 20 or later