pub struct CpuBackend;Expand description
Reference CPU backend. Dispatches its opset onto ndarray
kernels; storage is ArrayD<f32> end-to-end.
Implementations§
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn alloc_tensor(&self, shape: Vec<i64>) -> CpuTensor
pub fn alloc_tensor(&self, shape: Vec<i64>) -> CpuTensor
Allocate a zero-initialised tensor with the given shape. Single allocation seam for future pool / arena strategies.
Sourcepub fn wrap_array(&self, array: ArrayD<f32>) -> CpuTensor
pub fn wrap_array(&self, array: ArrayD<f32>) -> CpuTensor
Wrap a kernel-produced ArrayD<f32> as a CpuTensor.
Single wrapping seam for future pool / arena strategies.
Trait Implementations§
Source§impl AnyComponent for CpuBackend
impl AnyComponent for CpuBackend
Source§impl Backend for CpuBackend
bb::Backend Contract impl. Overrides execute to run through
graph_walker::execute_graph rather than the default per-op
walker.
impl Backend for CpuBackend
bb::Backend Contract impl. Overrides execute to run through
graph_walker::execute_graph rather than the default per-op
walker.
Source§fn materialize_from_wire(
&self,
type_hash: u64,
bytes: Vec<u8>,
) -> Result<Self::Tensor, Self::Error>
fn materialize_from_wire( &self, type_hash: u64, bytes: Vec<u8>, ) -> Result<Self::Tensor, Self::Error>
Decode wire bytes inside the backend so the CpuTensor
carries the ingress byte charge for slot-table release on
overwrite. v1 uses bincode.
Source§type Error = BackendError
type Error = BackendError
Library-maker-defined error type. The
From<BackendWalkError> bound lets the default per-op /
execute_graph_via_per_op walker surface graph-validation
failures as typed errors instead of panicking on
peer-supplied or malformed GraphProto bodies.Source§fn execute(
&self,
graph: &GraphProto,
inputs: HashMap<String, Self::Tensor>,
_attrs: BackendAttrs<'_>,
) -> Result<HashMap<String, Self::Tensor>, Self::Error>
fn execute( &self, graph: &GraphProto, inputs: HashMap<String, Self::Tensor>, _attrs: BackendAttrs<'_>, ) -> Result<HashMap<String, Self::Tensor>, Self::Error>
Execute every NodeProto in
graph.node against the value
env inputs. Returns the subset of values named in
graph.output. Read moreSource§fn add(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn add( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a + b with NumPy broadcasting.Source§fn sub(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn sub( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a - b with NumPy broadcasting.Source§fn mul(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn mul( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a * b with NumPy broadcasting.Source§fn div(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn div( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a / b with NumPy broadcasting.Source§fn neg(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn neg(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Element-wise unary negation.
Source§fn abs(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn abs(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Element-wise absolute value.
Source§fn sqrt(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn sqrt(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Element-wise square root.
Source§fn pow(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn pow( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a ** b with NumPy broadcasting.Source§fn exp(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn exp(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Element-wise natural exponential.
Source§fn log(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn log(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Element-wise natural logarithm.
Source§fn matmul(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn matmul( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Matrix multiplication (NumPy semantics: 2-D × 2-D + batched
higher-rank broadcasting).
Source§fn reduce_sum(
&self,
a: &Self::Tensor,
axes: &[i64],
keepdims: bool,
) -> Result<Self::Tensor, Self::Error>
fn reduce_sum( &self, a: &Self::Tensor, axes: &[i64], keepdims: bool, ) -> Result<Self::Tensor, Self::Error>
Sum-reduce
a along axes. keepdims = true preserves
the reduced dims as length-1.Source§fn reduce_mean(
&self,
a: &Self::Tensor,
axes: &[i64],
keepdims: bool,
) -> Result<Self::Tensor, Self::Error>
fn reduce_mean( &self, a: &Self::Tensor, axes: &[i64], keepdims: bool, ) -> Result<Self::Tensor, Self::Error>
Mean-reduce
a along axes.Source§fn reduce_max(
&self,
a: &Self::Tensor,
axes: &[i64],
keepdims: bool,
) -> Result<Self::Tensor, Self::Error>
fn reduce_max( &self, a: &Self::Tensor, axes: &[i64], keepdims: bool, ) -> Result<Self::Tensor, Self::Error>
Max-reduce
a along axes.Source§fn reduce_min(
&self,
a: &Self::Tensor,
axes: &[i64],
keepdims: bool,
) -> Result<Self::Tensor, Self::Error>
fn reduce_min( &self, a: &Self::Tensor, axes: &[i64], keepdims: bool, ) -> Result<Self::Tensor, Self::Error>
Min-reduce
a along axes.Source§fn reshape(
&self,
a: &Self::Tensor,
shape: &[i64],
) -> Result<Self::Tensor, Self::Error>
fn reshape( &self, a: &Self::Tensor, shape: &[i64], ) -> Result<Self::Tensor, Self::Error>
Reshape
a to the given dims. Total element count must
match.Source§fn transpose(
&self,
a: &Self::Tensor,
perm: &[i64],
) -> Result<Self::Tensor, Self::Error>
fn transpose( &self, a: &Self::Tensor, perm: &[i64], ) -> Result<Self::Tensor, Self::Error>
Transpose axes. Empty
perm reverses all dims.Source§fn concat(
&self,
inputs: &[&Self::Tensor],
axis: i64,
) -> Result<Self::Tensor, Self::Error>
fn concat( &self, inputs: &[&Self::Tensor], axis: i64, ) -> Result<Self::Tensor, Self::Error>
Concatenate
inputs along axis.Source§fn slice(
&self,
a: &Self::Tensor,
starts: &[i64],
ends: &[i64],
axes: &[i64],
steps: &[i64],
) -> Result<Self::Tensor, Self::Error>
fn slice( &self, a: &Self::Tensor, starts: &[i64], ends: &[i64], axes: &[i64], steps: &[i64], ) -> Result<Self::Tensor, Self::Error>
NumPy-style slice. Empty
axes defaults to all dims;
empty steps defaults to 1 per axis.Source§fn split(
&self,
a: &Self::Tensor,
axis: i64,
sizes: &[i64],
) -> Result<Vec<Self::Tensor>, Self::Error>
fn split( &self, a: &Self::Tensor, axis: i64, sizes: &[i64], ) -> Result<Vec<Self::Tensor>, Self::Error>
Split
a along axis into parts of the given sizes.
Empty sizes means equal-sized splits (count comes from
the consumer side downstream).Source§fn squeeze(
&self,
a: &Self::Tensor,
axes: &[i64],
) -> Result<Self::Tensor, Self::Error>
fn squeeze( &self, a: &Self::Tensor, axes: &[i64], ) -> Result<Self::Tensor, Self::Error>
Remove dimensions of size 1. Empty
axes removes all
size-1 dims.Source§fn unsqueeze(
&self,
a: &Self::Tensor,
axes: &[i64],
) -> Result<Self::Tensor, Self::Error>
fn unsqueeze( &self, a: &Self::Tensor, axes: &[i64], ) -> Result<Self::Tensor, Self::Error>
Insert dimensions of size 1 at the given axes.
Source§fn identity(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
fn identity(&self, a: &Self::Tensor) -> Result<Self::Tensor, Self::Error>
Identity / clone — pass-through useful for graph rewrites.
Source§fn cast(
&self,
a: &Self::Tensor,
dtype: i32,
) -> Result<Self::Tensor, Self::Error>
fn cast( &self, a: &Self::Tensor, dtype: i32, ) -> Result<Self::Tensor, Self::Error>
Cast to the given ONNX
DataType enum value (matches
bb_ir::proto::onnx::tensor_proto::DataType).Source§fn equal(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn equal( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a == b. Result is boolean-typed.Source§fn greater(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn greater( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a > b. Result is boolean-typed.Source§fn less(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn less( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise
a < b. Result is boolean-typed.Source§fn where(
&self,
cond: &Self::Tensor,
t: &Self::Tensor,
f: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn where( &self, cond: &Self::Tensor, t: &Self::Tensor, f: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Element-wise ternary:
where cond { t } else { f }.
Named r#where to dodge the reserved Rust keyword.Source§fn constant(&self, value: TensorProto) -> Result<Self::Tensor, Self::Error>
fn constant(&self, value: TensorProto) -> Result<Self::Tensor, Self::Error>
Materialize a constant from an ONNX
TensorProto. The
value attribute on the ONNX Constant op carries the
data; rank, dtype, raw bytes all come from the proto.Source§fn gather(
&self,
data: &Self::Tensor,
indices: &Self::Tensor,
axis: i64,
) -> Result<Self::Tensor, Self::Error>
fn gather( &self, data: &Self::Tensor, indices: &Self::Tensor, axis: i64, ) -> Result<Self::Tensor, Self::Error>
Gather slices of
data along axis indexed by indices.Source§fn dispatch(
&self,
graph: &GraphProto,
inputs: HashMap<String, Self::Tensor>,
attrs: BackendAttrs<'_>,
completion: CompletionHandle<HashMap<String, Self::Tensor>, Self::Error>,
) -> ContractResponse<HashMap<String, Self::Tensor>, Self::Error>
fn dispatch( &self, graph: &GraphProto, inputs: HashMap<String, Self::Tensor>, attrs: BackendAttrs<'_>, completion: CompletionHandle<HashMap<String, Self::Tensor>, Self::Error>, ) -> ContractResponse<HashMap<String, Self::Tensor>, Self::Error>
Dispatch a
BackendSubgraph carrier — the engine-facing entry
point for whole-subgraph execution. Read moreSource§impl BackendRuntime for CpuBackend
impl BackendRuntime for CpuBackend
Source§fn extension_opsets(&self) -> Vec<AtomicOpsetDecl>
fn extension_opsets(&self) -> Vec<AtomicOpsetDecl>
Additional opsets this backend supports beyond
atomic_opset. Default empty - backends that ship pure
ai.onnx v1 need not override. Read moreSource§fn materialize_from_wire(
&self,
type_hash: u64,
bytes: Vec<u8>,
) -> Result<Box<dyn SlotValue>, BackendMaterializeError>
fn materialize_from_wire( &self, type_hash: u64, bytes: Vec<u8>, ) -> Result<Box<dyn SlotValue>, BackendMaterializeError>
Engine-side bridge for
Backend::materialize_from_wire. The
derive forwards (type_hash, bytes) through the user’s
Contract method and re-boxes the typed Self::Tensor into a
[BackendTensorCarrier] wrapped in Box<dyn SlotValue> so
the engine can install it in the slot table without knowing
the backend’s concrete tensor type. Returns
BackendMaterializeError on backend error; the engine
surfaces this as
crate::bus::WireReceiveErrorKind::BackendMaterializeFailed. Read moreSource§fn atomic_opset(&self) -> AtomicOpsetDecl
fn atomic_opset(&self) -> AtomicOpsetDecl
Atomic-op opset this impl owns at minimum -
ai.onnx v1.Source§fn dispatch_atomic(
&mut self,
op_type: &str,
_inputs: &[(&str, &dyn SlotValue)],
_ctx: &mut RuntimeResourceRef<'_>,
) -> Result<DispatchResult, Self::Error>
fn dispatch_atomic( &mut self, op_type: &str, _inputs: &[(&str, &dyn SlotValue)], _ctx: &mut RuntimeResourceRef<'_>, ) -> Result<DispatchResult, Self::Error>
Dispatch a single op or
BackendSubgraph carrier. For
primitive ops (Add, Mul, …) each arm builds a one-node
GraphProto and calls Backend::execute. For the
BackendSubgraph op_type, the embedded GraphProto body
rides on the carrier NodeProto’s "body" attribute and the
derive arm calls Backend::dispatch so user overrides
(caching, async) reach the engine.Source§impl Clone for CpuBackend
impl Clone for CpuBackend
Source§fn clone(&self) -> CpuBackend
fn clone(&self) -> CpuBackend
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl ConcreteComponent for CpuBackend
impl ConcreteComponent for CpuBackend
Source§const TYPE_NAME: &'static str = "bytesandbrains::backends::cpu::CpuBackend"
const TYPE_NAME: &'static str = "bytesandbrains::backends::cpu::CpuBackend"
Stable identifier. Convention:
<crate>::<TypeName>.Source§const PACKAGE: ComponentPackage = ComponentPackage::Framework
const PACKAGE: ComponentPackage = ComponentPackage::Framework
Origin tag; defaults to
Application.Source§type Error = Infallible
type Error = Infallible
Error from
Self::new; use Infallible if construction
can’t fail.Source§fn new(_config: &Self::Config) -> Result<Self, Self::Error>
fn new(_config: &Self::Config) -> Result<Self, Self::Error>
Construct from
&Self::Config. Install calls this once per
slot.Source§const DEPENDENCIES: &'static [DependencyDecl] = _
const DEPENDENCIES: &'static [DependencyDecl] = _
Sibling components this depends on. Populated by the
bb::Concrete derive from #[bb::depends(...)].Source§impl Debug for CpuBackend
impl Debug for CpuBackend
Source§impl Default for CpuBackend
impl Default for CpuBackend
Source§fn default() -> CpuBackend
fn default() -> CpuBackend
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for CpuBackend
impl<'de> Deserialize<'de> for CpuBackend
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for CpuBackend
impl RefUnwindSafe for CpuBackend
impl Send for CpuBackend
impl Sync for CpuBackend
impl Unpin for CpuBackend
impl UnsafeUnpin for CpuBackend
impl UnwindSafe for CpuBackend
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedComponent for T
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>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> SlotValue for T
impl<T> SlotValue for T
Source§fn into_any_boxed(self: Box<T>) -> Box<dyn Any + Sync + Send>
fn into_any_boxed(self: Box<T>) -> Box<dyn Any + Sync + Send>
Repackage
Box<dyn SlotValue> as Box<dyn Any> for
Box::downcast. Required because the SlotValue and
Any vtables are distinct even though SlotValue: Any.Source§fn clone_boxed(&self) -> Box<dyn SlotValue>
fn clone_boxed(&self) -> Box<dyn SlotValue>
Polymorphic clone preserving the concrete type.
Source§fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
Wire-boundary encode (bincode + serde). Local forwarding
uses
clone_boxed instead.Source§fn type_hash(&self) -> u64
fn type_hash(&self) -> u64
Stable cross-Node type discriminator. FNV-1a of
std::any::type_name::<T>(); receiver decodes only on a
matching hash.Source§fn runtime_type(&self) -> &'static TypeNode
fn runtime_type(&self) -> &'static TypeNode
Source§fn charged_bytes(&self) -> usize
fn charged_bytes(&self) -> usize
Bytes the carrier owes against
NodeConfig::ingress_byte_budget. Slot-table eviction calls
this to release the charge. Default 0 — only
ingress-derived carriers register a non-zero resolver via
[register_charged_bytes!].