perf(tensilelite): compile the helper kernels with a cached precompiled header of the HIP headers #15288
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
yzhang93
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.pyholdsHelperKernelPch, an on-disk cache of 1 PCH of<hip/hip_runtime.h>,<hip/hip_ext.h>and<hip/hip_fp8.h>.~/.tensile/helper_pch/<key>/hip.pch, overridden byTENSILE_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=1turns it off.amdclang++ --versionoutput, 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.Toolchain/Component.py:CompilergainspchArgs,buildPchand apch_pathargument. 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,buildSourceCodeObjectFilesgets the PCH (new timerpython_kernel_build_src_co.pch, also listed inscripts/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, underTensile_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.
HelperKernelPchimportsfilelock, soprojects/hipsparselt/requirements-build.txtnow lists it, astensilelite/requirements.txtalready does.Tests: new
Tests/unit/test_helper_pch.py(63 cases, 9 using the real compiler and skipped without ROCm); 2 stub-compiler tests setTENSILE_DISABLE_HELPER_PCH. A session-scoped fixture in the unitconftest.pypoints 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.pychecks the key, cache hit, miss and eviction, temporary-directory cleanup, the disable switch, the single-target, launcher and--save-tempsrules, the fallbacks, and with a real compiler that a header touch keeps the PCH and a header edit selects a new one.~/.tensileis unchanged afterwards.pre-commit run --fileson 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 MBKernels.cppfor gfx950, median of 5:| | Time |
|---|---|
| Compile without the PCH | 2.937 s |
| PCH lookup on a hit (
--version,-###and the-E -dDfingerprint) | 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:--build-only, helper-kernel cache disabled, 32 cores, mean of 2 runs each).gemm_bias_strided_batched_gfx94028.23, 28.35 s to 25.34, 25.63 s;bf16_gradient_bias29.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)..hsacomembers byte-identical, and the helper.hsacocode, data and metadata identical with clang's random__hip_cuidsymbol masked.At this head:
test_helper_pch.py: 63 passed. With-fmodules-validate-system-headersback on the compile, the real-compiler header-touch test fails with clang's "mtime changed" error; without thefinallycleanup the interrupted-build test fails; without the.tmp_eviction the abandoned-temporaries test fails.-m 'not gpu'): 16744 passed, 593 failed, all from the local environment: 592 intest_custom_kernel_staggeru_metadata.py(the local assembler cannot assemble gfx1151) and 1 intest_package_cli.py(pandasis not installed in the local tox env).~/.tensilewas unchanged afterwards.projects/hipsparselt/requirements-build.txt,HelperKernelPchimports; withoutfilelockit fails as in Math CI.Math CI at
95ff471failed at checkout in the hipBLASLt jobs and on the missingfilelockin the hipSPARSELt jobs; it is being rerun.Related
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
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.