Skip to content

Commit e7dde59

Browse files
Fix gfx950 midbatch cap: restore rows>63 L<=65536 fold to bpr=1
C3 lossless A/B (port vs our original topk-robin branch) surfaced a regression at rows=128 L=65536: port 78.6us vs ours 49.6us. Root cause: the A3 midbatch_coord_cap port omitted the first rule (rows>63, L<=65536 -> cap=1) and floored the cap at 2, because the kernel had no bpr=1 single-workgroup path at the time. Phase B (B0 bpr=1 support + B2 fold) added that path, so restore the rule and lower the floor to 1. The rule caps blocks_per_row to 1 WITHOUT force_single_wg (short_max stays < L), so the row runs the mid tier with a single cooperating block (barrier-free, HIP one-block shape) instead of a width-2 cooperative grid that serializes a wide batch into extra co-resident waves. Verified gfx950: - config parity vs ours across rows{1..256} x L{8k..256k}: identical except the known benign pow2 rounding at rows=1 L=120000 (30->32, perf-neutral per robin's pow2 commit). - correctness 24/24 (regime A+B, random/ties/10LSBits) on the newly folded rows{64,128,256} L=65536. - perf: rows=128 L=65536 78.6->49.8us (== ours 49.9), rows=64 47.4us (== ours 47.5); ~5x faster than robin (251us). Co-authored-by: Cursor <[email protected]>
1 parent d839939 commit e7dde59

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎aiter/ops/flydsl/topk_per_row_decode.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,15 @@ def _default_kernel_config(
202202
# (num_rows > 16), the co-resident budget over-provisions blocks_per_row; the measured
203203
# cooperation optimum in the multi-block regime is well below it. Cap blocks_per_row by
204204
# a small L-keyed step. Only reduces blocks_per_row (a min), so results stay valid.
205-
# (The rows>63 short-mid cap of 1 is omitted; it needs the kernel's single-workgroup
206-
# launch path.) Env FLYDSL_TOPK_TIERED_MIDBATCH_CAP overrides the matched cap (0 off).
205+
# The first rule (rows>63, L<=65536 -> cap=1) folds a wide short-mid batch onto the
206+
# kernel's single-workgroup launch path (enabled by the Phase B bpr=1 support); it is
207+
# NOT paired with force_single_wg (short_max stays < L), so the row runs the mid tier
208+
# with a single cooperating block -- barrier-free, matching HIP's one-block shape.
209+
# Env FLYDSL_TOPK_TIERED_MIDBATCH_CAP overrides the matched cap (0 off).
207210
if arch == "gfx950" and max_model_len > tiered_short_max:
208211
mb_cap = None
209212
for mb_min_rows, mb_L_max, mb_cap_val in (
213+
(63, 65536, 1),
210214
(16, 131072, 4),
211215
(20, None, 6),
212216
(16, None, 8),
@@ -218,7 +222,7 @@ def _default_kernel_config(
218222
if mb_env is not None and mb_cap is not None:
219223
mb_cap = mb_env
220224
if mb_cap:
221-
blocks_per_row = max(2, min(blocks_per_row, mb_cap))
225+
blocks_per_row = max(1, min(blocks_per_row, mb_cap))
222226

223227
# Row-proportional parts (gfx950 only). The launch grid width is sized for the
224228
# padded buffer, so short rows over-provision cooperating workgroups; the kernel

0 commit comments

Comments
 (0)