Skip to content

perf(hip): band the prefill WMMA GEMM's blocks so row blocks share weights - #1648

Merged
ashhart merged 3 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-prefill
Oct 30, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-prefill

Conversation

@AbrahamCete

Copy link
Copy Markdown
Contributor

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's tile_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_tile in tiles/gemm.hpp is a bijection per z slice and handles a partial last band. The dot2 GEMM tile still uses plain blockIdx order, 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 main d33dcfc as before and this branch on top of it as after. The branch is now rebased onto main f350cd3 with no conflicts, and the checks marked "on f350cd3" below were rerun there.

  • Exactness:

    • Kernel bytes: the new test kernel_tests/affine/order.zig requires 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.
    • Served bytes: the cold replies' token_sha is identical between before and after at every size (2k faceb02af600, 8k 1ebfd15d62c7, 32k c8dfa0175e40, 64k d92b23432e24).
    • tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serial, run twice on each side:
      • Every cell reports alone equal 3/3 at 1 stream and 12/12 at 4 streams, serial 1/1, and 0 failed.
      • token_sha is the same before and after: code 2b28aa2108de, chat a06fab348fbe.
    • tf-qwen35-test check matches 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.

    • Server: --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:
      • code: 13.3 before and 13.3-13.4 after at 1 stream; 43.8-44.0 before and 44.0 after at 4 streams.
      • chat: 13.5-13.6 before and 13.6-13.7 after at 1 stream; 43.4-43.5 before and 43.5-43.6 after at 4 streams.
    • The 16-token replies of the cold runs decode at the same speed (before/after): 2k 12.96/12.98, 8k 12.17/12.18, 32k 11.93/11.94, 64k 8.32/8.31.
  • Prompt speed before and after: cold first request ttft_s from tools/bench_cache.py --require-cold --tokens 16.

    • Server: tensorfold-native serve --context 66560 --parallel 1 --prompt-cache-gib 0 --snapshot-dir none --max-snapshots 0, with a fresh server for each run.
    • Runs alternated B1 C1 B2 C2, giving 6 cold samples per cell. Every request reported cached_tokens = 0, and every run qualified.
    prompt main ttft (s) branch ttft (s) change
    2048 8.64 [8.58-8.75] 7.60 [7.57-7.62] -12.0%
    8192 35.52 [35.26-35.68] 31.42 [31.33-31.49] -11.5%
    32768 160.08 [158.82-161.12] 142.66 [142.18-142.96] -10.9%
    65536 365.73 [364.96-366.75] 330.83 [329.98-331.57] -9.5%
    • 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 main in 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 against main, 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_cache JSON.

    • Band height sweep on the 27B's seven prompt GEMM shapes:

      • row-major: 102.5 ms
      • bands of 2: 90.7 ms
      • bands of 4: 87.6 ms
      • bands of 8: 92.7 ms
      • bands of 16: 94.7 ms
      • bands of 32: 94.7 ms
      • column bands of 4: 87.3 ms

      I kept row bands of 4, which matches tile_of. They are best on down.

  • 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 against main'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).
    • Kernel contract: 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.
    • Contract limits with ROCm 7.13 hipcc: 220 problems before and after. No affine_wmma_gemm record exists.
    • tools/zig/lean_check.py, on f350cd3: 426 problems on main and on this branch, none new.
    • zig fmt --check clean.
    • Planted controls: giving the last band a full height, or giving one row block a band of two, makes the order test fail. The first also fails affine.affine x3, affine.rows and nemotron.moe x2.
  • Not run, and why:

    • gfx1100: I have no card. The matrix tile runs only on gfx11 WMMA (caps.matrix == .wmma11), so other GPUs never run band_tile, and the order test skips there.
    • Metal and CUDA: untouched.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Bytes unchanged: order test, served token_sha, and bench_concurrent alone and serial equal; tf-qwen35-test check matches before and after.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change.)
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt.
  • Prompt processing is no slower than the last release. (9.5-12% faster than main, which measures the same as 1.1.9.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (gfx1151 only; no Metal, CUDA or gfx1100.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The order test pins bytes, which the change keeps by construction, so it passes before and after. It fails on the planted remaps above and skips without the matrix tile.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

AbrahamCete and others added 3 commits October 30, 2026 20:58
…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
ashhart merged commit 4b287e3 into ashhart:main Oct 30, 2026
8 of 9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
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.

@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart, glad it landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants