Fix plan leak in cuTENSOR tensortrace! - #294
Merged
Merged
Conversation
`plan_trace` builds a `CuTensorPlan` and passes it to the plan-taking `cuTENSOR.reduce!`, which by contract does not free it. The reduction workspace (128 KiB) was therefore only reclaimed by the finalizer, which the GC has no reason to run promptly for device memory: 10^4 traces grew live device memory by 1.22 GiB. After the fix, 9.8 KiB. Also close a matching exception leak in `plan_trace`, where the operation descriptor and plan preference were destroyed after plan creation rather than in a `finally`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
cuTENSOR.jl itself uses no `finally` anywhere and accepts leaks on throw, both in `plan_reduction` and in the planless `reduce!`/`contract!`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
Author
|
Failure is windows + enzyme striking again |
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
plan_tracebuilds aCuTensorPlanand hands it to the plan-takingcuTENSOR.reduce!, which by contract does not free it — only the planless overload does. The reduction workspace is therefore reclaimed only by the finalizer, which the GC has no reason to run promptly for device memory.Measured on an RTX A6000: 128.0 KiB leaked per trace, so 10⁴ traces grew live device memory by 1.221 GiB. After the fix: 9.8 KiB, matching a non-tracing contraction control exactly.
Also closes a matching exception leak in
plan_trace, where the operation descriptor and plan preference were destroyed after plan creation rather than in afinally.Adds a regression test; the full
test/cutensor.jlsuite passes.🤖 Generated with Claude Code