← Back to Pull requests

perf(tensilelite): compile the helper kernels with a cached precompiled header of the HIP headers #15288

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 06, 2026 17:38 UTC
Author

JIRA ID : AIHPBLAS-5256

Motivation

TensileLite compiles Kernels.cpp, the C++ source of its helper kernels, with clang for every benchmark step and every library build. About 0.35 s of each such compile is parsing the HIP headers (HIP is AMD's GPU programming interface; its headers are the same for every compile). A precompiled header (PCH), a file in which clang stores already-parsed headers, removes most of that cost, but only if it is rebuilt whenever the compiler, the HIP headers or the flags change.

Technical Details

A new Toolchain/HelperKernelPch.py holds HelperKernelPch, an on-disk cache of 1 PCH of <hip/hip_runtime.h>, <hip/hip_ext.h> and <hip/hip_fp8.h>.

  • Location: ~/.tensile/helper_pch/<key>/hip.pch, overridden by TENSILE_HELPER_PCH_DIR. Entries are built in a temporary .tmp_ directory, renamed into place, and evicted after 30 days, like the existing helper-kernel cache. The temporary directory is removed however the build ends, and a .tmp_ directory older than a day (left by a killed process) is evicted. TENSILE_DISABLE_HELPER_PCH=1 turns it off.

  • Key (SHA-256): the exact PCH build arguments, the target, the full amdclang++ --version output, the resolved header search paths of the driver's own compile job, the PCH source, and a fingerprint of the PCH source preprocessed with -E -dD (with the build's include directory): the header contents, the headers lookup selects and the macros, as a fresh compile would see them. The fingerprint is computed on every lookup, so an edit to a HIP header selects a new PCH.

  • The PCH is built from stdin, so it does not record a file path and can be moved into place.
  • Toolchain/Component.py: Compiler gains pchArgs, buildPch and a pch_path argument. With it, the compile adds -include-pch <pch>. Clang does not check the modification times of the system headers in a PCH; the key covers their contents instead, so a reinstall of identical headers, or hosts that share a home but install ROCm separately, keep the PCH.

    Toolchain/Source.py: on a helper-cache miss, buildSourceCodeObjectFiles gets the PCH (new timer python_kernel_build_src_co.pch, also listed in scripts/analyze_timing.py) and compiles with it. If that compile fails, it compiles without the PCH. If that succeeds, the PCH entry is discarded and rebuilt next time; a second rejection turns the PCH off for that key for the rest of the process. No PCH is used for a multi-target compile, under Tensile_CXX_COMPILER_LAUNCHER (such as ccache), or with --save-temps.

    This applies to benchmark builds and to TensileCreateLibrary library builds that compile 1 target without a launcher. HelperKernelPch imports filelock, so projects/hipsparselt/requirements-build.txt now lists it, as tensilelite/requirements.txt already does.

    Tests: new Tests/unit/test_helper_pch.py (63 cases, 9 using the real compiler and skipped without ROCm); 2 stub-compiler tests set TENSILE_DISABLE_HELPER_PCH. A session-scoped fixture in the unit conftest.py points the helper-kernel cache and the PCH cache at a temporary directory, so unit tests leave nothing in ~/.tensile.

    Test Plan

    Run from projects/hipblaslt/tensilelite:

  • tox -e unit -- tensilelite/Tests/unit/test_helper_pch.py tensilelite/Tests/unit/characterization/ToolchainSource tensilelite/Tests/unit/test_arch_steppings.py checks the key, cache hit, miss and eviction, temporary-directory cleanup, the disable switch, the single-target, launcher and --save-temps rules, the fallbacks, and with a real compiler that a header touch keeps the PCH and a header edit selects a new one.

  • The full Python unit suite, checking that ~/.tensile is unchanged afterwards.

  • pre-commit run --files on the changed files checks formatting and lint.
  • Test Result

    At this head, per helper compile, on 1 pinned core of an EPYC 9454 with amdclang++ 22.0.0git roc-7.2.4, a 1.5 MB Kernels.cpp for gfx950, median of 5:

    | | Time |
    |---|---|
    | Compile without the PCH | 2.937 s |
    | PCH lookup on a hit (--version, -### and the -E -dD fingerprint) | 0.139 s |
    | Compile with the PCH | 2.149 s |
    | Warm total | 2.288 s: 0.649 s (22%) less than without the PCH |
    | Cold total (lookup and PCH build 1.218 s, then compile) | 3.368 s: 0.431 s more than without the PCH |

    These results were recorded on the original unsplit branch with amdclang++ 22.0.0git roc-7.2.1 on the gfx950 (MI355X) host, before the header fingerprint, so they do not include the lookup's 0.139 s per helper compile:

  • Per config, build wall time fell 0.77-2.78 s (5.8-8.9%) on 4 gfx950 configs (--build-only, helper-kernel cache disabled, 32 cores, mean of 2 runs each).

  • Summed helper compile time in the same builds: gemm_bias_strided_batched_gfx940 28.23, 28.35 s to 25.34, 25.63 s; bf16_gradient_bias 29.44, 31.58 s to 27.99, 28.70 s. The gfx942 build went from 34.26 s to 31.21 s (1 run, cold PCH).

  • Artifacts of those 5 builds, with and without the PCH, cold and warm: all non-.hsaco members byte-identical, and the helper .hsaco code, data and metadata identical with clang's random __hip_cuid symbol masked.
  • At this head:

  • test_helper_pch.py: 63 passed. With -fmodules-validate-system-headers back on the compile, the real-compiler header-touch test fails with clang's "mtime changed" error; without the finally cleanup the interrupted-build test fails; without the .tmp_ eviction the abandoned-temporaries test fails.

  • The helper toolchain, helper-cache and PCH tests: 1082 passed.

  • The full Python unit suite (-m 'not gpu'): 16744 passed, 593 failed, all from the local environment: 592 in test_custom_kernel_staggeru_metadata.py (the local assembler cannot assemble gfx1151) and 1 in test_package_cli.py (pandas is not installed in the local tox env). ~/.tensile was unchanged afterwards.

  • In a venv built from projects/hipsparselt/requirements-build.txt, HelperKernelPch imports; without filelock it fails as in Math CI.
  • Math CI at 95ff471 failed at checkout in the hipBLASLt jobs and on the missing filelock in the hipSPARSELt jobs; it is being rerun.

    Related

  • Work tracking: AIHPBLAS-5256
  • Device / Architecture Coverage

    This changes how helper kernels are compiled, for benchmark builds and for single-target TensileCreateLibrary builds; the compiled code is unchanged. The overlay requires CI coverage of helper-kernel compile changes on the affected archs, gfx942 and gfx950 at least. An arch that is only built counts as uncovered.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.
  • Risk level

    Medium (3/5): a new on-disk cache in the helper compile of benchmark and single-target library builds, about 15 MB per compiler, HIP header set, flag set and target. A wrong key would feed clang a mismatched PCH; the key includes the preprocessed HIP headers, and the compile-without-PCH fallback covers a PCH clang rejects. A compile that fails for a real source error runs twice and prints its error twice. A new build dependency, filelock, for hipSPARSELt's build venv.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yzhang93 Review duration: 34944m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). 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.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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 #15288"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.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: 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: 46.7% · Lower = rushed or shallow review
    46.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: 27.7% · Safe to merge
    27.7%