Skip to content

Commit c37d0fa

Browse files
committed
Document the semantics of copyto! and add pagelock!
1 parent f198f5c commit c37d0fa

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/KernelAbstractions.jl

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,45 @@ macro Const end
110110
"""
111111
copyto!(::Backend, dest::AbstractArray, src::AbstractArray)
112112
113-
Perform a `copyto!` operation that execution ordered with respect to the backend.
113+
Perform a `copyto!` operation that is execution ordered with respect to the backend.
114+
115+
!!! note
116+
On some backends it may be necessary to first call [`pagelock!`](@ref) on host memory,
117+
to enable fully asynchronous behaviour w.r.t to the host.
118+
119+
!!! warning
120+
While this function is always asynchronous w.r.t. to the device, it may be synchronous w.r.t to the host.
121+
Additionally 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.
124+
125+
```julia
126+
arr = zeros(64)
127+
GC.@preserve arr begin
128+
copyto!(backend, arr, ...)
129+
# other operations
130+
synchronize(backend)
131+
end
132+
```
114133
115134
!!! note
116135
Backend implementations **must** implement this function.
117136
"""
118137
function copyto! end
119138

139+
"""
140+
pagelock!(::Backend, dest::AbstractArray)
141+
142+
Pagelock (pin) a host memory buffer for a backend device. This may be necessary for [`copyto!`](@ref)
143+
to perform asynchronously w.r.t to the host/
144+
145+
!!! note
146+
Backends **may** implement this function.
147+
"""
148+
function pagelock!(::Backend, x)
149+
return nothing
150+
end
151+
120152
"""
121153
synchronize(::Backend)
122154

0 commit comments

Comments
 (0)