-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Leverage the existing GGML_F32_VEC helpers to vectorize ggml_vec_set_f32 for faster fills #16522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…e across SIMD registers and store in vector-sized chunks, while retaining the scalar tail for leftover elements and non-SIMD builds.
|
microbenchmarks show sometimes very little change, but sometimes a nice bump |
| inline static void ggml_vec_add1_f32(const int n, float * z, const float * x, const float v) { | ||
| #if defined(GGML_SIMD) | ||
| const int np = (n & ~(GGML_F32_STEP - 1)); | ||
|
|
||
| GGML_F32_VEC vv = GGML_F32_VEC_SET1(v); | ||
|
|
||
| for (int i = 0; i < np; i += GGML_F32_STEP) { | ||
| for (int j = 0; j < GGML_F32_ARR; ++j) { | ||
| GGML_F32_VEC ax = GGML_F32_VEC_LOAD(x + i + j*GGML_F32_EPR); | ||
| GGML_F32_VEC az = GGML_F32_VEC_ADD(ax, vv); | ||
| GGML_F32_VEC_STORE(z + i + j*GGML_F32_EPR, az); | ||
| } | ||
| } | ||
|
|
||
| for (int i = np; i < n; ++i) { | ||
| z[i] = x[i] + v; | ||
| } | ||
| #else | ||
| for (int i = 0; i < n; ++i) { | ||
| z[i] = x[i] + v; | ||
| } | ||
| #endif | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make the code consistent about how it handles the leftovers. Here we duplicate the scalar code, while in ggml_vec_add_f32 above we use a common loop iterator. I think we should do the same as in ggml_vec_add_f32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure thing. latest brings simd/scalar functions inline with each other.
|
Looks ready to merge, forgotten? |
|
Looks like we got some issues due to this PR being somewhat out of sync with recent CI additions: Edit: this one looks like it was already failing before merge: |
|
I am not sure what's the issue with the failing systems, so I have reverted this. Feel free to resubmit this change once the issue is fixed. |
…ec_set_f32 for faster fills (ggml-org#16522) * Leverage the existing GGML_F32_VEC helpers to broadcast the fill value across SIMD registers and store in vector-sized chunks, while retaining the scalar tail for leftover elements and non-SIMD builds. * Vectorize additional f32 helper loops * Normalize f32 helper tails for ggml vec ops --------- Co-authored-by: Aaron <[email protected]>
…ec_set_f32 for faster fills (ggml-org#16522) * Leverage the existing GGML_F32_VEC helpers to broadcast the fill value across SIMD registers and store in vector-sized chunks, while retaining the scalar tail for leftover elements and non-SIMD builds. * Vectorize additional f32 helper loops * Normalize f32 helper tails for ggml vec ops --------- Co-authored-by: Aaron <[email protected]>
Add a SIMD path to
ggml_vec_set_f32, broadcasting the fill value with the existing GGML_F32_VEC helpersKeep the scalar tail for leftover elements and non-SIMD builds