pub struct PitchedDeviceMemory<T: DeviceRepr> { /* private fields */ }Expand description
Owned 2D pitched CUDA device memory.
The logical dimensions are expressed in elements of T; the CUDA pitch is stored as a byte stride between rows.
Implementations§
Source§impl<T: DeviceRepr> PitchedDeviceMemory<T>
impl<T: DeviceRepr> PitchedDeviceMemory<T>
Sourcepub fn create_uninit(
context: &Arc<Context>,
width: usize,
height: usize,
) -> Result<PitchedDeviceMemory<MaybeUninit<T>>>
pub fn create_uninit( context: &Arc<Context>, width: usize, height: usize, ) -> Result<PitchedDeviceMemory<MaybeUninit<T>>>
Allocates pitched storage whose logical elements are uninitialized.
§Errors
Returns an error if size calculations overflow, a nonempty zero-sized element range is requested, the context cannot be bound, or CUDA cannot allocate pitched storage. Returns an error if CUDA returns a pointer or pitch that violates the requested row size, alignment, or address-range bounds.
Sourcepub fn zeroed(
context: &Arc<Context>,
width: usize,
height: usize,
) -> Result<Self>where
T: ZeroableDeviceRepr,
pub fn zeroed(
context: &Arc<Context>,
width: usize,
height: usize,
) -> Result<Self>where
T: ZeroableDeviceRepr,
Allocates pitched storage and completes zero initialization of its logical elements.
§Errors
Returns an error if allocation fails for the reasons create_uninit gives, access tracking fails, or CUDA cannot fill or synchronize.
Sourcepub fn filled(
context: &Arc<Context>,
width: usize,
height: usize,
value: u8,
) -> Result<Self>where
T: AnyBitPatternDeviceRepr,
pub fn filled(
context: &Arc<Context>,
width: usize,
height: usize,
value: u8,
) -> Result<Self>where
T: AnyBitPatternDeviceRepr,
Allocates pitched storage and completes a repeated byte fill of its logical elements.
§Errors
Returns an error if allocation fails for the reasons create_uninit gives, access tracking fails, or CUDA cannot fill or synchronize.
Sourcepub fn from_slice(
context: &Arc<Context>,
width: usize,
height: usize,
values: &[T],
) -> Result<Self>
pub fn from_slice( context: &Arc<Context>, width: usize, height: usize, values: &[T], ) -> Result<Self>
Allocates pitched storage and completes a copy of contiguous row-major host values.
§Errors
Returns an error if the source length differs from the logical element count, allocation fails for the reasons create_uninit gives, or CUDA cannot copy or synchronize.
Sourcepub unsafe fn from_raw(raw: RawPitchedDeviceMemory<T>) -> Result<Self>
pub unsafe fn from_raw(raw: RawPitchedDeviceMemory<T>) -> Result<Self>
Takes ownership of a pitched allocation in raw.context.
§Safety
raw.ptr must be the base of a live CUDA allocation compatible with cudaFree, with no other destruction owner.
It must contain initialized, valid T values at every logical element.
The pitch and dimensions must describe its storage, and previous accesses must be ordered before future consumers.
A null pointer is accepted for an empty shape.
§Errors
Returns an error if row or volume size calculations overflow or a nonempty zero-sized element range is requested.
Returns an error if nonempty storage has a null or misaligned pointer, a pitch smaller than the row width or not aligned for T, or an overflowing ending address.
Sourcepub fn into_raw(self) -> StdResult<RawPitchedDeviceMemory<T>, Self>
pub fn into_raw(self) -> StdResult<RawPitchedDeviceMemory<T>, Self>
Transfers raw ownership, or returns this buffer unchanged if another owner retains it.
The returned pointer must eventually be freed in the returned context.
§Errors
Returns the wrapper unchanged as the error if another owner, submission, graph, or foreign handle retains the allocation.
Sourcepub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ
pub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ
Returns the shared owner of the physical allocation, including row padding.
Sourcepub fn cast<U: AnyBitPatternDeviceRepr>(
self,
) -> StdResult<PitchedDeviceMemory<U>, Self>where
T: NoUninitDeviceRepr,
pub fn cast<U: AnyBitPatternDeviceRepr>(
self,
) -> StdResult<PitchedDeviceMemory<U>, Self>where
T: NoUninitDeviceRepr,
Reinterprets logical row bytes while preserving pitch, capacity, and allocation identity.
Row padding is excluded from the initialized representation.
§Errors
Returns the allocation unchanged as the error if U is zero-sized, its size does not divide the logical row byte width, or nonempty storage has a base pointer or pitch not aligned for U.
§Panics
Panics if the logical row byte width overflows usize.
Construction validates this width, so this cannot occur for a valid pitched allocation.
Sourcepub fn into_uninit(self) -> PitchedDeviceMemory<MaybeUninit<T>>
pub fn into_uninit(self) -> PitchedDeviceMemory<MaybeUninit<T>>
Erases logical element initialization without changing allocation ownership.
Sourcepub const fn as_mut_ptr(&mut self) -> *mut T
pub const fn as_mut_ptr(&mut self) -> *mut T
Returns the mutable base device pointer.
Sourcepub const fn as_device_ptr(&self) -> DevicePtr
pub const fn as_device_ptr(&self) -> DevicePtr
Returns the base pointer as a CUDA device pointer wrapper.
Sourcepub fn row_byte_width(&self) -> Result<usize>
pub fn row_byte_width(&self) -> Result<usize>
Returns the logical row width in bytes.
§Errors
Returns an error if width * size_of::<T>() overflows or T is a non-empty zero-sized element type.
Sourcepub fn byte_len(&self) -> Result<usize>
pub fn byte_len(&self) -> Result<usize>
Returns the physical allocation span described by pitch * height.
§Errors
Returns an error if pitch * height overflows.
Sourcepub fn copy_from_host(&mut self, src: &[T]) -> Result<()>
pub fn copy_from_host(&mut self, src: &[T]) -> Result<()>
Copies a contiguous host slice into this pitched device allocation.
src must contain exactly width * height elements in row-major order.
§Errors
Returns an error if src has the wrong length, byte-size arithmetic overflows, or CUDA rejects the 2D copy.
Sourcepub fn copy_to_host(&self, dst: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host(&self, dst: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
Copies this pitched device allocation into a contiguous host slice.
dst must contain exactly width * height elements and is filled in row-major order.
§Errors
Returns an error if dst has the wrong length, byte-size arithmetic overflows, or CUDA rejects the 2D copy.
Sourcepub unsafe fn copy_to_host_unchecked(&self, dst: &mut [T]) -> Result<()>
pub unsafe fn copy_to_host_unchecked(&self, dst: &mut [T]) -> Result<()>
Copies device values whose validity is established by the producing kernel.
§Safety
Every copied element must be initialized and valid for T.
§Errors
Returns an error if the destination length differs from the logical element count, transfer size calculations overflow, access tracking fails, the context cannot be bound, or CUDA cannot copy or synchronize.
Sourcepub fn copy_from_pitched(&mut self, src: &Self) -> Result<()>
pub fn copy_from_pitched(&mut self, src: &Self) -> Result<()>
Copies another pitched device allocation with the same shape into this one.
§Errors
Returns an error if the shapes differ, byte-size arithmetic overflows, or CUDA rejects the device-to-device 2D copy.
Sourcepub fn copy_from_host_scoped<'env>(
&'env mut self,
src: &'env [T],
stream: &StreamScope<'_, 'env>,
) -> Result<()>
pub fn copy_from_host_scoped<'env>( &'env mut self, src: &'env [T], stream: &StreamScope<'_, 'env>, ) -> Result<()>
Enqueues a host-to-device 2D copy from a contiguous host slice.
src must remain valid until stream reaches the copy.
The StreamScope lifetime enforces that requirement for safe callers.
§Errors
Returns an error if src has the wrong length, byte-size arithmetic overflows, or CUDA cannot enqueue the copy.
Sourcepub fn copy_to_host_scoped<'env>(
&'env self,
dst: &'env mut [T],
stream: &StreamScope<'_, 'env>,
) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host_scoped<'env>(
&'env self,
dst: &'env mut [T],
stream: &StreamScope<'_, 'env>,
) -> Result<()>where
T: AnyBitPatternDeviceRepr,
Enqueues a device-to-host 2D copy into a contiguous host slice.
dst must remain valid until stream reaches the copy.
The StreamScope lifetime enforces that requirement for safe callers.
§Errors
Returns an error if dst has the wrong length, byte-size arithmetic overflows, or CUDA cannot enqueue the copy.
Sourcepub fn set_zeroes(&mut self) -> Result<()>where
T: ZeroableDeviceRepr,
pub fn set_zeroes(&mut self) -> Result<()>where
T: ZeroableDeviceRepr,
Fills this pitched allocation with zero bytes.
§Errors
Returns an error if CUDA rejects the 2D memset.
Sourcepub fn set_value(&mut self, value: u8) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn set_value(&mut self, value: u8) -> Result<()>where
T: AnyBitPatternDeviceRepr,
Fills this pitched allocation with value bytes.
§Errors
Returns an error if CUDA rejects the 2D memset.
Sourcepub unsafe fn set_value_unchecked(&mut self, value: u8) -> Result<()>
pub unsafe fn set_value_unchecked(&mut self, value: u8) -> Result<()>
Fills storage with a byte pattern known to be valid for T.
§Safety
The repeated byte pattern must represent a valid value of T.
§Errors
Returns an error if access tracking fails, the context cannot be bound, the transfer size overflows, or CUDA cannot fill the memory or synchronize the default stream.
Sourcepub fn set_value_scoped<'env>(
&'env mut self,
value: u8,
stream: &StreamScope<'_, 'env>,
) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn set_value_scoped<'env>(
&'env mut self,
value: u8,
stream: &StreamScope<'_, 'env>,
) -> Result<()>where
T: AnyBitPatternDeviceRepr,
Enqueues a byte fill of this pitched allocation on stream.
§Errors
Returns an error if CUDA cannot enqueue the 2D memset.
Sourcepub fn row(&self, row: usize) -> Result<DeviceView<'_, T>>
pub fn row(&self, row: usize) -> Result<DeviceView<'_, T>>
Borrows one initialized logical row, excluding CUDA’s row padding.
§Errors
Returns an error if the row index is out of bounds, row offset calculations overflow, or the resulting range fails byte-length or alignment validation.
Sourcepub fn row_mut(&mut self, row: usize) -> Result<DeviceViewMut<'_, T>>
pub fn row_mut(&mut self, row: usize) -> Result<DeviceViewMut<'_, T>>
Exclusively borrows one logical row, excluding CUDA’s row padding.
§Errors
Returns an error if the row index is out of bounds, row offset calculations overflow, or the resulting range fails byte-length or alignment validation.
Source§impl<T: DeviceRepr> PitchedDeviceMemory<MaybeUninit<T>>
impl<T: DeviceRepr> PitchedDeviceMemory<MaybeUninit<T>>
Sourcepub fn initialize_from_host(
self,
values: &[T],
) -> Result<PitchedDeviceMemory<T>>
pub fn initialize_from_host( self, values: &[T], ) -> Result<PitchedDeviceMemory<T>>
Copies every logical element from host values and completes before promotion.
§Errors
Returns an error if the source length differs from the logical element count, transfer size calculations overflow, the context cannot be bound, or CUDA cannot copy or synchronize.
Sourcepub unsafe fn assume_init(self) -> PitchedDeviceMemory<T>
pub unsafe fn assume_init(self) -> PitchedDeviceMemory<T>
Marks all logical elements initialized without changing the owner or pitch.
§Safety
Every logical element must contain an initialized valid T value.
Producers must be ordered before subsequent consumers and complete before host readback.
Row padding remains uninitialized.