Skip to main content

PrimaryContext

Struct PrimaryContext 

Source
pub struct PrimaryContext { /* private fields */ }
Expand description

RAII wrapper for a CUDA primary context.

A primary context is the per-device, reference-counted context managed by the CUDA driver. Unlike a regular Context, the primary context is shared among all callers that retain it on the same device.

PrimaryContext::retain increments the driver’s reference count and PrimaryContext::release decrements it. When the count reaches zero, the driver destroys the context.

Implementations§

Source§

impl PrimaryContext

Source

pub fn retain(device: &Device) -> CudaResult<Self>

Retains the primary context on the given device.

If the primary context does not yet exist, the driver creates it. Each call to retain increments an internal reference count. The context remains alive until all retainers call release.

§Errors

Returns an error if the driver cannot be loaded or the retain fails (e.g., invalid device).

Source

pub fn release(self) -> CudaResult<()>

Releases this primary context, decrementing the driver’s reference count.

When the last retainer releases, the driver destroys the context and frees its resources. After calling this method the PrimaryContext is consumed and cannot be used further.

§Errors

Returns an error if the release call fails.

Source

pub fn set_flags(&self, flags: u32) -> CudaResult<()>

Sets the flags for the primary context.

The flags control scheduling behaviour (e.g., spin, yield, blocking). See context::flags for available values.

This must be called before the primary context is made active (i.e., before any retain or before all retainers have released). If the primary context is already active, this returns CudaError::PrimaryContextActive.

§Errors

Returns an error if the flags cannot be set.

Source

pub fn get_state(&self) -> CudaResult<(bool, u32)>

Returns the current state of the primary context.

Returns (active, flags) where:

  • active is true if the context is currently retained by at least one caller.
  • flags are the scheduling flags currently in effect.
§Errors

Returns an error if the state query fails.

Source

pub fn reset(&self) -> CudaResult<()>

Resets the primary context on this device.

This destroys all allocations, modules, and state associated with the primary context. The context is then re-created the next time it is retained.

§Errors

Returns an error if the reset fails.

Source

pub fn device(&self) -> &Device

Returns a reference to the device this primary context belongs to.

Source

pub fn raw(&self) -> CUcontext

Returns the raw CUcontext handle.

Trait Implementations§

Source§

impl Debug for PrimaryContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PrimaryContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PrimaryContext

Source§

fn drop(&mut self)

Release the primary context on drop.

Errors during release are logged but never propagated.

Source§

impl Send for PrimaryContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more