Skip to content

Commit 5d7868c

Browse files
committed
cmake : fix ARM feature detection
ggml-ci
1 parent 9e2301f commit 5d7868c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" OR
7171

7272
message(STATUS "ARM detected")
7373

74+
include(CheckCXXSourceRuns)
75+
7476
if (MSVC)
7577
add_compile_definitions(__aarch64__) # MSVC defines _M_ARM64 instead
7678
add_compile_definitions(__ARM_NEON)
@@ -79,20 +81,26 @@ if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" OR
7981
set(CMAKE_REQUIRED_FLAGS_PREV ${CMAKE_REQUIRED_FLAGS})
8082
string(JOIN " " CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "/arch:armv8.2")
8183

82-
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_DOTPROD)
84+
check_cxx_source_runs("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_DOTPROD)
8385
if (GGML_COMPILER_SUPPORT_DOTPROD)
8486
add_compile_definitions(__ARM_FEATURE_DOTPROD)
87+
88+
message(STATUS "ARM feature DOTPROD enabled")
8589
endif ()
8690

87-
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vmlaq_f32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_MATMUL_INT8)
91+
check_cxx_source_runs("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vmmlaq_f32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_MATMUL_INT8)
8892

8993
if (GGML_COMPILER_SUPPORT_MATMUL_INT8)
9094
add_compile_definitions(__ARM_FEATURE_MATMUL_INT8)
95+
96+
message(STATUS "ARM feature MATMUL_INT8 enabled")
9197
endif ()
9298

93-
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float16_t _a; float16x8_t _s = vdupq_n_f16(_a); return 0; }" GGML_COMPILER_SUPPORT_FP16_VECTOR_ARITHMETIC)
99+
check_cxx_source_runs("#include <arm_neon.h>\nint main() { float16_t _a; float16x8_t _s = vdupq_n_f16(_a); return 0; }" GGML_COMPILER_SUPPORT_FP16_VECTOR_ARITHMETIC)
94100
if (GGML_COMPILER_SUPPORT_FP16_VECTOR_ARITHMETIC)
95101
add_compile_definitions(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
102+
103+
message(STATUS "ARM feature FP16_VECTOR_ARITHMETIC enabled")
96104
endif ()
97105

98106
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_PREV})
@@ -109,21 +117,27 @@ if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" OR
109117
if (NOT USER_PROVIDED_MARCH)
110118
set(MARCH_FLAGS "-march=armv8.2a")
111119

112-
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_DOTPROD)
120+
check_cxx_source_runs("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_DOTPROD)
113121
if (GGML_COMPILER_SUPPORT_DOTPROD)
114122
set(MARCH_FLAGS "${MARCH_FLAGS}+dotprod")
115123
add_compile_definitions(__ARM_FEATURE_DOTPROD)
124+
125+
message(STATUS "ARM feature DOTPROD enabled")
116126
endif ()
117127

118128
set(TEST_I8MM_FLAGS "-march=armv8.2a+i8mm")
119129

120130
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
121-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${TEST_I8MM_FLAGS}")
122-
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vmmlaq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_MATMUL_INT8)
131+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${TEST_I8MM_FLAGS}")
132+
133+
check_cxx_source_runs("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vmmlaq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_MATMUL_INT8)
123134
if (GGML_COMPILER_SUPPORT_MATMUL_INT8)
124135
set(MARCH_FLAGS "${MARCH_FLAGS}+i8mm")
125136
add_compile_definitions(__ARM_FEATURE_MATMUL_INT8)
137+
138+
message(STATUS "ARM feature MATMUL_INT8 enabled")
126139
endif ()
140+
127141
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
128142

129143
list(APPEND ARCH_FLAGS "${MARCH_FLAGS}")

0 commit comments

Comments
 (0)