pub struct ErasedRawStridedPtr<'a> { /* private fields */ }Expand description
Pointer-backed dtype-erased input used by one-shot write entry points.
Unlike ErasedRawStridedRef, this descriptor does not create a shared
Rust reference at construction time. That lets the entry point reject an
input/output overlap before forming references to either side.
Implementations§
Source§impl<'a> ErasedRawStridedPtr<'a>
impl<'a> ErasedRawStridedPtr<'a>
Sourcepub unsafe fn from_raw_parts(
dtype: KernelDType,
data: NonNull<u8>,
byte_len: usize,
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<Self>
pub unsafe fn from_raw_parts( dtype: KernelDType, data: NonNull<u8>, byte_len: usize, dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Result<Self>
Create a pointer-backed descriptor from erased storage.
§Safety
data must point into an allocation whose alignment is suitable for
dtype, independently of the observed address. The allocation must
provide byte_len initialized, readable bytes with valid provenance
for 'a, and remain alive for 'a. For bool, the bytes may contain
invalid values temporarily. They must not be read or used to form a
typed reference until a caller has rejected overlap and
Self::try_as_ref_after_no_overlap has validated the complete extent.
The allocation may overlap a destination.
The original owner may perform synchronized sequential mutation through
the same-provenance raw pointer before conversion. No concurrent
mutation or conflicting access is permitted during overlap checking,
conversion, or consumer access.
§Errors
Returns StridedError::ByteLengthMismatch when byte_len is not
a whole number of dtype elements, and
StridedError::DataAlignmentMismatch when a non-empty data is
not aligned for dtype. Returns
StridedError::StrideLengthMismatch when dims and strides
have different lengths, and StridedError::OffsetOverflow when
a reachable offset is not representable: dim - 1 of a non-unit
extent does not fit isize, a stride times that last index or the
accumulated offsets overflow isize or go negative, or the highest
reachable offset is not below the storage length. A layout with a zero
extent skips this check.
Bool bytes are not checked here;
Self::try_as_ref_after_no_overlap does that.
Sourcepub fn from_ref(input: &ErasedRawStridedRef<'a>) -> Self
pub fn from_ref(input: &ErasedRawStridedRef<'a>) -> Self
Borrow a safe erased input as a pointer descriptor.
Sourcepub unsafe fn try_as_ref_after_no_overlap(
&self,
) -> Result<ErasedRawStridedRef<'_>>
pub unsafe fn try_as_ref_after_no_overlap( &self, ) -> Result<ErasedRawStridedRef<'_>>
Convert this pointer to an initialized descriptor after overlap checks.
§Safety
The caller must have proved that no mutable allocation overlaps this
pointer’s complete byte extent.
The allocation contract from Self::from_raw_parts must still hold.
No mutation or other conflicting access may occur during this conversion
or for the duration of the returned descriptor’s consumer access.
Bool bytes are validated here, immediately before typed access.
§Errors
Returns StridedError::InvalidBoolByte when dtype is Bool and
a byte of the extent is neither 0 nor 1. It repeats the extent
length, alignment, stride length and bounds checks
(StridedError::ByteLengthMismatch,
StridedError::DataAlignmentMismatch,
StridedError::StrideLengthMismatch,
StridedError::OffsetOverflow) that Self::from_raw_parts and
Self::from_ref already applied to the same values, so those
cannot fire again here.
pub fn dtype(&self) -> KernelDType
Sourcepub fn overlaps_mut(&self, dest: &ErasedRawStridedMut<'_>) -> Result<bool>
pub fn overlaps_mut(&self, dest: &ErasedRawStridedMut<'_>) -> Result<bool>
Check overlap with initialized mutable storage without reading it.
§Errors
Never returns Err in practice: both byte extents come from valid
descriptors, whose contracts already guarantee an allocation of that
size, so the end-address arithmetic cannot wrap. The Result only
carries that arithmetic’s StridedError::OffsetOverflow.
Sourcepub fn overlaps_uninit_mut(
&self,
dest: &ErasedRawStridedUninitMut<'_>,
) -> Result<bool>
pub fn overlaps_uninit_mut( &self, dest: &ErasedRawStridedUninitMut<'_>, ) -> Result<bool>
Check overlap with uninitialized mutable storage without reading it.
§Errors
Never returns Err in practice: both byte extents come from valid
descriptors, whose contracts already guarantee an allocation of that
size, so the end-address arithmetic cannot wrap. The Result only
carries that arithmetic’s StridedError::OffsetOverflow.