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
impl Storage
Sourcepub fn new<B>(b: B) -> Storagewhere
B: DynBackendStorage + 'static,
pub fn new<B>(b: B) -> Storagewhere
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.
Sourcepub fn from_dyn(b: Box<dyn DynBackendStorage>) -> Storage
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.
Sourcepub fn from_dyn_bundled(
b: Box<dyn DynBackendStorage>,
bundle: Arc<[OutputView]>,
) -> Result<Storage, Error>
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.
Sourcepub fn with_bundle(self, bundle: Arc<[OutputView]>) -> Result<Storage, Error>
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.
Sourcepub fn is_bundled(&self) -> bool
pub fn is_bundled(&self) -> bool
Whether this storage carries multi-output bundle metadata.
Sourcepub fn slot_count(&self) -> usize
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.
Sourcepub fn bundle(&self) -> Option<&[OutputView]>
pub fn bundle(&self) -> Option<&[OutputView]>
Borrow the full bundle slice, or None if this is a
single-output storage.
Sourcepub fn bundle_arc(&self) -> Option<Arc<[OutputView]>>
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.
Sourcepub fn slot_view(&self, idx: usize) -> Option<&OutputView>
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.
Sourcepub fn primary_dtype(&self) -> DType
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.
Sourcepub fn slot_dtype(&self, idx: usize) -> Option<DType>
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.
Sourcepub fn as_dyn(&self) -> &dyn DynBackendStorage
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>().
Sourcepub fn as_dyn_mut(&mut self) -> &mut dyn DynBackendStorage
pub fn as_dyn_mut(&mut self) -> &mut dyn DynBackendStorage
Mutable variant of Self::as_dyn.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: 'static,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: 'static,
Downcast the inner storage to a concrete backend type.
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: 'static,
Mutable variant of downcast_ref.
pub fn try_clone(&self, layout: &Layout) -> Result<Storage, Error>
Sourcepub fn device(&self) -> Arc<dyn DynBackendDevice> ⓘ
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.
pub fn dtype(&self) -> DType
Sourcepub fn with_stype(self, stype: SType) -> Storage
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.
Sourcepub fn same_device(&self, rhs: &Storage, op: &'static str) -> Result<(), Error>
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.
pub fn same_dtype(&self, rhs: &Storage, op: &'static str) -> Result<(), Error>
pub fn const_set(&mut self, v: Scalar, l: &Layout) -> Result<(), Error>
pub fn affine( &self, layout: &Layout, mul: f64, add: f64, ) -> Result<Storage, Error>
pub fn powf(&self, layout: &Layout, e: f64) -> Result<Storage, Error>
pub fn elu(&self, layout: &Layout, alpha: f64) -> Result<Storage, Error>
pub fn cmp( &self, op: CmpOp, rhs: &Storage, lhs_layout: &Layout, rhs_layout: &Layout, ) -> Result<Storage, Error>
pub fn reduce_op( &self, op: ReduceOp, layout: &Layout, reduce_dims: &[usize], ) -> Result<Storage, Error>
pub fn to_dtype(&self, layout: &Layout, dtype: DType) -> Result<Storage, Error>
pub fn to_cpu_storage(&self) -> Result<HostBuffer, Error>
pub fn unary_impl<B>(&self, layout: &Layout) -> Result<Storage, Error>where
B: UnaryOpT,
pub fn binary_impl<B>(
&self,
rhs: &Storage,
lhs_layout: &Layout,
rhs_layout: &Layout,
) -> Result<Storage, Error>where
B: BinaryOpT,
pub fn conv1d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConv1D, ) -> Result<Storage, Error>
pub fn conv_transpose1d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConvTranspose1D, ) -> Result<Storage, Error>
pub fn conv2d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConv2D, ) -> Result<Storage, Error>
pub fn conv_transpose2d( &self, l: &Layout, kernel: &Storage, kernel_l: &Layout, params: &ParamsConvTranspose2D, ) -> Result<Storage, Error>
pub fn avg_pool2d( &self, layout: &Layout, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<Storage, Error>
pub fn max_pool2d( &self, layout: &Layout, kernel_size: (usize, usize), stride: (usize, usize), ) -> Result<Storage, Error>
pub fn upsample_nearest1d( &self, layout: &Layout, sz: usize, ) -> Result<Storage, Error>
pub fn upsample_nearest2d( &self, layout: &Layout, h: usize, w: usize, ) -> Result<Storage, Error>
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>
pub fn where_cond( &self, layout: &Layout, t: &Storage, layout_t: &Layout, f: &Storage, layout_f: &Layout, ) -> Result<Storage, Error>
pub fn gather( &self, l: &Layout, indexes: &Storage, indexes_l: &Layout, d: usize, ) -> Result<Storage, Error>
pub fn scatter_set( &mut self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<(), Error>
pub fn scatter_add( &mut self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<(), Error>
pub fn index_add( &self, l: &Layout, indexes: &Storage, indexes_l: &Layout, source: &Storage, source_l: &Layout, d: usize, ) -> Result<Storage, Error>
pub fn index_select( &self, rhs: &Storage, lhs_l: &Layout, rhs_l: &Layout, d: usize, ) -> Result<Storage, Error>
pub fn matmul( &self, rhs: &Storage, bmnk: (usize, usize, usize, usize), lhs_layout: &Layout, rhs_layout: &Layout, ) -> Result<Storage, Error>
Sourcepub fn copy_strided_src(
&self,
dst: &mut Storage,
dst_offset: usize,
src_l: &Layout,
) -> Result<(), Error>
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.
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Storage
impl !UnwindSafe for Storage
impl Forget for Storage
impl Freeze for Storagewhere
*const dyn DynBackendStorage is !null: Freeze,
PhantomData<dyn DynBackendStorage>: Freeze,
*const ArcInner<[OutputView]> is !null: Freeze,
PhantomData<ArcInner<[OutputView]>>: Freeze,
*const u32 is !null: Freeze,
PhantomData<u32>: Freeze,
*const Encoding is !null: Freeze,
PhantomData<Encoding>: Freeze,
impl Move for Storage
impl Send for Storage
impl Sync for Storagewhere
BoxRaw<dyn DynBackendStorage>: Sync,
Arc<[OutputView]>: Sync,
SmallVecData<[Encoding; 1]>: Sync,
Encoding: Sync,
impl Unpin for Storage
impl UnsafeUnpin for Storagewhere
*const dyn DynBackendStorage is !null: UnsafeUnpin,
PhantomData<dyn DynBackendStorage>: UnsafeUnpin,
*const ArcInner<[OutputView]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[OutputView]>>: UnsafeUnpin,
*const u32 is !null: UnsafeUnpin,
PhantomData<u32>: UnsafeUnpin,
*const Encoding is !null: UnsafeUnpin,
PhantomData<Encoding>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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