perf(kernels): speed up linear-attention prefill ~2.6x (Q/K LDS tiling + dk-split) - #600
Open
donghanbj wants to merge 2 commits into
Open
perf(kernels): speed up linear-attention prefill ~2.6x (Q/K LDS tiling + dk-split)#600donghanbj wants to merge 2 commits into
donghanbj wants to merge 2 commits into
Conversation
…g + dk-split) The gated-delta chunked prefill kernel (linear_attention_prefill_chunked) was latency/LDS-bound on gfx1151. Two combined changes: - Cache the per-chunk K and Q tiles in LDS with a +1-float row pad (qk_stride = dk+1) to kill the 32-way LDS bank conflicts and drop the repeated global query reads in the P-matrix and output phases. - dk-split (HIPDNN_EP_LA_PREFILL_DK_SPLIT, default 4): g_split lanes cooperate on each output column and split the dk reduction of the two dv-wide phases (B and output), combined via warp shuffle (block = g_split*dv). Fixes the ~50%-idle-thread underutilization (256 threads vs dv=128 columns) and hides the latency-bound S reads. gfx1151 / Qwen3.5-35B-A3B (seq=1842): kernel 25.3 -> 9.7 ms (2.6x, standalone, 16 waves/SIMD, no scratch spill); end-to-end TTFT -18%, prefill throughput +22%, decode unchanged. Output cosine 0.9999996 vs the per-token decode oracle. Co-authored-by: Cursor <cursoragent@cursor.com>
donghanbj
requested review from
amd-mingw,
edelaye,
fhanuman,
qianglin-amd and
wcy123
as code owners
July 30, 2026 16:55
|
Thanks for opening a PR! This project follows LLVM's incremental-development and AI-tool-use Before requesting review, please check that:
Reviewers are assigned through |
L2 Accuracy Results (EP vs CPU)
Threshold: 0.01 | Run: 3440 - Commit: |
MorphiZen EP Performance Results
EPContext Export Performance
EPContext Import Performance
OGA Benchmark Results
OGA Wheel Smoke (Python benchmark_e2e.py)
Run: 3440 - Commit: |
Contributor
Author
|
/run-test models=all |
Contributor
|
ROCm OGA CI finished with result: UNSTABLE.
|
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.
Summary
Optimizes the gated-delta chunked linear-attention prefill kernel
(
linear_attention_prefill_chunked) on gfx1151, which was latency / LDS-bound.Two combined, orthogonal changes:
in LDS with a
+1-float row pad (qk_stride = dk + 1). This removes the 32-wayLDS bank conflicts (dk=128 is an exact multiple of the 32 banks) and drops the
repeated global
queryreads in the P-matrix and output phases.HIPDNN_EP_LA_PREFILL_DK_SPLIT, default 4) —g_splitlanescooperate on each output column and split the dk reduction of the two dv-wide
phases (B and output), combining via a warp shuffle (
block = g_split*dv). Thisfixes the ~50%-idle-thread underutilization (256 threads vs dv=128 columns) and
multiplies resident wavefronts to hide the latency-bound state reads. Falls back
to the per-column path (
g_split=1) when a shape can't satisfy the split.The decode path and everything outside the prefill kernel are unchanged.
Results (gfx1151 / Qwen3.5-35B-A3B, seq=1842)
Kernel occupancy 16 waves/SIMD, no scratch spill. Output is numerically identical
in quality: cosine 0.9999996 vs the per-token decode oracle.
Test plan
verified for all
g_splitin {1, 2, 4, 8}.1_build.bat: LIT 354/356 pass, plugin-registrar + output-allocator unittests pass.
thermal window: TTFT / prefill improved as above, generated text correct.