pub struct Context { /* private fields */ }
Implementations
sourceimpl Context
impl Context
sourcepub fn new(device: Device) -> CudaResult<Self>
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.
sourcepub unsafe fn reset(device: &Device) -> CudaResult<()>
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.
sourcepub fn set_flags(&self, flags: ContextFlags) -> CudaResult<()>
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.
sourcepub fn get_api_version(&self) -> CudaResult<CudaApiVersion>
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()?;
sourcepub fn drop(ctx: Context) -> DropResult<Context>
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
impl Send for Context
impl Sync for Context
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more