Skip to content

Commit 2efc170

Browse files
authored
cmake: Enable specifying exact PowerPC CPU architecture (#1138)
In the process, guard automatic CPU detection with GGML_NATIVE. https://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html#index-mcpu-10
1 parent 82d9ca4 commit 2efc170

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ option(GGML_RVV "ggml: enable rvv" ON)
126126
option(GGML_VXE "ggml: enable vxe" ON)
127127

128128
option(GGML_CPU_ALL_VARIANTS "ggml: build all variants of the CPU backend (requires GGML_BACKEND_DL)" OFF)
129-
set(GGML_CPU_ARM_ARCH "" CACHE STRING "ggml: CPU architecture for ARM")
129+
set(GGML_CPU_ARM_ARCH "" CACHE STRING "ggml: CPU architecture for ARM")
130+
set(GGML_CPU_POWERPC_CPUTYPE "" CACHE STRING "ggml: CPU type for PowerPC")
130131

131132

132133
if (WIN32)

src/ggml-cpu/CMakeLists.txt

+14-8
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,21 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
289289
endif()
290290
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64")
291291
message(STATUS "PowerPC detected")
292-
execute_process(COMMAND bash -c "grep POWER /proc/cpuinfo | head -n 1" OUTPUT_VARIABLE POWER_M)
293-
if (${POWER_M} MATCHES "POWER10")
294-
list(APPEND ARCH_FLAGS -mcpu=power10)
295-
elseif (${POWER_M} MATCHES "POWER9")
296-
list(APPEND ARCH_FLAGS -mcpu=power9)
297-
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
298-
list(APPEND ARCH_FLAGS -mcpu=powerpc64le -mtune=native)
292+
if (GGML_NATIVE)
293+
execute_process(COMMAND bash -c "grep POWER /proc/cpuinfo | head -n 1" OUTPUT_VARIABLE POWER_M)
294+
if (${POWER_M} MATCHES "POWER10")
295+
list(APPEND ARCH_FLAGS -mcpu=power10)
296+
elseif (${POWER_M} MATCHES "POWER9")
297+
list(APPEND ARCH_FLAGS -mcpu=power9)
298+
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
299+
list(APPEND ARCH_FLAGS -mcpu=powerpc64le -mtune=native)
300+
else()
301+
list(APPEND ARCH_FLAGS -mcpu=powerpc64 -mtune=native)
302+
endif()
299303
else()
300-
list(APPEND ARCH_FLAGS -mcpu=powerpc64 -mtune=native)
304+
if (GGML_CPU_POWERPC_CPUTYPE)
305+
list(APPEND ARCH_FLAGS -mcpu=${GGML_CPU_POWERPC_CPUTYPE})
306+
endif()
301307
endif()
302308
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
303309
message(STATUS "loongarch64 detected")

0 commit comments

Comments
 (0)