Skip to content

perf(dsv4): adaptive BLOCK_K for csa_translate_pack#1464

Merged
valarLip merged 2 commits into
mainfrom
csa-translate-pack-adaptive-blockk
Jul 5, 2026
Merged

perf(dsv4): adaptive BLOCK_K for csa_translate_pack#1464
valarLip merged 2 commits into
mainfrom
csa-translate-pack-adaptive-blockk

Conversation

@valarLip

@valarLip valarLip commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

What

Adaptive BLOCK_K tiling for the DSV4 csa_translate_pack Triton kernel.

The old launch used BLOCK_K = min(64, next_pow2(index_topk)), fixing the
per-program tile at ≤64 slots. A large decode batch therefore launches an
enormous grid of tiny workgroups (e.g. T=256, index_topk=2048 → 8192
workgroups). On gfx1250 the per-workgroup dispatch overhead grows steeply with
workgroup count, so those tiny tiles are dominated by launch/scheduling cost.

This grows the per-program tile while the grid still has enough workgroups to
fill the GPU — keeping T * cdiv(index_topk, BLOCK_K) at or above
_CSA_TARGET_WG (512). Large-T decode gets fat tiles that amortize launch
overhead; small-T stays fine-grained for occupancy. Tile floor stays 64, capped
at 1024.

Correctness

Kernel body and numerics are untouched — this only retunes the launch tiling.
Verified 10/10 correctness against the reference on gfx950.

Performance

  • gfx1250: up to 3.2× (11.3 → 3.5 µs) on large decode batches
  • gfx950: up to 1.5×
  • Small cases: unchanged

valarLip and others added 2 commits July 4, 2026 08:39
The previous BLOCK_K = min(64, next_pow2(index_topk)) fixes the per-program
tile at <=64 slots, so a large decode batch launches an enormous grid of tiny
workgroups (e.g. T=256, index_topk=2048 -> 8192 workgroups). On gfx1250 the
per-workgroup dispatch overhead grows steeply with workgroup count, so these
tiny tiles are dominated by launch/scheduling cost rather than useful work.

Grow the per-program tile while the grid still has enough workgroups to fill
the GPU: keep the workgroup count (T * cdiv(index_topk, BLOCK_K)) at or above
_CSA_TARGET_WG (512). Large-T decode then gets fat tiles that amortize launch
overhead, while small-T stays fine-grained for occupancy. Tile floor stays at
64 slots and is capped at 1024.

Measured up to 3.2x on gfx1250 (11.3 -> 3.5 us) and up to 1.5x on gfx950 for
large decode batches; small cases are unchanged. Kernel body and numerics are
untouched -- this only retunes the launch tiling.
…e writes

Mark the config-fixed stride/dim/cache_size args of _swa_write_kernel and
_update_compressor_states_kernel as tl.constexpr so the backend folds the
ring-buffer address arithmetic to constants and specializes pos%cache_size
(pow-2 -> bitmask). ~1.04-1.11x on both kernels, bit-exact.

Also fix update_compressor_states_reference to skip sentinel (-1) plan rows
like the kernel does (Python -1%N wraps to N-1, writing a garbage ring row).
@valarLip valarLip merged commit 4f21298 into main Jul 5, 2026
33 of 34 checks passed
@valarLip valarLip deleted the csa-translate-pack-adaptive-blockk branch July 5, 2026 08:29
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