← Back to Pull requests

perf(tensilelite): spread large kernels across the codegen run #15958

Closed
unknown closed this pull request without merging on Nov 25, 2026 14:56 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 23:17 UTC
Author

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


writeSolutionsAndKernelsTCL shuffles 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/library compared 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/unit on the final stack: 14737 passed, 536 failed, 404 skipped. The 536 failures are the same tests that fail on develop in this environment (529 in test_custom_kernel_staggeru_metadata.py, which disassembles custom kernels, 6 in test_arch_steppings.py that build generators in a subprocess, 1 in test_package_cli.py); no test fails on the stack that passes on develop, and the 17 new tests in test_compact_solution.py and test_matching_table.py pass. 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/library is byte-identical to the develop build except the helper-kernel code object Kernels.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 generated Kernels.cpp and Kernels.h are 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 in run.py; legacy wrapper sharing and empty-table handling in MatchingTable) 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


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

    Diff: 618 lines (+463 / -155) across 7 files Reviewer: yzhang93 Review duration: 13899m
    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
    0.50
    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.385
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #15958"
    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: 50.2% (MEDIUM) · Higher = larger blast radius
    50.2%
    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: 21.7% · Safe to merge
    21.7%