Skip to content

[Fix] SM100: use the allocated tensor memory base - #122

Merged
zcnrex merged 8 commits into
sgl-project:devfrom
henrylhtsang:fix/sm100-tmem-base
Nov 4, 2026
Merged

zcnrex merged 8 commits into
sgl-project:devfrom
henrylhtsang:fix/sm100-tmem-base

Conversation

@henrylhtsang

@henrylhtsang henrylhtsang commented Oct 27, 2026 •

Copy link
Copy Markdown

Motivation

Fixes deepseek-ai/DeepGEMM#479.

SM100 kernels assume tensor memory (TMEM) starts at column zero, although allocation returns a base address. Use that base for accesses and deallocation, following CUTLASS's allocation and accumulator setup and deallocation.

Modifications

  • Read the allocated base after synchronization in nine SM100 implementations: BF16 GEMM, Mega Gate, BF16/FP8/FP4 Mega MoE, BMK/BNK/MN, FP8/FP4 GEMM, dense/sparse MQA logits, and TF32 HC-prenorm.
  • Apply it to MMA operands and accumulators, scale factors, TMEM loads/stores, and deallocation. Remove assertions requiring base zero.
  • Add an HC-prenorm regression test that reserves 256 TMEM columns in a temporary header copy, requiring a nonzero kernel base. Check split and unsplit outputs against PyTorch on four CUDA streams, then restore the original JIT configuration.

Accuracy Tests

On one NVIDIA B300 (SM103), CUDA 13.2, PyTorch 2.13:

  • Revised regression test: passes with the fix for seeds 0, 1, and 2; the same test fails with CUDA launch errors for all three seeds against the base branch's headers.
  • Controlled diagnostic runs confirm the kernel's allocated TMEM base is 256. Unfixed code under memcheck reports tcgen05.dealloc on unallocated TMEM (exit 99).
  • Compute Sanitizer memcheck and synccheck: both pass with zero errors, including a subsequent run after restoring the original JIT configuration.
  • git diff --check, Python syntax validation, and static allocation/base/deallocation audit pass.

This reproduces the zero-base defect under a controlled allocation; it does not establish the original crash's scheduling interleaving.

Speed Tests and Profiling

Not run; no performance result is claimed.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

lightseek-bot and others added 5 commits October 27, 2026 04:23
A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>
@henrylhtsang

Copy link
Copy Markdown
Author

Validated on one NVIDIA B300 (CUDA 13.2, PyTorch 2.13):

  • The revised regression test passes with the fix for seeds 0, 1, and 2, and fails against the unfixed headers for all three seeds.
  • Fixed code passes Compute Sanitizer memcheck and synccheck with zero errors. Unfixed code reports tcgen05.dealloc on unallocated tensor memory under memcheck (exit 99).

The original concurrency-only test passed both versions. The revised test reserves 256 columns in a temporary header copy to require a nonzero base; diagnostic runs confirmed base 256.

Potentially we can drop the test if the temporary-header fixture is too intrusive.

@nvpohanh

Copy link
Copy Markdown

@Fridge003 Could you review this? Thanks!

@Fridge003

Copy link
Copy Markdown
Collaborator

Hi @henrylhtsang, can you please run the blackwell tests under https://github.com/sgl-project/DeepGEMM/tree/dev/sgl_deep_gemm/tests for this PR, and post their results? Thanks

@henrylhtsang

henrylhtsang commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

Tested b4911aa on one NVIDIA B300 SXM6 AC (SM103): CUDA 13.2 (nvcc 13.2.78), driver 595.91.07, PyTorch 2.13.0+cu132, GCC 13.3, Compute Sanitizer 2026.1.1.

bash sgl_deep_gemm/run_tests.sh --max-procs 1 (full profile): 15 passed, 2 failed, 7 skipped; exit 1.

  • Passed: BF16, einsum, FP8/FP4, HyperConnection (including the nonzero-TMEM-base regression), layout, attention, legacy, Mega Gate, Mega mHC, locality domains, lazy initialization, Mega MoE SiTU, L1 FP4 accuracy, L1 sentinel, and pre-dispatch. Attention ran all 240 dense, 900 paged, and 161 sparse cases enumerated by this commit.
  • Failed — test_mega_moe_sgl.py: missing deep_ep; the test requires DeepEP ElasticBuffer for its correctness reference.
  • Failed — test_sanitizer.py: its first dense-MQA memcheck invocation stopped at DG_JIT_CHECK_NO_SPILLS=1: PTXAS reported 24 bytes spill stores / 56 bytes spill loads. The same first case produces identical spills with the complete headers from base commit 4fbe51d (all other code unchanged), so this guard failure also occurs without this PR's changes. The sanitizer suite did not proceed beyond that failure.
  • Skipped: test_mega_moe.py (missing DeepEP); SiTU equal-transform (disabled by the runner for its documented CPU tolerance issue); NVFP4 alphas and global-token tests (require at least two ranks); three Hopper-only tests.

Additional single-GPU tests omitted by the main runner both passed with default arguments: test_mega_moe_bf16_trtllm.py and test_mega_moe_nvfp4_trtllm.py, including their negative controls.

Also ran test_hyperconnection.test_hc_prenorm_gemm_nonzero_tmem_base separately through test_sanitizer.py: memcheck and synccheck both passed, zero errors. The complete test gate remains non-green for the two failures above.


edit 1: checked the test_sanitizer.py no-spills failure further (compile bisect on the same B300 + CUDA 13.2 setup): started since upstream 057ca59 (Sep 30, 26/09/30 release), recovered in 51fbef7 (Oct 14, predates the merge), then went bad again from d0a3af7 (Oct 22) after merge 1f88317 (Oct 16) brought 057ca59 into dev. Identical kernel instantiation and spill bytes (24B stores / 56B loads) at every bad point. Unrelated to this PR.


edit 2: With DeepEP 2.1.0, both test_mega_moe.py and test_mega_moe_sgl.py passed on one B300 at b4911aa using --num-processes 1 --num-experts 256; all correctness checks stayed enabled. The default 384 experts exceeds DeepEP's 256-experts-per-rank limit. Dependencies: NCCL 2.30.4, NVSHMEM 3.4.5, TileLang 0.1.9, TileKernels 1.0.0, TVM FFI 0.1.6. The sanitizer spill failure remains unchanged.

@henrylhtsang

Copy link
Copy Markdown
Author

@Fridge003 any chance to get an approval and merge?

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.

5 participants