Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Document atdeviceswitch hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Dec 18, 2019
1 parent a3e4dfe commit 6f1e87e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,25 @@ end
device!(CuDevice(0))
end

const device!_listeners = Set{Function}()
"""
CUDAnative.atdeviceswitch(f::Function)
Register a function to be called after switching devices on a thread. The function is
passed two arguments: the `CuDevice` switched to, and the corresponding `CuContext`.
"""
atdeviceswitch(f::Function) = (pushfirst!(device!_listeners, f); nothing)
const device!_listeners = []

"""
device!(dev)
Sets `dev` as the current active device for the calling host thread. Devices can be
specified by integer id, or as a `CuDevice`. This is intended to be a low-cost operation,
only performing significant work when calling it for the first time for each device.
only performing significant work when calling it for the first time for each device on each
thread.
If your library or code needs to perform an action when the active device changes, add a
callback of the signature `(::CuDevice, ::CuContext)` to the `device!_listeners` set.
hook using [`CUDAnative.atdeviceswitch`](@ref).
"""
function device!(dev::CuDevice)
tid = Threads.threadid()
Expand Down

0 comments on commit 6f1e87e

Please sign in to comment.