File tree Expand file tree Collapse file tree 4 files changed +68
-8
lines changed Expand file tree Collapse file tree 4 files changed +68
-8
lines changed Original file line number Diff line number Diff line change @@ -134,8 +134,8 @@ jobs:
134134 include :
135135 - build : ' x64'
136136 os : ubuntu-22.04
137- - build : ' s390x-z15 ' # z15 because our CI runners are on z15
138- os : ubuntu-22 .04-s390x
137+ - build : ' s390x'
138+ os : ubuntu-24 .04-s390x
139139 # GGML_BACKEND_DL and GGML_CPU_ALL_VARIANTS are not currently supported on arm
140140 # - build: 'arm64'
141141 # os: ubuntu-22.04-arm
Original file line number Diff line number Diff line change @@ -308,6 +308,10 @@ function(ggml_add_cpu_backend_variant tag_name)
308308 set (GGML_INTERNAL_${feat} ON )
309309 endforeach ()
310310 elseif (GGML_SYSTEM_ARCH STREQUAL "s390x" )
311+ foreach (feat VXE2 NNPA)
312+ set (GGML_INTERNAL_${feat} OFF )
313+ endforeach ()
314+
311315 foreach (feat ${ARGN} )
312316 set (GGML_INTERNAL_${feat} ON )
313317 endforeach ()
@@ -377,9 +381,8 @@ if (GGML_CPU_ALL_VARIANTS)
377381 endif ()
378382 elseif (GGML_SYSTEM_ARCH STREQUAL "s390x" )
379383 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)
384+ ggml_add_cpu_backend_variant(z15 Z15 VXE2)
385+ ggml_add_cpu_backend_variant(z16 Z16 VXE2 NNPA)
383386 else ()
384387 message (FATAL_ERROR "Unsupported s390x target OS: ${CMAKE_SYSTEM_NAME} " )
385388 endif ()
Original file line number Diff line number Diff line change @@ -504,11 +504,18 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
504504 endforeach ()
505505 endif ()
506506
507- if (GGML_VXE OR GGML_INTERNAL_VXE )
508- message (STATUS "VX/VXE/ VXE2 enabled" )
507+ if (GGML_VXE OR GGML_INTERNAL_VXE2 )
508+ message (STATUS "VXE2 enabled" )
509509 list (APPEND ARCH_FLAGS -mvx -mzvector)
510- list (APPEND ARCH_DEFINITIONS GGML_VXE )
510+ list (APPEND ARCH_DEFINITIONS GGML_USE_VXE2 )
511511 endif ()
512+
513+ if (GGML_INTERNAL_NNPA)
514+ message (STATUS "NNPA enabled" )
515+ list (APPEND ARCH_DEFINITIONS GGML_USE_NNPA)
516+ endif ()
517+
518+ ggml_add_cpu_backend_features(${GGML_CPU_NAME} s390 ${ARCH_DEFINITIONS} )
512519 elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "wasm" )
513520 message (STATUS "Wasm detected" )
514521 list (APPEND GGML_CPU_SOURCES ggml-cpu/arch/wasm/quants.c)
Original file line number Diff line number Diff line change 1+ #include " ggml-backend-impl.h"
2+
3+ #if defined(__s390x__)
4+ #include < sys/auxv.h>
5+
6+ // find hwcap bits in asm/elf.h
7+ #ifndef HWCAP_VXRS_EXT2
8+ #define HWCAP_VXRS_EXT2 (1 << 15 )
9+ #endif
10+
11+ #ifndef HWCAP_NNPA
12+ #define HWCAP_NNPA (1 << 20 )
13+ #endif
14+
15+ struct s390x_features {
16+ bool has_vxe2 = false ;
17+ bool has_nnpa = false ;
18+
19+ s390x_features () {
20+ uint32_t hwcap = getauxval (AT_HWCAP);
21+ // NOTE: use hwcap2 with DFLT for z17 and later
22+ // uint32_t hwcap2 = getauxval(AT_HWCAP2);
23+
24+ has_vxe2 = !!(hwcap & HWCAP_VXRS_EXT2);
25+ has_nnpa = !!(hwcap & HWCAP_NNPA);
26+ }
27+ };
28+
29+ static int ggml_backend_cpu_s390x_score () {
30+ int score = 1 ;
31+ s390x_features sf;
32+
33+ // IBM z15 / LinuxONE 3
34+ #ifdef GGML_USE_VXE2
35+ if (!sf.has_vxe2 ) { return 0 ; }
36+ score += 1 << 1 ;
37+ #endif
38+
39+ // IBM z16 / LinuxONE 4 and z17 / LinuxONE 5
40+ #ifdef GGML_USE_NNPA
41+ if (!sf.has_nnpa ) { return 0 ; }
42+ score += 1 << 2 ;
43+ #endif
44+
45+ return score;
46+ }
47+
48+ GGML_BACKEND_DL_SCORE_IMPL (ggml_backend_cpu_s390x_score)
49+
50+ #endif // __s390x__
You can’t perform that action at this time.
0 commit comments