← Back to Pull requests

add warmup to hipblaslt tuning #796

Open
matthiasdiener opened this pull request with 64 lines diff across 2 files
View on GitHub
matthiasdiener matthiasdiener commented on Nov 06, 2026 23:51 UTC
Author

Description

TE's hipblaslt autotuning runs each candidate algorithm once untimed, then times
TE_HIPBLASLT_TUNING_RUN_COUNT calls (a few ms in total). That is too short for the GPU to settle,
so each candidate is timed in whatever power state the previous candidate left behind.

On gfx1250 the GPU can run above its power limit for ~60-100 ms after a period of lower power. A
slow candidate draws less power, so the candidate after it is timed with boost headroom and can look
faster than a candidate that is actually faster at sustained clocks.

As an example, BF16 TN 8192^3 tuned on a gfx1250 GPU:
algo 1 (default), algo 2 and algo 3 (both slow), algo 4.

Algo 4 timed 537 us vs 561 us for algo 1 and was picked, but sustained it is 16% slower (1624 vs 1926 TFLOPS).
8192x14336x4096 picked a 7% slower algorithm the same way. The same effect favors the first
candidate when tuning starts on an idle GPU.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Infra/Build change

  • Code refactoring
  • Changes

    Please list the changes introduced in this PR:

  • Change A

  • Change B
  • Checklist:

  • I have read and followed the contributing guidelines

  • The functionality is complete

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • My changes generate no new warnings

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes
  • Diff: 64 lines (+37 / -27) across 2 files Reviewer: Micky774 Review duration: 15145m
    All Vouch review confidence checks passed
    Residual risk 0.06 = Change Risk (0.29) × (1 − Review Confidence (0.81)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.29 · 64 lines diff across 2 files
    0.29
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.77 · 3 substantive comment(s)
    0.77
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    80%
    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.250
    Real PR Conversation Timeline
    5 items
    Micky774 Micky774 approved these changes on Nov 10, 2026 16:38 UTC
    Approved Reviewer

    Approved these changes.

    alextmagro alextmagro commented on code on Nov 13, 2026 20:49 UTC
    Code Review
    transformer_engine/common/gemm/rocm_gemm.cu:1
    @@ -1842,6 +1843,8 @@ void hipblaslt_gemm(const Tensor *inputA,
     
         int firstAlgo = getIntEnv("TE_HIPBLASLT_ALGO_SELECTION", 0, 0);
         int tuneLoopCount = getIntEnv("TE_HIPBLASLT_TUNING_RUN_COUNT", 0, 0);
    +    // gfx942/gfx950 reach their power limit within ~20 ms; gfx1250 runs above it for ~100 ms

    This isn't quite in line with my previous findings, I have found that gfx950 can take up to 0.5s to reach full power usage, and 0.25s to get to 95% of sclk speed. If we are running kernels back to back then I would consider at least adding a .5s warmup before kernel 1.

    ipanfilo ipanfilo commented on code on Nov 16, 2026 19:01 UTC
    Code Review
    transformer_engine/common/gemm/rocm_gemm.cu:1
    @@ -1909,31 +1908,41 @@ void hipblaslt_gemm(const Tensor *inputA,
                                                 workspace,                              /* workspace */
                                                 workspaceSize,
                                                 profilingStream));                       /* stream */
    +          }
               NVTE_CHECK_CUDA(hipStreamSynchronize(profilingStream));
    +        };
     
    -          //Profiling loop
    -          tuning_clock::time_point startTime = tuning_clock::now();
    -          for (int loop=0; loop<tuneLoopCount; loop++)
    +        for (int algo=firstAlgo; algo<algoTuneCount; algo++)
    +        {
    +            if (algoArr[algo].state != HIPBLAS_STATUS_SUCCESS)
    +            {
    +              continue;
    +            }
    +          tuning_clock::time_point warmupStart = tuning_clock::now();
    +          // Warm-up call; it may load the kernel, so tuneWarmupMs starts after it
    +          runAlgo(algo, 1);
    +          // Run for tuneWarmupMs (syncing ~every 10 ms) so timing sees this algo's own power-limited clock
    +          const tuning_clock::time_point warmupEnd = tuning_clock::now() + std::chrono::milliseconds(tuneWarmupMs);
    +          for (int64_t batch = 1; tuning_clock::now() < warmupEnd;)
               {
    -            NVTE_CHECK_HIPBLASLT(hipblasLtMatmul(handle,
    -                                            operationDesc,
    -                                            alpha_ptr,                                /* alpha */
    -                                            param.A,                                      /* A */
    -                                            Adesc,
    -                                            param.B,                                      /* B */
    -                                            Bdesc,
    -                                            beta_ptr,                                 /* beta */
    -                                            C,                                      /* C */
    -                                            Cdesc,
    -                                            D,                                      /* D */
    -                                            Ddesc,
    -                                            &algoArr[algo].algo,                    /* algo */
    -                                            workspace,                              /* workspace */
    -                                            workspaceSize,
    -                                            profilingStream));                       /* stream */
    +            const tuning_clock::time_point batchStart = tuning_clock::now();
    +            runAlgo(algo, batch);
    +            const tuning_clock::duration perCall = (tuning_clock::now() - batchStart) / batch;
    +            batch = std::max<int64_t>(1, std::chrono::milliseconds(10) / std::max(perCall, tuning_clock::duration(1)));
               }
    -          NVTE_CHECK_CUDA(hipStreamSynchronize(profilingStream));
    +
    +          //Profiling loop
    +          tuning_clock::time_point startTime = tuning_clock::now();
    +          runAlgo(algo, tuneLoopCount);
               tuning_clock::duration algoTime = tuning_clock::now() - startTime; 
    +          if (logTuning) {
    +            std::cout << "[INFO] hipBLASLt algo [" << algo << "] " << cached_algo.getAlgoId(algoArr[algo].algo)
    +                      << ": warm-up "
    +                      << std::chrono::duration_cast<std::chrono::microseconds>(startTime - warmupStart).count()
    +                      << " us, "

    Warmup takes dozens milliseconds, so maybe print at ms scale here and ns scale for per run is probably beyond measurement acuracy

    ipanfilo ipanfilo commented on code on Nov 16, 2026 19:05 UTC
    Code Review
    transformer_engine/common/gemm/rocm_gemm.cu:1
    @@ -1842,6 +1843,8 @@ void hipblaslt_gemm(const Tensor *inputA,
     
         int firstAlgo = getIntEnv("TE_HIPBLASLT_ALGO_SELECTION", 0, 0);
         int tuneLoopCount = getIntEnv("TE_HIPBLASLT_TUNING_RUN_COUNT", 0, 0);
    +    // gfx942/gfx950 reach their power limit within ~20 ms; gfx1250 runs above it for ~100 ms

    0.5s is honestly is a huge delay but for simplification may be use the same 200ms default for all arch

    Reviewers
    Assignees
    matthiasdiener matthiasdiener
    Labels
    risk: low confidence: 80.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: 29.4% (LOW) · Higher = larger blast radius
    29.4%
    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: 80.5% · Lower = rushed or shallow review
    80.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: 5.7% · Safe to merge
    5.7%