Skip to content

perf(hip): multi-row decode rounds weigh each slot's rows from one read of their values - #4754

Merged
ashhart merged 9 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-decode-rows-share-apply
Nov 24, 2026
Merged

ashhart merged 9 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-decode-rows-share-apply

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

At d = 256 on long spans (the Qwen checkpoints' served decode walk), every row of a decode round reads its slot's whole
value cache in the values step (tf_plan_apply_*), so the pending token and each drafted row of a stream pay for the
same reads. #4673 made a multi-row round's score step read a slot's keys once; this does the same for its values. A
multi-row round's values step is now two launches on today's grid: the rows of one-row slots take today's kernel body at
today's occupancy, and the rows of multi-row slots are weighed in chunks of four, a chunk's values read once. Each row
keeps the tree's operands and the order of its sums, so the partials' bytes are today's. One-row rounds keep today's
single launch. This is the apply half of #3811, stacked on the score half (#4673).

It follows the shape ashhart gave on #3811 (issuecomment-7077344772), as #4673 does:

Leading a chunk from first and count with the grid unchanged is the right fit for graph replay: the replay key
stays as it is, and a chunk never crosses a stream. One-row rounds should keep today's kernels.

For landing, what you listed: byte checks with NaN/inf-poisoned caches, rows away from the span's end and several
streams in one launch, the HIP contract SUMMARY line, and served receipts on the head: token hashes equal to main,
drafted equal to "draft": false, and decode at 131K and 262K with drafts on.

Design.

Timing. The values step against the tree's tf_plan_apply_* (the base's values step) on gfx1151, both launches:
medians of 15 alternated runs at the span's end after 3 warm-up pairs, each slot with its own K/V pool; the first of
three runs in microseconds, and the change in each of the three. 16/2 is 16 query heads over 2 KV heads (the
35B-A3B's shape), 24/4 is 24 over 4 (the 27B's):

Slots in the launch 16/2, 131K 16/2, 262K 24/4, 131K 24/4, 262K
{2} 1,633.8 -> 1,262.1 us, -22.0% to -22.8% 3,522.3 -> 2,677.4, -24.0% to -24.7% 3,266.0 -> 2,266.8, -30.2% to -30.6% 6,536.2 -> 4,555.3, -30.3% to -30.7%
{4} 3,324.0 -> 2,379.5, -28.4% to -29.3% 6,997.7 -> 4,911.0, -29.8% to -30.4% 6,476.5 -> 4,052.3, -37.4% to -38.1% 12,731.3 -> 7,986.6, -37.2% to -37.5%
{1, 1} 1,711.2 -> 1,728.7, +0.6% to +1.0% 3,490.2 -> 3,522.4, +0.6% to +0.9% 3,250.4 -> 3,270.7, +0.6% to +0.8% 6,456.8 -> 6,500.2, +0.5% to +0.7%
{1, 1, 1, 1} 3,416.1 -> 3,428.2, +0.4% to +0.7% 6,956.9 -> 7,004.5, +0.4% to +0.7% 6,447.4 -> 6,489.9, +0.7% 12,802.0 -> 12,880.9, +0.4% to +1.0%
{2, 1, 1} 3,491.2 -> 3,134.5, -10.2% to -10.6% 6,919.1 -> 6,145.6, -11.2% to -11.4% 6,521.4 -> 5,568.4, -14.5% to -15.2% 12,900.3 -> 10,957.0, -14.6% to -15.1%

Each side's interquartile range over its 15 runs is 0.1% to 3.8% (0.1% to 1.1% on the one-row slots). With the score
step, both steps on this stack against both on today's one-row kernels, one slot of 2 or 4 rows: -20.7% to -26.7%
(16/2) and -31.8% to -37.1% (24/4). The +0.4% to +1.0% left on one-row slots is the second launch's 4,096 to 32,768
blocks leaving at once (12 to 79 us a step), as in #4673. Served, the same no-drafts rounds read level (the Receipt).

Beyond the plan, or where it was silent; say which you want changed:

  • A values block takes at most eight heads: four rows' weights of eight heads are its 16 KiB of LDS. A launch whose
    values group is larger keeps today's kernel; the served groups are 8 and 6.
  • The chunk is four rows whatever the round holds (MTP's four rows a slot are one chunk); a slot of more rows is chunks
    of four and a tail, so the contract's slots add one of 6 rows, and the kernel test slots of 6 and 5.
  • The shared kernel reads the values with cache_load, the global load perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's score uses, where plan_apply_body uses
    load (a flat load); the bits are the same, and I did not time one against the other. Its body is
    __forceinline__: without it the kernel took 148 VGPRs and scratch.
  • As in perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673, a row weighed by both launches would get the same bytes from each, so no check can show it; the one
    predicate keeps the two sets apart. It would cost time, not bits.
  • contract_apply_rows.zig repeats three private helpers of contract_walk_rows.zig (mix, finite, nonFinite)
    instead of exporting them.
  • The no-drafts cost: an untried option is a second launch with fewer blocks (one for every four rows rather than one a
    row).

Size: +797/-92 in 13 files, four commits; 451 of those lines are the contract's test type. This is the second of the
two stacked pull requests, score then apply.

Checks on this head

  • Head commit: a26855e, four commits on perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head 00a2faf (on main a325f58). The fourth changes only
    docs/optimization-ledger.md; tools/evidence_index.py reads its row (open in qwen3_5's column, ? elsewhere)
    with no error. The kernel test, the contract, its limits, the timing and the host suite below ran on the first three
    commits as they stood before a last edit, which made one comment of plan.hpp (its namespace comment) one line
    instead of two; that comment and the ledger commit are the only differences from this head. The served receipts ran
    on 73abb2c, this head but the ledger commit; pr_check and the lean counts ran on a26855e. Before that edit,
    each of the three code commits passed its own checks from a git archive tree: zig fmt --check on its Zig files
    (the first has none), git diff --check, hip-host-test (89, 90 and 90 passed), check-hip-kernel-contract-host,
    hip-kernel-build and hip-kernel-contract-build.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head, as tools/pr_check.py runs it: 165 and
    165, 0 new. python3 tools/pr_check.py --base origin/main (merge base a325f58, the stack's 17 files) and
    --base 00a2faf00 (this pull request's 13): 0 errors, 1 advisory warning each (the changelog line needs this pull
    request's number).
  • Tests run, with the command and pass, fail and skip counts:
    • zig build hip-kernel-test -Dhip=true -Dhip-arch=gfx1151 on the GPU: 237 of 244 passed, 7 skipped, 0 failed.
      perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's test of a round's slots in one walk through planCausal, which requires the bits of each row walked alone
      in a one-row launch, in its scores and its rows, now also plants in each slot a NaN value only its last row weighs
      and an infinite one past all its rows, and adds slots of 6, 1 and 5 rows (a chunk of four and a tail).
    • zig build test test-golden -Dhip=true: 12,766 of 12,861 passed, 94 skipped, 1 failed. The failure is the one
      perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673 reports, not in files this changes: stage_hip_test "every staged call on HIP memory equals the reference,
      whole and in parts" (zig/src/fabric/tp/). One step ran from zig build's cache, so its 89 tests are not in these
      counts.
    • The host test of the dispatch (launches/plan.zig): chunks of four only where the score's blocks share and a
      values block takes at most eight heads; one-row launches, act, d = 128, short spans and groups of 16 heads keep
      their kernel; the served groups come out at 8 and 6.
    • zig fmt --check on the changed files and git diff --check: clean.
  • The new tests fail before their change:
    • the dispatch's host test without planApply's rule: use of undeclared identifier 'apply_rows';
    • the contract's registrations with no kernels behind them: error: HipFailed;
    • with the lab kernel's rule (every key of a chunk added, weighed 0 past a row's own), all four registrations go red
      at gate 1 (80 of 4227072 outputs differ in class; first at 32770: nan where float64 gives finite, 16 heads,
      fp16) and gate 3 (at 8x16x16387 its bytes differ from tf_plan_apply_f16's from byte 131080):
      SUMMARY gfx1151 196 kernels: 192 pass gates 1-4, 4 fail, 2 known findings; 62 controls: 62 red as planted, 0 missed; 4 limit problems; gates 626447 ms, limits 2795 ms
      (the two extra limit problems are that variant's 82 VGPRs against the recorded 81); the kernel test fails too, its
      first difference at the element of the NaN value only a slot's last row weighs;
    • before the four records held their values, hip-kernel-contract-limits reported them stale on all four chips.
  • CI: green on a26855e: fmt, zig, zig-b, zig-windows, zig-macos-dev-tools, pytest,
    release-paths (ubuntu-24.04), benchmark-clients (ubuntu, windows) and
    comfyui-moss-installer pass; host-nightly-linux and host-nightly-macos skipped.
  • Not run, and why:

Receipt

  • Main against branch: the base is perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head, not main, since this pull request is stacked on it: 00a2faf (B,
    on main a325f58) against 73abb2c (C, this head but the ledger commit), both built by the same script from
    clean git archive trees (ReleaseFast, gfx1151). One fresh server a run, alternated B1 C1 C2 B2 in every cell, an
    explicit --prompt-cache-gib on every start, temperature 0, seed 1234. Each start waited for a quiet machine
    (memory, no other server, the GPU idle for 10 s, no other /dev/kfd holder), and /dev/kfd was sampled every 3 s
    during every run; no foreign holder was sampled during any run. Every token hash below is a hash of perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's
    receipts, where main d7f1f40 and perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's commits gave it on all four servers.

    One stream with drafts (Qwen3.6-35B-A3B, MTP). perf(hip): score the planned decode walk at d = 256 without element tests #3508's turn method: K + 8 tokens cold, then 8 turns of the K kept
    tokens plus 200 fresh, 128 reply tokens, drafts on, off, off, on in each of two fresh stretches. Decode tok/s, medians
    of both servers a side:

    Kept tokens, stretch perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head this head change
    131,072, drafts on, stretch 1 28.68 (28.59-28.71) 30.30 (30.11-30.45) +5.64%
    131,072, drafts on, stretch 2 27.92 (27.83-28.18) 29.86 (29.76-29.94) +6.94%
    131,072, "draft": false 35.78 (35.74-35.88) 35.70 (35.56-35.89) -0.23%
    258,048, drafts on, stretch 1 17.90 (17.84-17.92) 18.59 (18.52-18.78) +3.86%
    258,048, drafts on, stretch 2 15.08 (15.07-15.08) 15.89 (15.83-15.91) +5.38%
    258,048, "draft": false 23.15 (23.13-23.18) 23.15 (23.06-23.18) +0.01%

    Pooled over both stretches, drafts on: 28.38 -> 30.02 tok/s (+5.78%) at 131,072 and 16.46 -> 17.22 (+4.60%) at
    258,048. The four drafts-on rows are faster beyond both sides' ranges; "draft": false is level. The first token of a
    resumed turn reads level: 0.738 s on both at 131K, 1.250 s against 1.254 s at 258K.

    Four streams (--parallel 4): four distinct prompts filled cold, then two rounds of prompt 1 alone (128 tokens)
    and the four together (256 each), with drafts on, then with "draft": false. Aggregate tok/s, medians:

    Cell perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head this head change
    35B-A3B 32,768, "draft": false 94.13 94.00 -0.14% (spread 0.19% / 0.15%)
    35B-A3B 32,768, drafts on, round 1 / 2 78.83 / 93.20 81.96 / 93.76 +3.96% / +0.60%
    35B-A3B 131,072, "draft": false 43.74 43.69 -0.11% (spread 0.89% / 1.40%)
    35B-A3B 131,072, drafts on, round 1 / 2 24.67 / 41.88 28.18 / 42.26 +14.23% / +0.90%
    27B 32,768, "draft": false 29.22 29.15 -0.23% (spread 0.40% / 0.35%)
    27B 32,768, drafts on, round 1 / 2 28.30 / 28.37 28.76 / 28.85 +1.61% / +1.68%

    Steady tok/s of the "draft": false rounds: -0.11% (35B 32K), -0.26% (35B 131K), +0.41% (27B 32K), all inside the
    spread. Prompt 1 alone with drafts on: +2.46% (35B 32K) and +9.43% (35B 131K), beyond the spread, and +0.32% (27B 32K),
    inside it. So the no-drafts rounds that carry the kernel's +0.4% to +1.0% read level served.

    One stream with drafts (Qwen3.8-27B). The same method, with --prompt-cache-gib 18 (one stream at a 262,144-token
    window takes 16.15 GiB); its drafts as served are copies (no draft head on HIP). Decode tok/s, medians of both servers
    a side:

    Kept tokens, stretch perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head this head change
    131,072, drafts on, stretch 1 9.43 (9.39-9.45) 9.63 (9.60-9.69) +2.10%
    131,072, drafts on, stretch 2 9.22 (9.16-9.23) 9.36 (9.33-9.39) +1.48%
    131,072, "draft": false 8.64 (8.59-8.65) 8.64 (8.60-8.65) +0.00%
    258,048, drafts on, stretch 1 6.56 (6.50-6.61) 6.59 (6.47-6.75) +0.43%
    258,048, drafts on, stretch 2 6.51 (6.47-6.59) 6.83 (6.81-6.85) +4.91%
    258,048, "draft": false 6.23 (6.20-6.24) 6.24 (6.20-6.24) +0.02%

    Pooled over both stretches, drafts on: 9.31 -> 9.49 tok/s (+1.95%) at 131,072 and 6.54 -> 6.78 (+3.70%) at 258,048.
    Three of the four drafts-on rows are faster beyond both sides' ranges; the first stretch at 258,048 (+0.43%) is inside
    them. "draft": false is level. The first token of a resumed turn reads level: 1.765 s against 1.767 s at 131K,
    2.890 s against 2.887 s at 258K. These speeds do not compare with perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's tables, which ran on main d7f1f40: this
    base is on a325f58, whose commits since then change the lanes' copy pricing and Qwen's HIP drafting (the list in
    perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673), and the 27B's drafts-on speed at 258,048 is 6.54 tok/s here on perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head against 5.34 with perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's
    commits on d7f1f40.

    Draft counts. In perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's 27B receipts the rounds, accepted and drafted counts were the same on all four servers;
    here they differ between the two sides, most at 258,048 kept tokens, where this head drafts and accepts more. In the
    35B-A3B's first stretch there, its turns take 102 to 107 rounds with 20 to 25 drafts accepted of 78 to 87, against
    111 rounds with 16 of 71 on both base servers; the 27B's turns draft 22 to 29 in the first stretch and 35 or 36 in the
    second, against 17 to 20 and 28 to 31. The two servers of one side do not always agree either (35B-A3B at 131,072,
    first stretch: 119 and 114 drafted on the base's two). The depth rule weighs forward and head timings that each
    server measures at start (measure in qwen3_5/backend/hip/engine/hip_lanes.zig and hip_costs.zig), so a cheaper
    multi-row round can buy deeper drafts. Those timings are not logged, so I cannot show which of them moved. Where the
    counts are close, this head is still faster: the 35B-A3B at 131,072 (+5.64% and +6.94%), and its second stretch at
    258,048 (111 rounds with 16 of 116 drafts accepted, against 110 with 17 of 115: +5.38%).

  • Boxes it reaches: HIP Qwen checkpoints with 256-wide heads (Qwen 3.5/3.6/3.8) in decode rounds of more than one row at
    spans of 16,384 keys or more, with at most eight query heads a values block (both served shapes): drafted rounds, and
    several streams together.

  • New switch? No.

  • Environment: TensorFold 00a2faf (perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head, on main a325f58) and 73abb2c (this head but the ledger
    commit) for the served cells and the checks, a26855e for pr_check; Zig 0.17.0; the served builds with the system
    hipcc (HIP 7.1.52801, Ubuntu clang 21.1.8) and LLVM 21's device bitcode, the kernel contract and records with ROCm
    10.1's hipcc (HIP 7.16.26385); Ryzen AI Max+ 395 (Strix Halo, gfx1151), unified memory; Ubuntu 26.04.1, kernel
    7.0.0-44; Qwen3.6-35B-A3B-MLX-4bit-MTP and Qwen3.8-27B-MLX-4bit. The served binaries (sha256 prefixes): base
    be3226bdf2d8 and head 3e092b693d07, one build of each for every cell (each build embeds its scratch path).

  • Paths and platforms: ran HIP gfx1151 at one rank, both checkpoints, one and four streams, drafts on and
    "draft": false, greedy. Not run: the list under Checks.

  • Exactness:

    • Base against this head: every reply is equal request by request on all four servers of a cell: 9 of 9 in each
      one-stream cell, 24 of 24 in each four-stream cell.
    • Drafted against "draft": false: one hash per stretch on every server. 35B-A3B at 131,072: 0dc71eaf9689 and
      354d2aa6522a; at 258,048: d42f2e2f48f7 and 9ced54eaca25. 27B at 131,072: 97a39f51eebf and 1be5faab3a2c;
      at 258,048: df07006606e7 and bab906d9141a.
    • Four streams: drafted against "draft": false and round 1 against round 2, one hash per phase and stream on every
      server (35B 32K: alone e05f32999d13, together 83dcb52f04c7, 46675e2d0063, d76858ae958d, bf9af62b9ee7;
      35B 131K: e88dce5eded4, then 00474f283746, 00e7354df7fa, 4ae3370f467e, 49946caeafa8; 27B 32K:
      28bb6ebb4d19, then 9aa3b4882600, 746ce67ba326, 97e08cce66af, 454d232851e5).
    • Every one of these hashes is perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's, so these replies equal main d7f1f40's in perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's receipts; no main
      server ran here.
    • Below the server, the contract's gate 3 and the kernel test above: the partials' bytes equal today's kernel's.
  • Main against this branch, same machine and checkpoint: the tables here, against perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head; perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's receipts hold
    main against its commits. Scripts and raw files: on request.

  • Decode speed before and after: the tables above.

  • Prompt speed before and after: n/a, the change reaches only the decode walk's values step. The served cells' cold
    first token (K + 8 tokens), the base's two servers against this head's: 35B-A3B 172.3 and 172.4 s against 173.1 and
    172.5 s at 131,072 (+0.3%, the two sides' servers do not overlap), and 551.2 and 551.1 s against 548.4 and 550.7 s at
    258,048 (-0.3%, nor do they); 27B 577.4 and 576.3 s against 576.2 and 580.1 s at 131,072, and 1,681.6 and 1,682.1 s
    against 1,680.2 and 1,682.7 s at 258,048. These are two servers a side and not tools/bench_cache.py --require-cold
    runs.

  • Licence of any new weights or drafter: n/a.

Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: the two launches as one operator,
    tf_plan_lone_apply_* then tf_plan_rows_apply_*, a replacement of tf_plan_apply_* (gate 3 requires its bytes), on
    fp32 scores and stats, for 16 query heads over 2 and 24 over 4, each in fp16 and bf16 caches (4 registrations):

    • gate 3: 17 shapes a registration, bit-equal: launches of 1 to 64 rows over slots of 3, 1, 4, 2 and 6 rows one
      position apart (at the span's end, mid-span, one past a tile's first key, at the span's start), launches of 5 and 7
      one-row slots, and spans of 16,384 to 262,144 keys. The values are NaN- and inf-poisoned: one key in 41 holds a NaN
      of some payload or an infinity at one element, and in each slot the value only its last row weighs and the one past
      all its rows are non-finite; the scores hold a NaN, an infinity and a negative infinity at keys some rows of a chunk
      weigh.
    • gate 1: the classes of float64's partials, with a NaN max added: 45,089 non-finite and 4,181,983 finite outputs at
      16 heads, fp16;
    • gate 4: exact sums at 262,144 keys, every key weighed 1, 1/2 or 1/4 over integer values, where fp16 sums would miss
      by 16,777,216x and bf16 by 20,971,520x (16 heads).
  • A planted control for each new kernel, and each one fails as planted, all red at shapes:

    • chunks led over the whole launch (every slot's first 0 and its count every row), so a chunk crosses a slot (fp16
      and bf16);
    • the chunks' launch alone, so no launch weighs the rows of one-row slots (fp16 and bf16).
    • A row weighed by both launches gets the same bytes from each, so it cannot be caught by bytes.
  • Each backend's SUMMARY line and exit status (gfx1151, ROCm 10.1's hipcc, HIP 7.16):

    SUMMARY gfx1151 196 kernels: 196 pass gates 1-4, 0 fail, 2 known findings; 62 controls: 62 red as planted, 0 missed; 2 limit problems; gates 644186 ms, limits 2802 ms (exit 1)

    The two limit problems are the FAIL limits live lines of tf_moe_combine_gate and tf_vl_resize, as on perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673,
    whose records this does not touch. zig build hip-kernel-contract-limits: the four new records PASS on all four
    chips. The step exits 1 with 11 problems, the same 11 as on perf(hip): multi-row decode rounds score each slot's rows from one read of their keys #4673's head, all in other groups: tf_moe_combine_gate
    (gfx1030, gfx1100, gfx1151), tf_vl_resize (all four chips), and the 6- and 8-bit relu2 stream tiles 2x8 and 4x4 on
    gfx1100.

    Records (hip_records_apply_rows.zig), the same on gfx1030, gfx1100, gfx1151 and gfx1201 but for one SGPR; no
    scratch on any chip:

    Launch Threads VGPRs SGPRs Static LDS bytes
    tf_plan_lone_apply_{f16,bf16} 256 42 44 8,192
    tf_plan_rows_apply_{f16,bf16} 256 81 61 (60 on gfx1201) 16,384

    tf_plan_lone_apply_* uses tf_plan_apply_*'s VGPRs and LDS (42, 8 KiB), so one-row slots keep its occupancy.

  • Chips I could not run: gfx1030, gfx1100 and gfx1201 (limits only).

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

ashhart and others added 9 commits November 24, 2026 00:37
…o plan.hpp

row_xor, wave_sum_dpp, kMaxGroup, kScoreKeys, kScoreSteps, cache_load,
score_fetch, score_store and plan_score256_body move verbatim into an
anonymous namespace of decode/plan.hpp, which now includes ops/common.hpp,
so a second kernel source can run tf_plan_score256_*'s body. Only one
comment changes, kScoreKeys' (kScoreKeysShort stays in plan.hip).

Pure code motion: with ROCm 10.1's hipcc, the disassembled code objects of
recurrence/gated_delta.hip, decode/decode.hip and decode/plan.hip, the
sources that include plan.hpp, are identical before and after on gfx1030,
gfx1100, gfx1151 and gfx1201. plan.hip falls from 599 to 486 lines.

Refs ashhart#3811
…ys at d 256

decode/plan_rows.hip, a new code object group, adds two score kernels
with tf_plan_score256_*'s arguments and grid, a block a plan row:

- tf_plan_lone_score256_f16 and _bf16 score the rows of one-row slots
  with plan_score256_body, the one-row kernel's body, and its LDS (one
  row's queries), and leave for the other rows;
- tf_plan_rows_score256_f16 and _bf16 score the multi-row slots' rows
  in chunks of two led from the slot's `first`: the chunk's first row's
  block reads the keys once, up to the further row's, and works each
  row's dots in the tree's operands and order, a key past a row's own
  scored -inf as the tree scores it; the other blocks leave, so a chunk
  never crosses a slot. Its LDS holds two rows' queries.

One predicate (plan_shared_at) picks the rows of the chunks for both, so
each row is scored by exactly one of them.

planScore is planCausalAs's score step on its own. With `.shared`, at
d = 256 on long spans with q fp32, it launches the two kernels on the
same grid; elsewhere, and with `.one`, it launches today's kernel.
planCausalAs passes `.one`, so no walk changes here.

The contract runs the two launches as one operator, a replacement of
tf_plan_score256_*, for both head groups (16 over 2, 24 over 4) and both
cache kinds. Gate 3 requires the replaced kernel's bytes on 16 shapes a
case: launches of 1 to 64 rows over slots of 3, 1, 4 and 2 rows one
position apart (at the span's end, mid-span, across a block's first key,
at the span's start) and over 5 and 7 one-row slots, spans of 16,384 to
262,144 keys, NaN and infinite keys that some rows of a chunk see and
others do not, and NaN queries. Its controls go red at gate 3: chunks
led over the whole launch (every slot's first 0, its count every row),
and the chunks' launch alone. Gate 5's records are ROCm 10.1's hipcc on
gfx1030, gfx1100, gfx1151 and gfx1201: tf_plan_lone_score256_* 108
VGPRs and 16 KiB of dynamic LDS, tf_plan_score256_*'s; and
tf_plan_rows_score256_* 115 VGPRs and 32 KiB.

Refs ashhart#3811
planCausalAs passes `.shared` to planScore when its launch holds more
than one row. At d = 256 on long spans with q fp32, the Qwen
checkpoints' served decode walk, a round's score step is then two
launches: the one-row slots' rows at the one-row kernel's occupancy, and
the multi-row slots' rows in chunks of two from one read of their keys.
One-row launches keep a single tf_plan_score256_* launch; q in the
cache's kind, d = 128 and spans under 16,384 keys keep their kernels;
softmax, the values' walk and the tiles' sum are unchanged. The grid,
the launch arguments and the replay key stay as they were.

The whole score step against the tree on gfx1151 (medians of 15
alternated runs): one slot of 2 or 4 rows -14.0% to -18.5% (16 heads
over 2) and -31.1% to -32.3% (24 over 4) at 131K and 262K keys; a
2-row slot with two 1-row slots -6.0% to -15.3%; 2 or 4 one-row slots
+0.6% to +0.9%, the second launch's blocks leaving at once.

A kernel test walks a round's slots one position apart through
planCausal (slots of 3, 1, 2 and 4 rows; 1, 4 and 3; four of one row;
and 2, 1, 1, 3, 1 and 4) with NaN and infinite keys and an infinite
value, and requires the bits of each row walked alone in a one-row
launch, in its scores and its rows. The pinned NaN digests of
plan_pin.zig, whose d = 256 q fp32 case is a two-row launch, are
unchanged.

Refs ashhart#3811
plan_apply_body, tf_plan_apply_*'s body, moves verbatim into the
anonymous namespace of decode/plan.hpp beside the d = 256 score's
pieces, so a second kernel source can run it. Only that namespace's
comment changes.

Pure code motion: with ROCm 10.1's hipcc, the disassembled code objects
and kernel notes of recurrence/gated_delta.hip, decode/decode.hip,
decode/plan.hip and decode/plan_rows.hip, the sources that include
plan.hpp, are identical before and after on gfx1030, gfx1100, gfx1151
and gfx1201. plan.hip falls from 486 to 421 lines.

Refs ashhart#3811
…lues at d 256

decode/plan_rows.hip adds two values kernels with tf_plan_apply_*'s
arguments and grid, a block a plan row:

- tf_plan_lone_apply_f16 and _bf16 weigh the rows of one-row slots
  with plan_apply_body, the one-row kernel's body, and its LDS, and
  leave for the other rows;
- tf_plan_rows_apply_f16 and _bf16 weigh the multi-row slots' rows in
  chunks of four led from the slot's `first`: the chunk's first row's
  block reads each value of its 128-key tile once, up to the furthest
  row's keys, a page at a time and eight ahead, and adds every row's
  and head's sum in key order with the tree's operands. A key past a
  row's own keys is left out of that row's sum, as the tree leaves it,
  not weighed 0, so a NaN or infinite value there cannot reach the row;
  a tile past a row's keys writes its zeros. The other blocks leave, so
  a chunk never crosses a slot. Its LDS holds four rows' weights of at
  most eight heads (16 KiB).

The score's predicate (plan_shared_at) picks the chunks' rows for both,
so each row is weighed by exactly one of them.

planApply is planCausalAs's values step on its own. With `.shared`, at
d = 256 on long spans with q fp32, where the score's blocks share, and
with at most eight heads a block (the served groups are 8 for 16 heads
over 2 and 6 for 24 over 4), it launches the two kernels on the same
grid; elsewhere, and with `.one`, today's kernel. planCausalAs passes
`.one`, so no walk changes here.

The contract runs the two launches as one operator, a replacement of
tf_plan_apply_*, for both head groups and both cache kinds, on fp32
scores and stats. Gate 3 requires the replaced kernel's bytes on 17
shapes a case: launches of 1 to 64 rows over slots of 3, 1, 4, 2 and 6
rows one position apart (at the span's end, mid-span, one past a tile's
first key, at the span's start) and over 5 and 7 one-row slots, spans
of 16,384 to 262,144 keys, NaN and infinite values at the key only a
slot's last row weighs, at the key past all its rows and at scattered
keys, and NaN and infinite scores. Gate 1 adds a NaN max; gate 4 weighs
every key 1, 1/2 or 1/4 and sums integer values. Its controls go red at
gate 3: chunks led over the whole launch (every slot's first 0, its
count every row), and the chunks' launch alone. With the lab
prototype's rule (every key of a chunk added, weighed 0 past a row's
own) gates 1 and 3 go red on all four registrations. Gate 5's records
are ROCm 10.1's hipcc on gfx1030, gfx1100, gfx1151 and gfx1201:
tf_plan_lone_apply_* 42 VGPRs and 8 KiB of LDS, tf_plan_apply_*'s; and
tf_plan_rows_apply_* 81 VGPRs and 16 KiB.

Refs ashhart#3811
planCausalAs passes the score's `.shared` to planApply too when its
launch holds more than one row. At d = 256 on long spans with q fp32,
the Qwen checkpoints' served decode walk, a round's values step is then
two launches: the one-row slots' rows at the one-row kernel's
occupancy, and the multi-row slots' rows in chunks of four from one
read of their values. One-row launches keep a single tf_plan_apply_*
launch; q in the cache's kind, d = 128, spans under 16,384 keys and
apply groups of more than eight heads keep their kernels; softmax and
the tiles' sum are unchanged. The grid, the launch arguments and the
replay key stay as they were.

The whole values step against the tree on gfx1151 (medians of 15
alternated runs, three runs): one slot of 2 or 4 rows -22.0% to -30.4%
(16 heads over 2) and -30.2% to -38.1% (24 over 4) at 131K and 262K
keys; a 2-row slot with two 1-row slots -10.2% to -15.2%; 2 or 4
one-row slots +0.4% to +1.0%, the second launch's blocks leaving at
once. The score and values steps together, one slot of 2 or 4 rows:
-20.7% to -26.7% (16 over 2) and -31.8% to -37.1% (24 over 4).

The kernel test of a round's slots in one walk adds a NaN value only a
slot's last row weighs and an infinite one past all its rows, and slots
of 6, 1 and 5 rows, and requires each row's bits walked alone, in its
scores and its rows; with the lab prototype's weight-0 rule it fails at
the first slots.

Refs ashhart#3811
@ashhart
ashhart force-pushed the perf/hip-decode-rows-share-apply branch from a26855e to 6a1789a Compare November 24, 2026 00:37
@ashhart
ashhart merged commit bbd867e into ashhart:main Nov 24, 2026
10 of 11 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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

Labels

None yet

Projects

None yet

2 participants