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
| Operation | Method | Constraints |
|---|---|---|
| Matrix multiply | FabricTensor::matmul | Both 2-D; inner dims match |
| Elementwise add | FabricTensor::add | Same shape |
| Elementwise mul | FabricTensor::mul | Same shape |
| Scalar multiply | FabricTensor::scale | Any shape |
| ReLU | FabricTensor::relu | Any shape |
| Softmax | FabricTensor::softmax | axis < ndim |
| Subtract | FabricTensor::subtract | Same shape |
| Sum axis | FabricTensor::sum_axis | axis < ndim |
| Sigmoid | FabricTensor::sigmoid | Any shape |
| Natural log | FabricTensor::ln | Any shape |
| Clamp | FabricTensor::clip | Any shape |
| Transpose | FabricTensor::transpose | ndim >= 2 |
| Reshape | FabricTensor::reshape | Same total elements |
Placement helpers:
FabricTensor::to_gpu/FabricTensor::to_cpuFabricTensor::device,FabricTensor::is_cpu,FabricTensor::is_gpu
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 MiBStructs§
- Fabric
Tensor - 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.