MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_vec_dot_f32

Function ggml_vec_dot_f32

ggml.c:1151–1186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1149inline static void ggml_vec_div_f32 (const int n, float * z, const float * x, const float * y) { for (int i = 0; i < n; ++i) z[i] = x[i]/y[i]; }
1150
1151static void ggml_vec_dot_f32(const int n, float * restrict s, const float * restrict x, const float * restrict y) {
1152#ifdef GGML_SIMD
1153 float sumf = 0.0f;
1154 const int np = (n & ~(GGML_F32_STEP - 1));
1155
1156 GGML_F32_VEC sum[GGML_F32_ARR] = { GGML_F32_VEC_ZERO };
1157
1158 GGML_F32_VEC ax[GGML_F32_ARR];
1159 GGML_F32_VEC ay[GGML_F32_ARR];
1160
1161 for (int i = 0; i < np; i += GGML_F32_STEP) {
1162 for (int j = 0; j < GGML_F32_ARR; j++) {
1163 ax[j] = GGML_F32_VEC_LOAD(x + i + j*GGML_F32_EPR);
1164 ay[j] = GGML_F32_VEC_LOAD(y + i + j*GGML_F32_EPR);
1165
1166 sum[j] = GGML_F32_VEC_FMA(sum[j], ax[j], ay[j]);
1167 }
1168 }
1169
1170 // reduce sum0..sum3 to sum0
1171 GGML_F32_VEC_REDUCE(sumf, sum);
1172
1173 // leftovers
1174 for (int i = np; i < n; ++i) {
1175 sumf += x[i]*y[i];
1176 }
1177#else
1178 // scalar
1179 ggml_float sumf = 0.0;
1180 for (int i = 0; i < n; ++i) {
1181 sumf += (ggml_float)(x[i]*y[i]);
1182 }
1183#endif
1184
1185 *s = sumf;
1186}
1187
1188static void ggml_vec_dot_f16(const int n, float * restrict s, ggml_fp16_t * restrict x, ggml_fp16_t * restrict y) {
1189 ggml_float sumf = 0.0;

Calls

no outgoing calls

Tested by

no test coverage detected