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

Function ggml_vec_scale_f32

ggml.c:1363–1392  ·  view source on GitHub ↗

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; }

Source from the content-addressed store, hash-verified

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) {
1364#if defined(GGML_USE_ACCELERATE)
1365 vDSP_vsmul(y, 1, &v, y, 1, n);
1366#elif defined(GGML_SIMD)
1367 const int np = (n & ~(GGML_F32_STEP - 1));
1368
1369 GGML_F32_VEC vx = GGML_F32_VEC_SET1(v);
1370
1371 GGML_F32_VEC ay[GGML_F32_ARR];
1372
1373 for (int i = 0; i < np; i += GGML_F32_STEP) {
1374 for (int j = 0; j < GGML_F32_ARR; j++) {
1375 ay[j] = GGML_F32_VEC_LOAD(y + i + j*GGML_F32_EPR);
1376 ay[j] = GGML_F32_VEC_MUL(ay[j], vx);
1377
1378 GGML_F32_VEC_STORE(y + i + j*GGML_F32_EPR, ay[j]);
1379 }
1380 }
1381
1382 // leftovers
1383 for (int i = np; i < n; ++i) {
1384 y[i] *= v;
1385 }
1386#else
1387 // scalar
1388 for (int i = 0; i < n; ++i) {
1389 y[i] *= v;
1390 }
1391#endif
1392}
1393
1394inline static void ggml_vec_norm_f32 (const int n, float * s, const float * x) { ggml_vec_dot_f32(n, s, x, x); *s = sqrtf(*s); }
1395inline static void ggml_vec_sqr_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = x[i]*x[i]; }

Calls

no outgoing calls

Tested by

no test coverage detected