Repository navigation
[SM100] Use oversized shared memory for Mega MoE on CC 10.7 - #120
Merged
Merged
Conversation
On arch 10.7 with CUDA 13.4, the Mega MoE pipeline budget becomes the oversized per-block limit (334848 B), so the kernel gets more stages. DeepJIT's launcher always sets MAX_DYNAMIC_SHARED_SIZE_BYTES, which the driver rejects above the opt-in limit, so Mega MoE launches through a local cuLaunchKernelEx path that sets CU_LAUNCH_ATTRIBUTE_SHARED_MEMORY_MODE when the chosen size needs it. DG_SM107_OVERSIZED_SMEM=0 keeps the normal budget. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…smem # Conflicts: # csrc/jit_kernels/heuristics/mega_moe.hpp
zcnrex
added a commit
that referenced
this pull request
Oct 27, 2026
* Use oversized shared memory for SM100 Mega MoE on CC 10.7 On arch 10.7 with CUDA 13.4, the Mega MoE pipeline budget becomes the oversized per-block limit (334848 B), so the kernel gets more stages. DeepJIT's launcher always sets MAX_DYNAMIC_SHARED_SIZE_BYTES, which the driver rejects above the opt-in limit, so Mega MoE launches through a local cuLaunchKernelEx path that sets CU_LAUNCH_ATTRIBUTE_SHARED_MEMORY_MODE when the chosen size needs it. DG_SM107_OVERSIZED_SMEM=0 keeps the normal budget. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Always use oversized shared memory for Mega MoE on CC 10.7 Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 2b2863a)
2 tasks done
zcnrex
pushed a commit
that referenced
this pull request
Oct 28, 2026
…ll (#126) On CC 10.7, `kind::mxf8f6f4` has a K=64 shape that reads E2M1 operands packed. FP8 x FP4 Mega MoE now uses it: - Routed FP4 weights stay packed in shared memory (64B swizzle). The host builds packed TMA maps with `fp4_unpacked_smem=false`. This halves each weight stage and the number of UMMAs. - Each 128-wide K block issues two K=64 UMMAs, each taking its two per-32 scale factors by id. - The FP8 shared expert splits each K block into two 64-wide halves, with 64B-swizzled activation and weight maps. - The stage heuristic counts packed weight stages. The dispatch pull can also run on SIMT lanes: each lane loads its 16-byte slices of the token, its scale factors and its top-k weight from the peer, then stores them locally. A token then costs one remote round trip instead of chunked TMA copies through the shared-memory send buffers. With the SIMT pull: - Dispatch warps keep 96 registers, since each lane holds its whole token slice. The epilogue gets 184 at <= 64 experts per rank. - Expert counts are pushed with `red.sys.add` instead of `atom.sys.add`. - The shared-memory budget stays at the normal 232448 bytes. Oversized mode (#120) shrinks L1, which the pull's in-flight remote loads need; with it, the SIMT pull is slower than the TMA pull. Hardening: - `red_add_rel` (u32) gets a "memory" clobber, so the elected lane's weight and metadata stores cannot be sunk past the release. - `fence.proxy.async.global` after the ring-slot empty wait, before SIMT stores overwrite a slot that TMA read in the previous wave. - The K=64 MMA issue is an `if constexpr`/`else`, so no instantiation has an unreachable loop. Both features are template switches set per launch: - K=64 is on by default for CC 10.7 FP8 x FP4 with packed FP4 weights, BLOCK_K 128 and per-32 scale factors. `DG_MEGA_MOE_SM107_K64=0` disables it. - The SIMT pull follows K=64. `DG_MEGA_MOE_SIMT_PULL=0/1` forces it. - With both off, the generated kernel is unchanged, oversized shared memory included. SM100, SM103 and the other MMA kinds are unaffected. Performance, on Rubin at EP4 with hidden 5120 and intermediate 2304: - Shapes: 48, 24 or 16 experts per rank; top-6, top-6 or top-3; one shared expert; 330-960 tokens per rank; localization on. - 8-16% faster per call than before (6-15% with localization off). - Output is bitwise equal to vLLM's SM107 DeepGEMM build. - K=64 changes the MMA accumulation order, so the output differs from the K=32 path by about 3e-5 relative L2. Tested on 4 Rubin GPUs, against the K=32 path on identical inputs: - Balanced, masked, hot-expert and empty-rank routing; 1-1920 tokens. - BLOCK_M 16-240, including ring wrap. - 96 experts per rank with 2 shared experts. - Per-32-block scale-factor stress. - Localization on and off, CUDA-graph replay and determinism. - Expert-receive stats are bitwise equal to the K=32 path; the SIMT-only output is bitwise equal too. Co-authored-by: Claude Opus 5.5 <[email protected]>
zcnrex
pushed a commit
that referenced
this pull request
Oct 29, 2026
…ll (#126) On CC 10.7, `kind::mxf8f6f4` has a K=64 shape that reads E2M1 operands packed. FP8 x FP4 Mega MoE now uses it: - Routed FP4 weights stay packed in shared memory (64B swizzle). The host builds packed TMA maps with `fp4_unpacked_smem=false`. This halves each weight stage and the number of UMMAs. - Each 128-wide K block issues two K=64 UMMAs, each taking its two per-32 scale factors by id. - The FP8 shared expert splits each K block into two 64-wide halves, with 64B-swizzled activation and weight maps. - The stage heuristic counts packed weight stages. The dispatch pull can also run on SIMT lanes: each lane loads its 16-byte slices of the token, its scale factors and its top-k weight from the peer, then stores them locally. A token then costs one remote round trip instead of chunked TMA copies through the shared-memory send buffers. With the SIMT pull: - Dispatch warps keep 96 registers, since each lane holds its whole token slice. The epilogue gets 184 at <= 64 experts per rank. - Expert counts are pushed with `red.sys.add` instead of `atom.sys.add`. - The shared-memory budget stays at the normal 232448 bytes. Oversized mode (#120) shrinks L1, which the pull's in-flight remote loads need; with it, the SIMT pull is slower than the TMA pull. Hardening: - `red_add_rel` (u32) gets a "memory" clobber, so the elected lane's weight and metadata stores cannot be sunk past the release. - `fence.proxy.async.global` after the ring-slot empty wait, before SIMT stores overwrite a slot that TMA read in the previous wave. - The K=64 MMA issue is an `if constexpr`/`else`, so no instantiation has an unreachable loop. Both features are template switches set per launch: - K=64 is on by default for CC 10.7 FP8 x FP4 with packed FP4 weights, BLOCK_K 128 and per-32 scale factors. `DG_MEGA_MOE_SM107_K64=0` disables it. - The SIMT pull follows K=64. `DG_MEGA_MOE_SIMT_PULL=0/1` forces it. - With both off, the generated kernel is unchanged, oversized shared memory included. SM100, SM103 and the other MMA kinds are unaffected. Performance, on Rubin at EP4 with hidden 5120 and intermediate 2304: - Shapes: 48, 24 or 16 experts per rank; top-6, top-6 or top-3; one shared expert; 330-960 tokens per rank; localization on. - 8-16% faster per call than before (6-15% with localization off). - Output is bitwise equal to vLLM's SM107 DeepGEMM build. - K=64 changes the MMA accumulation order, so the output differs from the K=32 path by about 3e-5 relative L2. Tested on 4 Rubin GPUs, against the K=32 path on identical inputs: - Balanced, masked, hot-expert and empty-rank routing; 1-1920 tokens. - BLOCK_M 16-240, including ring wrap. - 96 experts per rank with 2 shared experts. - Per-32-block scale-factor stress. - Localization on and off, CUDA-graph replay and determinism. - Expert-receive stats are bitwise equal to the K=32 path; the SIMT-only output is bitwise equal too. Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 5430b49)
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.
Summary
On compute capability 10.7 with CUDA 13.4, SM100 Mega MoE uses the oversized per-block shared-memory limit (334848 B instead of 232448 B). This gives its pipeline more stages; outputs are unchanged.
get_smem_capacity_for_mega_moe()returnsSM107ArchSpec::oversized_smem_capacityon arch 10.7. Other arches, and builds with older toolkits, are unchanged.CU_LAUNCH_ATTRIBUTE_SHARED_MEMORY_MODE = CU_SHARED_MEMORY_MODE_ALLOW_OVERSIZED_SHARED_MEMORY. DeepJIT's launcher always setsCU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, which the driver rejects above the opt-in limit.launch_with_shared_memory_mode(inimpls/runtime_utils.hpp) mirrorsjit->launchand callscuLaunchKernelExon the loaded kernel. It sets the same cooperative, cluster and PDL attributes and uses the current stream, plus the shared-memory mode.jit->launchwhen no mode is needed. Only the fp8xfp4 and bf16 Mega MoE launches use it.Validation
sm_107a, CUDA 13.4, CUTLASS 4.8.1:test_hyperconnection.pypasses.fp8xfp4on 4 GPUs at decode-sized token counts:🤖 Generated with Claude Code