Skip to content

feat: add sm120 support for DeepGEMM - #56

Merged
Fridge003 merged 9 commits into
sgl-project:devfrom
leavelet:sgl-sm120
Jul 14, 2026
Merged

Fridge003 merged 9 commits into
sgl-project:devfrom
leavelet:sgl-sm120

Conversation

@leavelet

@leavelet leavelet commented Jul 9, 2026

Copy link
Copy Markdown

No description provided.

@leavelet leavelet changed the title [WIP] feat: add sm120 support for DeepGEMM feat: add sm120 support for DeepGEMM Jul 10, 2026
Comment thread tests/test_bf16.py Resolved
RayWang96 and others added 9 commits July 14, 2026 01:08
…ped GEMM, einsum, prenorm)

Cherry-pick of deepseek-ai/DeepGEMM nv_dev commit 2073ddb (PR deepseek-ai#324) onto sgl/dev.
Stage 1 scope: dense + m-grouped FP8/FP4/BF16 GEMM, einsum, TF32 HC prenorm.

Conflict resolutions:
- scheduler/gemm.cuh: merged Scheduler template (dev kEnsureZeroPadding/kKAlignment/
  kSFKSpan + sm120 kSplitKFactor).
- heuristics/runtime.hpp: per-arch MK-alignment policy; preserved dev SM100 tuning {224,32,32}.
- gemm.hpp: kept dev m-grouped calls (ensure_zero_padding) + added sm120 arch-12 arms.
- Deferred to follow-ups: k-grouped GEMM (arch-12 -> UNREACHABLE, needs dev psum-SF API),
  MQA-logits (attention.hpp kept dev; smxx_*_mqa_logits.hpp removed; sm120 mqa .cuh orphaned).
- Tests: took dev's harness; sm120 arch-12 test gating to be re-added.
…kbone

- gemm.hpp k_grouped_fp8_gemm_nt_contiguous: define arch_major; stub arch-12 k-grouped
  (deferred to stage 2 per dev psum-SF API divergence).
- sm120_fp8_fp4_gemm_1d1d.cuh: reorder Scheduler<> args to dev's param order
  (kEnsureZeroPadding, kKAlignment, kSFKSpan) so it matches the merged scheduler template.

tvm-ffi _C.so now compiles clean with all sm120 apis edits.
New csrc/jit_kernels/impls/sm120_mqa_logits.hpp: SM120FP8MQALogitsRuntime + sm120_fp8_mqa_logits,
SM120FP4MQALogitsRuntime + sm120_fp4_mqa_logits, and a unified sm120_mqa_logits(is_fp4, ...)
mirroring dev's sm100_mqa_logits. Sourced from nv_dev's SM120 dense-MQA launchers, arch-branches
dropped per dev's per-arch convention.
attention.hpp: include sm120_mqa_logits.hpp; relax fp8/fp4 asserts to arch 12; block_kv=128 on
SM120; arch-12 dispatch arm in fp8_fp4_mqa_logits.

Validated on RTX PRO 6000: FP8 dense MQA head_dim=128 deterministic + runs.
KNOWN ISSUE (pre-existing nv_dev kernel): in-context compute race in sm120_fp8_mqa_logits.cuh
at head_dim in {32,64} (head_dim=128 clean). Needs kernel-level debug before enabling 32/64.
kSwizzleMode was hardcoded to 128 while the TMA descriptor uses swizzle_mode = head_dim
(and kSwizzleAlignment = head_dim*8 = the swizzle span). For head_dim in {32,64} the kernel
read smem with a 128B swizzle over a 32/64B-swizzled layout, mis-addressing reads into other
(valid, already-written) pipeline stages -> racecheck-clean but timing-dependent -> nondet
logits at deep KV pipelines. Set kSwizzleMode = kHeadDim (SwizzleContext supports B32/B64/B128).

Validated on RTX PRO 6000: dev test_mqa_logits PASSES all configs; head_dim 32/64/128 all
deterministic + numdiff ~6e-4. Pre-existing nv_dev kernel bug (upstream should take this too).
Same bug as the dense FP8 MQA kernel: kSwizzleMode hardcoded to 128 while the TMA descriptor
uses swizzle_mode = head_dim. Set kSwizzleMode = kHeadDim. (FP4 paged is head_dim=128-only with
kSwizzleMode=64 = packed kSMEMKBytes, so unaffected.) Validated by analogy to the dense fix;
exercised once paged MQA is wired (stage 3b).
- scheduler/sm120_paged_mqa_logits.cuh: SM120PagedMQALogitsScheduler + sm120_paged_mqa_logits_metadata
  (dev per-arch style; atom scheduler carried from nv_dev, sm120-named).
- sm120_fp8/fp4_paged_mqa_logits.cuh: point at the sm120-named scheduler.
- csrc/jit_kernels/impls/sm120_paged_mqa_logits.hpp: SM120 paged host launchers
  (metadata split_kv=128, fp8, fp4).
- attention.hpp: arch-12 wiring for get_paged_mqa_logits_metadata + fp8_fp4_paged_mqa_logits
  (split_kv=128, block_kv=64, relaxed fp8/fp4 asserts).
- test_attention.py: enable is_fp4 on arch 12 (head_dim=128) for dense + paged MQA.

Validated on RTX PRO 6000: dev test_mqa_logits (FP8+FP4 dense) and test_paged_mqa_logits
(FP8+FP4 paged, next_n 1 and 2) all PASS. Note: paged uses the atom scheduler; converting
to dev's q_token model (option Y) remains an optional follow-up refactor.
Add sm120_paged_mqa_logits(is_fp4, ...) with the exact same signature as dev's
sm100_paged_mqa_logits (routes to sm120_fp8/fp4_paged_mqa_logits internally; SM120's atom
scheduler ignores num_q_tokens_total/splits_per_chunk). attention.hpp now dispatches SM100
and SM120 paged identically. Dense/metadata entries already mirror sm100. Revalidated:
test_paged_mqa_logits (FP8+FP4) PASS.
- attention.hpp: arch-12 branch for fp8_gemm_nt_skip_head_mid (-> sm120_fp8_fp4_gemm_1d1d) +
  its missing include. Validated (test_gemm_skip_head_mid PASS).
- test gating for SM120 (consumer Blackwell): einsum tolerance 1e-10->1e-7 (FP32 accum order,
  not a DG bug); skip cuBLASLt FP8 perf-baseline + test_cublaslt_gemm (limited FP8/kernel-naming
  on SM120); guard empty-scores average; skip k-grouped (stub).

Full SM120 suite PASS: test_{layout,lazy_init,bf16,fp8_fp4,einsum,hyperconnection} + attention
(skip_head_mid/mqa/paged, FP8+FP4). Heavy attention sub-tests need isolation (memory), each
passes standalone. test_legacy N/A (Triton path); mega_moe* are SM90/SM100-specific.
…/tests/

Per sglang maintainer: tests/ should stay aligned with the deepgemm main branch (reduces rebase
complexity). Revert the cherry-pick's auto-merged SM120 changes to tests/test_bf16.py and
tests/test_einsum.py back to origin/dev. All SM120 test gating (FP4 enable, einsum 1e-7 tolerance,
cuBLAS/k-grouped skips) lives only under sgl_deep_gemm/tests/.
@Fridge003
Fridge003 merged commit 4bb3467 into sgl-project:dev Jul 14, 2026
zcnrex pushed a commit to zcnrex/DeepGEMM that referenced this pull request Aug 31, 2026
Helicoplacoidea pushed a commit to Helicoplacoidea/DeepGEMM that referenced this pull request Aug 31, 2026
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.

3 participants