Skip to content

cuda: hopper wgmma path review follow-up (multi-GPU correctness + hardening) - #45

Merged
bri-prism merged 2 commits into
prismfrom
fix/hopper-q1-review-followup-v2
Jun 11, 2026
Merged

bri-prism merged 2 commits into
prismfrom
fix/hopper-q1-review-followup-v2

Conversation

@bri-prism

Copy link
Copy Markdown
Collaborator

What

Review follow-up for #39 (merged): multi-GPU correctness and hardening for the Hopper wgmma
path, plus a wholesale clang-format of the file. Fixes originate from the post-merge triage of
Copilot's inline review comments.

Fixes

  • Repack cache: keyed on (device, wdata, N, K, wbits) instead of the bare weight pointer
    (ambiguous across devices/views), guarded by a mutex (ggml can dispatch from one host thread
    per device), and entries publish only after a one-time cudaStreamSynchronize — a consumer
    GEMM on a different stream previously had no ordering dependency on the repack kernel and
    could read uninitialized dense buffers.
  • Per-device attr_set / SM count: a second GPU previously skipped the dynamic-SMEM opt-in
    (launch failure) and inherited device 0's SM count (wrong stream-K grid).
  • CUDA_CHECK on allocations and attribute/device queries.
  • Defensive int8 clamp in the activation quantizer (unreachable in exact arithmetic — scale
    maps |x| <= amax to <= 127 — insurance against fp rounding at the boundary).
  • CMake: target_*-scoped compile definitions/includes/options for the opt-in instead of
    directory-wide; option help text covers Q2_0.

Verification (H100 SXM 80GB HBM3, single GPU)

  • Configure with -DGGML_CUDA_HOPPER_Q1=ON -DGGML_CUDA_CUTLASS_DIR=...: clean (exercises the
    new target-scoped wiring)
  • test-backend-ops -o MUL_MAT q1_0+q2_0: 86/86 OK — re-run after the clang-format commit too
  • llama-bench pp512 vs stock MMQ: +8.1% (Q1_0), +7.4% (Q2_0) — perf-neutral vs pre-fix
    (mutex is off the hot path; the stream sync is once per tensor)

The multi-GPU changes are code-reviewed but verified on a single GPU only — no multi-GPU
Hopper box was available. The cache key, per-device attrs, and SM-count fixes are
straightforwardly correct by construction; flagging for whoever runs the next multi-GPU sweep.

- repack cache: key on (device, wdata, N, K, wbits) with a mutex (ggml may
  dispatch from one host thread per device), and publish entries only after
  a one-time stream sync so consumers on other streams cannot observe
  uninitialized dense buffers
- per-device attr_set / SM count (a second GPU previously skipped the
  dynamic-SMEM opt-in and inherited device 0's SM count)
- CUDA_CHECK on allocations and attribute calls
- defensive int8 clamp in the activation quantizer (unreachable in exact
  arithmetic; insurance against fp rounding at the boundary)
- CMake: target-scoped compile definitions/includes/options instead of
  directory-wide; option help text covers Q2_0
@bri-prism
bri-prism requested a review from khosravipasha June 11, 2026 00:28
@bri-prism

Copy link
Copy Markdown
Collaborator Author

Perf proof: pre-fix vs post-fix vs stock (same pod, same build flags)

H100 SXM 80GB HBM3, single GPU. Pre-fix = the #39 merge commit (9b98ac8); post-fix = this
PR's head. Both built on-pod from clean clones; llama-bench -r 5; stock = same post-fix
binary with the env gate off. Pre-fix build uses the original flag-injection cmake wiring,
post-fix uses this PR's target-scoped wiring (so the cmake change is covered by the same A/B).

1-bit test model (Q1_0)

test pre-fix post-fix Δ fix stock MMQ post vs stock
pp512 3203.8 ± 197.9 3196.2 ± 192.8 −0.2% 2948.7 ± 164.3 +8.4%
pp2048 3342.8 ± 7.5 3344.2 ± 0.8 +0.0% 3069.8 ± 1.4 +8.9%

Ternary test model (Q2_0)

test pre-fix post-fix Δ fix stock MMQ post vs stock
pp512 3037.0 ± 175.3 3033.1 ± 175.8 −0.1% 2819.1 ± 153.0 +7.6%
pp2048 3040.3 ± 0.5 3025.7 ± 0.7 −0.5% 2812.4 ± 0.3 +7.6%

Correctness

test-backend-ops -o MUL_MAT (q1_0 + q2_0) on the post-fix build: 86/86 OK.

Reading

  • The fixes are perf-neutral within noise: worst case −0.5% (Q2 pp2048, where stderr is tight
    enough to resolve it) — consistent with the design: the cache mutex and one-time stream sync
    are off the steady-state hot path entirely.
  • The path's win over stock MMQ holds across both formats and batch sizes (+7.6–8.9%).
  • Multi-GPU behavior remains code-reviewed/single-GPU-verified as stated in the PR body.

@bri-prism

bri-prism commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator Author

Independent multi-GPU / multi-arch sweep of this branch (3 pods, all legs green):

2x H100 SXM5 — the multi-GPU fixes under real dual-GPU load (the gap called out in the PR; previously single-GPU-verified only):

  • layer-split across both devices: greedy generation text identical to the single-GPU control (CUDA_VISIBLE_DEVICES=0) for every format x path combo; dual-GPU perplexity finite and sane, and mmq-vs-wgmma ppl agree to 3 decimals (1-bit 12.416, 2-bit 10.310) — no misbehavior from the device-keyed repack cache or per-device statics
  • test-backend-ops -o MUL_MAT: all pass, 0 q1/q2 failures
  • wgmma gain survives the split: pp4096 +5.5–5.6% over MMQ on dual (13.6–14.3k t/s, 8B test models), +5.7–6.5% single; prefill scales ~1.47x dual/single; tg unchanged (expected at batch 1)

L40S (sm_89) — no-regression check: builds clean without GGML_CUDA_HOPPER_Q1 at arch 89, all test-backend-ops pass, coherent generation, healthy Q1_0/Q2_0 MMQ perf — the shared-file changes (dispatch hunk, CMake) are inert on Ada.

H200 — additional Hopper datapoint: wgmma path correct, +5.9–6.9% over MMQ at pp4096; ≈H100 absolute (prefill compute-bound; the extra HBM bandwidth doesn't move it at these shapes).

Raw bench output available internally on request. LGTM from this side — merge-ready.

@bri-prism
bri-prism merged commit 937c4bd into prism Jun 11, 2026
@khosravipasha
khosravipasha deleted the fix/hopper-q1-review-followup-v2 branch June 27, 2026 21:58
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