Skip to content

Commit 41bd8c3

Browse files
authored
cuTENSOR: Destroy plan description and preference after construction. (#2794)
[only subpackages]
1 parent 04fa3f9 commit 41bd8c3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lib/cutensor/src/operations.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function plan_elementwise_trinary(
104104
plan_pref = Ref{cutensorPlanPreference_t}()
105105
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)
106106

107-
CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
107+
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
108+
cutensorDestroyOperationDescriptor(desc[])
109+
cutensorDestroyPlanPreference(plan_pref[])
110+
return plan
108111
end
109112

110113
function elementwise_binary_execute!(
@@ -186,7 +189,10 @@ function plan_elementwise_binary(
186189
plan_pref = Ref{cutensorPlanPreference_t}()
187190
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)
188191

189-
CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
192+
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
193+
cutensorDestroyOperationDescriptor(desc[])
194+
cutensorDestroyPlanPreference(plan_pref[])
195+
return plan
190196
end
191197

192198
function permute!(
@@ -253,7 +259,10 @@ function plan_permutation(
253259
plan_pref = Ref{cutensorPlanPreference_t}()
254260
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)
255261

256-
CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
262+
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
263+
cutensorDestroyOperationDescriptor(desc[])
264+
cutensorDestroyPlanPreference(plan_pref[])
265+
return plan
257266
end
258267

259268
function contract!(
@@ -340,7 +349,10 @@ function plan_contraction(
340349
plan_pref = Ref{cutensorPlanPreference_t}()
341350
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)
342351

343-
CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
352+
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
353+
cutensorDestroyOperationDescriptor(desc[])
354+
cutensorDestroyPlanPreference(plan_pref[])
355+
return plan
344356
end
345357

346358
function reduce!(
@@ -415,5 +427,8 @@ function plan_reduction(
415427
plan_pref = Ref{cutensorPlanPreference_t}()
416428
cutensorCreatePlanPreference(handle(), plan_pref, algo, jit)
417429

418-
CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
430+
plan = CuTensorPlan(desc[], plan_pref[]; workspacePref=workspace)
431+
cutensorDestroyOperationDescriptor(desc[])
432+
cutensorDestroyPlanPreference(plan_pref[])
433+
return plan
419434
end

0 commit comments

Comments
 (0)