pub struct CpuBuffer { /* private fields */ }Expand description
A properly-aligned CPU heap buffer.
Uses Rust’s global allocator directly to guarantee alignment, which
Vec<u8> cannot guarantee beyond its element alignment (1 byte).
Implementations§
Source§impl CpuBuffer
impl CpuBuffer
Sourcepub fn zeros(numel: usize, dtype: DType) -> Result<Self>
pub fn zeros(numel: usize, dtype: DType) -> Result<Self>
Allocate a zero-initialised buffer for numel elements of dtype.
Sourcepub fn with_capacity(bytes: usize, align: usize) -> Result<Self>
pub fn with_capacity(bytes: usize, align: usize) -> Result<Self>
Allocate bytes bytes with the given alignment.
Sourcepub fn from_f32_slice(data: &[f32]) -> Result<Self>
pub fn from_f32_slice(data: &[f32]) -> Result<Self>
Wrap existing f32 data (copies into a new aligned allocation).
Sourcepub fn from_f32_vec(data: Vec<f32>) -> Result<Self>
pub fn from_f32_vec(data: Vec<f32>) -> Result<Self>
Take ownership of a Vec<f32> without copying.
Eliminates the allocation + memcopy overhead in from_f32_slice.
Used by hot matmul paths that already have a Vec
Sourcepub fn from_bytes_slice(data: &[u8]) -> Result<Self>
pub fn from_bytes_slice(data: &[u8]) -> Result<Self>
Wrap existing raw bytes (e.g., native BF16 or F16 from safetensors).
Sourcepub fn as_f32_slice(&self) -> &[f32]
pub fn as_f32_slice(&self) -> &[f32]
View as f32 slice (panics if not properly aligned/sized).
Sourcepub fn as_f32_slice_mut(&mut self) -> &mut [f32]
pub fn as_f32_slice_mut(&mut self) -> &mut [f32]
Mutable view as f32 slice.
pub fn as_mut_ptr(&mut self) -> *mut u8
Trait Implementations§
Source§impl Buffer for CpuBuffer
impl Buffer for CpuBuffer
Source§fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable raw byte slice (may be unavailable for GPU buffers).
impl Send for CpuBuffer
impl Sync for CpuBuffer
Auto Trait Implementations§
impl Freeze for CpuBuffer
impl RefUnwindSafe for CpuBuffer
impl Unpin for CpuBuffer
impl UnsafeUnpin for CpuBuffer
impl UnwindSafe for CpuBuffer
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
Mutably borrows from an owned value. Read more