Christian Kastner commited on
Commit
aac4d16
·
1 Parent(s): 08dc78e

cmake: Enable specifying exact PowerPC CPU architecture (ggml/1138)

Browse files

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

ggml/CMakeLists.txt CHANGED
@@ -130,7 +130,8 @@ option(GGML_RVV "ggml: enable rvv" ON)
130
  option(GGML_VXE "ggml: enable vxe" ON)
131
 
132
  option(GGML_CPU_ALL_VARIANTS "ggml: build all variants of the CPU backend (requires GGML_BACKEND_DL)" OFF)
133
- set(GGML_CPU_ARM_ARCH "" CACHE STRING "ggml: CPU architecture for ARM")
 
134
 
135
 
136
  if (WIN32)
 
130
  option(GGML_VXE "ggml: enable vxe" ON)
131
 
132
  option(GGML_CPU_ALL_VARIANTS "ggml: build all variants of the CPU backend (requires GGML_BACKEND_DL)" OFF)
133
+ set(GGML_CPU_ARM_ARCH "" CACHE STRING "ggml: CPU architecture for ARM")
134
+ set(GGML_CPU_POWERPC_CPUTYPE "" CACHE STRING "ggml: CPU type for PowerPC")
135
 
136
 
137
  if (WIN32)
ggml/src/ggml-cpu/CMakeLists.txt CHANGED
@@ -289,15 +289,21 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
289
  endif()
290
  elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64")
291
  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)
 
 
 
 
299
  else()
300
- list(APPEND ARCH_FLAGS -mcpu=powerpc64 -mtune=native)
 
 
301
  endif()
302
  elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
303
  message(STATUS "loongarch64 detected")
 
289
  endif()
290
  elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64")
291
  message(STATUS "PowerPC detected")
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()
303
  else()
304
+ if (GGML_CPU_POWERPC_CPUTYPE)
305
+ list(APPEND ARCH_FLAGS -mcpu=${GGML_CPU_POWERPC_CPUTYPE})
306
+ endif()
307
  endif()
308
  elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
309
  message(STATUS "loongarch64 detected")