Skip to content

Commit 3ef4fa2

Browse files
authored
Merge branch 'ggml-org:master' into master
2 parents 559331a + 0398752 commit 3ef4fa2

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
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)

src/llama-model.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const char * llm_type_name(llm_type type) {
114114
case LLM_TYPE_17B_16E: return "17Bx16E (Scout)";
115115
case LLM_TYPE_17B_128E: return "17Bx128E (Maverick)";
116116
case LLM_TYPE_A13B: return "A13B";
117+
case LLM_TYPE_7B_A1B: return "7B.A1B";
117118
case LLM_TYPE_8B_A1B: return "8B.A1B";
118119
case LLM_TYPE_21B_A3B: return "21B.A3B";
119120
case LLM_TYPE_30B_A3B: return "30B.A3B";
@@ -1843,8 +1844,10 @@ void llama_model::load_hparams(llama_model_loader & ml) {
18431844

18441845
ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps);
18451846

1846-
switch (hparams.n_layer) {
1847-
// TODO: Add llm type label (not sure this is useful)
1847+
switch (hparams.n_embd) {
1848+
case 1536: type = LLM_TYPE_7B_A1B; break;
1849+
case 2048: case 2560: type = LLM_TYPE_3B; break;
1850+
case 4096: type = LLM_TYPE_32B; break;
18481851
default: type = LLM_TYPE_UNKNOWN;
18491852
}
18501853

src/llama-model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ enum llm_type {
107107
LLM_TYPE_17B_16E, // llama4 Scout
108108
LLM_TYPE_17B_128E, // llama4 Maverick
109109
LLM_TYPE_A13B,
110+
LLM_TYPE_7B_A1B,
110111
LLM_TYPE_8B_A1B, // lfm2moe
111112
LLM_TYPE_21B_A3B, // Ernie MoE small
112113
LLM_TYPE_30B_A3B,

0 commit comments

Comments
 (0)