Skip to content

Clean up cuTENSOR plan memory #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged

Clean up cuTENSOR plan memory #212

merged 1 commit into from
Jun 30, 2025

Conversation

lkdvos
Copy link
Collaborator

@lkdvos lkdvos commented Jun 25, 2025

Improve memory management by ensuring proper destruction of operation descriptors and plan preferences in the cuTENSOR plan function.

This is the equivalent of https://github.com/JuliaGPU/CUDA.jl/pull/2794/files

Fixes #211

@lkdvos lkdvos requested a review from Jutho June 25, 2025 16:54
@lkdvos lkdvos merged commit 71191a6 into master Jun 30, 2025
14 checks passed
@lkdvos lkdvos deleted the memleak branch June 30, 2025 11:56
@@ -312,7 +312,10 @@ function plan_trace(@nospecialize(A::AbstractArray), Ainds::ModeType,
plan_pref = Ref{cutensorPlanPreference_t}()
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)

return CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how does this work; the OperationDescriptor and PlanPreference are copied by the CuTensorPlan constructor, so the original copies need to be destroyed afterwards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are used, and then no longer needed. To be honest, I didn’t check precisely what is going on the first time and just copied this over from the cuTENSOR implementation for reductions, so now I just adapted the changes from the PR there

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.

Potential memory leak for cuTENSOR contractions with minimal example
2 participants