Skip to main content

CudaViewMut

Struct CudaViewMut 

pub struct CudaViewMut<'a, T> { /* private fields */ }
Expand description

&mut [T] on a cuda device. A mutable sub-view into a CudaSlice created by CudaSlice::as_view_mut()/CudaSlice::slice_mut().

Implementations§

§

impl<T> CudaViewMut<'_, T>

pub fn len(&self) -> usize

Number of elements T that are in this view.

pub fn is_empty(&self) -> bool

pub fn as_view<'b>(&'b self) -> CudaView<'b, T>

Downgrade this to a &[T]

§

impl<'a, T> CudaViewMut<'a, T>

pub fn view_ptr(self, stream: &'a CudaStream) -> (u64, SyncOnDrop<'a>)

Identical behavior to DevicePtr::device_ptr(), but the lifetime on the returned [SyncOnDrop], matches the lifetime of the view.

§

impl<'a, T> CudaViewMut<'a, T>

pub fn view_ptr_mut(self, stream: &'a CudaStream) -> (u64, SyncOnDrop<'a>)

Identical behavior to DevicePtrMut::device_ptr_mut(), but the lifetime on the returned [SyncOnDrop], matches the lifetime of the view.

§

impl<'a, T> CudaViewMut<'a, T>

pub fn slice<'b>(&'b self, bounds: impl RangeBounds<usize>) -> CudaView<'b, T>

Creates a CudaView at the specified offset from the start of self.

Panics if range and 0...self.len() are not overlapping.

§Example
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
let mut view = slice.slice_mut(0..50);
let mut view2 = view.slice_mut(0..25);
do_something(&mut view2);

One cannot slice twice into the same CudaViewMut:

let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
let mut view = slice.slice_mut(0..50);
// cannot borrow twice from same view
let mut view1 = slice.slice_mut(0..25);
let mut view2 = slice.slice_mut(25..50);
do_something(view1, view2);

If you need non-overlapping mutable views into a CudaViewMut, you can use CudaViewMut::split_at_mut().

pub fn try_slice<'b>( &'b self, bounds: impl RangeBounds<usize>, ) -> Option<CudaView<'b, T>>

Fallible version of CudaViewMut::slice

pub unsafe fn transmute<'b, S>(&'b self, len: usize) -> Option<CudaView<'b, S>>

Reinterprets the slice of memory into a different type. len is the number of elements of the new type S that are expected. If not enough bytes are allocated in self for the view, then this returns None.

§Safety

This is unsafe because not the memory for the view may not be a valid interpretation for the type S.

pub fn slice_mut<'b>( &'b mut self, bounds: impl RangeBounds<usize>, ) -> CudaViewMut<'b, T>

Creates a CudaViewMut at the specified offset from the start of self.

Panics if range and 0...self.len() are not overlapping.

pub fn try_slice_mut<'b>( &'b mut self, bounds: impl RangeBounds<usize>, ) -> Option<CudaViewMut<'b, T>>

Fallible version of CudaViewMut::slice_mut

pub fn split_at_mut<'b>( &'b mut self, mid: usize, ) -> (CudaViewMut<'b, T>, CudaViewMut<'b, T>)

Splits the CudaViewMut into two at the given index.

Panics if mid > self.len.

This method can be used to create non-overlapping mutable views into a CudaViewMut.

let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
let mut view = slice.slice_mut(0..50);
// split the view into two non-overlapping, mutable views
let (mut view1, mut view2) = view.split_at_mut(25);
do_something(view1, view2);

pub fn try_split_at_mut<'b>( &'b mut self, mid: usize, ) -> Option<(CudaViewMut<'b, T>, CudaViewMut<'b, T>)>

Fallible version of CudaViewMut::split_at_mut.

Returns None if mid > self.len

pub fn chunks_exact_mut( self, chunk_size: usize, ) -> impl Iterator<Item = CudaViewMut<'a, T>>

Returns an iterarow over subviews of size chunk_size. Differs from std::slice::ChunksExactMut, in that it asserts that the chunk_size must divide evenly into the length, instead of returning a remainder.

pub unsafe fn transmute_mut<'b, S>( &'b mut self, len: usize, ) -> Option<CudaViewMut<'b, S>>

Reinterprets the slice of memory into a different type. len is the number of elements of the new type S that are expected. If not enough bytes are allocated in self for the view, then this returns None.

§Safety

This is unsafe because not the memory for the view may not be a valid interpretation for the type S.

Trait Implementations§

§

impl<'a, T> Debug for CudaViewMut<'a, T>
where T: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<T> DevicePtr<T> for CudaViewMut<'_, T>

§

fn device_ptr<'a>(&'a self, stream: &'a CudaStream) -> (u64, SyncOnDrop<'a>)

Retrieve the device pointer with the intent to read the device memory associated with it. Read more
§

impl<T> DevicePtrMut<T> for CudaViewMut<'_, T>

§

fn device_ptr_mut<'a>( &'a mut self, stream: &'a CudaStream, ) -> (u64, SyncOnDrop<'a>)

Retrieve the device pointer with the intent to modify the device memory associated with it. Read more
§

impl<T> DeviceSlice<T> for CudaViewMut<'_, T>

§

fn len(&self) -> usize

§

fn stream(&self) -> &Arc<CudaStream>

§

fn num_bytes(&self) -> usize

§

fn is_empty(&self) -> bool

Source§

impl<'a, 'b, T> IntoKernelParamStorage for &'a CudaViewMut<'b, T>

Source§

impl<'a, 'b, T> IntoKernelParamStorage for &'a mut CudaViewMut<'b, T>

Auto Trait Implementations§

§

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

§

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

§

impl<'a, T> Send for CudaViewMut<'a, T>
where T: Send,

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for CudaViewMut<'a, T>

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

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,