Skip to main content

neural_network/
backend.rs

1//! Allocation-neutral contract between the VFS adapter and an inference backend.
2use crate::{QuantizationEntry, TensorInfo};
3use file_system::Result;
4
5/// An immutable prepared model, with independent mutable execution storage per open.
6///
7/// Implementations own model lifetimes, arena allocation and error translation. Input and
8/// output views must refer directly to execution/model storage; the adapter never stages
9/// tensors. Backend selection and model loading belong to the runtime assembly.
10pub trait Backend: Send + Sync + 'static {
11    type Execution: Send + Sync + 'static;
12    type Input<'a>: AsMut<[u8]>
13    where
14        Self: 'a;
15    type Output<'a>: AsRef<[u8]>
16    where
17        Self: 'a;
18
19    fn create_execution(&self) -> Result<Self::Execution>;
20    fn owns_execution(&self, execution: &Self::Execution) -> bool;
21    fn input_count(&self) -> usize;
22    fn output_count(&self) -> usize;
23    fn input_info(&self, index: usize) -> Result<TensorInfo>;
24    fn output_info(&self, index: usize) -> Result<TensorInfo>;
25    fn input_quantization(&self, tensor: usize, entry: usize) -> Result<QuantizationEntry>;
26    fn output_quantization(&self, tensor: usize, entry: usize) -> Result<QuantizationEntry>;
27    fn input<'a>(
28        &self,
29        execution: &'a mut Self::Execution,
30        index: usize,
31    ) -> Result<Self::Input<'a>>;
32    fn output<'a>(&self, execution: &'a Self::Execution, index: usize) -> Result<Self::Output<'a>>;
33    fn compute(&self, execution: &mut Self::Execution) -> Result<()>;
34}