← Back to Pull requests

Add SM 12.0 tunings for keys-only DeviceBatchedTopK #11953

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 08, 2026 18:41 UTC
Author

Description

DeviceBatchedTopK has measured tunings for SM 10.0 and SM 10.3, but on SM 12.0 (GeForce / RTX PRO Blackwell) it runs the default policies. This PR adds SM 12.0 tunings for keys-only, non-deterministic requests, measured on an RTX 5090, plus a shared-memory reduction in the worker-per-segment agent.

As agreed in review, the wave-aware cluster-width search that earlier versions of this PR added to the dispatch has been split out. It will come back as a separate PR, folded into the existing launch-shape search without a new tuning flag and measured across architectures. dispatch_batched_topk.cuh now differs from main only in the policy selector.

Cluster backend (make_sm120_keys_cluster_policy), used for segments above 8K keys with max_k below the static maximum segment size:

  • Digit width by segment-size class:

  • - up to 16K keys: 10 bits, with the single-CTA path extended to 16K;
    - up to 512K: 9 bits;
    - [512K, 1M): 8 bits;
    - [1M, 2M): 11 bits;
    - 2M and above: 8 bits.
  • Chunks: 32 KiB above 16K keys.
  • Baseline (one worker per segment) backend (make_sm120_baseline_policy): the default worker shapes. Tiles of up to 1Ki keys use vectorized loads and direct stores, the 2Ki tile uses vectorized loads, and 4Ki and larger tiles keep the default warp-transpose loads and stores. The larger tiles were faster that way for decode-style batches with few segments and large k.

    Gating: the new policies apply only when the request is keys-only, uses determinism::not_guaranteed with tie_break::unspecified, and runs on exactly compute_capability{12, 0}. Pairs, deterministic and explicit tie-break requests, and every other compute capability keep their current policies.

    Changes outside SM 12.0:

  • policy_selector_from_types now evaluates the baseline-coverage check for the baseline policy it actually returns, so the baseline policy can vary per CC. Instead of folding over the target CCs as the TODO(bgruber) suggested, it evaluates coverage for each named baseline policy. That removes the invariant the old comment described, and the TODO now covers only the fully general per-CC case.

  • Independently of the CC, the worker-per-segment agent no longer reserves the large-segment epilogue's shared memory when only small segments can occur. This only lowers shared-memory use. Measured on its own, it is neutral or slightly faster.
  • Performance: RTX 5090, CUDA 13.2, against current main

    f32 keys, nvbench nv/cold/time/gpu/mean, speedup = main / PR. Every run was made one at a time with at least two interleaved main/PR rounds.

    segmented_topk.fixed.keys.base (segments of 64–1024 keys, 2^28 elements): 1.17x geomean over 19 configurations, 1.02x to 1.24x, none slower.

    segmented_topk.variable.keys.base (random pattern, k = 512, 1024, 2048; 1/4/16/64/256 segments). The 16K–1M segment sizes are disabled in the checked-in benchmark; I enabled them locally to reach the cluster tables.

    | max segment size | 1 seg | 4 segs | 16 segs | 64 segs | 256 segs | all |
    |---|---|---|---|---|---|---|
    | 512 | 1.006 | 1.000 | 1.003 | 1.010 | 1.118 | 1.026 |
    | 1K | 1.000 | 1.000 | 1.001 | 1.011 | 1.032 | 1.009 |
    | 2K | 1.000 | 1.007 | 1.008 | 1.003 | 1.016 | 1.007 |
    | 4K | 1.000 | 1.000 | 1.001 | 1.002 | 1.001 | 1.001 |
    | 8K | 1.007 | 1.002 | 1.005 | 1.000 | 1.000 | 1.003 |
    | 16K | 1.125 | 1.169 | 0.998 | 1.169 | 1.192 | 1.128 |
    | 32K | 1.168 | 1.056 | 1.127 | 1.181 | 1.220 | 1.149 |
    | 64K | 1.353 | 1.226 | 1.723 | 1.360 | 1.932 | 1.497 |
    | 128K | 1.167 | 1.065 | 1.242 | 1.126 | 1.116 | 1.142 |
    | 256K | 1.152 | 1.137 | 1.153 | 1.154 | 1.116 | 1.142 |
    | 512K | 1.244 | 1.304 | 1.165 | 1.229 | 1.191 | 1.226 |
    | 1M | 1.002 | 1.043 | 1.001 | 0.995 | 1.001 | 1.008 |

  • Up to 8K keys (baseline backend): 1.006x geomean over 60 configurations, with no regression over 2%.

  • 16K to 1M (cluster table): 1.18x geomean over 105 configurations.

  • Overall: 1.11x over 165 configurations.

  • Two configurations are about 3% slower: 16K with k=1024 and 16 segments (13.8 vs 14.3 µs), and 256K with k=512 and 4 segments (24.6 vs 25.4 µs). Both differences are within one or two GPU-timer steps at these sizes.
  • Correctness


  • All 18 top-k test binaries pass under C++17 and C++20 on SM 12.0: block top-k, the batched API and env tests, cluster layout, and segmented keys and pairs. All 60 top-k compile-fail tests pass.

  • -Xptxas -warn-double-usage reports no double-precision instructions in the top-k code.
  • History


  • First version: also narrowed the 1Ki and 2Ki baseline workers. That slowed decode-style batches with few segments (0.71–0.86x), so the third commit restored the default shapes.

  • SM 12.0 test file: catch2_test_device_batched_topk_sm120_tuning.cu was removed in bae4813ea at review request. It was also the source of the earlier CI failures (constant-expression errors on CTK 12.0, MSVC C4127, and the CTK 12.9 GCC 7 build timeout).

  • Width search: removed in this revision. Re-measuring without it showed that the earlier SM 12.0 baseline table (vectorized loads and direct stores on every tile) made 2K and 4K segments with few segments and large k up to 20% slower than main. The baseline table now applies those settings per tile size, as described above.

  • For the follow-up: with the width search on top of this PR, the 16K+ geomean rises from 1.18x to 1.25x, mostly at 16–256 segments. But 1M-key segments become up to 26% slower at 64–256 segments, so the criterion needs more work.
  • Notes for reviewers


  • Only SM 12.0 was measured, and only an RTX 5090. That is why the gate is cc == {12, 0} rather than >= 12.0.

  • These changes came out of an LLM-driven search (Claude Code agents) over the SM 12.0 tuning space, followed by several rounds of independent automated code review. Every measurement and test result above was run on the RTX 5090 described.
  • Checklist


  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: elstehle Review duration: 76694m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.59) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #11953"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.6% · Safe to merge
    32.6%
    Repository