perf(tensilelite): spread large kernels across the codegen run #15958
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 618 lines diff across 7 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.385
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #15958"
general
weight: 0.35
yzhang93
JIRA ID : N/A
This is PR 5 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), #15955 (worker heap hygiene), #15956 (compact solutions), #15957 (column matching tables), #15958 (kernel order). Each PR is based on the one before it. Measurements in the stack were taken on one machine (96 cores, 1.9 TB, MI300X, ROCm 7.2.4) with the tool from PR 1, for a full gfx942 build of 843 logic files (356190 solutions, 214059 kernels) at 96 jobs with the helper-kernel compile cache disabled.Motivation
Kernels reach the codegen pool grouped by logic file, so the GridBased libraries' largest kernels, each a transient of 1 GiB or more, land on all 96 workers at the same time. On develop the workers' summed PSS spikes to 62.4 GiB during codegen while averaging far less, and that spike is the build's memory peak once the parent has been shrunk by PRs 3 and 4. Shuffling the order lowers the expected number of large kernels in flight at once; it is not a bound on the peak, and a different logic set can still draw an order that clusters them.
Technical Details
writeSolutionsAndKernelsTCLshuffles the list of unique kernels with a fixed seed (_KERNEL_ORDER_SEED) before handing it to the pool, so the order is arbitrary but identical on every run of the same inputs. Results stay aligned with the shuffled list, which is also what the function returns, and nothing downstream depends on the order: code objects link their inputs sorted and kernel info is keyed by kernel name. Generated files do not change.Test Plan
Driver unit tests as in PR 2. Full gfx942 build on develop and on this branch (the top of the stack) under the sampler from PR 1, with every file under
out/librarycompared by SHA-256. For the ordering itself, the six-file CU-variant subset (1449 kernels, 96 workers) was built with and without the shuffle with each kernel's generation and assembly time recorded per worker.Test Result
pytest tensilelite/Tests/uniton the final stack: 14737 passed, 536 failed, 404 skipped. The 536 failures are the same tests that fail on develop in this environment (529 intest_custom_kernel_staggeru_metadata.py, which disassembles custom kernels, 6 intest_arch_steppings.pythat build generators in a subprocess, 1 intest_package_cli.py); no test fails on the stack that passes on develop, and the 17 new tests intest_compact_solution.pyandtest_matching_table.pypass. Full gfx942 build, 96 jobs, helper-kernel cache disabled:| | develop | this stack |
|---|---|---|
| peak summed PSS | 97.1 GiB | 29.8 GiB |
| peak summed RSS | 101.5 GiB | 34.2 GiB |
| parent peak | 36.0 GiB | 15.0 GiB |
| workers (98) peak summed PSS | 62.4 GiB | 22.3 GiB |
| wall clock | 1506 s | 1070 s |
Every file under
out/libraryis byte-identical to the develop build except the helper-kernel code objectKernels.so-000-gfx942.hsaco, which differs only in clang's__hip_cuid_*symbol: that identifier hashes the output path, and two develop builds into different directories differ in the same way. The generatedKernels.cppandKernels.hare identical. Solution and kernel counts match develop (356190 unique solutions, 214059 kernels, 20819 duplicate kernels) and the compact-solution fallback counter stayed at 0. The full-build numbers were taken on this stack before two test-compatibility refinements (patchable name dispatchers inrun.py; legacy wrapper sharing and empty-table handling inMatchingTable) that do not change what the build does; both subsets were rebuilt at the final commits and are byte-identical to develop.Shuffle on its own, CU-variant subset (1449 kernels on 96 workers; time per kernel is generation plus assembly):
| | file order | shuffled |
|---|---|---|
| codegen phase | 15.5 s | 10.4 s |
| per-kernel median / p90 / max | 0.49 / 1.49 / 3.76 s | 0.37 / 1.16 / 5.23 s |
| tail: first worker idle to last kernel done | 3.7 s | 1.1 s |
| last 10% of workers idle during the final | 3.2 s | 0.3 s |
In file order the largest kernels of the GridBased libraries sit together at the end of the list, so the phase ends with most workers idle while a few finish them; shuffled, they are spread through the run and the tail shrinks. The largest kernel takes about ten times the median on this subset. Automated GitHub checks are pending.
Submission Checklist
Risk level
Low (2/5): only the order in which kernels are handed to the pool changes; every written file is byte-identical to develop on the full gfx942 build. The memory benefit is statistical, not guaranteed: an unlucky order for a future logic set would at worst approach the clustered develop order, not exceed it.
🤖 Generated with Claude Code