Skip to main content

PitchedDeviceMemory

Struct PitchedDeviceMemory 

Source
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>

Source

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.

Source

pub fn zeroed( context: &Arc<Context>, width: usize, height: usize, ) -> Result<Self>

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.

Source

pub fn filled( context: &Arc<Context>, width: usize, height: usize, value: u8, ) -> Result<Self>

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.

Source

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.

Source

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.

Source

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.

Source

pub fn context(&self) -> &Arc<Context> ⓘ

Returns the allocation’s retained CUDA context.

Source

pub fn allocation(&self) -> &Arc<DeviceAllocation> ⓘ

Returns the shared owner of the physical allocation, including row padding.

Source

pub fn cast<U: AnyBitPatternDeviceRepr>( self, ) -> StdResult<PitchedDeviceMemory<U>, Self>

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.

Source

pub fn into_uninit(self) -> PitchedDeviceMemory<MaybeUninit<T>>

Erases logical element initialization without changing allocation ownership.

Source

pub const fn width(&self) -> usize

Returns the logical row width in elements.

Source

pub const fn height(&self) -> usize

Returns the logical number of rows.

Source

pub const fn pitch(&self) -> usize

Returns the row stride in bytes.

Source

pub const fn as_ptr(&self) -> *const T

Returns the base device pointer.

Source

pub const fn as_mut_ptr(&mut self) -> *mut T

Returns the mutable base device pointer.

Source

pub const fn as_device_ptr(&self) -> DevicePtr

Returns the base pointer as a CUDA device pointer wrapper.

Source

pub fn len(&self) -> Result<usize>

Returns the logical element count.

§Errors

Returns an error if width * height overflows.

Source

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.

Source

pub fn byte_len(&self) -> Result<usize>

Returns the physical allocation span described by pitch * height.

§Errors

Returns an error if pitch * height overflows.

Source

pub fn is_empty(&self) -> bool

Returns whether any dimension is zero.

Source

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.

Source

pub fn copy_to_host(&self, dst: &mut [T]) -> Result<()>

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.

Source

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.

Source

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.

Source

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.

Source

pub fn copy_to_host_scoped<'env>( &'env self, dst: &'env mut [T], stream: &StreamScope<'_, 'env>, ) -> Result<()>

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.

Source

pub fn set_zeroes(&mut self) -> Result<()>

Fills this pitched allocation with zero bytes.

§Errors

Returns an error if CUDA rejects the 2D memset.

Source

pub fn set_value(&mut self, value: u8) -> Result<()>

Fills this pitched allocation with value bytes.

§Errors

Returns an error if CUDA rejects the 2D memset.

Source

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.

Source

pub fn set_value_scoped<'env>( &'env mut self, value: u8, stream: &StreamScope<'_, 'env>, ) -> Result<()>

Enqueues a byte fill of this pitched allocation on stream.

§Errors

Returns an error if CUDA cannot enqueue the 2D memset.

Source

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.

Source

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

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Debug + DeviceRepr> Debug for PitchedDeviceMemory<T>

Source§

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

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

impl<T: DeviceRepr> DeviceRegionProvider for PitchedDeviceMemory<T>

Source§

fn region(&self) -> DeviceRegion<'_>

Borrows the exact allocation range described by this provider’s pointers.
Source§

impl<T: DeviceRepr + Send> Send for PitchedDeviceMemory<T>

Source§

impl<T: DeviceRepr + Sync> Sync for PitchedDeviceMemory<T>

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.