Skip to content

Commit a8f0eb8

Browse files
committed
ggml-cpu: Factor out feature detection build from x86
1 parent f470bc3 commit a8f0eb8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
function(ggml_add_cpu_backend_variant_impl tag_name)
216
if (tag_name)
317
set(GGML_CPU_NAME ggml-cpu-${tag_name})
@@ -306,18 +320,7 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
306320
# the feature check relies on ARCH_DEFINITIONS, but it is not set with GGML_NATIVE
307321
message(FATAL_ERROR "GGML_NATIVE is not compatible with GGML_BACKEND_DL, consider using GGML_CPU_ALL_VARIANTS")
308322
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})
323+
ggml_add_cpu_backend_features(${GGML_CPU_NAME} x86 ${ARCH_DEFINITIONS})
321324
endif()
322325
elseif (GGML_SYSTEM_ARCH STREQUAL "PowerPC")
323326
message(STATUS "PowerPC detected")

0 commit comments

Comments
 (0)