ggml: initial s390 feat detection

Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>
This commit is contained in:
Aaron Teo
2025-10-26 13:13:54 +08:00
parent 13f2cfad41
commit 66ec3a0717
3 changed files with 64 additions and 3 deletions

View File

@@ -377,9 +377,9 @@ if (GGML_CPU_ALL_VARIANTS)
endif() endif()
elseif (GGML_SYSTEM_ARCH STREQUAL "s390x") elseif (GGML_SYSTEM_ARCH STREQUAL "s390x")
if (CMAKE_SYSTEM_NAME MATCHES "Linux") if (CMAKE_SYSTEM_NAME MATCHES "Linux")
ggml_add_cpu_backend_variant(s390x_z15 Z15 VXE) ggml_add_cpu_backend_variant(s390x)
# ggml_add_cpu_backend_variant(s390x_z16 Z16 VXE) ggml_add_cpu_backend_variant(z15 Z15 VXE)
# ggml_add_cpu_backend_variant(s390x_z17 Z17 VXE) ggml_add_cpu_backend_variant(z16 Z16 VXE)
else() else()
message(FATAL_ERROR "Unsupported s390x target OS: ${CMAKE_SYSTEM_NAME}") message(FATAL_ERROR "Unsupported s390x target OS: ${CMAKE_SYSTEM_NAME}")
endif() endif()

View File

@@ -509,6 +509,8 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
list(APPEND ARCH_FLAGS -mvx -mzvector) list(APPEND ARCH_FLAGS -mvx -mzvector)
list(APPEND ARCH_DEFINITIONS GGML_VXE) list(APPEND ARCH_DEFINITIONS GGML_VXE)
endif() endif()
ggml_add_cpu_backend_features(${GGML_CPU_NAME} arm ${ARCH_DEFINITIONS})
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "wasm") elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "wasm")
message(STATUS "Wasm detected") message(STATUS "Wasm detected")
list (APPEND GGML_CPU_SOURCES ggml-cpu/arch/wasm/quants.c) list (APPEND GGML_CPU_SOURCES ggml-cpu/arch/wasm/quants.c)

View File

@@ -0,0 +1,59 @@
#include "ggml-backend-impl.h"
#if defined(__s390x__)
#include <sys/auxv.h>
// find hwcap bits in asm/elf.h
#ifndef HWCAP_VXRS_EXT
#define HWCAP_VXRS_EXT (1 << 13)
#endif
#ifndef HWCAP_VXRS_EXT2
#define HWCAP_VXRS_EXT2 (1 << 15)
#endif
#ifndef HWCAP_NNPA
#define HWCAP_NNPA (1 << 20)
#endif
struct s390x_features {
bool has_vxe = false;
bool has_vxe2 = false;
bool has_nnpa = false;
s390x_features() {
uint32_t hwcap = getauxval(AT_HWCAP);
uint32_t hwcap2 = getauxval(AT_HWCAP2);
has_vxe = !!(hwcap & HWCAP_VXRS_EXT);
has_vxe2 = !!(hwcap & HWCAP_VXRS_EXT2);
has_nnpa = !!(hwcap & HWCAP_NNPA);
GGML_LOG_INFO("s390x features detected: VXE=%d, VXE2=%d, NNPA=%d",
has_vxe, has_vxe2, has_nnpa);
}
};
static int ggml_backend_cpu_s390x_score() {
int score = 1;
s390x_features sf;
#ifdef GGML_USE_VXE
if (!sf.has_vxe) { return 0; }
score += 1 << 1;
#endif
#ifdef GGML_USE_VXE2
if (!sf.has_vxe2) { return 0; }
score += 1 << 2;
#endif
#ifdef GGML_USE_NNPA
if (!sf.has_nnpa) { return 0; }
score += 1 << 3;
#endif
return score;
}
GGML_BACKEND_DL_SCORE_IMPL(ggml_backend_cpu_s390x_score)
#endif // __s390x__