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

Function ggml_vec_dot_f16

ggml.c:1188–1222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;
1190
1191#if defined(GGML_SIMD)
1192 const int np = (n & ~(GGML_F16_STEP - 1));
1193
1194 GGML_F16_VEC sum[GGML_F16_ARR] = { GGML_F16_VEC_ZERO };
1195
1196 GGML_F16_VEC ax[GGML_F16_ARR];
1197 GGML_F16_VEC ay[GGML_F16_ARR];
1198
1199 for (int i = 0; i < np; i += GGML_F16_STEP) {
1200 for (int j = 0; j < GGML_F16_ARR; j++) {
1201 ax[j] = GGML_F16_VEC_LOAD(x + i + j*GGML_F16_EPR, j);
1202 ay[j] = GGML_F16_VEC_LOAD(y + i + j*GGML_F16_EPR, j);
1203
1204 sum[j] = GGML_F16_VEC_FMA(sum[j], ax[j], ay[j]);
1205 }
1206 }
1207
1208 // reduce sum0..sum3 to sum0
1209 GGML_F16_VEC_REDUCE(sumf, sum);
1210
1211 // leftovers
1212 for (int i = np; i < n; ++i) {
1213 sumf += (ggml_float)(GGML_FP16_TO_FP32(x[i])*GGML_FP16_TO_FP32(y[i]));
1214 }
1215#else
1216 for (int i = 0; i < n; ++i) {
1217 sumf += (ggml_float)(GGML_FP16_TO_FP32(x[i])*GGML_FP16_TO_FP32(y[i]));
1218 }
1219#endif
1220
1221 *s = sumf;
1222}
1223
1224// compute GGML_VEC_DOT_UNROLL dot products at once
1225// xs - x row stride in bytes

Calls

no outgoing calls

Tested by

no test coverage detected