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
3 changes: 2 additions & 1 deletion src/fft/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function release_plan!(plan)
function destroy()
handle != C_NULL && Threads.atomic_add!(N_PLANS_DESTROYED, 1)
# Pin to `ctx`, since eviction may run this under a different context.
AMDGPU.context!(() -> rocfft_plan_destroy(handle), ctx)
# HIP-level, since eviction can run in a finalizer.
HIP.context!(() -> rocfft_plan_destroy(handle), ctx)
end
push!(destroy, IDLE_HANDLES, key, value)
end
Expand Down
3 changes: 2 additions & 1 deletion src/hip/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function HIPStream(priority::Symbol = :normal)
stream = HIPStream(stream_ref[], priority, d, HIPContext(d), true)
return finalizer(stream) do s
Base.@atomic s.valid = false
AMDGPU.context!(s.ctx) do
# Not `AMDGPU.context!`: finalizers run on arbitrary tasks.
HIP.context!(s.ctx) do
hipStreamDestroy(s.stream)
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/core/tls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ end
# Must return true without segfaulting on an already-finalized stream.
@test AMDGPU.HIP.isdone(s) == true
end

if length(AMDGPU.devices()) > 1
@testset "Stream finalizer keeps the running task's device" begin
# Finalizers run on whichever task triggers GC. The stream finalizer
# must not move that task onto the stream's device.
default = fetch(@async AMDGPU.device())
other = first(d for d in AMDGPU.devices() if d != default)
s = AMDGPU.device!(() -> HIPStream(), other)
@test s.device == other
@test fetch(@async (finalize(s); AMDGPU.device())) == default
end
end
end
Loading