Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

Owns a typed contiguous buffer on one device. The boxed DynBackendStorage is the actual byte holder; Storage is a thin wrapper that gives the eager-dispatch op methods (matmul, conv, unary, binary, …) somewhere to live.

Optionally carries a bundle side-table describing how the inner buffer is partitioned into multiple logically independent outputs. See OutputView and the module-level “Multi-output bundles” doc for the contract.

We do not implement Clone because cloning storage may fail on out-of-memory; use Self::try_clone for the fallible version.

Implementations§

Source§

impl Storage

Source

pub fn new<B>(b: B) -> Storage
where B: DynBackendStorage + 'static,

Construct storage from any concrete DynBackendStorage implementor.

This is the backend-agnostic entry point — backends provide a type implementing DynBackendStorage, and Storage::new boxes it. Single-output (no bundle metadata); use Storage::from_dyn_bundled for the multi-output case.

Source

pub fn from_dyn(b: Box<dyn DynBackendStorage>) -> Storage

Wrap an already-boxed dyn DynBackendStorage. Used by callers (notably the quantized fast-paths) that produce a Box<dyn ..> directly from trait dispatch. Single-output; use Storage::from_dyn_bundled for the multi-output case.

Source

pub fn from_dyn_bundled( b: Box<dyn DynBackendStorage>, bundle: Arc<[OutputView]>, ) -> Result<Storage, Error>

Wrap an already-boxed dyn DynBackendStorage together with a per-slot bundle side-table. Used by multi-output op authors: the backend allocates one bundled byte buffer (whose dtype_dyn() is the primary/slot-0 dtype), and the caller attaches the slot metadata here.

Validates at construction time that bundle[0].dtype == inner.dtype_dyn() so callers can trust Storage::dtype() ≡ Storage::primary_dtype() ≡ Storage::slot_dtype(0) on a bundled storage.

Source

pub fn with_bundle(self, bundle: Arc<[OutputView]>) -> Result<Storage, Error>

Attach a bundle side-table to an existing single-output Storage. The dtype check from Storage::from_dyn_bundled applies. Panics in debug_assertions mode if a bundle is already attached — re-bundling silently is a contract bug.

Source

pub fn is_bundled(&self) -> bool

Whether this storage carries multi-output bundle metadata.

Source

pub fn slot_count(&self) -> usize

Number of logical output slots in this storage. 1 for single-output storage; for a bundled storage, the number of OutputView entries.

Source

pub fn bundle(&self) -> Option<&[OutputView]>

Borrow the full bundle slice, or None if this is a single-output storage.

Source

pub fn bundle_arc(&self) -> Option<Arc<[OutputView]>>

Clone the Arc<[OutputView]> handle. Used by Op::View’s realization path: a View’s output storage shares this Arc so the bundle stays alive as long as any view holds a reference.

Source

pub fn slot_view(&self, idx: usize) -> Option<&OutputView>

Per-slot view for idx. Returns None for out-of-range indices or for single-output storage with idx != 0. For single-output storage with idx == 0 this returns None as well — the slot’s dtype/shape live in the (Storage::dtype, caller-supplied Layout) pair, NOT in a synthetic OutputView.

Source

pub fn primary_dtype(&self) -> DType

Primary slot’s dtype — for a bundled storage this is slot 0’s dtype (enforced equal to the inner backend dtype at construction time); for single-output storage this is just the inner dtype. Use Self::slot_dtype when the consumer is talking about a specific bundle slot, not the primary one.

Source

pub fn slot_dtype(&self, idx: usize) -> Option<DType>

Dtype of a specific bundle slot. Returns None for out-of-range indices or for single-output storage. For single-output storage, callers should use Self::dtype directly.

Source

pub fn as_dyn(&self) -> &dyn DynBackendStorage

Borrow the inner storage as a DynBackendStorage trait object.

Backends that need to peel back to their concrete storage type can downcast via storage.as_dyn().as_any().downcast_ref::<MyStorage>().

Source

pub fn as_dyn_mut(&mut self) -> &mut dyn DynBackendStorage

Mutable variant of Self::as_dyn.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: 'static,

Downcast the inner storage to a concrete backend type.

Source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: 'static,

Mutable variant of downcast_ref.

Source

pub fn try_clone(&self, layout: &Layout) -> Result<Storage, Error>

Source

pub fn device(&self) -> Arc<dyn DynBackendDevice> ⓘ

Return an Arc to the owning device as a trait object. fuel-core wraps this in its Device newtype; other consumers (fuel-graph, tests) can use the trait object directly.

Source

pub fn dtype(&self) -> DType

Source

pub fn with_stype(self, stype: SType) -> Storage

Attach an encoding scheme to this storage (consuming builder). Does not touch the bytes or the logical dtype — only describes HOW the bytes are encoded. See fuel_ir::SType.

Source

pub fn stype(&self) -> &SType

The encoding scheme. Empty = plain dense dtype.

Source

pub fn same_device(&self, rhs: &Storage, op: &'static str) -> Result<(), Error>

Pre-G this method consulted Device::same_device for the Metal pointer-identity check; post-G it goes through the DynBackendDevice::same_device_dyn trait method which has the same semantics.

Source

pub fn same_dtype(&self, rhs: &Storage, op: &'static str) -> Result<(), Error>

Source

pub fn const_set(&mut self, v: Scalar, l: &Layout) -> Result<(), Error>

Source

pub fn affine( &self, layout: &Layout, mul: f64, add: f64, ) -> Result<Storage, Error>

Source

pub fn powf(&self, layout: &Layout, e: f64) -> Result<Storage, Error>

Source

pub fn elu(&self, layout: &Layout, alpha: f64) -> Result<Storage, Error>

Source

pub fn cmp( &self, op: CmpOp, rhs: &Storage, lhs_layout: &Layout, rhs_layout: &Layout, ) -> Result<Storage, Error>

Source

pub fn reduce_op( &self, op: ReduceOp, layout: &Layout, reduce_dims: &[usize], ) -> Result<Storage, Error>

Source

pub fn to_dtype(&self, layout: &Layout, dtype: DType) -> Result<Storage, Error>

Source

pub fn to_cpu_storage(&self) -> Result<HostBuffer, Error>

Source

pub fn inplace_op1( &mut self, l: &Layout, c: &dyn InplaceOp1, ) -> Result<(), Error>

Source

pub fn inplace_op2( &mut self, l1: &Layout, t2: &Storage, l2: &Layout, c: &dyn InplaceOp2, ) -> Result<(), Error>

Source

pub fn inplace_op3( &mut self, l1: &Layout, t2: &Storage, l2: &Layout, t3: &Storage, l3: &Layout, c: &dyn InplaceOp3, ) -> Result<(), Error>

Source

pub fn unary_impl<B>(&self, layout: &Layout) -> Result<Storage, Error>
where B: UnaryOpT,

Source

pub fn binary_impl<B>( &self, rhs: &Storage, lhs_layout: &Layout, rhs_layout: &Layout, ) -> Result<Storage, Error>
where B: BinaryOpT,

Source

pub fn conv1d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConv1D, ) -> Result<Storage, Error>

Source

pub fn conv_transpose1d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConvTranspose1D, ) -> Result<Storage, Error>

Source

pub fn conv2d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConv2D, ) -> Result<Storage, Error>

Source

pub fn conv_transpose2d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConvTranspose2D, ) -> Result<Storage, Error>

Source

pub fn avg_pool2d( &self, layout: &Layout, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<Storage, Error>

Source

pub fn max_pool2d( &self, layout: &Layout, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<Storage, Error>

Source

pub fn upsample_nearest1d( &self, layout: &Layout, sz: usize, ) -> Result<Storage, Error>

Source

pub fn upsample_nearest2d( &self, layout: &Layout, h: usize, w: usize, ) -> Result<Storage, Error>

Source

pub fn upsample_bilinear2d( &self, layout: &Layout, h: usize, w: usize, align_corners: bool, scale_h: Option<f64>, scale_w: Option<f64>, ) -> Result<Storage, Error>

Source

pub fn where_cond( &self, layout: &Layout, t: &Storage, layout_t: &Layout, f: &Storage, layout_f: &Layout, ) -> Result<Storage, Error>

Source

pub fn gather( &self, l: &Layout, indexes: &Storage, indexes_l: &Layout, d: usize, ) -> Result<Storage, Error>

Source

pub fn scatter_set( &mut self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<(), Error>

Source

pub fn scatter_add( &mut self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<(), Error>

Source

pub fn index_add( &self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<Storage, Error>

Source

pub fn index_select( &self, rhs: &Storage, lhs_l: &Layout, rhs_l: &Layout, d: usize, ) -> Result<Storage, Error>

Source

pub fn matmul( &self, rhs: &Storage, bmnk: (usize, usize, usize, usize), lhs_layout: &Layout, rhs_layout: &Layout, ) -> Result<Storage, Error>

Source

pub fn copy_strided_src( &self, dst: &mut Storage, dst_offset: usize, src_l: &Layout, ) -> Result<(), Error>

self, the source, can be strided whereas dst is contiguous.

Source

pub fn copy2d( &self, dst: &mut Storage, d1: usize, d2: usize, src_s: usize, dst_s: usize, src_o: usize, dst_o: usize, ) -> Result<(), Error>

Trait Implementations§

Source§

impl Debug for Storage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more