Struct Context

Source
pub struct Context { /* private fields */ }

Implementations§

Source§

impl Context

Source

pub fn new(device: Device) -> CudaResult<Self>

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.

Source

pub unsafe fn reset(device: &Device) -> CudaResult<()>

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.

Source

pub fn set_flags(&self, flags: ContextFlags) -> CudaResult<()>

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

Source

pub fn as_raw(&self) -> CUcontext

Returns the raw handle to this context.

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
cust::init(cust::CudaFlags::empty())?;
let device = Device::get_device(0)?;
let context = Context::new(device)?;
let version = context.get_api_version()?;
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::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§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ContextHandle for Context

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 Send for Context

Source§

impl Sync 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.