Skip to content

[SM100] Use the K=64 MXF8F6F4 MMA in the dense 1D1D kernel on CC 10.7 - #133

Merged
zcnrex merged 4 commits into
sgl-project:devfrom
zcnrex:chunan/sm107-1d1d-wide-k
Nov 3, 2026
Merged

zcnrex merged 4 commits into
sgl-project:devfrom
zcnrex:chunan/sm107-1d1d-wide-k

Conversation

@zcnrex

@zcnrex zcnrex commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On CC 10.7 (sm_107a), kind::mxf8f6f4 with instruction-descriptor bit 31 (k_size_) set issues K=64 per MMA and reads two per-32 UE8M0 scale factors. cute::UMMA::make_instr_desc_block_scaled has no K argument and always leaves the bit at 0, which means K=32. This PR sets the bit in the dense 1D1D kernel.

  • sm100_fp8_fp4_gemm_1d1d.cuh: kIsMXF8KMajor (next to kIsMXF4) marks e4m3 × e4m3 GEMMs that are K-major with per-32 scales on both sides. UMMA_K is 64 for those when compiling for __CUDA_ARCH__ == 1070 (the JIT builds sm_107a only for CC 10.7) and the GEMM is not k-grouped. instr_desc.k_size_ is set from UMMA_K == 64 on the MXF8F6F4 path. The existing per-32 scale-factor id arithmetic already gives ids 0 and 2 for a K=64 step, which is what the wide MMA reads.
  • For MXF4 the same bit selects K=96, so it stays 0 there (not kIsMXF4 in the k_size_ expression).
  • Other architectures compile the K=32 path unchanged. Host code is unchanged.

Motivation

DeepSeek-V4.1-Flash's dense attention projections (wqkv_a, wq_b, wo_a, wo_b, indexer q_b) run through this kernel with MXFP8 × MXFP8 operands. At prefill-sized M the tensor pipe is the limit, and K=64 does more work per issued MMA.

Validation

Setup: sm_107a, CUDA 13.4, this branch's header on the 0.2.5.post2 package. MXFP8 inputs use per-32 scale jitter of 2^[-4, 4].

Accuracy: relative error against an fp32 reference changes by at most 1.7e-9 on every shape below (bf16 last-bit differences only).

Timing: the base and PR arms alternate 8 times per row, each in a fresh process (ABAB/BABA, CUDA graph, kineto median of 5 rounds). Δ is the median of the 8 per-pair deltas, and the range is the min..max over those pairs.

  • Large rotating-weight shapes vary a lot between processes, which shows up as wide pair ranges.
  • An A/A run (base vs base, wqkv_a M=4096, on all 4 GPUs) is within ±0.5% per pair.
GEMM (N × K) M Δ pair range
wo_b 5120 × 8192 16384 -7.6% -18.7 .. -0.9
wo_b 5120 × 8192 4096 -13.8% -31.4 .. -9.6
wo_b 5120 × 8192 1024 -16.7% -43.5 .. +22.5
wo_b 5120 × 8192 256 -3.3% -27.3 .. -1.1
wqkv_a 1792 × 5120 16384 -13.9% -25.1 .. -4.7
wqkv_a 1792 × 5120 4096 -12.4% -34.7 .. +41.9
wqkv_a 1792 × 5120 1024 -0.4% -0.4 .. -0.4
wqkv_a 1792 × 5120 256 -0.0% -0.4 .. +0.0
wq_b 32768 × 1280 16384 -6.3% -15.8 .. +3.8
wq_b 32768 × 1280 4096 -8.6% -22.3 .. +20.1
wq_b 32768 × 1280 1024 -7.4% -35.3 .. +33.4
wq_b 32768 × 1280 256 -9.7% -32.3 .. +9.9
idx q_b 4096 × 1280 16384 -6.6% -19.7 .. -3.7
idx q_b 4096 × 1280 4096 -6.3% -36.0 .. +9.7
idx q_b 4096 × 1280 1024 -5.7% -6.2 .. -5.7
idx q_b 4096 × 1280 256 -0.6% -0.6 .. -0.6
wo_a 1024 × 4096 16384 -9.3% -30.1 .. +12.4
wo_a 1024 × 4096 4096 -2.3% -10.7 .. +17.4
wo_a 1024 × 4096 1024 +0.4% +0.4 .. +0.4
wo_a 1024 × 4096 256 +0.5% +0.5 .. +0.5
wo_a einsum, 8 groups of 1024 × 4096 16384 -6.9% -7.1 .. -6.8
wo_a einsum, 8 groups of 1024 × 4096 4096 -8.1% -9.5 .. -7.5
wo_a einsum, 8 groups of 1024 × 4096 256 -4.4% -4.9 .. -2.3

Swap-AB with a small BLOCK_M. Rows that run swap-AB with BLOCK_M 48–160 were also measured one shape per process, where pairs are tight.

  • wqkv_a M=4096 (BLOCK_M 144): -0.8%
  • wo_a M=4096 (BLOCK_M 160): -2.9%
  • wo_b M=512 (BLOCK_M 112): -3.0%
  • idx q_b M=512 (BLOCK_M 96): -1.8%
  • BLOCK_M 48–96: within ±0.5%

So wide K is not gated on UMMA_N. The wqkv_a M=4096 row in the main table (-12.4%) is noisy; -0.8% is the better estimate.

Unit tests: tests/test_fp8_fp4.py test_gemm and test_m_grouped_gemm_masked pass (run on the first commit; later commits only widen the gate and rename the flag). Their configurations (128/128 and 128/32 granularities, FP4 operands) do not take the wide-K path, so the e4m3 × e4m3 per-32 case is covered only by the A/B above.

🤖 Generated with Claude Code

zcnrex and others added 4 commits November 3, 2026 13:05
On sm_107f, `kind::mxf8f6f4` with descriptor bit 31 set issues K=64 per
instruction and reads two per-32 UE8M0 scale factors. Enable it in the dense
1D1D kernel for e4m3 x e4m3, K-major, per-32-scaled, non-k-grouped GEMMs, except
when swap-AB makes UMMA_N smaller than 192. Other architectures compile the
existing K=32 path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Match `__CUDA_ARCH__ == 1070` (the JIT builds `sm_107a` only for CC 10.7),
drop the `not kIsMXF4` term implied by e4m3 x e4m3, and drop the swap-AB
`BLOCK_M >= 192` clause: re-measured at swap-AB BLOCK_M 48-160, wide K is
-0.4..-3.0% or within +0.5%, and the earlier +17.6% was run-to-run noise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace `kUseWideK` with `kIsMXF8KMajor` (e4m3 x e4m3, per-32 scales,
K-major on both sides), decide the wide K once in `UMMA_K`, and derive
`instr_desc.k_size_` from it. `UMMA_K` and the descriptor are unchanged
for every instantiation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Removed redundant definition of kIsSM107 in the CUDA architecture check.
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