From: Georgi Gerganov Date: Sat, 7 Jan 2023 14:10:16 +0000 (+0200) Subject: ggml : use vDSP_sve and vDSP_maxv from Accelerate X-Git-Tag: upstream/1.7.4~1639 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=d51fc3ee0a0038cdf1522ca3d58b58299de41eb8;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp ggml : use vDSP_sve and vDSP_maxv from Accelerate --- diff --git a/ggml.c b/ggml.c index c88eb227..38e79e76 100644 --- 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); } //