Skip to content

One CTA an SM, six K stages and two accumulators: the configuration cuBLASLt runs (#80) - #86

Merged
feitreim merged 6 commits into
mainfrom
80-wide-stage
Aug 5, 2026
Merged

feitreim merged 6 commits into
mainfrom
80-wide-stage

Conversation

@feitreim

@feitreim feitreim commented Aug 5, 2026

Copy link
Copy Markdown
Owner

cuBLASLt's kernel was decoded in #80 as nvjet_tst_128x256_64x6_2x1_2cta: our tile, our cluster, our BLOCK_K — and six K stages at one CTA an SM against our three at two. This PR is that configuration, with the three resources the halving frees actually spent.

Twelve of fourteen model rows cross 0.90; the mean goes 0.906 → 0.939 against a same-day main, and the accumulator handoff — the term #84 left as the whole residual — is measured at 4 815 → 100 SM ticks.

The change is three constants and one 16 KiB

STAGES        3 →   6     the ring cuBLASLt runs
ACCUM_COLS  256 → 512     the SM's whole tensor memory, as SLOTS = 2 accumulators
STAGE_N      64 → 128     the bf16 staging tile the freed shared memory affords

CTAS_PER_SM keeps its old formula 512 / ACCUM_COLS and now reads 1 — and for the first time the two residency limits agree instead of one binding before the other is consulted: the six-stage ring is 196 608 B and asks for one CTA an SM independently. MAX_CLUSTERS falls out at 74.

Increment 1 — the accumulator is a ping-pong

Every route to overlapping the drain with the next item's MMA died on the same fact: a second 256-column accumulator needs tensor memory an SM does not have at two CTAs an SM. At one it has exactly enough. Consecutive items alternate between the two halves of one 512-column allocation (Tile::slot), and the release moves from empty(i + 1) to empty(i + SLOTS) — what the next item waits on is no longer this item's drain but the one before it, which has had a whole item's MMA to finish.

This is 80-column-halves' discipline lifted onto a full-width tile. It cost that branch ×1.50 on the operand fill because it had to split 256 columns; here the tile does not change at all, and the ping-pong costs one register.

Increment 2 — the bf16 drain gets the wide staging tile

STAGE_N was 64 because four [32, 128] staging tiles are 32 768 B against 16 384, and at two CTAs an SM the plan had no such 16 KiB. So the bf16 band was (32/16)·(64/64) = 2 .x8 issues a pass and four exposed TMEM latencies a band, where #84 got the fp32 store down to two. At 128 a band is exactly ISSUE_LIMIT issues behind one wait and exactly the 128 registers a thread holds — the shape Wide's half-row has had since #84 — so the bf16 band leaves tensor memory in two waits and the drain is two passes instead of four. Reduce keeps its own REDUCE_N = 64, since the reduction store's box is what fixes that width, and simply borrows a prefix of the wider buffer.

Plan: 114 816 B → 229 632 B, against the 232 448 the device's own MAX_SHARED_MEMORY_PER_BLOCK_OPTIN grants a CTA. cuBLASLt declares 213 280.

The phase probe says the handoff is gone

80-pingpong-probe carries the clock64 instrument with the ping-pong itself behind a const, so before and after are one binary at the same residency, the same six stages and the same plan — only SLOTS differs. Per item, rank-0 SM ticks:

qkv fwd, K = 3072 one slot ping-pong
ACC — issuer waiting the previous drain's release 4 815 100
MMA 27 153 27 459
FILL — issuer waiting stage 0 — 118
FEED — issuer waiting stages 1.. — 3 411
DRAIN — a band warp's epilogue 7 990 10 470
DONE — a band warp waiting the MMA out 24 179 17 310
item 32 162 27 736
wall 0.8756 ms 0.8028 ms (−8.3%)

Four shapes, same story: ACC 4 289 → 114 and 4 244 → 114 at the gate_up geometry, 4 679 → 100 at K = 9216. The handoff is not smaller, it is off the critical path — the drain itself gets slower (7 990 → 10 470, it now contends with a running MMA) and the item gets 14% shorter anyway.

What is left of the issuer's item is the feed: FEED is 3 411 of 27 736 ticks at K = 3072 and 9 422 of 81 045 at K = 9216 — 12% either way — where FILL is 118 and ACC is 100. That is the next term, and it is not one this PR's structure can reach: six stages is 196 608 B and a seventh does not fit.

model_shapes, --features cublas, B200

Two sessions of this branch against a same-day main @ 0b652de. pp is the mean of three sessions of increment 1 alone (80-ping-pong), kept because it is what separates the two increments.

row mode main pp (inc 1) this PR Δ vs main
qkv fwd 24576×3072×9216 f32 store 0.891 0.938 0.938 +0.047
o_proj fwd 24576×3072×3072 f32 store 0.899 0.963 0.962 +0.063
gate_up fwd 6144×3072×8192 f32 store 0.875 0.935 0.931 +0.056
down fwd 6144×4096×3072 f32 store 0.895 0.953 0.962 +0.067
bwd qkv dx 24576×9216×3072 f32 store 0.982 0.973 0.972 −0.010
bwd gate_up dx 6144×8192×3072 f32 store 0.966 0.959 0.963 −0.003
bwd down dx 6144×3072×4096 f32 store 0.885 0.942 0.948 +0.063
bwd qkv dW 3072×24576×9216 f32 acc-T 0.952 0.929 0.930 −0.022
bwd o_proj dW 3072×24576×3072 f32 acc-T 0.941 0.913 0.918 −0.023
bwd gate_up dW 3072×6144×8192 f32 acc-T 0.905 0.920 0.915 +0.010
bwd down dW 4096×6144×3072 f32 acc-T 0.797 0.928 0.928 +0.131
lm_head fwd 24576×3072×50432 bf16 store 0.854 0.895 0.895 +0.041
bwd lm_head dx 24576×50432×3072 bf16 store 0.909 0.897 0.900 −0.009
bwd lm_head dW 3072×24576×50432 bf16 acc-T 0.935 0.962 0.979 +0.044
mean 0.906 0.936 0.939 +0.033

bwd down dW — the row this issue has never moved — goes 0.797 → 0.928, and its wave arithmetic is why: 192 tiles over 74 clusters is 86.5% last-wave efficiency where over 148 it was 64.9%, and 86.4% is what #84 recorded cuBLASLt itself reaching on that shape.

What is honestly not there yet

lm_head fwd sits at 0.895 on the session mean and it is the one row that misses the bar. Both bf16 store rows are also by far the noisiest in the table — 0.933 / 0.888 / 0.863 across three sessions of increment 1 — because they are the two biggest matrices in the model and their cuBLASLt denominators move 3–5% between containers. Increment 2 is what moved them, and the honest measurement of it is the absolute throughput, not the ratio:

bf16 store row inc 1 (comparable sessions) this PR Δ
lm_head fwd 1 589.4 TF/s 1 635.0 +2.9%
bwd lm_head dx 1 591.4 TF/s 1 629.9 +2.4%

On those same sessions the ratios are 0.876 → 0.895 and 0.870 → 0.900. So the wide staging tile is worth about two points on each, and lm_head fwd still needs about half a point more.

Square bench, same-day main

shape mode main this PR
4096³ bf16 store 0.900 0.933
bf16 acc 0.699 0.691
f32 store 0.877 0.921
f32 acc 0.835 0.872
8192³ bf16 store 0.974 0.967
bf16 acc 0.892 0.921
f32 store 0.887 0.955
f32 acc 0.861 0.931
16384³ bf16 store 0.967 1.022
bf16 acc 0.920 0.967
f32 store 0.922 0.913
f32 acc 0.871 0.914

Nine cells improve by 3–7 points, three sit within ±0.01. No per-shape dispatch was needed — the CTA halving refunds at every square size, including the deep-K rows the gate was worried about.

One caveat on the record: increment 1 alone measured 16384³ f32 store at 0.875 in its own container and this PR measures 0.913, and this PR does not touch the fp32 store path at all — 5.955 ms against 5.612 ms for the same code. That cell is the one #83 and #84 both recorded moving the wrong way for L2 reasons at a 1 GiB C, and it is worth ±0.04 between containers. Read it loosely.

Full-step A/B, same container, both orders

--baseline-ref 0b652de, run at d0725de — the head adds one const _: () = assert! and nothing else. Only the === baseline === / === candidate === pair is the measurement; compare_profile emits four profiles and the two build-time ones are not it.

order 1 (main first) order 2 (this PR first) mean
full step 401.769 → 399.154 (−2.62) 403.510 → 403.184 (+0.33) −1.14 ms
fifteen GEMM rows −4.663 −3.787 −4.22 ms

The two orders agree on the GEMM-row sum to 0.9 ms and disagree on the full step by 2.9, so the GEMM-row sum is the number: −4.22 ms of 166, −2.5%. Only GEMM rows can move here, and the ~60 others carry ±2 ms of container noise between the two runs — which is also why the implied second-position penalty comes out negative this time where #84 measured +4.97 ms from both orders independently. Read the full-step column loosely and the GEMM column as the measurement.

Per row, mean of the two orders:

kernel Δ
backward.experts.down_weight_gemm −1.456
forward.experts.gate_up_gemm −1.348
backward.experts.down_input_gemm −0.705
forward.qkv_proj.gemm −0.528
forward.experts.down_gemm −0.429
backward.o_proj.input_gemm −0.315
forward.o_proj.gemm −0.281
forward.lm_head.gemm −0.219
backward.experts.gate_up_weight_gemm −0.014
backward.experts.gate_up_input_gemm +0.050
backward.qkv_proj.input_gemm +0.052
backward.lm_head.weight_gemm +0.103
backward.o_proj.weight_gemm +0.178
backward.lm_head.input_gemm +0.327
backward.qkv_proj.weight_gemm +0.361

The three rows that pay are the dW transposed-walk rows, which is exactly what model_shapes says: bwd qkv dW and bwd o_proj dW are the two rows this configuration costs 2 points on, and they are the two rows whose tile counts (432 and 144) were already quantizing well over 148 clusters and now quantize no better over 74.

GROUP stays 8, and now for a reason

The brief on this increment asked not to inherit GROUP = 8 blindly through a halved cluster count. Measured at 16 on this branch: neutral to slightly worse on absolute throughput at every row and nothing on the two bf16 rows it was aimed at (qkv fwd 1824 TF/s against 1809/1778, but o_proj 1734 against 1779/1765, bwd qkv dx 1761 against 1814/1784, bwd lm_head dx 1606 against 1650/1610).

The arithmetic agrees. grouped walks GROUP tile-rows down a column before moving right, so a wave of MAX_CLUSTERS clusters covers a GROUP × (MAX_CLUSTERS / GROUP) rectangle of tiles, and the operand footprint in flight is smallest when that rectangle is square. At 148 clusters GROUP = 8 gave 8 × 18.5 — lopsided. At 74 it gives 8 × 9.25, and √74 = 8.60. The constant was tuned for the wrong residency and the new one happens to be what it wanted.

Gates

  1. --kernel gemm parity: green, all shapes, both layouts, store and accumulate. ptxas 134 / 168 / 146, zero spill on all three. The budgets are ratcheted to those, and two of them rose by one register — the ping-pong's sequence % SLOTS and the bf16 drain's wider band. That the counts barely moved is itself the result: at one CTA an SM a thread is granted the architecture's 255 rather than the ~170 twelve warps left it, so the ceiling that closed The drain runs beside the next item's MMA, not in front of it (#80 remedy 2) #83's two-band hoist is gone and nothing in this kernel needed it.
  2. --kernel ops: green.
  3. --kernel model: green on rerun. The first run took the known stochastic miss of the MoE overfit assertion at 0.0597 against the 0.05 bound — the same value The drain runs beside the next item's MMA, not in front of it (#80 remedy 2) #83 and The item stream has no boundary, and the drain lifts half-rows behind one wait (#80) #84 both recorded — with every numerical parity row green above it.
  4. model_shapes: two sessions of this branch plus three of increment 1 and one of main, all above.
  5. Square bench: above.
  6. Full-step A/B: both orders, above.

Branches preserved

  • 80-ping-pong — increment 1 alone (deep ring + ping-pong, STAGE_N still 64), the measurement point the two increments are separated at.
  • 80-pingpong-probe — the phase probe on this kernel, with gemm_probe_f32_noping as the one-slot control. A stopwatch does not belong in the shipped module.

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.

1 participant