@@ -88,32 +88,45 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
88
88
endif ()
89
89
90
90
if (GGML_NATIVE )
91
- list (APPEND ARCH_FLAGS -mcpu=native )
92
-
93
- set (CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS} )
94
-
95
91
# -mcpu=native does not always enable all the features in some compilers,
96
92
# so we check for them manually and enable them if available
97
93
94
+ execute_process (
95
+ COMMAND ${CMAKE_C_COMPILER} -mcpu=native -E -v -
96
+ INPUT_FILE "/dev/null"
97
+ OUTPUT_QUIET
98
+ ERROR_VARIABLE ARM_MCPU
99
+ RESULT_VARIABLE ARM_MCPU_RESULT
100
+ )
101
+ if (NOT ARM_MCPU_RESULT )
102
+ string (REGEX MATCH "-mcpu=[^ ']+" ARM_MCPU_FLAG "${ARM_MCPU} " )
103
+ endif ()
104
+ if ("${ARM_MCPU_FLAG} " STREQUAL "" )
105
+ set (ARM_MCPU_FLAG -mcpu=native )
106
+ message (STATUS "ARM -mcpu not found, -mcpu=native will be used" )
107
+ endif ()
108
+
109
+ set (CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS} )
98
110
include (CheckCXXSourceRuns )
99
111
100
- set (CMAKE_REQUIRED_FLAGS "${ARCH_FLAGS } +dotprod" )
112
+ set (CMAKE_REQUIRED_FLAGS "${ARM_MCPU_FLAG } +dotprod" )
101
113
check_cxx_source_runs (
102
114
"#include <arm_neon.h>\n int main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }"
103
115
GGML_COMPILER_SUPPORT_DOTPROD )
104
116
if (GGML_COMPILER_SUPPORT_DOTPROD )
105
- set (ARCH_FLAGS "${ARCH_FLAGS } +dotprod" )
117
+ set (ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX } +dotprod" )
106
118
endif ()
107
119
108
- set (CMAKE_REQUIRED_FLAGS "${ARCH_FLAGS } +i8mm" )
120
+ set (CMAKE_REQUIRED_FLAGS "${ARM_MCPU_FLAG } +i8mm" )
109
121
check_cxx_source_runs (
110
122
"#include <arm_neon.h>\n int main() { int8x16_t _a, _b; int32x4_t _s = vmmlaq_s32(_s, _a, _b); return 0; }"
111
123
GGML_COMPILER_SUPPORT_I8MM )
112
124
if (GGML_COMPILER_SUPPORT_I8MM )
113
- set (ARCH_FLAGS "${ARCH_FLAGS } +i8mm" )
125
+ set (ARM_MCPU_FLAG_FIX "${ARM_MCPU_FLAG_FIX } +i8mm" )
114
126
endif ()
115
127
116
128
set (CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} )
129
+ list (APPEND ARCH_FLAGS "${ARM_MCPU_FLAG}${ARM_MCPU_FLAG_FIX} " )
117
130
118
131
else ()
119
132
if (GGML_CPU_ARM_ARCH )
0 commit comments