Struct rustacuda::context::Context

source ·
pub struct Context { /* private fields */ }
Expand description

Owned handle to a CUDA context.

The context will be destroyed when this goes out of scope. If this is the current context on the current OS thread, the next context on the stack (if any) will be made current. Note that the context will be destroyed even if other threads are still using it. Attempts to access the destroyed context from another thread will return an error.

Implementations§

Create a CUDA context for the given device.

Example:
use rustacuda;
use rustacuda::device::Device;
use rustacuda::context::{Context, ContextFlags};

rustacuda::init(rustacuda::CudaFlags::empty()).unwrap();
let device = Device::get_device(0).unwrap();
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();

Get the API version used to create this context.

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

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let version = context.get_api_version().unwrap();

Returns an non-owning handle to this context.

This is useful for sharing a single context between threads (though see the module-level documentation for safety details!).

Example:
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
let unowned = context.get_unowned();

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::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device).unwrap();
match Context::drop(context) {
    Ok(()) => println!("Successfully destroyed"),
    Err((e, ctx)) => {
        println!("Failed to destroy context: {:?}", e);
        // Do something with ctx
    },
}

Trait Implementations§

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

Returns the argument unchanged.

Calls U::from(self).

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

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.