Skip to main content

Context

Struct Context 

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

A CUDA context created by cuCtxCreate.

Multiple Context clones refer to the same underlying driver context.

Implementations§

Source§

impl Context

Source

pub fn new(device: &Device) -> Result<Self>

Create a new context on device with default scheduling flags.

Source

pub fn with_flags(device: &Device, flags: u32) -> Result<Self>

Create a new context on device, passing flags verbatim to cuCtxCreate. See baracuda_cuda_sys::types::CUcontext_flags for the permitted values.

Source

pub fn current() -> Result<Option<CUcontext>>

Retrieve the thread’s currently-current context, if any. Returns Ok(None) when no context is current.

Note: the returned Context is a non-owning view — its Drop will not call cuCtxDestroy on the handle. Use this only for interop inspection, not lifecycle management.

Source

pub fn set_current(&self) -> Result<()>

Make this context current on the calling thread.

Source

pub fn push(&self) -> Result<()>

Push this context onto the thread’s context stack.

Source

pub fn pop() -> Result<CUcontext>

Pop the top context off the thread’s context stack.

Source

pub fn synchronize(&self) -> Result<()>

Block the calling thread until all work previously submitted to streams in this context has completed.

Source

pub fn api_version(&self) -> Result<u32>

API version this context was created with (major1000 + minor10, e.g. 12060).

Source

pub fn current_device() -> Result<Device>

Device ordinal of the thread’s currently-current context. Fails with CUDA_ERROR_INVALID_CONTEXT if no context is current.

Source

pub fn current_flags() -> Result<u32>

Flags the current context was created with (SCHED_*, MAP_HOST, etc.).

Operates on the thread’s current context, so make sure you’ve made this one current first.

Source

pub fn get_limit(limit: u32) -> Result<usize>

Query a resource limit of the current context. limit is one of baracuda_cuda_sys::types::CUlimit.

Source

pub fn set_limit(limit: u32, value: usize) -> Result<()>

Set a resource limit of the current context. limit is one of baracuda_cuda_sys::types::CUlimit. Not all limits are writable on every device.

Source

pub fn cache_config() -> Result<u32>

Current context’s L1/shared-memory preference. Values are from baracuda_cuda_sys::types::CUfunc_cache.

Source

pub fn set_cache_config(config: u32) -> Result<()>

Set the current context’s L1/shared-memory preference.

Source

pub fn stream_priority_range() -> Result<(i32, i32)>

Hardware-supported stream priority range (least_priority, greatest_priority). On most GPUs that’s (0, -1) — lower numbers = higher priority.

Source

pub fn enable_peer_access(peer: &Context) -> Result<()>

Enable peer access from the current context to peer’s context. After this call, kernels in the current context can read/write allocations owned by peer.

Source

pub fn disable_peer_access(peer: &Context) -> Result<()>

Source

pub fn device(&self) -> Device

The Device this context was created on.

Source

pub fn as_raw(&self) -> CUcontext

Raw CUcontext. Use with care.

Source

pub fn id(&self) -> Result<u64>

Driver-assigned 64-bit context ID. Useful for correlating CUPTI / Nsight traces against this Context.

Source

pub fn record_event(&self, event: &Event) -> Result<()>

Record event on this context (rather than tying it to a specific stream). CUDA 12+.

Source

pub fn wait_event(&self, event: &Event) -> Result<()>

Make this context wait on event. CUDA 12+.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Context

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.