ggerganov commited on
Commit
ed14a8b
·
unverified ·
1 Parent(s): 496acd2

ggml : use vDSP_sve and vDSP_maxv from Accelerate

Browse files
Files changed (1) hide show
  1. ggml.c +24 -1
ggml.c CHANGED
@@ -1039,7 +1039,30 @@ inline static void ggml_vec_gelu_f32(const int n, float * y, const float * x) {
1039
  }
1040
  #endif
1041
 
1042
- 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; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1043
  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); }
1044
 
1045
  //
 
1039
  }
1040
  #endif
1041
 
1042
+ inline static void ggml_vec_sum_f32(const int n, float * s, const float * x) {
1043
+ #ifndef GGML_USE_ACCELERATE
1044
+ ggml_float sum = 0.0;
1045
+ for (int i = 0; i < n; ++i) {
1046
+ sum += x[i];
1047
+ *s += sum;
1048
+ }
1049
+ #else
1050
+ vDSP_sve(x, 1, s, n);
1051
+ #endif
1052
+ }
1053
+
1054
+ inline static void ggml_vec_max_f32(const int n, float * s, const float * x) {
1055
+ #ifndef GGML_USE_ACCELERATE
1056
+ ggml_float max = -INFINITY;
1057
+ for (int i = 0; i < n; ++i) {
1058
+ max = MAX(max, x[i]);
1059
+ }
1060
+ *s = max;
1061
+ #else
1062
+ vDSP_maxv(x, 1, s, n);
1063
+ #endif
1064
+ }
1065
+
1066
  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); }
1067
 
1068
  //