pub struct Buffer { /* private fields */ }Expand description
A buffer that knows where its bytes live.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new_host(shape: Shape, data: Vec<u8>) -> Buffer
pub fn new_host(shape: Shape, data: Vec<u8>) -> Buffer
Create a buffer holding data, tagged as residing on device.
On Cpu this is just storage; on Metal callers will use
to_device to move it into device memory once the runtime
integrates with the arena.
pub fn shape(&self) -> &Shape
pub fn device(&self) -> Device
pub fn dtype(&self) -> DType
pub fn num_elements(&self) -> usize
pub fn byte_size(&self) -> usize
Sourcepub fn as_f32(&self) -> &[f32]
pub fn as_f32(&self) -> &[f32]
Read as &[f32]. Panics if dtype isn’t F32 — explicit type
check (plan #59 spirit: don’t let mismatches go silent).
pub fn as_f32_mut(&mut self) -> &mut [f32]
Sourcepub fn to_device(self, device: Device) -> Buffer
pub fn to_device(self, device: Device) -> Buffer
“Move to device” — explicit transfer call. CPU is a no-op (the bytes are already where they need to be). Metal routes through the backend (TODO: wire to rlx-metal::arena once a caller needs it).
Sourcepub fn to_host(self) -> Buffer
pub fn to_host(self) -> Buffer
“Read back to host” — explicit transfer. CPU no-op; Metal blocks on completion + memcpy back from MTLBuffer (TODO).
Sourcepub fn host_bytes(&self) -> &[u8] ⓘ
pub fn host_bytes(&self) -> &[u8] ⓘ
Raw bytes — host-side access. Panics if the buffer is on a non-host device (would silently read uninitialized host memory otherwise).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnsafeUnpin for Buffer
impl UnwindSafe for Buffer
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
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