Check if the package has been configured successfully and is ready to use.
This call is intended for packages that support conditionally using an available GPU. If you fail to check whether CUDA is functional, actual use of functionality might warn and error.
Check whether the local system provides an installation of the CUDA driver and toolkit. Use this function if your code loads packages that require CUDA.jl.
Note that CUDA-dependent packages might still fail to load if the installation is broken, so it's recommended to guard against that and print a warning to inform the user:
using CUDA if has_cuda() try using CuArrays catch ex @warn "CUDA is installed, but CuArrays.jl fails to load" exception=(ex,catch_backtrace()) end end
Check whether the local system provides an installation of the CUDA driver and toolkit, and if it contains a CUDA-capable GPU. See
has_cuda for more details.
Note that this function initializes the CUDA API in order to check for the number of GPUs.
Get or create a CUDA context for the current thread (as opposed to
CuCurrentContext which may return
nothing if there is no context bound to the current thread).
Bind the current host thread to the context
Note that the contexts used with this call should be previously acquired by calling
context, and not arbitrary contexts created by calling the
Sets the active context for the duration of
dev as the current active device for the calling host thread. Devices can be specified by integer id, or as a
CuDevice (slightly faster).
If your library or code needs to perform an action when the active device changes, add a hook using
Sets the active device for the duration of
Note that this call is intended for temporarily switching devices, and does not change the default device used to initialize new threads or tasks.
Reset the CUDA state associated with a device. This call with release the underlying context, at which point any objects allocated in that context will be invalidated.
If your library or code needs to perform an action when the active context changes, add a hook using
CUDA.atdevicereset. Resetting the device will also cause subsequent API calls to fire the
If you have a library or application that maintains its own global state, you might need to react to context or task switches:
Register a function to be called after switching to or initializing a task on a thread.
Use this hook to invalidate thread-local state that depends on the current task.
Register a function to be called after switching to or initializing a device on a thread.
Use this hook to invalidate thread-local state that depends on the current device. If that state is also context dependent, be sure to query the context in your callback.
Register a function to be called after resetting devices. The function is passed one argument: the device which has been reset.
Use this hook to invalidate global state that depends on the current device.