Skip to content

Commit e863769

Browse files
vchuravymaleadt
andauthored
Apply suggestions from code review
Co-authored-by: Tim Besard <[email protected]>
1 parent d5c67f6 commit e863769

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/KernelAbstractions.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,19 @@ macro Const end
110110
"""
111111
copyto!(::Backend, dest::AbstractArray, src::AbstractArray)
112112
113-
Perform a `copyto!` operation that is execution ordered with respect to the backend.
114-
For most uses `Base.copyto!` provides a fully synchronous interface.
113+
Perform an asynchronous `copyto!` operation that is execution ordered with respect to the back-end.
115114
116-
!!! note
117-
On some backends it may be necessary to first call [`pagelock!`](@ref) on host memory,
118-
to enable fully asynchronous behaviour w.r.t to the host.
115+
For most users, `Base.copyto!` should suffice, performance a simple, synchronous copy.
116+
Only when you know you need asynchronicity w.r.t. the host, you should consider using
117+
this asynchronous version, which requires additional lifetime guarantees as documented below.
119118
120119
!!! warning
121-
If the function is asynchronous w.r.t to the host, the user is required to gurantuee, the lifetime
122-
of the host buffer. Otherwise the user may cause a use-after-free, because the GC was able to prove that the host
123-
buffer can be freed.
120+
121+
Because of the asynchronous nature of this operation, the user is required to guarantee that the lifetime
122+
of the source extends past the *completion* of the copy operation as to avoid a use-after-free. It is not
123+
sufficient to simply use `GC.@preserve` around the call to `copyto!`, because that only extends the
124+
lifetime past the operation getting queued. Instead, it may be required to `synchronize()`,
125+
or otherwise guarantee that the source will still be around when the copy is executed:
124126
125127
```julia
126128
arr = zeros(64)
@@ -131,6 +133,11 @@ For most uses `Base.copyto!` provides a fully synchronous interface.
131133
end
132134
```
133135
136+
!!! note
137+
138+
On some back-ends it may be necessary to first call [`pagelock!`](@ref) on host memory
139+
to enable fully asynchronous behavior w.r.t to the host.
140+
134141
!!! note
135142
Backend implementations **must** implement this function.
136143
"""

0 commit comments

Comments
 (0)