Skip to content

[SM100] Use oversized shared memory for Mega MoE on CC 10.7 - #120

Merged
zcnrex merged 3 commits into
sgl-project:devfrom
zcnrex:sm107-mega-moe-oversized-smem
Oct 27, 2026
Merged

zcnrex merged 3 commits into
sgl-project:devfrom
zcnrex:sm107-mega-moe-oversized-smem

Conversation

@zcnrex

@zcnrex zcnrex commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

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() returns SM107ArchSpec::oversized_smem_capacity on arch 10.7. Other arches, and builds with older toolkits, are unchanged.
  • The launch needs CU_LAUNCH_ATTRIBUTE_SHARED_MEMORY_MODE = CU_SHARED_MEMORY_MODE_ALLOW_OVERSIZED_SHARED_MEMORY. DeepJIT's launcher always sets CU_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES, which the driver rejects above the opt-in limit.
  • To avoid that without changing the DeepJIT submodule, launch_with_shared_memory_mode (in impls/runtime_utils.hpp) mirrors jit->launch and calls cuLaunchKernelEx on the loaded kernel. It sets the same cooperative, cluster and PDL attributes and uses the current stream, plus the shared-memory mode.
  • It falls back to jit->launch when no mode is needed. Only the fp8xfp4 and bf16 Mega MoE launches use it.
  • Once DeepJIT has a launch option for the shared-memory mode, this helper can be replaced by that option.

Validation

sm_107a, CUDA 13.4, CUTLASS 4.8.1:

  • test_hyperconnection.py passes.
  • Mega MoE fp8xfp4 on 4 GPUs at decode-sized token counts:
    • outputs are bitwise identical between the oversized and normal budgets over repeated, interleaved rounds;
    • the oversized config chooses more stages and its smem exceeds the opt-in limit.

🤖 Generated with Claude Code

zcnrex and others added 3 commits October 23, 2026 00:08
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]>
…smem

# Conflicts:
#	csrc/jit_kernels/heuristics/mega_moe.hpp
@zcnrex
zcnrex merged commit 2b2863a into sgl-project:dev Oct 27, 2026
@zcnrex
zcnrex deleted the sm107-mega-moe-oversized-smem branch October 27, 2026 06:01
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)
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)
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