Skip to main content

Buffer

Trait Buffer 

Source
pub trait Buffer:
    Send
    + Sync
    + Debug {
    // Required methods
    fn as_bytes(&self) -> &[u8] ;
    fn as_bytes_mut(&mut self) -> &mut [u8] ;
    fn len(&self) -> usize;
    fn alignment(&self) -> usize;
    fn device(&self) -> &str;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A raw byte buffer backing a tensor.

Implementations may reside on CPU heap, GPU device memory, or shared (unified) memory. The trait is object-safe so backends can return Arc<dyn Buffer>.

Required Methods§

Source

fn as_bytes(&self) -> &[u8]

Returns a raw byte slice over all elements.

Source

fn as_bytes_mut(&mut self) -> &mut [u8]

Returns a mutable raw byte slice (may be unavailable for GPU buffers).

Source

fn len(&self) -> usize

Total capacity in bytes.

Source

fn alignment(&self) -> usize

Alignment used when this buffer was allocated.

Source

fn device(&self) -> &str

Textual description of where the buffer lives (e.g. “cpu”, “metal”).

Provided Methods§

Source

fn is_empty(&self) -> bool

True if the buffer has zero capacity.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§