Skip to content

Commit 21ae3b9

Browse files
authored
ggml : add test for SVE and disable when it fails (#10906)
1 parent 0a11f8b commit 21ae3b9

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
8282
if (MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
8383
message(FATAL_ERROR "MSVC is not supported for ARM, use clang")
8484
else()
85-
check_cxx_compiler_flag(-mfp16-format=ieee COMPILER_SUPPORTS_FP16_FORMAT_I3E)
86-
if (NOT "${COMPILER_SUPPORTS_FP16_FORMAT_I3E}" STREQUAL "")
85+
check_cxx_compiler_flag(-mfp16-format=ieee GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E)
86+
if (NOT "${GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E}" STREQUAL "")
8787
list(APPEND ARCH_FLAGS -mfp16-format=ieee)
8888
endif()
8989

@@ -106,28 +106,28 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
106106
message(STATUS "ARM -mcpu not found, -mcpu=native will be used")
107107
endif()
108108

109-
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
110109
include(CheckCXXSourceRuns)
111110

112-
set(CMAKE_REQUIRED_FLAGS "${ARM_MCPU_FLAG}+dotprod")
113-
check_cxx_source_runs(
114-
"#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }"
115-
GGML_COMPILER_SUPPORT_DOTPROD)
116-
if (GGML_COMPILER_SUPPORT_DOTPROD)
117-
set(ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX}+dotprod")
118-
endif()
111+
function(check_arm_feature tag code)
112+
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
113+
set(CMAKE_REQUIRED_FLAGS "${ARM_MCPU_FLAG}+${tag}")
114+
check_cxx_source_runs(
115+
"${code}"
116+
GGML_MACHINE_SUPPORTS_${tag}
117+
)
118+
if (GGML_MACHINE_SUPPORTS_${tag})
119+
set(ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX}+${tag}" PARENT_SCOPE)
120+
else()
121+
set(ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX}+no${tag}" PARENT_SCOPE)
122+
endif()
123+
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
124+
endfunction()
119125

120-
set(CMAKE_REQUIRED_FLAGS "${ARM_MCPU_FLAG}+i8mm")
121-
check_cxx_source_runs(
122-
"#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vmmlaq_s32(_s, _a, _b); return 0; }"
123-
GGML_COMPILER_SUPPORT_I8MM)
124-
if (GGML_COMPILER_SUPPORT_I8MM)
125-
set(ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX}+i8mm")
126-
endif()
126+
check_arm_feature(dotprod "#include <arm_neon.h>\nint main() { int8x16_t _a, _b; volatile int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }")
127+
check_arm_feature(i8mm "#include <arm_neon.h>\nint main() { int8x16_t _a, _b; volatile int32x4_t _s = vmmlaq_s32(_s, _a, _b); return 0; }")
128+
check_arm_feature(sve "#include <arm_sve.h>\nint main() { svfloat32_t _a, _b; volatile svfloat32_t _c = svadd_f32_z(svptrue_b8(), _a, _b); return 0; }")
127129

128-
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
129130
list(APPEND ARCH_FLAGS "${ARM_MCPU_FLAG}${ARM_MCPU_FLAG_FIX}")
130-
131131
else()
132132
if (GGML_CPU_ARM_ARCH)
133133
list(APPEND ARCH_FLAGS -march=${GGML_CPU_ARM_ARCH})

0 commit comments

Comments
 (0)