|
76 | 76 | # Create a per-call execution_info with the current task's stream and workbuffer. |
77 | 77 | # rocfft_execution_info_set_stream must be called on the same OS thread as rocfft_execute; |
78 | 78 | # 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} |
80 | 80 | info_ref = Ref{rocfft_execution_info}() |
81 | 81 | rocfft_execution_info_create(info_ref) |
82 | 82 | 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) |
86 | 91 | end |
87 | | - return info |
88 | 92 | end |
89 | 93 |
|
90 | 94 | 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}) |
238 | 242 | end |
239 | 243 |
|
240 | 244 | 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 |
244 | 249 | end |
245 | 250 |
|
246 | 251 | function unsafe_execute!( |
247 | 252 | plan::cROCFFTPlan{T,K,false,N}, X::ROCArray{T,N}, Y::ROCArray{T}, |
248 | 253 | ) 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 |
252 | 259 | end |
253 | 260 |
|
254 | 261 | function unsafe_execute!( |
255 | 262 | plan::rROCFFTPlan{T,ROCFFT_FORWARD,false,N}, |
256 | 263 | X::ROCArray{T,N}, Y::ROCArray{<:rocfftComplexes,N}, |
257 | 264 | ) where {T<:rocfftReals,N} |
258 | 265 | @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 |
262 | 271 | end |
263 | 272 |
|
264 | 273 | function unsafe_execute!( |
265 | 274 | plan::rROCFFTPlan{T,ROCFFT_INVERSE,false,N}, |
266 | 275 | X::ROCArray{T,N}, Y::ROCArray{<:rocfftReals,N}, |
267 | 276 | ) where {T<:rocfftComplexes,N} |
268 | 277 | @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 |
272 | 283 | end |
273 | 284 |
|
274 | 285 | function LinearAlgebra.mul!(y::ROCArray{Ty}, p::ROCFFTPlan{T,K,false}, x::ROCArray{T}) where {T,Ty,K} |
|
0 commit comments