Struct DeviceBox

Source
pub struct DeviceBox<'a> { /* private fields */ }
Expand description

An owned device-allocated buffer

Implementations§

Source§

impl<'a> DeviceBox<'a>

Source

pub fn alloc(handle: &Rc<Handle<'a>>, size: u64) -> CudaResult<Self>

Allocate an uninitialized buffer of size size on the device

Source

pub fn new(handle: &Rc<Handle<'a>>, input: &[u8]) -> CudaResult<Self>

Allocate a new initialized buffer on the device matching the size and content of input.

Source

pub fn new_stream<'b>( handle: &Rc<Handle<'a>>, input: &'b [u8], stream: &'b mut Stream<'a>, ) -> CudaResult<Self>

Allocates a new uninitialized buffer on the device, then asynchronously fills it with input. input must not be dropped or mutated until stream.sync is called. Does not allocate the memory asynchronously.

Source

pub fn new_stream_buf( handle: &Rc<Handle<'a>>, input: Vec<u8>, stream: &mut Stream<'a>, ) -> CudaResult<Self>

Allocates a new uninitialized buffer on the device, then synchronously fills it with input. input will be dropped when the stream is synced or dropped. Does not allocate the memory asynchronously.

Source

pub fn new_ffi<T>(handle: &Rc<Handle<'a>>, input: &[T]) -> CudaResult<Self>

Allocates a new initialized buffer on the device matching the size and content of input. Note that memory is directly copied, so [T] must be Sized should not contain any pointers, references, unsized types, or other non-FFI safe types.

Source

pub fn new_ffi_stream<'b, T>( handle: &Rc<Handle<'a>>, input: &'b [T], stream: &'b mut Stream<'a>, ) -> CudaResult<Self>

Allocates a new uninitialized buffer on the device, then synchronously fills it with input. Note that memory is directly copied, so [T] must be Sized should not contain any pointers, references, unsized types, or other non-FFI safe types. input must not be dropped or mutated until stream.sync is called. Does not allocate the memory asynchronously.

Source

pub fn new_ffi_stream_buf<'b, T>( handle: &Rc<Handle<'a>>, input: Vec<T>, stream: &'b mut Stream<'a>, ) -> CudaResult<Self>

Allocates a new uninitialized buffer on the device, then synchronously fills it with input. Note that memory is directly copied, so [T] must be Sized should not contain any pointers, references, unsized types, or other non-FFI safe types. input will be dropped when the stream is synced or dropped. Does not allocate the memory asynchronously.

Source

pub fn leak(self)

Leaks the DeviceBox, similar to Box::leak.

Source

pub unsafe fn from_raw(raw: DevicePtr<'a>) -> Self

Constructs a DeviceBox from a device pointer.

Methods from Deref<Target = DevicePtr<'a>>§

Source

pub fn as_raw(&self) -> u64

Source

pub fn copy_to<'b>(&self, target: &DevicePtr<'b>) -> CudaResult<()>

Synchronously copies data from self to target. Panics if length is not equal.

Source

pub fn copy_to_stream<'b, 'c: 'b + 'a>( &self, target: &DevicePtr<'b>, stream: &mut Stream<'c>, ) -> CudaResult<()>
where 'a: 'b,

Asynchronously copies data from self to target. Panics if length is not equal.

Source

pub fn copy_from<'b>(&self, source: &DevicePtr<'b>) -> CudaResult<()>

Synchronously copies data from source to self. Panics if length is not equal.

Source

pub fn copy_from_stream<'b: 'a, 'c: 'a + 'b>( &self, source: &DevicePtr<'b>, stream: &mut Stream<'c>, ) -> CudaResult<()>

Asynchronously copies data from source to self. Panics if length is not equal.

Source

pub fn subslice(&self, from: u64, to: u64) -> Self

Gets a subslice of this slice from [from:to]

Source

pub fn len(&self) -> u64

Gets the length of this slice

Source

pub fn is_empty(&self) -> bool

Check if the slice’s length is 0

Source

pub fn load(&self) -> CudaResult<Vec<u8>>

Synchronously loads the data from this slice into a local buffer

Source

pub unsafe fn load_stream(&self, stream: &mut Stream<'a>) -> CudaResult<Vec<u8>>

Asynchronously loads the data from this slice into a local buffer. The contents of the buffer are undefined until stream.sync is called. The output must not be dropped until the stream is synced.

Source

pub fn store(&self, data: &[u8]) -> CudaResult<()>

Synchronously stores host data from data to self.

Source

pub fn store_stream<'b>( &self, data: &'b [u8], stream: &'b mut Stream<'a>, ) -> CudaResult<()>

Asynchronously stores host data from data to self. The data must not be dropped or mutated until stream.sync is called.

Source

pub fn store_stream_buf( &self, data: Vec<u8>, stream: &mut Stream<'a>, ) -> CudaResult<()>

Asynchronously stores host data from data to self. data will be dropped once the Stream is synced or dropped.

Source

pub fn memset_d8(&self, data: u8) -> CudaResult<()>

Synchronously set the contents of self to data repeated to fill length

Source

pub fn memset_d8_stream( &self, data: u8, stream: &mut Stream<'a>, ) -> CudaResult<()>

Asynchronously set the contents of self to data repeated to fill length

Source

pub fn memset_d16(&self, data: u16) -> CudaResult<()>

Synchronously set the contents of self to data repeated to fill length. Panics if Self::len is not a multiple of 2.

Source

pub fn memset_d16_stream( &self, data: u16, stream: &mut Stream<'a>, ) -> CudaResult<()>

Asynchronously set the contents of self to data repeated to fill length. Panics if Self::len is not a multiple of 2.

Source

pub fn memset_d32(&self, data: u32) -> CudaResult<()>

Synchronously set the contents of self to data repeated to fill length. Panics if Self::len is not a multiple of 4.

Source

pub fn memset_d32_stream( &self, data: u32, stream: &mut Stream<'a>, ) -> CudaResult<()>

Asynchronously set the contents of self to data repeated to fill length. Panics if Self::len is not a multiple of 4.

Source

pub fn handle(&self) -> &Rc<Handle<'a>>

Gets a reference to the owning handle

Trait Implementations§

Source§

impl<'a> AsRef<DevicePtr<'a>> for DeviceBox<'a>

Source§

fn as_ref(&self) -> &DevicePtr<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Deref for DeviceBox<'a>

Source§

type Target = DevicePtr<'a>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> DerefMut for DeviceBox<'a>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a> Drop for DeviceBox<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, 'b> KernelParameters for &'b DeviceBox<'a>

WARNING: this is unsafe!

Source§

fn params(&self, out: &mut Vec<Vec<u8>>)

Auto Trait Implementations§

§

impl<'a> Freeze for DeviceBox<'a>

§

impl<'a> RefUnwindSafe for DeviceBox<'a>

§

impl<'a> !Send for DeviceBox<'a>

§

impl<'a> !Sync for DeviceBox<'a>

§

impl<'a> Unpin for DeviceBox<'a>

§

impl<'a> UnwindSafe for DeviceBox<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.