| Crates.io | feagi-npu-runtime |
| lib.rs | feagi-npu-runtime |
| version | 0.0.1-beta.4 |
| created_at | 2025-12-23 22:53:08.46245+00 |
| updated_at | 2026-01-25 21:43:48.386778+00 |
| description | Runtime abstraction traits and implementations for FEAGI neural processing across platforms |
| homepage | https://feagi.org |
| repository | https://github.com/feagi/feagi-core |
| max_upload_size | |
| id | 2002501 |
| size | 109,946 |
Runtime abstraction traits for cross-platform FEAGI neural processing
Part of FEAGI - Framework for Evolutionary AGI
feagi-runtime defines the trait abstraction layer that enables FEAGI's burst engine to run on different platforms without code changes.
This crate contains ONLY trait definitions - no concrete implementations.
| Runtime | Platform | Storage | Target |
|---|---|---|---|
feagi-runtime-std |
Desktop/Server | Vec<T> (dynamic) |
x86_64, ARM64 |
feagi-runtime-embedded |
ESP32, Arduino, STM32 | [T; N] (fixed) |
Embedded |
feagi-runtime-cuda |
NVIDIA GPU | CudaSlice<T> (GPU VRAM) |
CUDA |
feagi-runtime-wasm |
Browser | Float32Array (typed) |
WASM |
Defines platform capabilities and creates storage:
pub trait Runtime: Send + Sync {
type NeuronStorage<T: NeuralValue>: NeuronStorage<Value = T>;
type SynapseStorage: SynapseStorage;
fn create_neuron_storage<T: NeuralValue>(&self, capacity: usize) -> Result<Self::NeuronStorage<T>>;
fn create_synapse_storage(&self, capacity: usize) -> Result<Self::SynapseStorage>;
fn supports_parallel(&self) -> bool;
fn memory_limit(&self) -> Option<usize>;
}
Abstracts System-of-Arrays (SoA) for neurons:
pub trait NeuronStorage: Send + Sync {
type Value: NeuralValue;
fn membrane_potentials(&self) -> &[Self::Value];
fn thresholds(&self) -> &[Self::Value];
fn leak_coefficients(&self) -> &[f32];
// ... 20+ properties
fn add_neuron(&mut self, /* ... */) -> Result<usize>;
fn add_neurons_batch(&mut self, /* ... */) -> Result<Vec<usize>>;
}
Abstracts System-of-Arrays (SoA) for synapses:
pub trait SynapseStorage: Send + Sync {
fn source_neurons(&self) -> &[u32];
fn target_neurons(&self) -> &[u32];
fn weights(&self) -> &[u8];
// ... other properties
fn add_synapse(&mut self, /* ... */) -> Result<usize>;
}
Implement these traits for your platform:
use feagi_runtime::{Runtime, NeuronStorage, SynapseStorage};
// Your platform-specific storage
pub struct MyNeuronArray<T: NeuralValue> {
membrane_potentials: MyPlatformVector<T>,
// ...
}
impl<T: NeuralValue> NeuronStorage for MyNeuronArray<T> {
type Value = T;
fn membrane_potentials(&self) -> &[T] {
self.membrane_potentials.as_slice()
}
// ... implement all required methods
}
// Your runtime
pub struct MyRuntime;
impl Runtime for MyRuntime {
type NeuronStorage<T: NeuralValue> = MyNeuronArray<T>;
type SynapseStorage = MySynapseArray;
fn create_neuron_storage<T: NeuralValue>(&self, capacity: usize) -> Result<Self::NeuronStorage<T>> {
Ok(MyNeuronArray::new(capacity))
}
fn supports_parallel(&self) -> bool { true }
fn memory_limit(&self) -> Option<usize> { Some(1024 * 1024) }
}
Use concrete runtime implementations:
use feagi_runtime_std::StdRuntime;
use feagi_burst_engine::RustNPU;
use std::sync::Arc;
// Desktop runtime
let runtime = Arc::new(StdRuntime);
let npu = RustNPU::new(runtime, 1_000_000, 10_000_000)?;
npu.process_burst()?;
Traits compile to direct function calls (monomorphization):
// Generic code
fn process<R: Runtime>(runtime: &R) {
let storage = runtime.create_neuron_storage(1000)?;
// ... uses storage
}
// Compiles to platform-specific code (no vtables)
process(&StdRuntime); // → Vec-based code
process(&EmbeddedRuntime); // → array-based code
Same burst processing code works everywhere:
// feagi-burst-engine works with any Runtime
pub struct RustNPU<R: Runtime, T: NeuralValue> {
neuron_storage: RwLock<R::NeuronStorage<T>>,
synapse_storage: RwLock<R::SynapseStorage>,
runtime: Arc<R>,
}
// Used on desktop
let desktop_npu = RustNPU::<StdRuntime, f32>::new(/*...*/);
// Same code, different platform
let embedded_npu = RustNPU::<EmbeddedRuntime, f32>::new(/*...*/);
Compile-time guarantees for platform compatibility:
// This won't compile - embedded runtime has fixed capacity
let embedded = EmbeddedRuntime;
embedded.create_neuron_storage(1_000_000)?; // ❌ Compile error
// This is correct
const MAX_NEURONS: usize = 10_000;
embedded.create_neuron_storage(MAX_NEURONS)?; // ✅ OK
All implementations MUST guarantee:
count() (not capacity())add_neuron() increments count()[x0, y0, z0, x1, y1, z1, ...]All implementations MUST guarantee:
count()source_neurons[i] and target_neurons[i] are valid neuron IDsTrait contracts are tested in each runtime implementation:
# Test std runtime
cd feagi-runtime-std && cargo test
# Test embedded runtime
cd feagi-runtime-embedded && cargo test
# Test CUDA runtime
cd feagi-runtime-cuda && cargo test
| Crate | Purpose |
|---|---|
feagi-runtime (this crate) |
Trait definitions |
feagi-runtime-std |
Desktop/server implementation |
feagi-runtime-embedded |
ESP32/embedded implementation |
feagi-runtime-cuda |
NVIDIA GPU implementation |
feagi-runtime-wasm |
Browser/WASM implementation |
feagi-burst-engine |
Uses Runtime trait |
When implementing a new runtime:
feagi-runtime-{platform}NeuronStorage traitSynapseStorage traitRuntime traitNew runtime implementations welcome! See CONTRIBUTING.md
Platforms we'd love to support:
Licensed under Apache License 2.0
Copyright © 2025 Neuraville Inc.