perf(tensilelite): hold parsed solutions as compressed blobs in the TCL parent #15956
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.289
Real PR Conversation Timeline
1 comments
"Review active on #15956"
general
weight: 0.35
yzhang93
JIRA ID : N/A
This is PR 3 of 5 in a stack that lowers the memory high-water mark of the device-library build (
TensileCreateLibrary, "TCL"). The stack, in order: #15954 (memory sampler, merged), #15955 (worker heap hygiene, merged), #15956 (compact solutions, this PR), #15957 (column matching tables), #15958 (kernel order). Each PR is based on the one before it. Measurements were taken on one machine (96 cores, 1.9 TB, MI300X, ROCm 7.2.4) with the sampler from #15954, for a full gfx942 build of 843 logic files (356190 solutions, 214059 kernels) at 96 jobs with the helper-kernel compile cache disabled.Motivation
The TCL parent keeps every parsed
Solutionfrom logic loading until the library files are written, but it reads only a small subset of each solution's state while it organizes kernel jobs. The full state is needed only inside workers: kernel codegen, helper-kernel construction, and library naming. Holding the full objects in the parent is one of the two large parent-side costs (the other is the matching tables, addressed in #15957).Measured for this PR alone, on the same base (develop at ad7e83e8a8a, which already contains #15954 and #15955) and the same machine:
| | develop (ad7e83e) | this PR | change |
|---|---|---|---|
| Parent peak PSS | 36.1 GiB | 28.4 GiB | -7.7 (-21%) GiB |
| Peak summed PSS, whole process tree | 91.0 GiB | 81.3 GiB | -9.7 (-11%) GiB |
| Wall clock | 1778 s | 1559 s | -219 s (-12%) |
The time moves between phases: loading the logic files 193 s to 94 s, passing kernel info to the libraries 56 s to 7 s, kernel codegen 1185 s to 1221 s (workers now hydrate each kernel), library writing unchanged at 136 s.
An earlier version of this description estimated about 140 KB per solution and about 50 GiB for a full build; that estimate was wrong (it predates the matching-table work and the slim worker results) and has been replaced by the measurement above. Thanks to @newling for the measurement that caught it.
Technical Details
SolutionStructs/CompactSolution.pyholds aSolutionas a zlib-compressed pickle (a few KB) plus a tuple of the values the parent reads (SUMMARY_KEYS, exactly the keys the TCL parent touches), the kernel file base, the emitted symbol used as the compile key, the dedupe key, the full name used for hashing, and the helper-kernel names. It implements theMappingprotocol over that summary with an overlay for the keys the parent writes (codeObjectFile,BaseName,Kernel), andhydrate()rebuilds the realSolutionwith the overlay applied. A read of any other key hydrates transiently and is counted (fallbackReads, printed at the end of a run); after repeated misses the object is promoted to a cached copy, which every later query, includinglen(), iteration andkeys(), reuses. Hashing and equality between compact solutions followSolutionsemantics so deduplication throughdict.fromkeysis unchanged; a compact and a full solution compare unequal in both directions, as two full solutions of different types already do. The dedupe key appendscodeObjectFileandDeviceNamesat lookup time because the parent assignscodeObjectFileafter compaction and the per-CU-count libraries share kernel names. Compaction records thesplitGSUnaming mode and the dispatchers inrun.pyraise if asked for the other mode.In
create_library/run.pythe parse worker compacts everyoriginalSolutionbefore the library is pickled back to the parent,processKernelSourcehydrates in the worker, helper-kernel setup uses the precomputed names and hydrates only the solutions that introduce a new helper, and the parent-side reads and writes go through theMappinginterface.SolutionLibrary.applyNaminghydrates once per solution. ThesolDictloop inmain()is removed: it recomputed a key for every solution and nothing read the result, and on aCompactSolutionit would have hydrated every solution in the parent. Solution indices, library trees and every written file are unchanged.The seven follow-up commits (promotion reuse, symmetric equality,
splitGSUcheck, summary-key trim, removal of unused wrapper attributes, docstring correction, tests against the production dispatchers) are @newling's, cherry-picked from the review branch linked in the comments with authorship kept.Test Plan
Tests/unit/test_compact_solution.py(12 tests) checks the summary against the real state, hashing and equality including symmetry with a fullSolution, hydration with the overlay, the fallback counter and promotion includinglen()/iteration/keys(), the pickle round trip, the dedupe key withcodeObjectFile, thesplitGSUmode check in both directions with GSU 1 and 2, and that naming through therun.pydispatchers matches naming through real solutions. The characterization tests for the driver andLibraryIOcover the parse and write paths. Subset builds (gfx942/Equality/, and the CU-count subset that exercises shared kernel names across libraries) compared by file hash against develop at the same base; one full gfx942 build compared the same way and measured with the sampler.Test Result
Full unit suite (
pytest tensilelite/Tests/unit) at this head, run from an exported tree: 16412 passed, 607 failed, 4 errors, 466 skipped. Develop at the same tip (2aee29b156a) in the same environment: 16400 passed, 607 failed, 4 errors, 466 skipped, with exactly the same failing and erroring test ids. All of them are environment-dependent (test_custom_kernel_staggeru_metadata.pydisassembles custom kernels;test_arch_steppings.py,test_install_task.pyandtest_client_identity_build.pybuild in subprocesses; one case each intest_package_cli.pyandtest_memwatch.py; twosource_onlychecks need the parentCMakeLists.txtand pass from the git checkout). No test fails here that passes on develop; the 12 extra passes are this PR's tests.Subsets: every file under
out/libraryis identical to develop except the helper code objectKernels.so-000-gfx942.hsaco, whose symbol set and.textare identical and which differs only in clang's path-hashed__hip_cuid_symbol (the helper cache was disabled, so it is recompiled per run). Fallback reads in the parent: 0.Full gfx942 build: all 1205 files under
out/libraryare identical to develop exceptKernels.so-000-gfx942.hsaco, whose 23823-symbol set and 11.4 MB.textare identical and which differs only in__hip_cuid_*. Solution and kernel counts match develop (356190 unique solutions, 214059 kernels, 20819 duplicate kernels). Fallback reads in the parent: 0. Memory and time are in the table above.Submission Checklist
Risk level
Medium (3/5): changes how the parent represents every parsed solution. The library files are produced from the same objects as before and are byte-identical on the subsets and on the full gfx942 build; a code path that reads an unlisted key is slower, not wrong, and is reported by the fallback counter.
🤖 Generated with Claude Code