Context

Struct 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§

Source§

impl Context

Source

pub fn create_and_push( flags: ContextFlags, device: Device, ) -> CudaResult<Context>

Create a CUDA context for the given device.

§Example
rustacuda::init(rustacuda::CudaFlags::empty())?;
let device = Device::get_device(0)?;
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
Source

pub fn get_api_version(&self) -> CudaResult<CudaApiVersion>

Get the API version used to create this context.

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

§Example
rustacuda::init(rustacuda::CudaFlags::empty())?;
let device = Device::get_device(0)?;
let context = Context::create_and_push(ContextFlags::MAP_HOST | ContextFlags::SCHED_AUTO, device)?;
let version = context.get_api_version()?;
Source

pub fn get_unowned(&self) -> UnownedContext

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)?;
let unowned = context.get_unowned();
Source

pub fn drop(ctx: Context) -> DropResult<Context>

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

Trait Implementations§

Source§

impl Debug for Context

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ContextHandle for Context

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> 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, 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.