Skip to content

perf(cuda/quant): sm_120/sm_121-tuned quantized GEMM for Blackwell prefill #637

Closed

Description

@inureyes

Part of #623. Depends on #625 (upstream JIT qmm rework changes the starting point) and should follow #629 (MoE prefill fix determines which GEMM path matters most).

Context

The only architecture-specialized quantized GEMM in the CUDA path is qmm_sm90, compiled solely when 90a (Hopper) is in MLX_CUDA_ARCHITECTURES (MLX_CUDA_SM90A_ENABLED gate: src/lib/mlxcel-core/build.rs:265-271; docs docs/installation.md:101-105). A GB10 build passes 121, so supports_qmm_sm90 is false and quantized prefill matmuls fall through to qmm_sm80 (Ampere-class tiles) or qmm_naive (src/lib/mlx-cpp/patches/mlx/backend/cuda/quantized/quantized.cpp:53-113). Blackwell (sm_120/121 consumer-class: no wgmma/TMA from sm_90a, but 5th-gen tensor cores incl. fp4/fp8 paths and larger shared memory) gets a two-generations-old kernel for the compute-bound phase.

Decode is not the target here: it is GEMV-shaped and bandwidth-bound (qmv/fp_qmv, plus upstream qmv_wide after #625). The payoff is prefill and batched prefill on long prompts, plus MoE grouped GEMM shapes.

Upstream is also moving here (QQMM both-sides-quantized work targets compute capability 10.0+; Hopper QMM heuristics; NAX kernels). This issue is research-then-implement: prefer upstream adoption over local kernels.

Scope

Quantify the gap and close what is real. Explicitly allowed outcome: a findings doc concluding the sm_80 path is within noise of achievable on sm_121, with profile evidence, plus an upstream issue if a kernel gap is confirmed. Otherwise: an sm_120-tuned qmm in the overlay.

Implementation plan

  1. Quantify (needs perf(bench): long-prompt prefill benchmark coverage and serving TTFT/decode-rate telemetry #624 long-prompt bench): prefill tok/s at 2048/8192/32768 on llama-3.1-8b-4bit and qwen2.5-7b-4bit; compute achieved TFLOPS and compare against (a) the same model's bf16 prefill (cuBLAS/cuDNN-backed, the practical ceiling) and (b) ncu-measured tensor-core utilization of the current qmm_sm80 path.
  2. Determine the dispatch actually taken on sm_121 post-chore(mlx): upgrade pinned MLX commit, rebase CUDA overlays, GB10 re-baseline and outlier triage #625 (upstream JIT qmm may already pick better tiles): instrument or nsys the kernel names.
  3. Evaluate upstream options in order:
    a. current upstream qmm JIT with sm_120-appropriate tile parameters (may be a heuristics-only patch);
    b. upstream QQMM path if it supports sm_120/121 (it targets cc 10.0+; verify whether 12.x consumer parts are included or Blackwell-datacenter only);
    c. NAX kernel family applicability.
  4. If a local kernel is warranted, add an sm_120 specialization beside qmm_sm80 in the overlay (patches/mlx/backend/cuda/quantized/qmm/): CUTLASS-based int4-group dequant-in-epilogue GEMM or an mma.sync 16x8x32-tile hand kernel; gate on __CUDA_ARCH__ >= 1200 with runtime dispatch in quantized.cpp, and make sure the build's arch handling (sm_arch_with_suffix, build.rs:334-340) compiles it for 121 (note the known divergence: auto-detect emits 121a, release workflow passes 121; keep both working).
  5. Parity: quantized-matmul unit comparisons vs qmm_naive outputs across group sizes 32/64/128 and bits 4/8 on representative shapes; model-level greedy parity on llama-3.1-8b-4bit.

Acceptance criteria

  • Findings doc in docs/benchmark_results/: achieved-vs-ceiling table, kernel dispatch map on sm_121, and go/no-go rationale. This is required regardless of outcome.
  • If implementing: >= 25% prefill tok/s improvement at 8192-token prompts on llama-3.1-8b-4bit on GB10, no decode regression, parity green.
  • If not implementing: upstream issue filed with the ncu evidence and linked in the doc; epic checklist updated.
  • cargo test --features cuda passes; both 121 and 121a arch strings build.

Validation

cargo build --release --features cuda
ncu --set roofline ./target/release/mlxcel-bench-decode --model ./models/llama-3.1-8b-4bit --prompt-tokens 8192 --max-tokens 1
./target/release/mlxcel-bench-decode --model ./models/llama-3.1-8b-4bit --prompt-tokens 8192

References

  • Arch gating: src/lib/mlxcel-core/build.rs:250-340; dispatch patches/mlx/backend/cuda/quantized/quantized.cpp:53-113; kernels patches/.../qmm/.
  • Release arch matrix: docs/installation.md:119-122 (aarch64: 90a;100;121).
  • Baseline gap datum: dense CUDA prefill median is 1.64x Metal M1 Ultra, but that is against a much weaker Metal GPU; the bf16-vs-4bit prefill ratio on GB10 itself is the honest ceiling comparison.

Activity

  1. added
    type:performance
    status:ready
    priority:medium
    area:core
    on Jul 2, 2026
  2. added a commit that references this issue on Jul 10, 2026
  3. added
    status:done
    and removed
    status:ready
    on Jul 10, 2026
  4. added 2 commits that reference this issue on Jul 10, 2026
    4e8dbc6
    4967942
  5. self-assigned this
    on Aug 31, 2026
  6. added 3 commits that reference this issue on Oct 27, 2026
    70fff88
    c72084e
    c90c9d1
  7. added 2 commits that reference this issue on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:corepriority:mediumstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions