Skip to content

[Perf] preshuffle_gemm: vectorize scale_a epilogue load (4x32b -> 1x128b)#791

Open
coderfeli wants to merge 1 commit into
mainfrom
rlcr/pshuf-scale-vec
Open

[Perf] preshuffle_gemm: vectorize scale_a epilogue load (4x32b -> 1x128b)#791
coderfeli wants to merge 1 commit into
mainfrom
rlcr/pshuf-scale-vec

Conversation

@coderfeli

Copy link
Copy Markdown
Collaborator

Summary

Vectorize the per-row scale_a load in the fp8/int8 preshuffle GEMM epilogue:
the 4 contiguous per-row scales (base offset is 4-aligned) now load as one
128-bit buffer_load
instead of four 32-bit loads.

Why

An LLVM-IR diff of this kernel vs the aiter reference (matched config) showed the
compute is identical, and the only extra memory traffic was un-vectorized scale
loads: 34 scalar i32 buffer loads vs the reference's 16 vectorized <4 x i32>
(total raw.ptr.buffer.load 69 vs 46). This change cuts our scalar scale loads to
2 and brings the total buffer.load count to 46 — matching the reference.

Measurements (5cb28f6-based build, gfx950, order-swapped A/B, median)

shape (M×N×K) before after
256×6144×1536 ~465 ~479 TFLOPS (+3%)
32768×3072×1536 ~1628 ~1674 TFLOPS (+2.8%, won 4/4 rounds)
2048×4096×512 ~738 ~738 (neutral — not load-bound)

Larger-M shapes benefit most (more epilogue tiles → the 23-fewer-loads compound).

Correctness (no threshold changes)

verify_output (rtol/atol 0.1) + OOB guard pass for fp8, int8 (shares the scale
path), and ragged M=127. Uses the same buffer_ops.buffer_load(vec_width=4)
pattern as kernels/blockscale_preshuffle_gemm.py.

🤖 Generated with Claude Code

The fp8/int8 epilogue loaded the 4 contiguous per-row scale_a values as 4
separate 32-bit buffer loads. IR diff vs the aiter reference showed this as the
sole extra memory traffic (34 scalar i32 loads vs the reference's 16 vectorized;
total buffer.load 69 vs 46). Load them as one 128b buffer_load
(buffer_ops.buffer_load vec_width=4), matching the reference's 46 total loads.

Verified on a 5cb28f6-based build (matching bindings), order-swapped A/B
median-of-N, gfx950:
  - shape 256x6144x1536 : ~465 -> ~479 TFLOPS (+3%)
  - shape 32768x3072x1536: ~1628 -> ~1674 TFLOPS (+2.8%, won 4/4 rounds)
  - shape 2048x4096x512  : neutral (not load-bound)
Correctness (verify_output + OOB) passes for fp8, int8, and ragged M=127.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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