Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,45 @@ macro Const end
"""
copyto!(::Backend, dest::AbstractArray, src::AbstractArray)

Perform a `copyto!` operation that execution ordered with respect to the backend.
Perform a `copyto!` operation that is execution ordered with respect to the backend.
For most uses `Base.copyto!` provides a fully synchronous interface.

!!! note
On some backends it may be necessary to first call [`pagelock!`](@ref) on host memory,
to enable fully asynchronous behaviour w.r.t to the host.

!!! warning
If the function is asynchronous w.r.t to the host, the user is required to gurantuee, the lifetime
of the host buffer. Otherwise the user may cause a use-after-free, because the GC was able to prove that the host
buffer can be freed.

```julia
arr = zeros(64)
GC.@preserve arr begin
copyto!(backend, arr, ...)
# other operations
synchronize(backend)
end
```

!!! note
Backend implementations **must** implement this function.
"""
function copyto! end

"""
pagelock!(::Backend, dest::AbstractArray)

Pagelock (pin) a host memory buffer for a backend device. This may be necessary for [`copyto!`](@ref)
to perform asynchronously w.r.t to the host/

!!! note
Backends **may** implement this function.
"""
function pagelock!(::Backend, x)
return nothing
end

"""
synchronize(::Backend)

Expand Down
Loading