← Back to Pull requests

perf(tensilelite): build client MX inputs once per launch and reuse them across solutions #14725

Closed
unknown closed this pull request without merging on Nov 07, 2026 02:40 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 00:45 UTC
Author

JIRA ID : AIHPBLAS-5431

Motivation

Tuning MXFP8 kernels for gfx950 (for example with geko, which starts one tensilelite-client per generation) spends most of each launch preparing inputs. With HostPreSwizzle scales the client:

  • generates the MX data three times per launch: once at problem setup, then twice for the first solution, which re-runs the canonical pass on unchanged descriptors and regenerates the data again to get pre-swizzled scales;

  • re-uploads every pristine input to the GPU and refreshes the CPU copies before every solution, even though the swizzled layout only changes with the solution's MFMA K.
  • For a 2.3 GB batched MXFP8 problem, input preparation takes about 30 s of a 33 s launch, 10x the 3 s BF16 needs for the same problem and tiles. This PR roughly halves the launch time and cuts the per-candidate overhead from 0.29 s to 0.16 s.

    Technical Details

    Two commits, both limited to the TensileLite client's DataInitialization:

    1. Reuse MX inputs across solutions of the same problem (DataInitialization.hpp). preSolution re-initializes MX inputs only when the problem or the solution's MFMA K changes. With validation off, prepareGPUInputs no longer re-runs initializeCPUInputs on every run.
    2. Build MX inputs once per launch (DataInitialization.cpp, DataInitializationHelpers.hpp):
    - The canonical pass is skipped when the data and scale descriptors are unchanged.
    - The swizzled GPU scale is built from the canonical copy instead of regenerating the data. detail::naturalMXScaleFromCanonical (the inverse of restrideMXScaleBufferKFast) recovers the scales generateMXInput emitted. detail::swizzleNaturalMXScale applies generateMXInput's swizzle with the same grid. For gfx950 that is {MN, K blocks}, with K blocks taken along the operand's K dimension, so it is correct for every transpose. Generation is seeded, so the bytes match regenerating with the layout.
    - The mx-data-generator=0 path, which kept its own per-batch copy of the natural scales to swizzle, now uses the same helpers.
    - 2D MX scales (MXBlockFree > 1, #13630) already swizzle the downsampled canonical copy, so only their generation is skipped on unchanged descriptors.

    Test Plan

  • Unit tests (tensilelite-tests, DataInit_test.cpp, 34 new):

  • - SwizzleNaturalMXScaleTest (32 cases): swizzleNaturalMXScale applied to generateMXInput's unswizzled scales must equal what generateMXInput emits with the layout. It covers gfx950 and gfx1250, A and B, both transposes, FP8 and FP4, and K = 512 and K = 576 (padded K blocks). A sentinel byte checks the swizzled size.
    - NaturalMXScaleFromCanonical (2 cases): must invert the K-fast restride and copy the prefix otherwise.
  • Full tensilelite-tests suite on MI355X, develop vs this PR.

  • Tensile end-to-end on gfx950 with the develop and PR clients (--prebuilt-client): common/gemm/gfx950/subtile_mxfp4.yaml (NT, full validation), common/gemm/gfx950/mx32f8_tn.yaml, common/gemm/gfx950/fp8_mxfp4_bf16_tn_act.yaml and common/ductile/gfx950/f8_tn_mx_subtile.yaml.

  • Benchmark: one client launch per problem on two geko MoE proxies, 10 subtile MXFP8 TN candidates (MFMA 16x16x128, tiles 64x64 to 256x64, DepthU 256/512, PrefetchGlobalRead 1/2), num-elements-to-validate=128, MXScaleFormat 1. MI355X, 256-core host, ROCm 7.2. Medians of 3 runs on an otherwise idle GPU, and of 6 runs for three concurrent launches on separate GPUs (as when several tuning jobs share a host). "Setup" is the time to the first result row. The BF16 reference uses the same problems, bias/activation and macro tiles with MFMA 16x16x32 and DepthU 64/128 (20 candidates, so its launch time is not comparable).
  • Test Result

  • Unit tests: 745 passed and 6 arch-gated skips (develop: 711 passed and the same 6 skips). Using the K-major grid for every operand fails the 8 non-K-major gfx950 cases, and 948 results of subtile_mxfp4.yaml.

  • Tensile end-to-end: develop and this PR give the same pass counts with no failures:
  • | config | validated results |
    | --- | --- |
    | common/gemm/gfx950/subtile_mxfp4.yaml | 9,937 |
    | common/gemm/gfx950/mx32f8_tn.yaml | 34,816 |
    | common/gemm/gfx950/fp8_mxfp4_bf16_tn_act.yaml | 360 |
    | common/ductile/gfx950/f8_tn_mx_subtile.yaml | 1 |

    subtile_mxfp8_multi_du_multi_partition.yaml and mxfp4_fp8_bf16_tn_act.yaml fail during kernel generation (IndexError in the subtile kernel writer) on both, before the client runs.

  • Benchmark: all 10 candidates pass validation on every build, including full validation at batch 6. Per-candidate GFLOPS match develop within 0.3%, and the best solution is the same. BF16 timings are the same on develop and this PR.
  • | problem | | develop | + commit 1 | + commit 2 (this PR) | BF16 reference |
    | --- | --- | --- | --- | --- | --- |
    | 1152x64x384x5120 (A: 2.3 GB) | launch | 33.0 s | 31.7 s | 15.4 s | |
    | | setup | 29.9 s | 29.8 s | 13.5 s | 3.1 s |
    | | per further candidate | 0.29 s | 0.16 s | 0.16 s | 0.22 s |
    | 5120x64x384x576 (padded K blocks) | launch | 18.0 s | 17.7 s | 9.5 s | |
    | | setup | 15.8 s | 16.1 s | 7.9 s | 2.2 s |
    | | per further candidate | 0.20 s | 0.13 s | 0.13 s | 0.14 s |
    | 1152x64x384x5120, three concurrent launches | launch | 45.6 s | 43.3 s | 18.5 s | |

    With validation off (num-elements-to-validate=0, 2 runs), setup goes from 36–37 s to 12.9 s for 1152x64x384x5120 and from 20.5–23.4 s to 7.7 s for 5120x64x384x576, with the same per-candidate times.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: yzhang93 Review duration: 11634m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). 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%
    56%
    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 #14725"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 56.8% · Lower = rushed or shallow review
    56.8%
    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%