pub struct CpuStorageBytes { /* private fields */ }Expand description
CPU storage holding bytes addressable by Rust pointer.
Cloning is cheap — bumps the inner Arc’s refcount without
copying bytes. Mutating through bytes_mut / as_slice_mut
performs copy-on-write: if the Arc is uniquely held, the bytes
are mutated in place; if shared, the bytes clone before mutation
so other holders see the unchanged data.
Implementations§
Source§impl CpuStorageBytes
impl CpuStorageBytes
Sourcepub fn from_zero_bytes(len_bytes: usize) -> Self
pub fn from_zero_bytes(len_bytes: usize) -> Self
Allocate len_bytes zero-initialized bytes, 64-byte aligned.
Sourcepub fn alloc(byte_count: usize) -> Self
pub fn alloc(byte_count: usize) -> Self
Phase 7.5 A4 substrate alloc. Allocates byte_count zero-
initialized bytes, 64-byte aligned. Synonym for
Self::from_zero_bytes; named alloc for symmetry with
the GPU backend allocators.
Sourcepub fn from_bytes(src: &[u8]) -> Self
pub fn from_bytes(src: &[u8]) -> Self
Allocate a fresh aligned buffer and copy src into it.
Sourcepub fn from_slice<T: Pod>(data: &[T]) -> Self
pub fn from_slice<T: Pod>(data: &[T]) -> Self
Allocate a fresh aligned buffer and copy a typed slice into
it. T must be Pod (Copy + Zeroable + ’static + no
padding); covers every standard ML dtype.
Sourcepub fn align(&self) -> usize
pub fn align(&self) -> usize
Alignment in bytes (always CPU_ALIGN_BYTES).
Sourcepub fn as_slice<T: Pod>(&self) -> Result<&[T]>
pub fn as_slice<T: Pod>(&self) -> Result<&[T]>
Borrow the bytes as a typed slice. Returns Err if the byte
length isn’t a multiple of T’s size or the buffer alignment
can’t satisfy T’s alignment requirement.
Production-correct: no panic. The 64-byte allocation
alignment is sufficient for every Pod type up to and
including u64/f64, so the alignment-check failure path
is unreachable for standard dtypes — but we still surface it
as Result for unusual Pod types (e.g., [u8; 128]).
Sourcepub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
Copy-on-write mutable byte access. If this storage is the
sole holder of its Arc, returns a &mut [u8] into the
existing buffer. If the Arc is shared, clones the bytes
into a fresh Arc first so other holders are unaffected.
Centralized CoW boundary: every mutating call site goes
through here, so callers don’t need to remember to clone
manually. Cost when Arc is unique: one atomic load (no
copy). Cost when shared: one allocation + one memcpy.
Sourcepub fn as_slice_mut<T: Pod>(&mut self) -> Result<&mut [T]>
pub fn as_slice_mut<T: Pod>(&mut self) -> Result<&mut [T]>
Copy-on-write typed mutable view. Same CoW semantics as
bytes_mut; returns Err on a bytemuck cast failure.
Sourcepub fn is_uniquely_owned(&self) -> bool
pub fn is_uniquely_owned(&self) -> bool
Whether this storage’s bytes are uniquely owned (no other
CpuStorageBytes shares the same Arc). Useful for tests and
for reasoning about CoW behavior.
Trait Implementations§
Source§impl BackendStorage for CpuStorageBytes
impl BackendStorage for CpuStorageBytes
Source§impl Clone for CpuStorageBytes
impl Clone for CpuStorageBytes
Auto Trait Implementations§
impl Freeze for CpuStorageBytes
impl RefUnwindSafe for CpuStorageBytes
impl Send for CpuStorageBytes
impl Sync for CpuStorageBytes
impl Unpin for CpuStorageBytes
impl UnsafeUnpin for CpuStorageBytes
impl UnwindSafe for CpuStorageBytes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more