pub struct CpuTensor(/* private fields */);Expand description
f32-dense CPU-resident tensor handle. Arc-shared so intra-Node
clones (FedAvg’s per-peer buffer insert, slot-table writes, etc.)
are refcount bumps rather than Vec<f32> deep copies. The
underlying CpuBackendBuffer is owned by the backend, which is
free to pool / reuse / free the storage at a later milestone
without API churn (the handle shape stays identical).
Implementations§
Source§impl CpuTensor
impl CpuTensor
Sourcepub fn from_array(data: ArrayD<f32>) -> Self
pub fn from_array(data: ArrayD<f32>) -> Self
Wrap an existing ArrayD<f32> in a fresh backend buffer.
charged_bytes = 0 — kernel outputs and test fixtures don’t
arrive via the wire and therefore don’t hold an ingress
charge. The wire path uses the crate-private
from_wire_buffer helper from CpuBackend::materialize_from_wire.
Sourcepub fn from_vec(shape: Vec<i64>, data: Vec<f32>) -> Self
pub fn from_vec(shape: Vec<i64>, data: Vec<f32>) -> Self
Construct from ONNX-signed shape + flat row-major data via
ndarray::ArrayD::from_shape_vec. Equivalent to
Self::new but spelled out for callers preferring the
builder-style name.
Sourcepub fn into_array(self) -> ArrayD<f32>
pub fn into_array(self) -> ArrayD<f32>
Clone the backend buffer into an owned ArrayD<f32>. The
Arc shape means the buffer cannot be unwrapped in-place
(other handles may share it), so this always pays the
ndarray deep copy. Test-only callers needing flat data
should prefer Self::flat_data.
Sourcepub fn new(dims: Vec<i64>, data: Vec<f32>) -> Self
pub fn new(dims: Vec<i64>, data: Vec<f32>) -> Self
Construct from ONNX-signed shape + flat row-major data.
Panics if the dims product doesn’t match the data length —
callers needing strict checking use Self::new_checked.
Sourcepub fn new_checked(
dims: Vec<i64>,
data: Vec<f32>,
) -> Result<Self, CpuTensorError>
pub fn new_checked( dims: Vec<i64>, data: Vec<f32>, ) -> Result<Self, CpuTensorError>
Construct + validate dims_product(&dims) == data.len().
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Observe the underlying Arc<CpuBackendBuffer> strong-refcount.
One strong holder means the caller holds the only handle to
the buffer; future pooling implementations (v2) read this to
decide whether to return the buffer to the pool on drop. Tests
use this to prove the wire-decode path lands a single carrier
in the slot table with no spurious clones.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CpuTensor
impl<'de> Deserialize<'de> for CpuTensor
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>,
Source§impl Tensor for CpuTensor
impl Tensor for CpuTensor
Source§fn dims(&self) -> &[i64]
fn dims(&self) -> &[i64]
-1
for dynamic dims.Source§fn len(&self) -> usize
fn len(&self) -> usize
Source§fn to_proto(&self) -> TensorProto
fn to_proto(&self) -> TensorProto
TensorProto. The result is
portable across backends declaring the same scalar type.Source§fn from_proto(proto: TensorProto) -> Result<Self, TensorSerializationError>
fn from_proto(proto: TensorProto) -> Result<Self, TensorSerializationError>
TensorProto. Returns an
error if the proto’s elem_type / shape doesn’t match
Self’s expectations.Auto Trait Implementations§
impl Freeze for CpuTensor
impl RefUnwindSafe for CpuTensor
impl Send for CpuTensor
impl Sync for CpuTensor
impl Unpin for CpuTensor
impl UnsafeUnpin for CpuTensor
impl UnwindSafe for CpuTensor
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
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>
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>
Source§fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>
clone_boxed instead.Source§fn type_hash(&self) -> u64
fn type_hash(&self) -> u64
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
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!].