]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
ggml : use vDSP_sve and vDSP_maxv from Accelerate
authorGeorgi Gerganov <redacted>
Sat, 7 Jan 2023 14:10:16 +0000 (16:10 +0200)
committerGeorgi Gerganov <redacted>
Sat, 7 Jan 2023 14:10:16 +0000 (16:10 +0200)
ggml.c

diff --git a/ggml.c b/ggml.c
index c88eb22741f3f23b8e6d6005acb89891b14c5c43..38e79e764b9dcdea88702f5752e3c1c4746969dc 100644 (file)
--- a/ggml.c
+++ b/ggml.c
@@ -1039,7 +1039,30 @@ inline static void ggml_vec_gelu_f32(const int n, float * y, const float * x) {
 }
 #endif
 
-inline static void ggml_vec_sum_f32     (const int n, float * s, const float * x) { ggml_float sum = 0.0; for (int i = 0; i < n; ++i) sum += x[i]; *s += sum; }
+inline static void ggml_vec_sum_f32(const int n, float * s, const float * x) {
+#ifndef GGML_USE_ACCELERATE
+    ggml_float sum = 0.0;
+    for (int i = 0; i < n; ++i) {
+        sum += x[i];
+        *s += sum;
+    }
+#else
+    vDSP_sve(x, 1, s, n);
+#endif
+}
+
+inline static void ggml_vec_max_f32(const int n, float * s, const float * x) {
+#ifndef GGML_USE_ACCELERATE
+    ggml_float max = -INFINITY;
+    for (int i = 0; i < n; ++i) {
+        max = MAX(max, x[i]);
+    }
+    *s = max;
+#else
+    vDSP_maxv(x, 1, s, n);
+#endif
+}
+
 inline static void ggml_vec_norm_inv_f32(const int n, float * s, const float * x) { ggml_vec_norm_f32(n, s, x); *s = 1./(*s); }
 
 //