Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/TensorOperationscuTENSORExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ function TO.tensortrace!(

# map to reduction operation
plan = plan_trace(A, Ainds, opA, C, Cinds, OP_IDENTITY, OP_ADD)
return reduce!(plan, α, A, β, C)
reduce!(plan, α, A, β, C)
CUDACore.unsafe_free!(plan) # the plan-taking `reduce!` does not free the plan
return C
end

function cuTENSOR.CuTensorDescriptor(
Expand Down
22 changes: 22 additions & 0 deletions test/cutensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,28 @@ if cuTENSOR.functional()
end
end

@testset "tensortrace! does not leak plans" begin
# each leaked plan holds on to a 128 KiB reduction workspace
A = CuArray(randn(Float32, 64, 64, 64, 64))
C = CUDACore.zeros(Float32, 64, 64)
@tensor C[a, b] = A[a, c, b, c] # warm up

GC.gc(true)
CUDACore.reclaim()
CUDACore.synchronize()
GC.enable(false)
try
live0 = CUDACore.memory_stats().live
for _ in 1:1000
@tensor C[a, b] = A[a, c, b, c]
end
CUDACore.synchronize()
@test CUDACore.memory_stats().live - live0 < 2^20 # would be 125 MiB if leaking
finally
GC.enable(true)
end
end

@testset "Issues" verbose = true begin
@testset "Issue PR #186" begin
# https://github.com/Jutho/TensorOperations.jl/pull/186
Expand Down
Loading