Skip to main content

TensorStorage

Trait TensorStorage 

Source
pub trait TensorStorage:
    Send
    + Sync
    + Debug {
    // Required methods
    fn data_ptr(&self) -> *const u8;
    fn data_ptr_mut(&mut self) -> *mut u8;
    fn size_bytes(&self) -> usize;
    fn device(&self) -> &Device;
    fn to_device(&self, device: &Device) -> Result<Arc<dyn TensorStorage>>;
    fn clone_storage(&self) -> Arc<dyn TensorStorage> ;

    // Provided method
    fn as_candle_tensor(&self) -> Option<&CandleTensor> { ... }
}
Expand description

Tensor storage trait - abstracts how data is actually stored

Required Methods§

Source

fn data_ptr(&self) -> *const u8

Get raw data pointer (for unsafe operations)

Source

fn data_ptr_mut(&mut self) -> *mut u8

Get mutable data pointer (for unsafe operations)

Source

fn size_bytes(&self) -> usize

Get data size in bytes

Source

fn device(&self) -> &Device

Get device where data is stored

Source

fn to_device(&self, device: &Device) -> Result<Arc<dyn TensorStorage>>

Copy data to another device

Source

fn clone_storage(&self) -> Arc<dyn TensorStorage>

Clone the storage

Provided Methods§

Source

fn as_candle_tensor(&self) -> Option<&CandleTensor>

Try to get the underlying Candle tensor (if this is CandleStorage)

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§