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
impl Context
Sourcepub fn new(device: &Device) -> Result<Self>
pub fn new(device: &Device) -> Result<Self>
Create a new context on device with default scheduling flags.
Sourcepub fn with_flags(device: &Device, flags: u32) -> Result<Self>
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.
Sourcepub fn current() -> Result<Option<CUcontext>>
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.
Sourcepub fn set_current(&self) -> Result<()>
pub fn set_current(&self) -> Result<()>
Make this context current on the calling thread.
Sourcepub fn synchronize(&self) -> Result<()>
pub fn synchronize(&self) -> Result<()>
Block the calling thread until all work previously submitted to streams in this context has completed.
Sourcepub fn api_version(&self) -> Result<u32>
pub fn api_version(&self) -> Result<u32>
API version this context was created with (major1000 + minor10, e.g. 12060).
Sourcepub fn current_device() -> Result<Device>
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.
Sourcepub fn current_flags() -> Result<u32>
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.
Sourcepub fn get_limit(limit: u32) -> Result<usize>
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.
Sourcepub fn set_limit(limit: u32, value: usize) -> Result<()>
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.
Sourcepub fn cache_config() -> Result<u32>
pub fn cache_config() -> Result<u32>
Current context’s L1/shared-memory preference. Values are from
baracuda_cuda_sys::types::CUfunc_cache.
Sourcepub fn set_cache_config(config: u32) -> Result<()>
pub fn set_cache_config(config: u32) -> Result<()>
Set the current context’s L1/shared-memory preference.
Sourcepub fn stream_priority_range() -> Result<(i32, i32)>
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.
Sourcepub fn enable_peer_access(peer: &Context) -> Result<()>
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.
Sourcepub fn disable_peer_access(peer: &Context) -> Result<()>
pub fn disable_peer_access(peer: &Context) -> Result<()>
Revert enable_peer_access.
Sourcepub fn id(&self) -> Result<u64>
pub fn id(&self) -> Result<u64>
Driver-assigned 64-bit context ID. Useful for correlating
CUPTI / Nsight traces against this Context.
Sourcepub fn record_event(&self, event: &Event) -> Result<()>
pub fn record_event(&self, event: &Event) -> Result<()>
Record event on this context (rather than tying it to a specific
stream). CUDA 12+.
Sourcepub fn wait_event(&self, event: &Event) -> Result<()>
pub fn wait_event(&self, event: &Event) -> Result<()>
Make this context wait on event. CUDA 12+.