Skip to content

Commit 4f73d0a

Browse files
authored
ci : fix binaries release failure for s390x (binaries may not work yet) (ggml-org#16664)
* devops: initial patch Signed-off-by: Aaron Teo <[email protected]> * devops: forgot the z15 suffix Signed-off-by: Aaron Teo <[email protected]> * devops: attempt at impl GGML_CPU_ALL_VARIANTS for s390x Signed-off-by: Aaron Teo <[email protected]> * devops: rm baseline version Signed-off-by: Aaron Teo <[email protected]> --------- Signed-off-by: Aaron Teo <[email protected]>
1 parent cec5edb commit 4f73d0a

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

ggml/src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ function(ggml_add_cpu_backend_variant tag_name)
307307
foreach (feat ${ARGN})
308308
set(GGML_INTERNAL_${feat} ON)
309309
endforeach()
310+
elseif (GGML_SYSTEM_ARCH STREQUAL "s390x")
311+
foreach (feat ${ARGN})
312+
set(GGML_INTERNAL_${feat} ON)
313+
endforeach()
310314
endif()
311315

312316
ggml_add_cpu_backend_variant_impl(${tag_name})
@@ -371,6 +375,14 @@ if (GGML_CPU_ALL_VARIANTS)
371375
else()
372376
message(FATAL_ERROR "Unsupported PowerPC target OS: ${CMAKE_SYSTEM_NAME}")
373377
endif()
378+
elseif (GGML_SYSTEM_ARCH STREQUAL "s390x")
379+
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
380+
ggml_add_cpu_backend_variant(s390x_z15 Z15 VXE)
381+
# ggml_add_cpu_backend_variant(s390x_z16 Z16 VXE)
382+
# ggml_add_cpu_backend_variant(s390x_z17 Z17 VXE)
383+
else()
384+
message(FATAL_ERROR "Unsupported s390x target OS: ${CMAKE_SYSTEM_NAME}")
385+
endif()
374386
else()
375387
message(FATAL_ERROR "GGML_CPU_ALL_VARIANTS not yet supported with ${GGML_SYSTEM_ARCH} on ${CMAKE_SYSTEM_NAME}")
376388
endif()

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -466,29 +466,45 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
466466
list(APPEND ARCH_FLAGS "-march=${MARCH_STR}" -mabi=lp64d)
467467
elseif (GGML_SYSTEM_ARCH STREQUAL "s390x")
468468
message(STATUS "s390x detected")
469-
list(APPEND GGML_CPU_SOURCES ggml-cpu/arch/s390/quants.c)
470-
file(READ "/proc/cpuinfo" CPUINFO_CONTENTS)
471-
string(REGEX REPLACE "machine[ \t\r\n]*=[ \t\r\n]*([0-9]+)" "\\1" S390X_M ${CPUINFO_CONTENTS})
472-
473-
# TODO: Separation to determine activation of VX/VXE/VXE2
474-
if (${S390X_M} MATCHES "8561|8562")
475-
message(STATUS "z15 target")
476-
list(APPEND ARCH_FLAGS -march=z15)
477-
elseif (${S390X_M} MATCHES "3931")
478-
message(STATUS "z16 target")
479-
list(APPEND ARCH_FLAGS -march=z16)
480-
elseif (${S390X_M} MATCHES "9175|9176")
481-
# NOTE: Only available from GCC 15.1.0 onwards. Any z17 machine with compile issues must first verify their GCC version.
482-
# binutils must also be updated to the latest for the -march=z17 flag to work. Otherwise, use -march=arch15.
483-
message(STATUS "z17 target")
484-
list(APPEND ARCH_FLAGS -march=arch15)
485-
else()
486-
message(STATUS "Unknown target")
487-
message(WARNING "Unknown target. If you are compiling for z14 and earlier, you might have to add -DGGML_VXE=OFF.")
488-
list(APPEND ARCH_FLAGS -march=native -mtune=native)
469+
list(APPEND GGML_CPU_SOURCES
470+
ggml-cpu/arch/s390/quants.c)
471+
472+
# for native compilation
473+
if (GGML_NATIVE)
474+
# check machine level to determine target
475+
file(READ "/proc/cpuinfo" CPUINFO_CONTENTS)
476+
string(REGEX REPLACE "machine[ \t\r\n]*=[ \t\r\n]*([0-9]+)" "\\1" S390X_M ${CPUINFO_CONTENTS})
477+
478+
# TODO: Separation to determine activation of VX/VXE/VXE2
479+
if (${S390X_M} MATCHES "8561|8562")
480+
message(STATUS "z15 target")
481+
list(APPEND ARCH_FLAGS -march=z15)
482+
elseif (${S390X_M} MATCHES "3931")
483+
message(STATUS "z16 target")
484+
list(APPEND ARCH_FLAGS -march=z16)
485+
elseif (${S390X_M} MATCHES "9175|9176")
486+
# NOTE: Only available from GCC 15.1.0 onwards. Any z17 machine with compile issues must first verify their GCC version.
487+
# binutils must also be updated to the latest for the -march=z17 flag to work. Otherwise, use -march=arch15.
488+
message(STATUS "z17 target")
489+
list(APPEND ARCH_FLAGS -march=arch15)
490+
else()
491+
message(STATUS "Unknown target")
492+
message(WARNING "Unknown target. If you are compiling for z14 and earlier, you might have to add -DGGML_VXE=OFF.")
493+
list(APPEND ARCH_FLAGS -march=native -mtune=native)
494+
endif()
495+
# for cross-compilation
496+
elseif(GGML_CPU_ALL_VARIANTS)
497+
# range through IBM z15 to z17
498+
# NOTE: update when a new hardware level is released
499+
foreach (ZHW RANGE 15 17)
500+
if(DEFINED GGML_INTERNAL_Z${ZHW})
501+
message(STATUS "z${ZHW} cross-compile target")
502+
list(APPEND ARCH_FLAGS -march=z${ZHW})
503+
endif()
504+
endforeach()
489505
endif()
490506

491-
if (GGML_VXE)
507+
if (GGML_VXE OR GGML_INTERNAL_VXE)
492508
message(STATUS "VX/VXE/VXE2 enabled")
493509
list(APPEND ARCH_FLAGS -mvx -mzvector)
494510
list(APPEND ARCH_DEFINITIONS GGML_VXE)

0 commit comments

Comments
 (0)