perf(tensilelite): store matching-table rows by column #15957
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 #15957"
general
weight: 0.35
yzhang93
JIRA ID : N/A
This is PR 4 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), #15957 (column matching tables, this PR), #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
A matching library maps a problem size to a solution, with a measured speed for Equality and Range tables. The gfx942 logic set holds about 40 million such rows, and the TCL parent keeps all of them as
{"key": [...], "index": IndexSolutionLibrary, "speed": f}dicts from logic loading until the libraries are written. Each dict row costs roughly 300 to 400 bytes (281 measured for 1M rows with shared key ints; about 370 in the full build, where every row owns its int objects); the column form costs under 60. After #15956 these rows are the largest remaining parent-side cost.Measured for this PR alone, on the same machine as the #15956 measurement. The #15956 column is its head built on develop at ad7e83e8a8a; this PR's column is its head on develop at 0edc429eadd. The intervening develop commits touch kernel codegen, not the parent's tables, and the parent figure agrees with @newling's independent measurement of 13.4 GiB for this change:
| | #15956 head | this PR | change |
|---|---|---|---|
| Parent peak PSS | 28.4 GiB | 15.0 GiB | -13.4 (-47%) GiB |
| Peak summed PSS, whole process tree | 81.3 GiB | 70.9 GiB | -10.4 (-13%) GiB |
| Wall clock | 1559 s | 1347 s | -212 s (-14%) |
Technical Details
tensilelite/MatchingTable.pystores a table by column: an int64 key matrix, a float64 speed vector with a per-row flag for speeds that were ints (logic files mark unmeasured sizes with an int0, and msgpack encodes int and float differently), and a list of solution references. It supportslen, indexing (materializing one legacy row dict), iteration,+=andsortfor merging, andstate(), which yields exactly the list of dicts the legacy form serializes to. Sorting is a stable lexsort over the key columns, the same order as sorting the row dicts by key.MatchingLibrary.FromOriginalStatebuilds the columns directly from the logic file's rows and sorts once. The row dicts, with one sharedIndexSolutionLibraryper solution as before, are built only when a value cannot be stored exactly or NumPy is not installed. A value the columns cannot hold exactly (a non-int key element, an int speed beyond float64's exact range) raisesNotExactlyRepresentable; the library builder catches it, warns with the distance, the logic file and the reason, and keeps the legacy rows, so a future logic file cannot quietly cost the parent the row-dict memory for its table and for every table merged with it. NumPy is imported on first use rather than at module load: the TheRock source build runspython -m tensilelite logic ...with an interpreter that imports the source tree without installingrequirements.txt, and a module-level import broke its gfx942 and gfx950 builds. Such an environment builds as before and only forgoes the memory saving; the driver prints one warning in the parent before logic loading, since the parse workers share its environment. A legacy and a column table merge as row dicts.MeshBasedtables (new on develop) have no speed column, likeGridBased.MatchingLibrary.mergegives an empty receiver a shallow copy of the donor's table rather than the table object itself. Later merges rebind the receiver's arrays and lists in place on the table object, so sharing it would have added the receiver's later rows to the donor as well; the solution objects stay shared, as they must for reindexing. This fix is @newling's commit from the review branch linked in the comments, cherry-picked with authorship kept. Nothing else readstableoutside this module and its tests.Test Plan
Tests/unit/test_matching_table.py(16 tests) comparesstate()against the sorted legacy rows for float, GridBased (no speed) and mixed int/float speeds, merging in both directions including empty tables, the error for each value that would not round-trip, pickling, shared row wrappers, the direct construction against rows built from dicts (including a skipped row whose solution is missing), the fallback to row dicts when NumPy is absent, the per-table warning and the quiet paths, that merging into an empty library leaves the donor's table independent in both forms, andMatchingLibraryend to end. Subset builds (gfx942/Equality/, and the CU-count subset with a lazy library that merges an all-int and an all-float table) 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: 16429 passed, 606 failed, 4 errors, 466 skipped. Develop with the same tensilelite content (2aee29b156a), run side by side in the same environment: 16400 passed, 607 failed, 4 errors, 466 skipped. Every failure and error on this head also fails on develop; they are the environment-dependent sets (test_custom_kernel_staggeru_metadata.pydisassembles custom kernels;test_arch_steppings.py,test_install_task.pyandtest_client_identity_build.pybuild in subprocesses; one case intest_package_cli.py; twosource_onlychecks that need the parentCMakeLists.txtand pass from the git checkout). The one test that failed on develop's run but not on this head's istest_memwatch.py::test_summary_and_csv_account_for_a_shell_in_the_tree, which is timing-sensitive under the parallel runner. The 29 extra passes are this stack's tests.Subsets: every file under
out/library(139 and 13 files) is identical to develop at the same base 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_(the helper cache was disabled, so it is recompiled per run). Fallback reads in the parent: 0. No table fell back to row dicts.Full gfx942 build: all 1205 files are identical to the #15956 build and to the develop build except the helper code object, with the same cuid-only difference; 356190 unique solutions and 20819 duplicate kernels, as on develop. Fallback reads in the parent: 0; no table fell back to row dicts. Phase times against the #15956 head: logic loading 94 s to 59 s, passing kernel info 7.5 s to 7.2 s, kernel codegen 1221 s to 1135 s, library writing 137 s to 92 s. Memory and time are in the table above.
Submission Checklist
Risk level
Medium (3/5): changes the in-memory form of every matching table. Serialization is checked against the legacy form in unit tests and by byte comparison of every
.datfile on the subsets and on the full gfx942 build; a table the columns cannot hold falls back to the legacy form with a warning rather than failing the build.🤖 Generated with Claude Code