Skip to content

Commit 2fc5ddc

Browse files
Port gfx950 kernel B0: relax blocks_per_row floor to 1 for short tier (bpp==11)
Prerequisite for batch_coresident_cap (grid=1 fold). Kernel previously rejected blocks_per_row < 2; now allows 1 when the barrier-free single- workgroup short tier exists (tier_mode auto/short + bits_per_pass==11), keeping the >=2 floor for mid/long forced modes and bpp==10. Also parameterize the vec-block ceil-div shift on LOAD_VEC (LOAD_VEC_LOG2) instead of a hardcoded 2 (no-op at LOAD_VEC=4). Dispatch output unchanged (_kernel_config identical to Phase A); this only opens the path for Phase B2. gfx942 unaffected. Co-authored-by: Cursor <[email protected]>
1 parent d783300 commit 2fc5ddc

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎aiter/ops/flydsl/kernels/topk_per_row_decode_tiered.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
BLOCK_THREADS = 1024
6666
WARP_SIZE = 64
6767
LOAD_VEC = 4
68+
# log2(LOAD_VEC); LOAD_VEC must be a power of two. vec_blocks = ceil(row_len/LOAD_VEC)
69+
# is a right shift, so the shift amount must track LOAD_VEC, not a hardcoded width.
70+
LOAD_VEC_LOG2 = LOAD_VEC.bit_length() - 1
6871
# Default histogram-scan staging (one of 1/2/4/8)
6972
SCAN_STAGES = 2
7073

@@ -162,8 +165,17 @@ def create_topk_per_row_decode_tiered_kernel(
162165
raise ValueError(f"bits_per_pass must be 10 or 11, got {bits_per_pass}")
163166
if scan_stages not in (1, 2, 4, 8):
164167
raise ValueError(f"scan_stages must be one of (1, 2, 4, 8), got {scan_stages}")
165-
if not 2 <= blocks_per_row <= 32:
166-
raise ValueError(f"blocks_per_row must be in [2, 32], got {blocks_per_row}")
168+
169+
# blocks_per_row == 1 collapses the launch to grid=(1, num_rows): every row runs
170+
# the barrier-free single-workgroup short tier (no cooperative parts, so no dead
171+
# blocks hogging co-resident slots). Only valid when the short tier exists
172+
# (auto/short + bpp==11); mid/long forced modes still need >=2 cooperating parts.
173+
_min_blocks_per_row = 1 if (tier_mode in ("auto", "short") and bits_per_pass == 11) else 2
174+
if not _min_blocks_per_row <= blocks_per_row <= 32:
175+
raise ValueError(
176+
f"blocks_per_row must be in [{_min_blocks_per_row}, 32], got {blocks_per_row}"
177+
)
178+
167179
if mid_cap < 2 or long_cap < 2:
168180
raise ValueError(f"mid_cap/long_cap must be >= 2, got {mid_cap}/{long_cap}")
169181
if mid_max < short_max:
@@ -705,7 +717,7 @@ def write_vec_block(vblk, local_k, kth_bits):
705717
global_vec_tid_idx = arith.index_cast(T.index, global_vec_tid)
706718
vec_blocks_i32 = ArithValue(
707719
ArithValue(row_len) + ArithValue(c_vec) - ArithValue(c_one)
708-
).shrui(fx.Int32(2))
720+
).shrui(fx.Int32(LOAD_VEC_LOG2))
709721
vec_blocks_idx = arith.index_cast(T.index, vec_blocks_i32)
710722

711723
def scan_pass(pass_id: int, current_k, current_bits, barrier_token: int):

0 commit comments

Comments
 (0)