SYCL: reduce allocation overhead during flash attention#22732
Open
sanmai wants to merge 2 commits intoggml-org:masterfrom
Open
SYCL: reduce allocation overhead during flash attention#22732sanmai wants to merge 2 commits intoggml-org:masterfrom
sanmai wants to merge 2 commits intoggml-org:masterfrom
Conversation
sanmai
commented
May 5, 2026
|
|
||
| sycl::half * alloc(size_t n_elems) { | ||
| ptr = buf.ensure_half(n_elems); | ||
| return ptr; |
Author
There was a problem hiding this comment.
the calling code does not use the return value but pool_alloc::alloc returns so keep doing that too to reduce the surprise if someone changes the old code to use the return value later
sanmai
commented
May 5, 2026
| ggml_sycl_pool_alloc<sycl::half> K_f16(pool); | ||
| ggml_sycl_pool_alloc<sycl::half> V_f16(pool); | ||
| ggml_sycl_fattn_alloc K_f16(fbuf.K); | ||
| ggml_sycl_fattn_alloc V_f16(fbuf.V); |
Author
There was a problem hiding this comment.
I considered adding a no-op template to make it look more uniform:
ggml_sycl_fattn_alloc<sycl::half> K_f16(fbuf.K);
ggml_sycl_fattn_alloc<sycl::half> V_f16(fbuf.V);
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #22585
Overview
I found that flash attention allocated quite a few K/V buffers with little reuse, which remained in the legacy pool until teardown. And it sounds like a better strategy is to allocate the FA buffers outside the common pool and grow them on demand. So that at most, FA uses the largest buffers it needs.
Arguably, there are more optimal strategies: we still leave the buffers occupied. That said, there aren't evictions in the legacy pool, so at very least we are in a better spot.
ggml_sycl_fattn_alloc::allocis called again so no queue sync should be needed but I added one anyway just to be extra safeAdditional information
Memory benchmarks with B60 and Qwen3.6-35B-A3B UD-Q4_K_M, q4_0:
Baseline (without buffers)
Smaller prompt:
Larger prompt:
With buffers
Smaller prompt:
68.80 MiB savings compared to the baseline.
Larger prompt:
that's 272.87 total for the pool plus the two FA buffers, or 897.37 MiB savings compare to the baseline. In a memory constrained environment it could be a deal breaker.
It spills into the common memory breakdown just as one expects.
Requirements