Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build2cmake/src/templates/cpu/preamble.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ endif()
{% endif %}

add_compile_definitions(CPU_KERNEL)

check_for_sve(HAVE_SVE)
if(HAVE_SVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+sve")
endif()
Comment on lines +46 to +49
Copy link
Member

@danieldk danieldk Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will end up compiling all source files with armv8.2-a+sve if the compiler supports it, which means CPU kernels will fail on all ARM64 devices without SVE.

I think the best way to tackle this is to have some code with the default flags that does a CPU feature check and dispatches to SVE/non-SVE paths (even if the non-SVE path just raises an error message). The kernel with the SVE path can then be compiled with the -march=armv8.2-a+sve flag.

Here is a similar case where a kernel is compiled to work with AVX512 and non-AVX512:

https://github.com/huggingface/kernels-community/blob/04a14c8356fa6020746ef47d1fd63ac4c7b5978d/rmsnorm/build.toml#L8
https://github.com/huggingface/kernels-community/blob/04a14c8356fa6020746ef47d1fd63ac4c7b5978d/rmsnorm/build.toml#L19

13 changes: 13 additions & 0 deletions build2cmake/src/templates/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,16 @@ function (define_gpu_extension_target GPU_MOD_NAME)

install(TARGETS ${GPU_MOD_NAME} LIBRARY DESTINATION ${GPU_DESTINATION} COMPONENT ${GPU_MOD_NAME})
endfunction()

include(CheckCXXSourceCompiles)

macro(check_for_sve HAVE_SVE_VAR)
set(CMAKE_REQUIRED_FLAGS "-march=armv8.2-a+sve")
check_cxx_source_compiles("
#include <arm_sve.h>
int main() {
svint32_t v = svdup_s32(0);
return svaddv_s32(svptrue_b32(), v);
}
" ${HAVE_SVE_VAR})
endmacro()