Expand description
CUDA context management with RAII semantics.
A CUDA context is the primary interface through which a CPU thread
interacts with a GPU. It owns driver state such as loaded modules, allocated
memory, and streams. This module provides the Context type, an RAII
wrapper around CUcontext that automatically calls cuCtxDestroy on drop.
§Thread safety
The CUDA Driver API is thread-safe, and (since CUDA 4.0) a context may be
current on multiple threads simultaneously; “current-ness” is a per-thread
property set with cuCtxSetCurrent. Accordingly Context is both
Send and Sync (auto-derived from its fields), so it can be wrapped
in an Arc<Context> and shared across threads. Each
thread that issues driver calls must first make the context current on
itself via set_current.
§Examples
use oxicuda_driver::context::Context;
use oxicuda_driver::device::Device;
oxicuda_driver::init()?;
let device = Device::get(0)?;
let ctx = Context::new(&device)?;
ctx.set_current()?;
// ... launch kernels, allocate memory ...
ctx.synchronize()?;Modules§
- flags
- Context scheduling flags passed to
Context::with_flags.
Structs§
- Context
- RAII wrapper for a CUDA context.