Skip to content

Commit d79bfe9

Browse files
committed
ggml-cpu: Limit ARM GGML_CPU_ALL_VARIANTS to Linux for now
The other platforms will need their own specific variants. This also fixes the bug that the the variant-building branch was always being executed as the else-branch of GGML_NATIVE=OFF. The branch is moved to an elseif-branch which restores the previous behavior.
1 parent 0a9ae27 commit d79bfe9

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

ggml/src/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ ggml_add_backend(CPU)
295295
if (GGML_CPU_ALL_VARIANTS)
296296
if (NOT GGML_BACKEND_DL)
297297
message(FATAL_ERROR "GGML_CPU_ALL_VARIANTS requires GGML_BACKEND_DL")
298+
elseif (GGML_CPU_ARM_ARCH)
299+
message(FATAL_ERROR "Cannot use both GGML_CPU_ARM_ARCH and GGML_CPU_ALL_VARIANTS")
298300
endif()
299301
if (GGML_SYSTEM_ARCH STREQUAL "x86")
300302
ggml_add_cpu_backend_variant(x64)
@@ -308,10 +310,7 @@ if (GGML_CPU_ALL_VARIANTS)
308310
# MSVC doesn't support AMX
309311
ggml_add_cpu_backend_variant(sapphirerapids SSE42 AVX F16C AVX2 BMI2 FMA AVX512 AVX512_VBMI AVX512_VNNI AVX512_BF16 AMX_TILE AMX_INT8)
310312
endif()
311-
elseif(GGML_SYSTEM_ARCH STREQUAL "ARM")
312-
if (GGML_CPU_ARM_ARCH)
313-
message(FATAL_ERROR "Cannot use both GGML_CPU_ARM_ARCH and GGML_CPU_ALL_VARIANTS")
314-
endif()
313+
elseif(GGML_SYSTEM_ARCH STREQUAL "ARM" AND CMAKE_SYSTEM_NAME MATCHES "Linux")
315314
# Many of these features are optional so we build versions with popular
316315
# combinations and name the backends based on the version they were
317316
# first released with
@@ -324,7 +323,7 @@ if (GGML_CPU_ALL_VARIANTS)
324323
ggml_add_cpu_backend_variant(armv9.2_1 DOTPROD FP16_VECTOR_ARITHMETIC SVE MATMUL_INT8 SME)
325324
ggml_add_cpu_backend_variant(armv9.2_2 DOTPROD FP16_VECTOR_ARITHMETIC SVE MATMUL_INT8 SVE2 SME)
326325
else()
327-
message(FATAL_ERROR "GGML_CPU_ALL_VARIANTS not yet supported on ${GGML_SYSTEM_ARCH}")
326+
message(FATAL_ERROR "GGML_CPU_ALL_VARIANTS not yet supported with ${GGML_SYSTEM_ARCH} on ${CMAKE_SYSTEM_NAME}")
328327
endif()
329328
elseif (GGML_CPU)
330329
ggml_add_cpu_backend_variant_impl("")

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -152,47 +152,49 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
152152
else()
153153
if (GGML_CPU_ARM_ARCH)
154154
list(APPEND ARCH_FLAGS -march=${GGML_CPU_ARM_ARCH})
155-
else()
156-
# Begin with the lowest baseline
157-
set(ARM_MCPU "armv8-a")
158-
set(ARCH_TAGS "")
159-
set(ARCH_DEFINITIONS "")
160-
161-
# When a feature is selected, bump the MCPU to the first
162-
# version that supported it
163-
if (GGML_INTERNAL_DOTPROD)
164-
set(ARM_MCPU "armv8.2-a")
165-
set(ARCH_TAGS "${ARCH_TAGS}+dotprod")
166-
list(APPEND ARCH_DEFINITIONS GGML_USE_DOTPROD)
167-
endif()
168-
if (GGML_INTERNAL_FP16_VECTOR_ARITHMETIC)
169-
set(ARM_MCPU "armv8.2-a")
170-
set(ARCH_TAGS "${ARCH_TAGS}+fp16")
171-
list(APPEND ARCH_DEFINITIONS GGML_USE_FP16_VECTOR_ARITHMETIC)
172-
endif()
173-
if (GGML_INTERNAL_SVE)
174-
set(ARM_MCPU "armv8.2-a")
175-
set(ARCH_TAGS "${ARCH_TAGS}+sve")
176-
list(APPEND ARCH_DEFINITIONS GGML_USE_SVE)
177-
endif()
178-
if (GGML_INTERNAL_MATMUL_INT8)
179-
set(ARM_MCPU "armv8.6-a")
180-
set(ARCH_TAGS "${ARCH_TAGS}+i8mm")
181-
list(APPEND ARCH_DEFINITIONS GGML_USE_MATMUL_INT8)
182-
endif()
183-
if (GGML_INTERNAL_SVE2)
184-
set(ARM_MCPU "armv8.6-a")
185-
set(ARCH_TAGS "${ARCH_TAGS}+sve2")
186-
list(APPEND ARCH_DEFINITIONS GGML_USE_SVE2)
187-
endif()
188-
if (GGML_INTERNAL_SME)
189-
set(ARM_MCPU "armv9.2-a")
190-
set(ARCH_TAGS "${ARCH_TAGS}+sme")
191-
list(APPEND ARCH_DEFINITIONS GGML_USE_SME)
192-
endif()
155+
elseif(GGML_CPU_ALL_VARIANTS)
156+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
157+
# Begin with the lowest baseline
158+
set(ARM_MCPU "armv8-a")
159+
set(ARCH_TAGS "")
160+
set(ARCH_DEFINITIONS "")
161+
162+
# When a feature is selected, bump the MCPU to the first
163+
# version that supported it
164+
if (GGML_INTERNAL_DOTPROD)
165+
set(ARM_MCPU "armv8.2-a")
166+
set(ARCH_TAGS "${ARCH_TAGS}+dotprod")
167+
list(APPEND ARCH_DEFINITIONS GGML_USE_DOTPROD)
168+
endif()
169+
if (GGML_INTERNAL_FP16_VECTOR_ARITHMETIC)
170+
set(ARM_MCPU "armv8.2-a")
171+
set(ARCH_TAGS "${ARCH_TAGS}+fp16")
172+
list(APPEND ARCH_DEFINITIONS GGML_USE_FP16_VECTOR_ARITHMETIC)
173+
endif()
174+
if (GGML_INTERNAL_SVE)
175+
set(ARM_MCPU "armv8.2-a")
176+
set(ARCH_TAGS "${ARCH_TAGS}+sve")
177+
list(APPEND ARCH_DEFINITIONS GGML_USE_SVE)
178+
endif()
179+
if (GGML_INTERNAL_MATMUL_INT8)
180+
set(ARM_MCPU "armv8.6-a")
181+
set(ARCH_TAGS "${ARCH_TAGS}+i8mm")
182+
list(APPEND ARCH_DEFINITIONS GGML_USE_MATMUL_INT8)
183+
endif()
184+
if (GGML_INTERNAL_SVE2)
185+
set(ARM_MCPU "armv8.6-a")
186+
set(ARCH_TAGS "${ARCH_TAGS}+sve2")
187+
list(APPEND ARCH_DEFINITIONS GGML_USE_SVE2)
188+
endif()
189+
if (GGML_INTERNAL_SME)
190+
set(ARM_MCPU "armv9.2-a")
191+
set(ARCH_TAGS "${ARCH_TAGS}+sme")
192+
list(APPEND ARCH_DEFINITIONS GGML_USE_SME)
193+
endif()
193194

194-
list(APPEND ARCH_FLAGS "-march=${ARM_MCPU}${ARCH_TAGS}")
195-
ggml_add_cpu_backend_features(${GGML_CPU_NAME} aarch64 ${ARCH_DEFINITIONS})
195+
list(APPEND ARCH_FLAGS "-march=${ARM_MCPU}${ARCH_TAGS}")
196+
ggml_add_cpu_backend_features(${GGML_CPU_NAME} aarch64 ${ARCH_DEFINITIONS})
197+
endif()
196198
endif()
197199
endif()
198200

0 commit comments

Comments
 (0)