Skip to content

perf(b12x/gemm): allow multi-wave DSMEM split-K on full-device SM121 (GB10) - #185

Open
nero- wants to merge 1 commit into
local-inference-lab:mainfrom
nero-:sm121-dsmem-multiwave
Open

nero- wants to merge 1 commit into
local-inference-lab:mainfrom
nero-:sm121-dsmem-multiwave

Conversation

@nero-

@nero- nero- commented Nov 30, 2026

Copy link
Copy Markdown

Summary

Follow-up to #169.

sm120_dsmem_auto_enabled enforces a single-wave cluster residency bound (n_blocks <= (active_sms // split_k) * 2). On 188-SM SM120 GPUs this covers decode projections up to n_blocks <= 188 (split_k=2) and <= 94 (split_k=4), but on 48-SM SM121 (DGX Spark GB10) it caps auto DSMEM at n_blocks <= 48 (N <= 768) for split_k=2 and <= 24 (N <= 384) for split_k=4 — silently disabling DSMEM on every major decode projection (qkv_a, wo_a, o_proj, dual_bf16, lm_head) even when B12X_TC_GEMV_DSMEM_SPLIT=1 is set.

This PR adds sm120_dsmem_requires_single_wave(device, *, stream=None):

  • SM120 (120) behavior is 100% unchanged (always returns True).
  • Opt-in policy is unchanged (B12X_TC_GEMV_DSMEM_SPLIT=1, default=False).
  • Full-device SM121 (active_sms >= total_sms) allows multi-wave split_k in (2, 4) DSMEM clusters while retaining all occupancy & safety guards (n_tiles == 1, max_rows_for_split4, ctas_per_sm >= 1, potential >= cluster_size, active_clusters >= 1).
  • Partitioned SM121 green contexts (active_sms < total_sms) retain the single-wave cap and safely fall back to L2 split-K.

Changes

  • flashinfer/experimental/b12x/_lib/utils/dsmem.py:
    • Add sm120_dsmem_requires_single_wave (resolving _cuda_device_ordinal before get_sm_version so non-CUDA devices safely return True), export in __all__, and wire into sm120_dsmem_auto_enabled.
  • flashinfer/experimental/b12x/gemm/bf16_gemv/_dual_tc.py, _tensor_core.py, blockscaled/_mxfp8_tc_gemv.py, wo_projection/_tc_gemv.py:
    • Pass require_single_wave=auto_dsmem and sm120_dsmem_requires_single_wave(ordinal) to validate_launcher_dsmem_cluster.
  • tests/experimental/b12x/test_sm120_dsmem_splitk.py:
    • Add _clear_sm_version_cache autouse fixture + major=12, minor=0 in test_dsmem_offline_compile_worker_never_calls_cuda_driver to prevent @lru_cache cross-test leakage.
    • Adapt the SM120-sized act_primary >= 72 assertion in test_dsmem_real_green_ctx_occupancy_and_zero_scratch_bloat to check act_primary > act_green on SM121.
    • Add test_sm121_dsmem_multiwave_auto_gating_and_green_ctx and real GB10 test_sm121_multiwave_dsmem_0ulp_parity (qkv_a 1792x5120 sk=4, wo_a 2x1024x4096 sk=2, varied UE8M0 scales).

Cold-L2 CUDA-Graph Evidence (NVIDIA GB10 / SM121, 48 SMs, 0–2350 MHz cap, 128 MiB L2 flush)

Negative latency delta = faster. All DSMEM outputs verified 0-ULP bit-exact vs L2 split-K with 0 L2 split-K scratch/flags VRAM.

Kernel (N × K) M nblk sk=1 (µs) sk=2 L2 sk=2 DSMEM sk=4 L2 sk=4 DSMEM Best DSMEM vs sk=1 Best DSMEM vs L2
mxfp8(512×5120) 1 / 6 32 34.8 / 34.8 35.0 / 35.9 34.8 / 35.3 36.7 / 36.6 35.5 / 35.7 0.0% / +1.4% -0.6% / -1.7%
mxfp8(1792×5120) (qkv_a) 1 / 6 112 95.1 / 95.3 95.4 / 96.4 91.3 / 92.1 96.2 / 96.9 89.0 / 89.1 -6.4% / -6.5% -7.5% / -8.0%
mxfp8(2048×5120) 1 / 6 128 107.4 / 107.7 107.6 / 108.5 102.5 / 103.3 107.5 / 107.8 98.3 / 99.2 -8.5% / -7.9% -8.6% / -8.0%
mxfp8(5120×2048) (o_proj) 1 / 6 320 102.3 / 102.6 104.5 / 105.4 94.7 / 95.3 103.5 / 103.7 92.2 / 93.1 -9.9% / -9.3% -10.9% / -10.2%
mxfp8(8192×5120) 1 / 6 512 262.1 / 262.2 263.2 / 265.0 240.6 / 242.7 269.2 / 269.3 232.3 / 232.5 -11.4% / -11.3% -13.7% / -13.7%
dual_bf16(512+384×5120) 1 / 6 56 81.8 / 81.8 85.2 / 86.9 80.9 / 81.7 90.9 / 90.8 83.9 / 85.0 -1.1% / -0.1% -5.0% / -6.0%
woa_mxfp8(2×1024×4096) 1 / 6 128 86.9 / 87.2 88.0 / 88.1 82.8 / 83.9 91.1 / 91.4 84.0 / 85.9 -4.7% / -3.8% -5.9% / -4.8%
bf16_lm(32320×5120) 1 / 6 2020 1382.5 / 1398.3 1426.3 / 1433.1 1359.9 / 1374.1 1483.0 / 1472.7 1334.2 / 1345.6 -3.5% / -3.8% -10.0% / -8.6%

Verification (NVIDIA GB10 / SM121)

FLARE_RUN_CUDA_TESTS=1 pytest -v tests/experimental/b12x/test_sm120_dsmem_splitk.py

Result: 15 passed, 0 failed in 14.64s (including real CUDA green-context test and multi-wave 0-ULP parity tests).

…(GB10)

Follow-up to flashinfer-ai#169.

PR flashinfer-ai#169 introduced `sm120_dsmem_auto_enabled` with a single-wave cluster cap
(`n_blocks <= (active_sms // split_k) * 2`). On 188-SM SM120 GPUs this permits
`n_blocks <= 188` at `split_k=2` and `<= 94` at `split_k=4`, covering decode
projections such as `qkv_a` (112 blocks) and `wo_a` (128 blocks). On 48-SM
SM121 (DGX Spark GB10), however, the same cap restricts auto DSMEM to
`n_blocks <= 48` (`N <= 768`) at `split_k=2` and `<= 24` (`N <= 384`) at
`split_k=4`, silently gating DSMEM off on every major decode projection even
when `B12X_TC_GEMV_DSMEM_SPLIT=1` is set.

Cold-L2 CUDA-graph measurements on NVIDIA GB10 (SM121, 48 SMs, 0-2350 MHz cap,
128 MiB L2 flush) show multi-wave `split_k in (2, 4)` DSMEM clusters beat L2
split-K across all 16 tested cases (-4.1% to -13.7% latency, 0-ULP parity, 0
scratch VRAM) and beat `split_k=1` on medium/large projections (`qkv_a
1792x5120`: -6.5%; `2048x5120`: -7.9% to -8.5%; `o_proj 5120x2048`: -9.3% to
-9.9%; `woa_mxfp8 2x1024x4096`: -3.8% to -4.7%; `8192x5120`: -11.3% to -11.4%;
`bf16_lm 32320x5120`: -3.5% to -3.8%).

Changes:
- Add `sm120_dsmem_requires_single_wave(device, *, stream=None)` in
  `flashinfer/experimental/b12x/_lib/utils/dsmem.py`:
  - Returns `True` for all non-SM121 devices (100% unchanged SM120 behavior)
    and for non-CUDA inputs.
  - Returns `False` on full-device SM121 (`active_sms >= total_sms`) while
    reverting to `True` on partitioned SM121 green contexts
    (`active_sms < total_sms`).
- Use `sm120_dsmem_requires_single_wave` in `sm120_dsmem_auto_enabled` and in
  the `require_single_wave` check across all 4 TC-GEMV compiler modules
  (`_dual_tc.py`, `_tensor_core.py`, `_mxfp8_tc_gemv.py`,
  `wo_projection/_tc_gemv.py`). Opt-in policy (`B12X_TC_GEMV_DSMEM_SPLIT=1`,
  `default=False`) and all safety guards (`split_k in (2, 4)`, `n_tiles == 1`,
  `max_rows_for_split4`, `ctas_per_sm >= 1`, `potential >= cluster_size`,
  `active_clusters >= 1`) remain unchanged.
- Add SM121 multi-wave unit tests, green-context partition checks, and real
  GB10 multi-wave `0-ULP` parity tests in
  `tests/experimental/b12x/test_sm120_dsmem_splitk.py`, and clear
  `get_sm_version`'s `@lru_cache` between mocked tests.

Verification (NVIDIA GB10, SM121):
- `FLARE_RUN_CUDA_TESTS=1 pytest -v tests/experimental/b12x/test_sm120_dsmem_splitk.py`:
  15 passed, 0 failed in 14.64s.

Signed-off-by: Jonathan Gutierrez <john.gtz@icloud.com>
@original-el8

Copy link
Copy Markdown

#193 (6ce11d2e9) merged default-on (2, 4) DSMEM split-K for SM121 in sm120_dsmem_split_enabled along with sm120_dsmem_auto_requires_single_wave(device) (return get_sm_version(device) != 121) wired across _dual_tc.py, _tensor_core.py, _mxfp8_tc_gemv.py, and wo_projection/_tc_gemv.py, which causes the current merge conflict on this branch.

Two pieces from this PR are still missing on main and worth keeping in a focused rework onto origin/main:

  1. Partitioned SM121 green-context single-wave guard (flashinfer/experimental/b12x/_lib/utils/dsmem.py): sm120_dsmem_auto_requires_single_wave on main checks only get_sm_version(device) != 121 without inspecting stream or comparing get_active_sm_count(ordinal, stream=stream) against multi_processor_count (and without guarding non-CUDA devices before get_sm_version). Passing stream=stream from sm120_dsmem_auto_enabled and returning True when active_sms < total_sms preserves single-wave residency (falling back to L2 split-K) on partitioned SM121 green contexts such as an 8-SM partition while keeping multi-wave (2, 4) DSMEM enabled on full-device GB10.
  2. SM121 test hygiene and green-context coverage (tests/experimental/b12x/test_sm120_dsmem_splitk.py):
    • _clear_sm_version_cache autouse fixture and explicit major=12, minor=0 on the mocked get_device_properties in test_dsmem_offline_compile_worker_never_calls_cuda_driver so @lru_cache state cannot leak across tests.
    • Updating test_dsmem_real_green_ctx_occupancy_and_zero_scratch_bloat (act_primary > act_green on SM121 instead of the 188-SM act_primary >= 72 bound) so the real green-context test passes on 48-SM GB10.
    • test_sm121_dsmem_multiwave_auto_gating_and_green_ctx and test_sm121_multiwave_dsmem_0ulp_parity (updated for SM121's new default-on (2, 4) gating without needing B12X_TC_GEMV_DSMEM_SPLIT=1).

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.

2 participants