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>
impl<T> CudaViewMut<'_, T>
§impl<'a, T> CudaViewMut<'a, T>
impl<'a, T> CudaViewMut<'a, T>
pub fn view_ptr(self, stream: &'a CudaStream) -> (u64, SyncOnDrop<'a>)
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>
impl<'a, T> CudaViewMut<'a, T>
pub fn view_ptr_mut(self, stream: &'a CudaStream) -> (u64, SyncOnDrop<'a>)
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>
impl<'a, T> CudaViewMut<'a, T>
pub fn slice<'b>(&'b self, bounds: impl RangeBounds<usize>) -> CudaView<'b, 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>>
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>>
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>
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>>
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>)
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>)>
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>>
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>>
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.