Skip to content

Commit 7fe03e7

Browse files
authored
ggml-cpu: x86 feature detection is specific to x86 (#13811)
1 parent 952f395 commit 7fe03e7

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
299299
endif()
300300
endif()
301301
endif()
302+
303+
if (GGML_BACKEND_DL)
304+
if (GGML_NATIVE)
305+
# the feature check relies on ARCH_DEFINITIONS, but it is not set with GGML_NATIVE
306+
message(FATAL_ERROR "GGML_NATIVE is not compatible with GGML_BACKEND_DL, consider using GGML_CPU_ALL_VARIANTS")
307+
endif()
308+
309+
# The feature detection code is compiled as a separate target so that
310+
# it can be built without the architecture flags
311+
# Since multiple variants of the CPU backend may be included in the same
312+
# build, using set_source_files_properties() to set the arch flags is not possible
313+
set(GGML_CPU_FEATS_NAME ${GGML_CPU_NAME}-feats)
314+
add_library(${GGML_CPU_FEATS_NAME} OBJECT ggml-cpu/cpu-feats-x86.cpp)
315+
target_include_directories(${GGML_CPU_FEATS_NAME} PRIVATE . .. ../include)
316+
target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE ${ARCH_DEFINITIONS})
317+
target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE GGML_BACKEND_DL GGML_BACKEND_BUILD GGML_BACKEND_SHARED)
318+
set_target_properties(${GGML_CPU_FEATS_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
319+
target_link_libraries(${GGML_CPU_NAME} PRIVATE ${GGML_CPU_FEATS_NAME})
320+
endif()
302321
elseif ("${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "ppc64le " OR "${CMAKE_SYSTEM_PROCESSOR} " STREQUAL "powerpc ")
303322
message(STATUS "PowerPC detected")
304323
if (GGML_NATIVE)
@@ -477,25 +496,6 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
477496
target_compile_options(${GGML_CPU_NAME} PRIVATE ${ARCH_FLAGS})
478497
target_compile_definitions(${GGML_CPU_NAME} PRIVATE ${ARCH_DEFINITIONS})
479498

480-
if (GGML_BACKEND_DL)
481-
if (GGML_NATIVE)
482-
# the feature check relies on ARCH_DEFINITIONS, but it is not set with GGML_NATIVE
483-
message(FATAL_ERROR "GGML_NATIVE is not compatible with GGML_BACKEND_DL, consider using GGML_CPU_ALL_VARIANTS")
484-
endif()
485-
486-
# The feature detection code is compiled as a separate target so that
487-
# it can be built without the architecture flags
488-
# Since multiple variants of the CPU backend may be included in the same
489-
# build, using set_source_files_properties() to set the arch flags is not possible
490-
set(GGML_CPU_FEATS_NAME ${GGML_CPU_NAME}-feats)
491-
add_library(${GGML_CPU_FEATS_NAME} OBJECT ggml-cpu/cpu-feats-x86.cpp)
492-
target_include_directories(${GGML_CPU_FEATS_NAME} PRIVATE . .. ../include)
493-
target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE ${ARCH_DEFINITIONS})
494-
target_compile_definitions(${GGML_CPU_FEATS_NAME} PRIVATE GGML_BACKEND_DL GGML_BACKEND_BUILD GGML_BACKEND_SHARED)
495-
set_target_properties(${GGML_CPU_FEATS_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)
496-
target_link_libraries(${GGML_CPU_NAME} PRIVATE ${GGML_CPU_FEATS_NAME})
497-
endif()
498-
499499
if (EMSCRIPTEN)
500500
set_target_properties(${GGML_CPU_NAME} PROPERTIES COMPILE_FLAGS "-msimd128")
501501
endif()

0 commit comments

Comments
 (0)