Skip to main content

DeviceSlice

Struct DeviceSlice 

Source
pub struct DeviceSlice<'a, T: DeviceRepr> { /* private fields */ }
Expand description

Immutable view into a range of a DeviceBuffer.

Implementations§

Source§

impl<'a, T: DeviceRepr> DeviceSlice<'a, T>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_raw(&self) -> CUdeviceptr

Source

pub unsafe fn from_raw_parts<'b>( ptr: CUdeviceptr, len: usize, ) -> DeviceSlice<'b, T>

Construct a DeviceSlice from a raw device pointer and element count.

The lower-level escape hatch backing DeviceBuffer::view_as — use this when the source buffer is not a baracuda DeviceBuffer (e.g. a pointer received from a foreign CUDA library, or a byte-shaped storage substrate that erases the original buffer type at the boundary).

§Safety

The caller must guarantee:

  1. ptr points to at least len * size_of::<T>() bytes of device memory in the calling thread’s current CUDA context.
  2. The pointer is properly aligned for T. cuMemAlloc returns 256-byte-aligned pointers, but sub-slicing with a non-multiple element offset can reduce alignment.
  3. The pointed-to region remains live, with no concurrent mutation through any other path, for the lifetime 'b.
  4. The contents are a valid bit-pattern for T (trivially true for T: DeviceRepr since all DeviceRepr types have no invalid bit patterns).
Source

pub fn slice(&self, range: Range<usize>) -> DeviceSlice<'_, T>

Borrow a sub-range. Panics on out-of-bounds / inverted ranges.

Trait Implementations§

Source§

impl<'a, T: Clone + DeviceRepr> Clone for DeviceSlice<'a, T>

Source§

fn clone(&self) -> DeviceSlice<'a, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T: DeviceRepr> Debug for DeviceSlice<'a, T>

Source§

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

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

impl<'a, T: DeviceRepr> DevicePtr<T> for DeviceSlice<'a, T>

Source§

fn device_ptr(&self) -> CUdeviceptr

Raw device pointer to element 0.
Source§

fn len(&self) -> usize

Number of T elements visible through this pointer.
Source§

fn is_empty(&self) -> bool

true if len is 0.
Source§

fn byte_size(&self) -> usize

Size in bytes (len * size_of::<T>()).
Source§

impl<'a, T: DeviceRepr> KernelArg for &DeviceSlice<'a, T>

Source§

impl<'a, T: Copy + DeviceRepr> Copy for DeviceSlice<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for DeviceSlice<'a, T>

§

impl<'a, T> RefUnwindSafe for DeviceSlice<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for DeviceSlice<'a, T>
where T: Sync,

§

impl<'a, T> Sync for DeviceSlice<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for DeviceSlice<'a, T>

§

impl<'a, T> UnsafeUnpin for DeviceSlice<'a, T>

§

impl<'a, T> UnwindSafe for DeviceSlice<'a, T>
where T: RefUnwindSafe,

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.