Skip to content

Commit ac90ee3

Browse files
committed
use vmmlaq_s32 for compile option i8mm check
1 parent 8797958 commit ac90ee3

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,36 @@ if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" OR
9999
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_PREV})
100100
elseif (APPLE)
101101
if (GGML_NATIVE)
102-
set(MARCH_FLAGS "-march=armv8.2a")
102+
set(USER_PROVIDED_MARCH FALSE)
103+
foreach(flag_var IN ITEMS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_REQUIRED_FLAGS)
104+
if ("${${flag_var}}" MATCHES "-march=[a-zA-Z0-9+._-]+")
105+
set(USER_PROVIDED_MARCH TRUE)
106+
break()
107+
endif()
108+
endforeach()
103109

104-
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)
105-
if (GGML_COMPILER_SUPPORT_DOTPROD)
106-
set(MARCH_FLAGS "${MARCH_FLAGS}+dotprod")
107-
add_compile_definitions(__ARM_FEATURE_DOTPROD)
108-
endif ()
110+
if (NOT USER_PROVIDED_MARCH)
111+
set(MARCH_FLAGS "-march=armv8.2a")
109112

110-
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)
111-
if (GGML_COMPILER_SUPPORT_MATMUL_INT8)
112-
add_compile_definitions(__ARM_FEATURE_MATMUL_INT8)
113-
set(MARCH_FLAGS "${MARCH_FLAGS}+i8mm")
114-
endif ()
113+
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)
114+
if (GGML_COMPILER_SUPPORT_DOTPROD)
115+
set(MARCH_FLAGS "${MARCH_FLAGS}+dotprod")
116+
add_compile_definitions(__ARM_FEATURE_DOTPROD)
117+
endif ()
115118

116-
list(APPEND ARCH_FLAGS "${MARCH_FLAGS}")
119+
set(TEST_I8MM_FLAGS "-march=armv8.2a+i8mm")
120+
121+
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
122+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${TEST_I8MM_FLAGS}")
123+
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)
124+
if (GGML_COMPILER_SUPPORT_MATMUL_INT8)
125+
set(MARCH_FLAGS "${MARCH_FLAGS}+i8mm")
126+
add_compile_definitions(__ARM_FEATURE_MATMUL_INT8)
127+
endif ()
128+
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
129+
130+
list(APPEND ARCH_FLAGS "${MARCH_FLAGS}")
131+
endif ()
117132
endif ()
118133
else()
119134
check_cxx_compiler_flag(-mfp16-format=ieee COMPILER_SUPPORTS_FP16_FORMAT_I3E)

0 commit comments

Comments
 (0)