Skip to content

Commit 959beea

Browse files
committed
robustness
1 parent 0b647b6 commit 959beea

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/fft/fft.jl

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,19 @@ end
7676
# Create a per-call execution_info with the current task's stream and workbuffer.
7777
# rocfft_execution_info_set_stream must be called on the same OS thread as rocfft_execute;
7878
# creating it fresh per-call avoids any OS-thread binding issues from task migration.
79-
function make_execution_info(plan::ROCFFTPlan)
79+
function with_execution_info(f::F, plan::ROCFFTPlan) where {F}
8080
info_ref = Ref{rocfft_execution_info}()
8181
rocfft_execution_info_create(info_ref)
8282
info = info_ref[]
83-
rocfft_execution_info_set_stream(info, AMDGPU.stream())
84-
if length(plan.workarea) > 0
85-
rocfft_execution_info_set_work_buffer(info, plan.workarea, length(plan.workarea))
83+
try
84+
rocfft_execution_info_set_stream(info, AMDGPU.stream())
85+
if length(plan.workarea) > 0
86+
rocfft_execution_info_set_work_buffer(info, plan.workarea, length(plan.workarea))
87+
end
88+
return f(info)
89+
finally
90+
rocfft_execution_info_destroy(info)
8691
end
87-
return info
8892
end
8993

9094
const xtypenames = ("complex forward", "complex inverse", "real forward", "real inverse")
@@ -238,37 +242,44 @@ function assert_applicable(p::ROCFFTPlan{T,K}, X::ROCArray{T}, Y::ROCArray{Ty})
238242
end
239243

240244
function unsafe_execute!(plan::cROCFFTPlan{T,K,true,N}, X::ROCArray{T,N}) where {T,K,N}
241-
info = make_execution_info(plan)
242-
rocfft_execute(plan, [pointer(X),], C_NULL, info)
243-
rocfft_execution_info_destroy(info)
245+
in_buffer = [pointer(X)]
246+
with_execution_info(plan) do info
247+
rocfft_execute(plan, in_buffer, C_NULL, info)
248+
end
244249
end
245250

246251
function unsafe_execute!(
247252
plan::cROCFFTPlan{T,K,false,N}, X::ROCArray{T,N}, Y::ROCArray{T},
248253
) where {T,N,K}
249-
info = make_execution_info(plan)
250-
rocfft_execute(plan, [pointer(X),], [pointer(Y),], info)
251-
rocfft_execution_info_destroy(info)
254+
in_buffer = [pointer(X)]
255+
out_buffer = [pointer(Y)]
256+
with_execution_info(plan) do info
257+
rocfft_execute(plan, in_buffer, out_buffer, info)
258+
end
252259
end
253260

254261
function unsafe_execute!(
255262
plan::rROCFFTPlan{T,ROCFFT_FORWARD,false,N},
256263
X::ROCArray{T,N}, Y::ROCArray{<:rocfftComplexes,N},
257264
) where {T<:rocfftReals,N}
258265
@assert plan.xtype == rocfft_transform_type_real_forward
259-
info = make_execution_info(plan)
260-
rocfft_execute(plan, [pointer(X),], [pointer(Y),], info)
261-
rocfft_execution_info_destroy(info)
266+
in_buffer = [pointer(X)]
267+
out_buffer = [pointer(Y)]
268+
with_execution_info(plan) do info
269+
rocfft_execute(plan, in_buffer, out_buffer, info)
270+
end
262271
end
263272

264273
function unsafe_execute!(
265274
plan::rROCFFTPlan{T,ROCFFT_INVERSE,false,N},
266275
X::ROCArray{T,N}, Y::ROCArray{<:rocfftReals,N},
267276
) where {T<:rocfftComplexes,N}
268277
@assert plan.xtype == rocfft_transform_type_real_inverse
269-
info = make_execution_info(plan)
270-
rocfft_execute(plan, [pointer(X),], [pointer(Y),], info)
271-
rocfft_execution_info_destroy(info)
278+
in_buffer = [pointer(X)]
279+
out_buffer = [pointer(Y)]
280+
with_execution_info(plan) do info
281+
rocfft_execute(plan, in_buffer, out_buffer, info)
282+
end
272283
end
273284

274285
function LinearAlgebra.mul!(y::ROCArray{Ty}, p::ROCFFTPlan{T,K,false}, x::ROCArray{T}) where {T,Ty,K}

test/hip_rocarray/fft.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,15 @@ end
357357

358358
Y = p * X
359359

360-
task = Threads.@spawn d_p * d_X # executes FFT on separate AMDGPU stream
361-
d_Y = fetch(task)
360+
for _ in 1:10
361+
task = Threads.@spawn begin # executes FFT on separate AMDGPU stream
362+
yield()
363+
d_p * d_X
364+
end
365+
d_Y = fetch(task)
362366

363-
@test isapprox(collect(d_Y), Y; rtol=MYRTOL, atol=MYATOL)
367+
@test isapprox(collect(d_Y), Y; rtol=MYRTOL, atol=MYATOL)
368+
end
364369
end
365370

366371
end # testset FFT

0 commit comments

Comments
 (0)