Skip to main content

CpuBackend

Struct CpuBackend 

Source
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

Source

pub fn new() -> Self

Construct a fresh backend.

Source

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.

Source

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

Source§

fn as_any(&self) -> &dyn Any

Downcast view - immutable.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Downcast view - mutable.
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.

Source§

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

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§

type Tensor = CpuTensor

Native tensor representation.
Source§

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

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>

Element-wise a - b with NumPy broadcasting.
Source§

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>

Element-wise a / b with NumPy broadcasting.
Source§

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>

Element-wise absolute value.
Source§

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>

Element-wise a ** b with NumPy broadcasting.
Source§

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>

Element-wise natural logarithm.
Source§

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>

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>

Mean-reduce a along axes.
Source§

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>

Min-reduce a along axes.
Source§

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>

Transpose axes. Empty perm reverses all dims.
Source§

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>

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>

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>

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>

Insert dimensions of size 1 at the given axes.
Source§

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>

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>

Element-wise a == b. Result is boolean-typed.
Source§

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>

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>

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>

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>

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>

Dispatch a BackendSubgraph carrier — the engine-facing entry point for whole-subgraph execution. Read more
Source§

impl BackendRuntime for CpuBackend

Source§

type Error = OpError

Backend-impl-specific error type.
Source§

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

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

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>

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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl ConcreteComponent for CpuBackend

Source§

const TYPE_NAME: &'static str = "bytesandbrains::backends::cpu::CpuBackend"

Stable identifier. Convention: <crate>::<TypeName>.
Source§

const PACKAGE: ComponentPackage = ComponentPackage::Framework

Origin tag; defaults to Application.
Source§

type Config = ()

Per-deployment config. Use () for stateless concretes.
Source§

type Error = Infallible

Error from Self::new; use Infallible if construction can’t fail.
Source§

fn new(_config: &Self::Config) -> Result<Self, Self::Error>

Construct from &Self::Config. Install calls this once per slot.
Source§

fn serialize(&self) -> Vec<u8>

Serialize state to bytes, including config-derived fields.
Source§

fn restore(bytes: &[u8]) -> Result<Self, RestoreError>

Reconstruct from serialize output.
Source§

const DEPENDENCIES: &'static [DependencyDecl] = _

Sibling components this depends on. Populated by the bb::Concrete derive from #[bb::depends(...)].
Source§

impl Debug for CpuBackend

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CpuBackend

Source§

fn default() -> CpuBackend

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CpuBackend

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CpuBackend

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedComponent for T
where T: Any + Send + Sync,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SlotValue for T

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcast surface — recover the concrete type.
Source§

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>

Polymorphic clone preserving the concrete type.
Source§

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

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

Runtime TypeNode for this value. Returns the leaf registered via [register_type_node!] or TYPE_ANY. Consulted at wire boundaries + TypeSolver seeding; the atomic-dispatch hot path uses compile-time-stamped closures.
Source§

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!].
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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