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

Function ggml_vec_mad_f32_unroll

ggml.c:1311–1360  ·  view source on GitHub ↗

xs and vs are byte strides of x and v

Source from the content-addressed store, hash-verified

1309
1310// xs and vs are byte strides of x and v
1311inline static void ggml_vec_mad_f32_unroll(const int n, const int xs, const int vs, float * restrict y, const float * restrict xv, const float * restrict vv) {
1312
1313 const float * restrict x[GGML_VEC_MAD_UNROLL];
1314 const float * restrict v[GGML_VEC_MAD_UNROLL];
1315
1316 for (int i = 0; i < GGML_VEC_MAD_UNROLL; ++i) {
1317 x[i] = (const float *) ((const char *) xv + i*xs);
1318 v[i] = (const float *) ((const char *) vv + i*vs);
1319 }
1320
1321#if defined(GGML_SIMD)
1322 const int np = (n & ~(GGML_F32_STEP - 1));
1323
1324 GGML_F32_VEC vx[GGML_VEC_MAD_UNROLL];
1325
1326 for (int k = 0; k < GGML_VEC_MAD_UNROLL; ++k) {
1327 vx[k] = GGML_F32_VEC_SET1(v[k][0]);
1328 }
1329
1330 GGML_F32_VEC ax[GGML_VEC_MAD_UNROLL][GGML_F32_ARR];
1331 GGML_F32_VEC ay[GGML_F32_ARR];
1332
1333 for (int i = 0; i < np; i += GGML_F32_STEP) {
1334 for (int j = 0; j < GGML_F32_ARR; j++) {
1335 ay[j] = GGML_F32_VEC_LOAD(y + i + j*GGML_F32_EPR);
1336
1337 for (int k = 0; k < GGML_VEC_MAD_UNROLL; ++k) {
1338 ax[k][j] = GGML_F32_VEC_LOAD(x[k] + i + j*GGML_F32_EPR);
1339 ay[j] = GGML_F32_VEC_FMA(ay[j], ax[k][j], vx[k]);
1340 }
1341
1342 GGML_F32_VEC_STORE(y + i + j*GGML_F32_EPR, ay[j]);
1343 }
1344 }
1345
1346 // leftovers
1347 for (int k = 0; k < GGML_VEC_MAD_UNROLL; ++k) {
1348 for (int i = np; i < n; ++i) {
1349 y[i] += x[k][i]*v[k][0];
1350 }
1351 }
1352#else
1353 // scalar
1354 for (int k = 0; k < GGML_VEC_MAD_UNROLL; ++k) {
1355 for (int i = 0; i < n; ++i) {
1356 y[i] += x[k][i]*v[k][0];
1357 }
1358 }
1359#endif
1360}
1361
1362//inline static void ggml_vec_scale_f32(const int n, float * y, const float v) { for (int i = 0; i < n; ++i) y[i] *= v; }
1363inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected