Repository navigation
[SM103] Mega MoE: add native K=96 Ultra MMA mainloop for NVFP4 on Blackwell Ultra - #161
Merged
Merged
Conversation
zcnrex
approved these changes
Nov 23, 2026
zcnrex
added a commit
that referenced
this pull request
Nov 28, 2026
…178) PR #161 made the host size the dispatch region as max(expert_token_count, dispatch_send_buffer), matching the union it added to the FP8xFP4 kernel. The BF16 kernel shares that host function but kept the two as separate 1 KiB-aligned fields, so its SharedStorage is 1 KiB larger than the launched dynamic smem and its barriers sit past the end. On B300 the 2-rank bf16xbf16 test (hidden 1024, 8 experts) faults on warp 1's dispatch-barrier init (Warp Out-of-range Address, STS at smem 0x35c40 with smem_size=219524), and DeepEP reports it later as symmetric.hpp:136 Cuda failure 700. The two lifetimes are disjoint in the BF16 kernel as well: the counts are last used before the dispatch NVLink barrier and the pull buffer only after. Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blackwell Ultra (
CC 10.3) introduces nativeK = 96block-scaled FP4 Tensor Core instructions (tcgen05.mma.cta_group::2.kind::mxf4nvf4.block_scale.block16,SM103_MMA_F4_2x1SM_SS_ULTRAin CUTLASS) that process 96 FP4 elements per MMA atom (1.5xtheK = 64width ofSM100). Currently onCC 10.3,csrc/runtime/jit.hppcompiles with-arch=sm_100fandsm100_fp8_fp4_mega_moe.cuhruns the 4-chunkK = 64mainloop.Following the
SM107ArchSpec/use_sm107_k64pattern from #113 and #133, this PR adds native SM103K = 96Ultra MMA support across all NVFP4 MegaMoEBLOCK_Mcandidates ({16, 64, 128, 192, 240}):csrc/runtime/jit.hpp,heuristics/sm100.hpp): select-arch=sm_103aonCC 10.3with NVCC >= 12.9 and addSM103ArchSpec::is_current().2 x 3) TMA pipeline onBLOCK_M = 192& compact 32-col TMEM SF ring onBLOCK_M = 240(heuristics/mega_moe.hpp,sm100_fp8_fp4_mega_moe.cuh):K = 96Ultra super-step spans 3256-elementBLOCK_Kstages (3 x 256 = 768 = 8 x 96FP4 elements).expert_token_count(used only in Dispatch/Cleanup) withdispatch_send_bufferinSharedStorage, and use asymmetricstore_block_m_l1 = 32, store_block_m_l2 = 8onBLOCK_M = 192whenuse_sm103_k96is active so 6 TMA stages (230,788 B) fit inside the227 KiB(232,448 B) shared-memory budget, giving double-buffered 3-stageK = 96super-steps.BLOCK_M <= 192(kFreeTmemCols >= 128), allocate multi-slot 3-chunk TMEM SF rings (kNumK96SFSlotsup to 4; 3 slots =108cols atBLOCK_M = 192).BLOCK_M = 240(UMMA_N = 240,kFreeTmemCols = 512 - 480 = 32 < 36), 3-chunk SF slots do not fit; whenumma_n <= 128(valid_m <= 128), each 2-chunkK = 96SF window needs2 x 4 (SFA) + 2 x 4 (SFB) = 16columns, fitting two disjoint double-bufferedK = 96SF slots (480..495and496..511) inside the 32 free TMEM columns while tiles withumma_n > 128use double-buffered 2-slotK = 64(480..491and492..503).K = 96+K = 64-tail mainloop (sm100_fp8_fp4_mega_moe.cuh):#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ == 1030)andkUseSM103K96(controllable viaDG_MEGA_MOE_SM103_K96, default1onCC 10.3forNVFP4,BLOCK_K == 256,GRAN_K == 16,BLOCK_M <= 240).num_k_blocks / 33-stage groups via 8K = 96lbo_mode = 1Ultra MMAs across 256B-strided SMEM sub-blocks and automatically drains anynum_k_blocks % 3remainder (0, 1, 2blocks, e.g.K = 7168 -> 28 = 9 x 3 + 1orK = 5120 -> 20 = 6 x 3 + 2) with theK = 64path across all weight layouts (GateUpBlock8,RowShuffled,GateUpInterleaved,UpGateBlock16) and shared experts.CC 10.0), SM107 (CC 10.7), and non-NVFP4 MMA kinds are completely unchanged.Tests
Verified on 8x B300 (
CC 10.3):test_mega_moe_pre_dispatch,test_mega_moe_nvfp4_trtllmacross bothBLOCK_M = 192andBLOCK_M = 240,test_mega_moe_nvfp4_alphas,test_mega_moe_l1_fp4_accuracy,test_mega_moe_l1_sentinel,test_mega_moe_situ,test_mega_moe_global_tokens8-rank NVFP4 / 2-rank MXFP4 / 2-rankx_scales) — all pass.-arch=sm_103a:test_bf16.py(GEMM + m-grouped + k-grouped),test_mega_gate.py,test_mega_mhc.py, andtest_fp8_fp4.py test_gemm— all pass.setup.py/build_sgl_deep_gemm.shbuilds compile cleanly with zero additional register spills onsm_103a.Microbenchmark & NCU
8x B300 (
EP = 8) standalonenvfp4_mega_moemicrobenchmark (fast_math=True, use_x_scales=True, median of 60 iterations across slowest rank; comparingdev, this PR withDG_MEGA_MOE_SM103_K96=0, and this PR with defaultDG_MEGA_MOE_SM103_K96=1):H, I, E, top_k)M/rank, routing)BLOCK_Mdev(us)K96=0(us)K96=1(us / TFLOPS/GPU)K96=1vsdevdevH=7168, I=5120, E=384, K=4M=16, uniform34.4 TF)H=7168, I=5120, E=384, K=4M=2048, uniform2,897.2 TF)H=7168, I=5120, E=384, K=4M=2048, skewed2,086.6 TF)H=7168, I=5120, E=384, K=4M=4096, uniform3,919.4 TF)H=7168, I=5120, E=384, K=4M=4096, skewed2,628.5 TF)H=7168, I=5120, E=384, K=4M=5120, uniform4,061.6 TF)H=7168, I=5120, E=384, K=4M=8192, uniform4,323.5 TF)H=7168, I=5120, E=384, K=4M=8192, skewed2,116.7 TF)H=7168, I=2048, E=256, K=8M=8, uniform29.5 TF)H=7168, I=2048, E=256, K=8M=2048, uniform2,361.1 TF)H=7168, I=2048, E=256, K=8M=2048, skewed1,725.4 TF)(In combination with #162 where skewed multi-block prefill selects
BLOCK_M = 240atM = 4096with ~50%umma_n <= 128tail tiles, the compactBLOCK_M = 240K = 96ring reduces skewedM = 4096kernel time by up to10.4%overBLOCK_M = 240K = 64while remaining 100% bitwise exact.)Nsight Compute (
2026.3.0) 1-GPU (EP = 1,H=7168, I=5120, E_local=48, top_k=4) hardware counters confirming the2/3Tensor Core pipe duty-cycle reduction from1.5xK = 96MMA throughput and 6-stage SMEM fit:sm__pipe_tensor_cycles_activeM=4096, uniformdevBM=192, S=48/48, 5-stgM=4096, uniformPR (K96=0)BM=192, S=48/48, 5-stgM=4096, uniformPR (K96=1)BM=192, S=32/8, 6-stg0.68x)M=4096, skeweddevBM=192, S=48/48, 5-stgM=4096, skewedPR (K96=1)BM=192, S=32/8, 6-stg0.68x)