|
| 1 | +function(ggml_add_cpu_backend_features cpu_name arch) |
| 2 | + # The feature detection code is compiled as a separate target so that |
| 3 | + # it can be built without the architecture flags |
| 4 | + # Since multiple variants of the CPU backend may be included in the same |
| 5 | + # build, using set_source_files_properties() to set the arch flags is not possible |
| 6 | + set(GGML_CPU_FEATS_NAME ${cpu_name}-feats) |
| 7 | + add_library(${GGML_CPU_FEATS_NAME} OBJECT ggml-cpu/arch/${arch}/cpu-feats.cpp) |
| 8 | + target_include_directories(${GGML_CPU_FEATS_NAME} PRIVATE . .. ../include) |
| 9 | + target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE ${ARGN}) |
| 10 | + target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE GGML_BACKEND_DL GGML_BACKEND_BUILD GGML_BACKEND_SHARED) |
| 11 | + set_target_properties(${GGML_CPU_FEATS_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 12 | + target_link_libraries(${cpu_name} PRIVATE ${GGML_CPU_FEATS_NAME}) |
| 13 | +endfunction() |
| 14 | + |
1 | 15 | function(ggml_add_cpu_backend_variant_impl tag_name)
|
2 | 16 | if (tag_name)
|
3 | 17 | set(GGML_CPU_NAME ggml-cpu-${tag_name})
|
@@ -143,6 +157,49 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
|
143 | 157 | else()
|
144 | 158 | if (GGML_CPU_ARM_ARCH)
|
145 | 159 | list(APPEND ARCH_FLAGS -march=${GGML_CPU_ARM_ARCH})
|
| 160 | + elseif(GGML_CPU_ALL_VARIANTS) |
| 161 | + if (CMAKE_SYSTEM_NAME MATCHES "Linux") |
| 162 | + # Begin with the lowest baseline |
| 163 | + set(ARM_MCPU "armv8-a") |
| 164 | + set(ARCH_TAGS "") |
| 165 | + set(ARCH_DEFINITIONS "") |
| 166 | + |
| 167 | + # When a feature is selected, bump the MCPU to the first |
| 168 | + # version that supported it |
| 169 | + if (GGML_INTERNAL_DOTPROD) |
| 170 | + set(ARM_MCPU "armv8.2-a") |
| 171 | + set(ARCH_TAGS "${ARCH_TAGS}+dotprod") |
| 172 | + list(APPEND ARCH_DEFINITIONS GGML_USE_DOTPROD) |
| 173 | + endif() |
| 174 | + if (GGML_INTERNAL_FP16_VECTOR_ARITHMETIC) |
| 175 | + set(ARM_MCPU "armv8.2-a") |
| 176 | + set(ARCH_TAGS "${ARCH_TAGS}+fp16") |
| 177 | + list(APPEND ARCH_DEFINITIONS GGML_USE_FP16_VECTOR_ARITHMETIC) |
| 178 | + endif() |
| 179 | + if (GGML_INTERNAL_SVE) |
| 180 | + set(ARM_MCPU "armv8.2-a") |
| 181 | + set(ARCH_TAGS "${ARCH_TAGS}+sve") |
| 182 | + list(APPEND ARCH_DEFINITIONS GGML_USE_SVE) |
| 183 | + endif() |
| 184 | + if (GGML_INTERNAL_MATMUL_INT8) |
| 185 | + set(ARM_MCPU "armv8.6-a") |
| 186 | + set(ARCH_TAGS "${ARCH_TAGS}+i8mm") |
| 187 | + list(APPEND ARCH_DEFINITIONS GGML_USE_MATMUL_INT8) |
| 188 | + endif() |
| 189 | + if (GGML_INTERNAL_SVE2) |
| 190 | + set(ARM_MCPU "armv8.6-a") |
| 191 | + set(ARCH_TAGS "${ARCH_TAGS}+sve2") |
| 192 | + list(APPEND ARCH_DEFINITIONS GGML_USE_SVE2) |
| 193 | + endif() |
| 194 | + if (GGML_INTERNAL_SME) |
| 195 | + set(ARM_MCPU "armv9.2-a") |
| 196 | + set(ARCH_TAGS "${ARCH_TAGS}+sme") |
| 197 | + list(APPEND ARCH_DEFINITIONS GGML_USE_SME) |
| 198 | + endif() |
| 199 | + |
| 200 | + list(APPEND ARCH_FLAGS "-march=${ARM_MCPU}${ARCH_TAGS}") |
| 201 | + ggml_add_cpu_backend_features(${GGML_CPU_NAME} arm ${ARCH_DEFINITIONS}) |
| 202 | + endif() |
146 | 203 | endif()
|
147 | 204 | endif()
|
148 | 205 |
|
@@ -306,18 +363,7 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
|
306 | 363 | # the feature check relies on ARCH_DEFINITIONS, but it is not set with GGML_NATIVE
|
307 | 364 | message(FATAL_ERROR "GGML_NATIVE is not compatible with GGML_BACKEND_DL, consider using GGML_CPU_ALL_VARIANTS")
|
308 | 365 | endif()
|
309 |
| - |
310 |
| - # The feature detection code is compiled as a separate target so that |
311 |
| - # it can be built without the architecture flags |
312 |
| - # Since multiple variants of the CPU backend may be included in the same |
313 |
| - # build, using set_source_files_properties() to set the arch flags is not possible |
314 |
| - set(GGML_CPU_FEATS_NAME ${GGML_CPU_NAME}-feats) |
315 |
| - add_library(${GGML_CPU_FEATS_NAME} OBJECT ggml-cpu/arch/x86/cpu-feats.cpp) |
316 |
| - target_include_directories(${GGML_CPU_FEATS_NAME} PRIVATE . .. ../include) |
317 |
| - target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE ${ARCH_DEFINITIONS}) |
318 |
| - target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE GGML_BACKEND_DL GGML_BACKEND_BUILD GGML_BACKEND_SHARED) |
319 |
| - set_target_properties(${GGML_CPU_FEATS_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) |
320 |
| - target_link_libraries(${GGML_CPU_NAME} PRIVATE ${GGML_CPU_FEATS_NAME}) |
| 366 | + ggml_add_cpu_backend_features(${GGML_CPU_NAME} x86 ${ARCH_DEFINITIONS}) |
321 | 367 | endif()
|
322 | 368 | elseif (GGML_SYSTEM_ARCH STREQUAL "PowerPC")
|
323 | 369 | message(STATUS "PowerPC detected")
|
|
0 commit comments