summaryrefslogtreecommitdiff
path: root/llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp')
-rw-r--r--llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp b/llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp
new file mode 100644
index 0000000..5f4405a
--- /dev/null
+++ b/llama.cpp/ggml/src/ggml-cpu/arch/s390/cpu-feats.cpp
@@ -0,0 +1,50 @@
+#include "ggml-backend-impl.h"
+
+#if defined(__s390x__)
+#include <sys/auxv.h>
+
+// find hwcap bits in asm/elf.h
+#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_vxe2 = false;
+ bool has_nnpa = false;
+
+ s390x_features() {
+ uint32_t hwcap = getauxval(AT_HWCAP);
+ // NOTE: use hwcap2 with DFLT for z17 and later
+ // uint32_t hwcap2 = getauxval(AT_HWCAP2);
+
+ has_vxe2 = !!(hwcap & HWCAP_VXRS_EXT2);
+ has_nnpa = !!(hwcap & HWCAP_NNPA);
+ }
+};
+
+static int ggml_backend_cpu_s390x_score() {
+ int score = 1;
+ s390x_features sf;
+
+// IBM z15 / LinuxONE 3
+#ifdef GGML_USE_VXE2
+ if (!sf.has_vxe2) { return 0; }
+ score += 1 << 1;
+#endif
+
+// IBM z16 / LinuxONE 4 and z17 / LinuxONE 5
+#ifdef GGML_USE_NNPA
+ if (!sf.has_nnpa) { return 0; }
+ score += 1 << 2;
+#endif
+
+ return score;
+}
+
+GGML_BACKEND_DL_SCORE_IMPL(ggml_backend_cpu_s390x_score)
+
+#endif // __s390x__