← Back to Pull requests

feat(hipblaslt): add HIPBLASLT_TUNING_MODE=online #15312

Closed
unknown closed this pull request without merging on Nov 21, 2026 20:23 UTC
View on GitHub
unknown unknown commented on Nov 06, 2026 20:24 UTC
Author

JIRA ID : AIHPBLAS-4906

Motivation

tune mode finds better kernels than the heuristic, but its search blocks the first call of each shape. online mode gets those gains from the application's own hipblasLtMatmul calls, with no separate tuning run and no call waiting on the GPU.

Technical details

Online works like tune: same cache key, one search per key, one row per key appended to HIPBLASLT_TUNING_CACHE_PATH, rows marked with the mode that measured them, and later calls replayed by the existing cache path. A key the file already covers is replayed, not explored.

The differences:

  • The search is spread over about K×R real calls: each of the heuristic's top K candidates is run R times, after a few untimed cold calls that run the heuristic's pick. The winner is the fastest sample (MIN); optionally a challenger must beat the heuristic's pick by a minimum percentage.

  • Each trial launch is bracketed by an event pair that a later call reads without syncing, with a single hipEventElapsedTime (no hipEventQuery), so reading a pair never touches a stream and cannot invalidate a graph capture on any thread. Event pairs are pre-set with their timestamps reversed, so a pair the launch never recorded reads ≤ 0 and is discarded.

  • Only the first exact problem under a key is sampled; others (e.g. a different beta) run default selection until the row exists, then replay it.

  • Only hipblasLtMatmul with a null algo is tuned. Never explored or timed: caller-supplied algos; hipblasLtMatmulAlgoGetHeuristic (it never reaches the tuner and is answered from the cache file, as in cache mode); the hipblaslt_ext GEMM and grouped GEMM APIs; pointer-array batches; HIPBLASLT_ADAPTIVE_SM_COUNT calls; fused GEMM+all-to-all calls; calls dispatched to rocRoller (block-scaled MX problems by default, or all with HIPBLASLT_USE_ROCROLLER=1). Graph-captured calls are never explored or timed either; they get the winner once there is one. Online mode never replaces an algo the caller passes, including one returned by hipblasLtMatmulAlgoGetHeuristic: a caller that passes an algo gets exactly that kernel.

  • Live event pairs are capped per device; at the cap, other keys' finished pairs are reclaimed (and unrecorded ones retired), else the call runs untimed.

  • The caller's HIP error state is never cleared or altered: a call on a thread holding an unread error is not timed, and an error the tuner causes is cleared only on a clean thread. A failed row write is logged and never fails the matmul.
  • Unchanged: with mode off each hook is a single branch; cache and tune behaviour and logs are unchanged apart from the new mode column.

    Reviewing

    The branch is split into commits so it can be reviewed one step at a time; each step's code commit is followed by its tests, and every commit builds on its own. It will be squash-merged.

    1. feat: record the measuring mode in tuning-cache rows — a mode column so tune and online rows never cover each other.
    2. test: cover the tuning_mode column.
    3. feat: add best-effort launch events to SolutionAdapter — optional start/stop events around a launch (EventRecording::BestEffort), where an event failure never fails the launch.
    4. test: cover best-effort and strict launch events.
    5. feat: add the OnlineTuner engine — exploration, sampling and the event-pair pool, not yet called from anywhere.
    6. test: OnlineTuner unit tests.
    7. feat: wire online tuning into hipblasLtMatmul — the mode, its hooks and scope rules.
    8. test: end-to-end online tuning tests.
    9. docs: document HIPBLASLT_TUNING_MODE=online.

    Commits 1–4 are small and independent of the tuner; most of the review is in 5 and 7. Changes made after review started are additional commits on top (with develop merged in), so they can be reviewed separately.

    Configuration

    Online reads tune's variables with smaller defaults, and the startup line shows the values in effect; see env-variables.rst.

    | Variable | online default |
    |---|---|
    | HIPBLASLT_TUNING_MAX_CANDIDATES (K; below 2 turns online off) | 5 |
    | HIPBLASLT_TUNING_HOT_ITERS (R) | 3 |
    | HIPBLASLT_TUNING_COLD_ITERS | 3 |
    | HIPBLASLT_TUNING_MIN_IMPROVEMENT_PCT (new, online only) | 0 |
    | HIPBLASLT_TUNING_MAX_EVENT_PAIRS (new, online only) | 4096 |

    Test Plan

  • TuningStore: the row mode column, old rows reading as tune, modes never covering each other.

  • HipSolutionAdapterEventTest_multi_gpu (two GPUs; there is no single-GPU variant): best-effort and strict launch events.

  • OnlineTuner (+ _multi_gpu): engine unit tests (budgets, sampling ownership, claim-once, event-pair cap and reclaim, unrecorded pairs, read-back during a capture of the pair's stream, the caller's HIP error state, per-device pools).

  • TuningOnline_pre_checkin: end-to-end explore, record and replay, replay after an in-process reset that stands in for a later process (no test spawns a second process for this), out-of-scope calls, graph capture on this and another thread (on a created stream and on the null stream, which must leave no HIP error), hipStreamLegacy, the cap, and several threads dispatching two keys at once (correct results, one row per key, no HIP error left).

  • Existing tuning gate suites and the quick tier for regressions.
  • Negative controls: targeted mutations of the engine were confirmed to fail the corresponding tests.

    Test Result

    On gfx950, release build, ROCm 7.2.3, with develop merged in. No failures; the only tests not on develop are this PR's. TuningOnline_pre_checkin and OnlineTuner also passed on ROCm 7.0.2 before review.

    | Suite | this branch |
    |---|---|
    | Tuning gate suites (cache, tune, store, scratch, adapter) | 188 pass, 5 skip |
    | TuningOnline_pre_checkin | 16 pass |
    | OnlineTuner | 12 pass |
    | Quick tier (smoke, HostUnit, TuningStore, OnlineTuner) | 1230 pass, 10 skip |
    | multi_gpu (2 GPUs) | 4 pass (before review; not re-run) |

    In coverage builds, AProblemOnTheLegacyStreamIsExploredAndRecorded is skipped: clang's coverage runtime calls hipStreamGetDevice on the launch stream, which fails for hipStreamLegacy (the same reason StreamKNullStream is excluded from coverage runs).

    Performance

  • On our bf16 GEMM test set on gfx950, default settings gave a modest average improvement in kernel time over mode off.

  • Once a key is tuned, its host cost is that of cache replay. Small GEMMs dominated by host cost are limited by that shared replay path, which cache mode pays too.
  • Known limitations

  • Pick stability depends on K, R and the cold calls: with few samples, near-tied candidates can swap. HIPBLASLT_TUNING_MIN_IMPROVEMENT_PCT can require a margin over the heuristic's pick. The defaults may be retuned.

  • Calls differing only in leading dimensions are separate keys, each explored.

  • Adaptive SM count is not tuned.

  • The engine's unit tests compile a private copy of the tuner, so coverage and static builds leave them out. Making the tuner its own static target, constructed with an explicit configuration, is planned as a follow-up.
  • Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yzhang93 Review duration: 21599m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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
    Real PR Conversation Timeline
    1 comments
    "Review active on #15312"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%