@@ -110,13 +110,53 @@ macro Const end
110
110
"""
111
111
copyto!(::Backend, dest::AbstractArray, src::AbstractArray)
112
112
113
- Perform a `copyto!` operation that execution ordered with respect to the backend.
113
+ Perform an asynchronous `copyto!` operation that is execution ordered with respect to the back-end.
114
+
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.
118
+
119
+ !!! warning
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:
126
+
127
+ ```julia
128
+ arr = zeros(64)
129
+ GC.@preserve arr begin
130
+ copyto!(backend, arr, ...)
131
+ # other operations
132
+ synchronize(backend)
133
+ end
134
+ ```
114
135
115
136
!!! note
116
- Backend implementations **must** implement this function.
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
+
141
+ !!! note
142
+ Backends **must** implement this function.
117
143
"""
118
144
function copyto! end
119
145
146
+ """
147
+ pagelock!(::Backend, dest::AbstractArray)
148
+
149
+ Pagelock (pin) a host memory buffer for a backend device. This may be necessary for [`copyto!`](@ref)
150
+ to perform asynchronously w.r.t to the host/
151
+
152
+ This function should return `nothing`; or `missing` if not implemented.
153
+
154
+
155
+ !!! note
156
+ Backends **may** implement this function.
157
+ """
158
+ function pagelock! end
159
+
120
160
"""
121
161
synchronize(::Backend)
122
162
@@ -562,6 +602,10 @@ function functional(::Backend)
562
602
return missing
563
603
end
564
604
605
+ function pagelock! (:: Backend , x)
606
+ return missing
607
+ end
608
+
565
609
include (" nditeration.jl" )
566
610
using . NDIteration
567
611
import . NDIteration: get
0 commit comments