@@ -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