Struct CudaSlice
pub struct CudaSlice<T> { /* private fields */ }Expand description
Vec<T> on a cuda device. You can allocate and modify this with CudaStream.
This object is thread safe.
Implementations§
§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
pub fn stream(&self) -> &Arc<CudaStream>
pub fn stream(&self) -> &Arc<CudaStream>
The stream this object was allocated on and later will be dropped on.
§impl<T> CudaSlice<T>where
T: DeviceRepr,
impl<T> CudaSlice<T>where
T: DeviceRepr,
pub fn try_clone(&self) -> Result<CudaSlice<T>, DriverError>
pub fn try_clone(&self) -> Result<CudaSlice<T>, DriverError>
Allocates copy of self and schedules a device to device copy of memory.
§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
pub fn as_view_mut(&mut self) -> CudaViewMut<'_, T>
§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
pub fn slice(&self, bounds: impl RangeBounds<usize>) -> CudaView<'_, T>
pub fn slice(&self, bounds: impl RangeBounds<usize>) -> CudaView<'_, T>
Creates a CudaView at the specified offset from the start of self.
Panics if range.start >= self.len.
§Example
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
let mut view = slice.slice(0..50);
do_something(&view);Like a normal slice, borrow checking prevents the underlying CudaSlice from being dropped.
let view = {
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
// cannot return view, since it borrows from slice
slice.slice(0..50)
};
do_something(&view);pub fn try_slice(
&self,
bounds: impl RangeBounds<usize>,
) -> Option<CudaView<'_, T>>
pub fn try_slice( &self, bounds: impl RangeBounds<usize>, ) -> Option<CudaView<'_, T>>
Fallible version of CudaSlice::slice().
pub fn slice_mut(
&mut self,
bounds: impl RangeBounds<usize>,
) -> CudaViewMut<'_, T>
pub fn slice_mut( &mut self, bounds: impl RangeBounds<usize>, ) -> CudaViewMut<'_, T>
Creates a CudaViewMut 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);
do_something(&mut view);Like a normal mutable slice, borrow checking prevents the underlying CudaSlice from being dropped.
let mut view = {
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
// cannot return view, since it borrows from slice
slice.slice_mut(0..50)
};
do_something(&mut view);Like with normal mutable slices, one cannot mutably slice twice into the same CudaSlice:
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
let mut view1 = slice.slice_mut(0..50);
// cannot borrow twice from slice
let mut view2 = slice.slice_mut(50..100);
do_something(view1, view2);If you need non-overlapping mutable views into a CudaSlice, you can use CudaSlice::split_at_mut().
pub fn try_slice_mut(
&mut self,
bounds: impl RangeBounds<usize>,
) -> Option<CudaViewMut<'_, T>>
pub fn try_slice_mut( &mut self, bounds: impl RangeBounds<usize>, ) -> Option<CudaViewMut<'_, T>>
Fallible version of CudaSlice::slice_mut
pub unsafe fn transmute<S>(&self, len: usize) -> Option<CudaView<'_, S>>
pub unsafe fn transmute<S>(&self, len: usize) -> Option<CudaView<'_, 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 unsafe fn transmute_mut<S>(
&mut self,
len: usize,
) -> Option<CudaViewMut<'_, S>>
pub unsafe fn transmute_mut<S>( &mut self, len: usize, ) -> Option<CudaViewMut<'_, 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 split_at(&self, mid: usize) -> (CudaView<'_, T>, CudaView<'_, T>)
pub fn try_split_at(
&self,
mid: usize,
) -> Option<(CudaView<'_, T>, CudaView<'_, T>)>
pub fn try_split_at( &self, mid: usize, ) -> Option<(CudaView<'_, T>, CudaView<'_, T>)>
Fallible version of CudaSlice::split_at. Returns None if mid > self.len.
pub fn split_at_mut(
&mut self,
mid: usize,
) -> (CudaViewMut<'_, T>, CudaViewMut<'_, T>)
pub fn split_at_mut( &mut self, mid: usize, ) -> (CudaViewMut<'_, T>, CudaViewMut<'_, T>)
Splits the CudaSlice into two at the given index, returning two CudaViewMut for the two halves.
Panics if mid > self.len.
This method can be used to create non-overlapping mutable views into a CudaSlice.
let mut slice = stream.alloc_zeros::<u8>(100).unwrap();
// split the slice into two non-overlapping, mutable views
let (mut view1, mut view2) = slice.split_at_mut(50);
do_something(view1, view2);pub fn try_split_at_mut(
&mut self,
mid: usize,
) -> Option<(CudaViewMut<'_, T>, CudaViewMut<'_, T>)>
pub fn try_split_at_mut( &mut self, mid: usize, ) -> Option<(CudaViewMut<'_, T>, CudaViewMut<'_, T>)>
Fallible version of CudaSlice::split_at_mut.
Returns None if mid > self.len.
§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
pub fn leak(self) -> u64
pub fn leak(self) -> u64
Takes ownership of the underlying sys::CUdeviceptr. It is up to the owner to free this value.
Drops the underlying host_buf if there is one.