pub struct PrimaryContext { /* private fields */ }Expand description
A retained reference to a device’s primary context — the one shared
with the CUDA Runtime API (cudart). Use this when you need to mix
driver-API kernels/streams with framework code that relies on the
runtime API (most ML frameworks do).
Each PrimaryContext::retain bumps a refcount on the device’s
primary context; Drop calls cuDevicePrimaryCtxRelease. The context
itself is destroyed when the refcount hits zero.
Implementations§
Source§impl PrimaryContext
impl PrimaryContext
Sourcepub fn retain(device: &Device) -> Result<Self>
pub fn retain(device: &Device) -> Result<Self>
Increment the refcount on device’s primary context and return a
handle to it. Equivalent to cuDevicePrimaryCtxRetain.
Sourcepub fn reset(device: &Device) -> Result<()>
pub fn reset(device: &Device) -> Result<()>
Forcibly destroy the primary context on device, releasing all
resources and resetting refcounts. Any outstanding handles
returned by retain become dangling — only call this when you
know nobody else (Runtime API, other libraries) is using the
primary context. Equivalent to cuDevicePrimaryCtxReset.