pub struct Context { /* private fields */ }

Implementations

Retains the primary context for this device and makes it current, incrementing the internal reference cycle that CUDA keeps track of. There is only one primary context associated with a device, multiple calls to this function with the same device will return the same internal context.

This will NOT push the context to the stack, primary contexts do not interoperate with the context stack.

Resets the primary context associated with the device, freeing all allocations created inside of the context. You must make sure that nothing else is using the context or using CUDA on the device in general. For this reason, it is usually highly advised to not use this function.

Safety

Nothing else should be using the primary context for this device, otherwise, spurious errors or segfaults will occur.

Sets the flags for the device context, these flags will apply to any user of the primary context associated with this device.

Returns the raw handle to this context.

Get the API version used to create this context.

This is not necessarily the latest version supported by the driver.

Example
cust::init(cust::CudaFlags::empty())?;
let device = Device::get_device(0)?;
let context = Context::new(device)?;
let version = context.get_api_version()?;

Destroy a Context, returning an error.

Destroying a context can return errors from previous asynchronous work. This function destroys the given context and returns the error and the un-destroyed context on failure.

Example
let context = Context::new(device)?;
match Context::drop(context) {
    Ok(()) => println!("Successfully destroyed"),
    Err((e, ctx)) => {
        println!("Failed to destroy context: {:?}", e);
        // Do something with ctx
    },
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.