Repository navigation
perf(hip): band the prefill WMMA GEMM's blocks so row blocks share weights - #1648
Merged
Merged
Conversation
This was referenced Oct 30, 2026
…ights The matrix tile maps its block id onto (column block, row block) in bands of four row blocks, as CUDA's tile_of does, so a band walks the same column blocks while their weights are cached. Every tile runs the same operations in the same order; only which block computes it changes. Qwen3.8-27B on gfx1151, cold prompt: 2048 tokens 8.56 -> 7.48 s, 8192 tokens 35.24 -> 31.04 s. A kernel test pins the matrix tile's bytes to the dot2 tile's on the served shapes and band edges.
…e's order test band_tile only runs where the matrix tile does (gfx11 WMMA), which is where the order test runs, so the test exercises the remap on every GPU that uses it. Two served shapes were missing: a call of one row block (33 to 128 rows) and a call of one column block with a partial band. A planted remap that gives one row block a band of two fails only the new shape in this test.
ashhart
force-pushed
the
perf/hip-prefill
branch
from
October 30, 2026 20:58
31d714e to
fff6abd
Compare
7 of 9 tasks
Owner
|
Thank you @AbrahamCete. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0 It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog. |
Contributor
Author
|
Thanks @ashhart, glad it landed. |
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.
What this changes
The HIP matrix tile (
affine_wmma_gemm, the prompt GEMM on gfx11) now maps its block id onto (column block, row block) in bands of four row blocks, the same idea as CUDA'stile_of. Within a band, the blocks walk the column blocks together while those columns' weights are still in cache. Every tile runs the same operations in the same order; only which block computes it changes, so the output bytes are identical. On Qwen3.8-27B on gfx1151, cold prefill is 9.5-12% faster from 2k to 64k tokens.The launch grid is unchanged.
band_tileintiles/gemm.hppis a bijection per z slice and handles a partial last band. The dot2 GEMM tile still uses plainblockIdxorder, and the new kernel test uses it as the reference.Receipt
Environment: Ryzen AI Max+ 395 (gfx1151), Ubuntu 26.04, Zig 0.17.0, Ubuntu clang 21 hipcc (ROCm 7.13 from TheRock for the contract limits), checkpoint Qwen3.8-27B-MLX-4bit. The receipts were measured with
maind33dcfc as before and this branch on top of it as after. The branch is now rebased ontomainf350cd3 with no conflicts, and the checks marked "on f350cd3" below were rerun there.Exactness:
kernel_tests/affine/order.zigrequires the matrix tile's output digest to equal the dot2 GEMM tile's on 16 shapes. These are the 27B's prompt projections at 2048 rows, rows that are not a multiple of 128 or of the band (1000, 1300, 300), one row block (100), one column block (n 48 and n 130 at 2048 rows), a 35B routed product, and 8-bit.token_shais identical between before and after at every size (2kfaceb02af600, 8k1ebfd15d62c7, 32kc8dfa0175e40, 64kd92b23432e24).tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serial, run twice on each side:token_shais the same before and after: code2b28aa2108de, chata06fab348fbe.tf-qwen35-test checkmatches before and after: 27B 42 passed, 0 failed, 5 skipped; 35B-A3B 46/0/1.Decode speed before and after: unchanged, because the matrix tile does not run inside lane rounds.
--context 4096 --parallel 4 --prompt-cache-gib 0. Runs alternated B1 C1 B2 C2.tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0, median decode in tok/s:fibonacci-raw: 13.30, 13.30 before; 13.28, 13.35 after.gpu-chat-no-think: 13.61, 13.54 before; 13.66, 13.66 after.bench_concurrent, aggregate tok/s:Prompt speed before and after: cold first request
ttft_sfromtools/bench_cache.py --require-cold --tokens 16.tensorfold-native serve --context 66560 --parallel 1 --prompt-cache-gib 0 --snapshot-dir none --max-snapshots 0, with a fresh server for each run.cached_tokens = 0, and every run qualified.The gain shrinks with length because attention, which this change does not touch, takes a growing share of the prompt pass.
Release 1.1.9 (465e48b) measured the same as
mainin an earlier run of the same protocol: 8.68, 35.87, 160.05 and 366.62 s.tf-qwen35-test prefill <27B> 2048, alternated 3 times againstmain, gives a median of 8.509 s before and 7.439 s after (-12.6%).The prompts are fixed token arrays, made from a corpus of TensorFold docs and server sources and tokenized by the checkpoint. I can attach the arrays, the request bodies and the raw
bench_cacheJSON.Band height sweep on the 27B's seven prompt GEMM shapes:
I kept row bands of 4, which matches
tile_of. They are best ondown.Tests run:
hip-kernel-test(binary run directly), on f350cd3: 107 passed, 0 failed, 0 skipped. The order test is the only new test; at d33dcfc it was 104 againstmain's 103.test-qwen35-hip-host,hip-host-test,check-native-hip-host, on f350cd3: exit 0.tf-qwen35-test prefill <27B> 2048, on f350cd3: 7.475 s (274 tok/s).SUMMARY gfx1151 49 kernels: 49 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 126 limit problems, the same before and after.affine_wmma_gemmrecord exists.tools/zig/lean_check.py, on f350cd3: 426 problems onmainand on this branch, none new.zig fmt --checkclean.affine.affinex3,affine.rowsandnemotron.moex2.Not run, and why:
caps.matrix == .wmma11), so other GPUs never runband_tile, and the order test skips there.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Bytes unchanged: order test, servedtoken_sha, andbench_concurrentalone and serial equal;tf-qwen35-test checkmatches before and after.)SUMMARYline is in the receipt.main, which measures the same as 1.1.9.)