Skip to main content

Module context

Module context 

Source
Expand description

CUDA context management with RAII semantics.

A CUDA context is the primary interface through which a CPU thread interacts with a GPU. It owns driver state such as loaded modules, allocated memory, and streams. This module provides the Context type, an RAII wrapper around CUcontext that automatically calls cuCtxDestroy on drop.

§Thread safety

CUDA contexts can be migrated between threads via cuCtxSetCurrent. The Context type implements Send to allow this. It does not implement Sync because the driver binds a context to a single thread at a time. Use Arc<Context> together with explicit set_current calls when sharing across threads.

§Examples

use oxicuda_driver::context::Context;
use oxicuda_driver::device::Device;

oxicuda_driver::init()?;
let device = Device::get(0)?;
let ctx = Context::new(&device)?;
ctx.set_current()?;
// ... launch kernels, allocate memory ...
ctx.synchronize()?;

Modules§

flags
Context scheduling flags passed to Context::with_flags.

Structs§

Context
RAII wrapper for a CUDA context.