Skip to content

cuda contract: release each case's buffers so the full run fits in memory (test-only) - #1845

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Maxrio9:cuda/test-contract-lifetime
Nov 7, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Maxrio9:cuda/test-contract-lifetime

Conversation

@Maxrio9

@Maxrio9 Maxrio9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Test-only change, requested as its own PR in #1730 / #1731, rebased onto #2042.

#2042 frees each kernel's device buffers through Rig.reset in the release hook. This keeps that hook and extends what it frees:

  • Rig.finishGates frees the device buffers and the host copies (seen, outs, host, slots) of a finished kernel. release calls it where the Rig has it, and reset where it does not.
  • The registered owners and modules are scoped in registered(), so their destructors run before the standalone suites allocate theirs. The closing phase moved to contract_finish.zig, so contract_tests.zig stays under 600 lines (597).

Math, shapes, name-derived seeds, controls and bounds are unchanged. No production code is touched.

Checked on current main (7eae7dc0): zig build test-kernel-contract and the new test-cuda-contract-lifetime-host pass on a host without a GPU, and the lean check adds no new problem. Tests added: the Rig test (each buffer freed once, reusable afterwards) and a gates test that release runs once after success, failure and a planted control.

Not run: the full GPU kernel-contract on this rebased version. My earlier GPU run (511 kernels passing gates 1-4, 340/340 controls caught, nvcc 13.0.88) was on the pre-#2042 version of this change, so I haven't measured peak memory since the rebase. It does not fix the limit-record problems that untouched main reports.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Thank you, @Maxrio9, and thanks for splitting this out of #1730/#1731 as asked. You were first to this. @BlivionIaG's
#2042, which frees each kernel's device buffers through Rig.reset after its gates, is queued to land. Your change
still does more than that: finishGates also frees each fixture's host arrays, and registered() ends the owners
and modules before the standalone suites allocate theirs. Could you rebase onto main once #2042 is in, folding your
finish hook into its release hook (so release calls finishGates where a Rig has it), and keep
contract_tests.zig at 600 lines or fewer? Two small things for the rebase: the commits carry a personal email
rather than your GitHub noreply address, and the body's AI attribution line should go. We'll run the full contract
on a GB10 with peak memory per case and post the numbers.

@Maxrio9

Maxrio9 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased onto main now that #2042 is in; head 8c8f66e8. finish is folded into the release hook: release calls Rig.finishGates where a Rig has it and reset where it does not. The registered owners and modules still end before the standalone suites, the closing phase is in contract_finish.zig, and contract_tests.zig is 597 lines. The commit uses my GitHub noreply address and the AI line is gone from the body.

On a host without a GPU, zig build test-kernel-contract and test-cuda-contract-lifetime-host pass and the lean check adds nothing new. I have not re-run the full GPU contract on this version, so there's no peak-memory number from me; your GB10 run would be the first. I merged main into the branch rather than rebasing (a rebase would need a force-push), so the PR history has an extra merge commit that a squash removes.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9. Everything from our last note is in, and folding finishGates into #2042's release hook is the shape we hoped for. We'll run the full contract on a GB10 against main with peak memory per case and post the numbers here. If you mark it ready for review in the meantime, it lands right after that run; the extra merge commit goes away in the squash.

@ashhart

ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Our GB10 run of the full kernel contract on this head (8c8f66e8), against its merge base with main: both runs completed. Every FAIL line on this head is also on main (384 on each), and the launch limits are the same (2 on each), so nothing new fails.

One thing we said we'd post and haven't: peak memory per case. Our contract job doesn't record it yet, so these numbers don't show the saving itself. I'll add a per-case memory reading to the job and run it again on this head.

@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

@Maxrio9, here's the memory reading we owed. Our GB10 job now samples MemAvailable through the whole kernel contract run, on this head (8c8f66e8) and on its merge base with main:

MemAvailable at start lowest during the run drawn down
main 121.6 GB 67.1 GB 54.5 GB
this branch 120.1 GB 97.1 GB 23.0 GB

So releasing each case's buffers cuts the run's peak by about 31.5 GB, or 58%. Nothing new fails: 384 FAIL lines on each run, all shared with main, and 2 limit lines on each. That was the last thing on our side. If you mark it ready for review, it goes in the landing queue.

@Maxrio9
Maxrio9 marked this pull request as ready for review November 6, 2026 09:57
@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9 for marking it ready. The 09:55 update only carries main's only filter through run and the closing phase, and a full run still does the same thing in the same order as the head we measured, so our numbers stand. It's in the landing queue now, and we'll add the CHANGELOG line when it lands.

@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

/atc exchange 19208e74fc1102cd6905274a24254d0292f0aa8388185774ddb050443be6d3d1

@ashhart
ashhart force-pushed the cuda/test-contract-lifetime branch from 034ac09 to ca3973f Compare November 7, 2026 01:14
@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9. The branch's merge commits kept it from replaying onto today's main, so I put your three commits together as one (ca3973ff2f) on current main, under your name. The change is the same as your branch's net diff, and the landing gate's host checks pass on it. It's in our landing queue now.

Maxrio9 and others added 2 commits November 7, 2026 02:18
…registered owners so the full run fits in memory

The three commits of this branch (7ab0e70, 40a2db2, d3b4d57) as one, on current main: each case
releases its buffers and host copies, registered owners are scoped to their case, and the contract's closing
phase moves to contract_finish.zig so contract_tests.zig stays under 600 lines.
@ashhart
ashhart force-pushed the cuda/test-contract-lifetime branch from ca3973f to 557bb78 Compare November 7, 2026 02:18
@ashhart
ashhart merged commit 05bee87 into ashhart:main Nov 7, 2026
0 of 7 checks passed
@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thank you @Maxrio9. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants