← Back to Pull requests

fix(rocprim): kernel tuner tuning template and device benchmark fixes #15571

Closed
unknown closed this pull request without merging on Nov 19, 2026 16:13 UTC
View on GitHub
unknown unknown commented on Nov 11, 2026 18:37 UTC
Author

Motivation

While auto-tuning gfx950 in #14598, we compared the tuned configs against develop. About 400 benchmark cases came out flat or slower. We traced them to bugs in the rocPRIM benchmarks and the Kernel Tuner rather than to the configs themselves. They fall into three groups:

1. Configs that measured the same: some benchmarks never passed the tuned config to rocPRIM, so every candidate ran the default config.
2. Search too narrow: the tuner tried only a small fraction of the valid configs, some of which then failed at runtime.
3. Tuned at one problem shape: the tuner timed one input shape and size, while the benchmarks sweep many.

This PR should be merged before #14598. The gfx950 configs in #14598 need to be re-tuned with these fixes.

## Technical Details

### Group 1: Configs that measured the same

1. adjacent_difference and histogram benchmarks ignored Config
benchmark_device_adjacent_difference.hpp called common::dispatch_adjacent_difference without <Config>. benchmark_device_histogram.hpp called histogram_even, multi_histogram_even, histogram_range and multi_histogram_range without it. Every tuning candidate therefore ran default_config and timed the same (1.00–1.02× spread). Fixed by passing Config to both the temp-storage query and the timed call. The histogram meta() labels now report the real config instead of "default".

2. segmented_topk_air never launched a kernel
MinSegmentLength defaulted to 0, so k = min_segment_length / 2 was always 0. rocPRIM returns early when K == 0, so the benchmark timed an empty call and reported ~26 TB/s.
- The default minimum is now 100, with static_asserts requiring a minimum of at least 2 and no larger than the maximum.
- generate_offsets merges a too-short tail into the previous segment.
- Results for this benchmark are not comparable with develop.

3. Histogram tuner shapes and scoring
- The tuner now uses the benchmark's per-type bin scale instead of 1. The scale changes how low-entropy inputs spread across bins, and so how much atomic contention there is.
- int128 uses the benchmark's 16 × 16 and 256 × 1 shapes.
- Configs are scored by the geometric mean of time instead of the mean of bytes per second.

### Group 2: Search too narrow

4. merge_sort_block_merge measured a different config from the one it emitted
The template timed <bs, ipt, 0, 128, bs, ipt>, while the tuner recorded, and confgen emitted, odd-even 256 / 1 / 201072. The template now builds the config from the recorded parameters.

5. merge_sort_block_merge inf results
The benchmark's default-config pre-sort produces blocks smaller than any merge tile above 1024 items. rocPRIM then returns hipErrorAssert, the benchmark skips timing, and the tuner records inf. confgen discards those configs anyway. The restriction now requires block_size * ipt <= 1024, which removes every inf and leaves 10 configs per type, small enough for brute_force.

6. select_unique_by_key template did not compile
There was no benchmark_type override, so the template referenced a benchmark class that doesn't exist. It now uses device_select_unique_by_key_benchmark.

7. radix_sort_onesweep LDS probe

7. radix_sort_onesweep LDS probe

  • The probe cached the last ipt it tested, even after a failure, and accepted every smaller ipt. That let oversized configs through, giving 123 CompilationFailedConfig entries. It now caches both the largest ipt that fit and the smallest that didn't.

  • It probed ipt, but the onesweep kernel's LDS is sized by sort_ipt.

  • The LDS limit now comes from the device (160 KiB on gfx950), and the wave size is 64 on gfx9.
  • 8. --param-overrides for staged tuning
    Kernel Tuner counts repeat visits and cache hits against max_fevals, so dual_annealing tried only ~38 distinct configs per type in segmented_radix_sort's ~1.1M-config space. The new flag takes a JSON object that replaces parameter value lists. A value of "best" pins a parameter, for each type, to its best cached result, which allows staged brute-force tuning. Parameter names and order are unchanged, so existing caches stay compatible. run_tuning.py now also forwards --save-metadata.

    Group 3: Tuned at one problem shape

    9. Geometric mean as the default score
    The base template scores a config by the geometric mean of ms/GiB over all queued benchmarks, so each shape counts equally. With one queued benchmark this is just its time. Six duplicate get_time overrides were removed. search_n, adjacent_find and run_length_encode previously used an arithmetic mean, which let the slowest shape decide.

    10. Tuner shapes now match the benchmarks

  • binary_search, lower_bound, upper_bound: time sorted needles as well as unsorted.

  • find_first_of: one benchmark per keys size {1, 10, 100, 1000, 10000} (10000 is new), with the benchmark's batch settings.

  • adjacent_difference (and in-place): time both left and right.
  • 11. Tuning size matches the benchmark
    adjacent_difference (and in-place) and search_n now tune at 2 GiB, and reduce at 512 MiB. All were previously tuned at 128 MiB.

    Test Plan


  • Syntax-compiled benchmark_device_segmented_topk_air.cpp for gfx950.

  • Rendered the histogram tuner template and syntax-compiled it for gfx950 for int8, int128, int64, short, half and float.

  • Rendered the binary_search, lower_bound, upper_bound, find_first_of, adjacent_difference(_inplace), search_n and reduce templates and checked the queued benchmarks.
  • Test Results


  • Every syntax compile and template render above succeeded.
  • Submission Checklist


  • Review the contributing guidelines.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: amd-jmahovsky Review duration: 11376m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #15571"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 57% (MEDIUM) · Higher = larger blast radius
    57%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 22.5% · Safe to merge
    22.5%