Expand description
Primary context management (one per device, reference counted by driver).
Every CUDA device has exactly one primary context that is shared
among all users of that device within the same process. The primary
context is reference-counted by the CUDA driver: it is created on the
first PrimaryContext::retain call and destroyed when the last
retainer releases it.
Primary contexts are the recommended way to share a device context across multiple libraries and subsystems in the same process, because the driver ensures only one context exists per device.
§Example
use oxicuda_driver::device::Device;
use oxicuda_driver::primary_context::PrimaryContext;
oxicuda_driver::init()?;
let dev = Device::get(0)?;
let pctx = PrimaryContext::retain(&dev)?;
let (active, flags) = pctx.get_state()?;
println!("active={active}, flags={flags}");
pctx.release()?;Structs§
- Primary
Context - RAII wrapper for a CUDA primary context.