Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimises the
GGML_OP_SUM
operation, as implemented in #16539.The original implementation performed the sum op on one thread as follows:
resulting the following
./test-backend-ops perf -o SUM
log:Implementation
To fix this, I've modified the host-side code to launch
nth
threads in one threadgroup, so that each thread sums a strided chunk (similar toop_sum_rows
).simd_sum(sumf)
is used to perform a partial sum within each SIMD groupsimd_sum(v)
is used to do a reduction across SIMD groups (only SIMD group 0 is involved here)nth
value is calculated similarly toop_sum_rows
Resulting in the following performance log via
./test-backend-ops perf -o SUM
:Note that this is still quite a bit slower than
SUM_ROWS
,So there may be room for improvement in the current kernel implementation.