Skip to main content

neural_network/
loader.rs

1//! Dynamic model loader interface.
2use crate::{Backend, ModelBuffer, ModelEncoding};
3use file_system::Result;
4
5/// Lower-half interface for backends capable of dynamic model loading at runtime.
6///
7/// An implementation of `Loader` is mounted as a VFS device (e.g. `/devices/nn/cpu`).
8/// Guest applications open the node, write the model bytes sequentially, and send
9/// the `LOAD` control command to instantiate a [`Backend`].
10pub trait Loader: Send + Sync + 'static {
11    /// The concrete backend produced by this loader.
12    type Backend: Backend;
13
14    /// Parse, verify, and instantiate an inference backend from an owned aligned model buffer.
15    fn load(&self, encoding: ModelEncoding, model: ModelBuffer) -> Result<Self::Backend>;
16
17    /// Maximum model size in bytes accepted by this loader.
18    ///
19    /// Writes beyond this bound return [`file_system::IoErrorKind::FileTooLarge`].
20    fn maximum_model_size(&self) -> usize;
21}