Crate grafos_tensor

Crate grafos_tensor 

Source
Expand description

grafos-tensor – Tensor operations backed by leased fabric memory.

This crate provides FabricTensor, an N-dimensional tensor whose data is stored as contiguous row-major f32 values backed by fabric memory acquired through FBMU (Fabric Bootstrap Memory Unit) leases. Every constructor validates that the fabric has sufficient capacity before allocating, and holds the lease for the lifetime of the tensor.

§Supported operations

OperationMethodConstraints
Matrix multiplyFabricTensor::matmulBoth 2-D; inner dims match
Elementwise addFabricTensor::addSame shape
Elementwise mulFabricTensor::mulSame shape
Scalar multiplyFabricTensor::scaleAny shape
ReLUFabricTensor::reluAny shape
SoftmaxFabricTensor::softmaxaxis < ndim
SubtractFabricTensor::subtractSame shape
Sum axisFabricTensor::sum_axisaxis < ndim
SigmoidFabricTensor::sigmoidAny shape
Natural logFabricTensor::lnAny shape
ClampFabricTensor::clipAny shape
TransposeFabricTensor::transposendim >= 2
ReshapeFabricTensor::reshapeSame total elements

Placement helpers:

With gpu feature enabled, operations on GPU-placed tensors dispatch through the v1 fabricbios_gpu_v1 session surface — specifically a private submit_signal_kernel helper that opens a transient grafos_std::gpu::GpuSession on the tensor’s held GpuLease, module_loads the kernel binary, launches with [1,1,1] grid/block dims, syncs, and lets the session/module drop (RAII). Numerical outputs are still computed on the CPU path; GPU dispatch is control-path signaling only under the current mock kernels. See docs/grafos-tensor-guide.md for the full programming model.

Operator overloading is provided for &FabricTensor: + (elementwise add), * (elementwise mul), and * f32 (scalar mul).

§Quick start

use grafos_tensor::FabricTensor;

let a = FabricTensor::from_slice(&[2, 3], &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).unwrap();
let b = FabricTensor::from_slice(&[3, 2], &[7.0, 8.0, 9.0, 10.0, 11.0, 12.0]).unwrap();
let c = a.matmul(&b).unwrap();
assert_eq!(c.shape(), &[2, 2]);
assert_eq!(c.get(&[0, 0]).unwrap(), 58.0);

§Operator overloading

use grafos_tensor::FabricTensor;

let a = FabricTensor::from_slice(&[3], &[1.0, 2.0, 3.0]).unwrap();
let b = FabricTensor::from_slice(&[3], &[4.0, 5.0, 6.0]).unwrap();

let sum = (&a + &b).unwrap();        // elementwise add
let prod = (&a * &b).unwrap();       // elementwise mul
let scaled = (&a * 2.0f32).unwrap(); // scalar mul

§Testing

On native targets, initialize the mock FBMU backend before creating tensors:

grafos_std::host::reset_mock();
grafos_std::host::mock_set_fbmu_arena_size(1 << 20); // 1 MiB

Structs§

FabricTensor
N-dimensional tensor backed by a fabric memory lease.
Shape
Shape metadata for an N-dimensional tensor.

Enums§

Device
Placement of tensor data in the fabric.

Type Aliases§

Result
Result alias using FabricError.