← Back to Pull requests

perf(tensilelite): hold parsed solutions as compressed blobs in the TCL parent #15956

Closed
unknown closed this pull request without merging on Nov 21, 2026 22:05 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 23:16 UTC
Author

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 Solution from 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.py holds a Solution as 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 the Mapping protocol over that summary with an overlay for the keys the parent writes (codeObjectFile, BaseName, Kernel), and hydrate() rebuilds the real Solution with 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, including len(), iteration and keys(), reuses. Hashing and equality between compact solutions follow Solution semantics so deduplication through dict.fromkeys is unchanged; a compact and a full solution compare unequal in both directions, as two full solutions of different types already do. The dedupe key appends codeObjectFile and DeviceNames at lookup time because the parent assigns codeObjectFile after compaction and the per-CU-count libraries share kernel names. Compaction records the splitGSU naming mode and the dispatchers in run.py raise if asked for the other mode.

In create_library/run.py the parse worker compacts every originalSolution before the library is pickled back to the parent, processKernelSource hydrates 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 the Mapping interface. SolutionLibrary.applyNaming hydrates once per solution. The solDict loop in main() is removed: it recomputed a key for every solution and nothing read the result, and on a CompactSolution it 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, splitGSU check, 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 full Solution, hydration with the overlay, the fallback counter and promotion including len()/iteration/keys(), the pickle round trip, the dedupe key with codeObjectFile, the splitGSU mode check in both directions with GSU 1 and 2, and that naming through the run.py dispatchers matches naming through real solutions. The characterization tests for the driver and LibraryIO cover 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.py disassembles custom kernels; test_arch_steppings.py, test_install_task.py and test_client_identity_build.py build in subprocesses; one case each in test_package_cli.py and test_memwatch.py; two source_only checks need the parent CMakeLists.txt and 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/library is identical to develop except the helper code object Kernels.so-000-gfx942.hsaco, whose symbol set and .text are 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/library are identical to develop except Kernels.so-000-gfx942.hsaco, whose 23823-symbol set and 11.4 MB .text are 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


  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.
  • 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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yzhang93 Review duration: 8568m
    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 #15956"
    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%