1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use std::collections::HashMap;
use anyhow::Error;
use hotg_rune_core::Shape;
use log::Record;
pub(crate) trait Callbacks: Send + Sync + 'static {
fn loaded(&self, _rune: &RuneGraph<'_>) -> Result<(), Error>;
fn read_capability(
&self,
id: u32,
meta: &NodeMetadata,
buffer: &mut [u8],
) -> Result<usize, Error>;
fn write_output(
&self,
id: u32,
meta: &NodeMetadata,
data: &[u8],
) -> Result<(), Error>;
fn load_model(
&self,
id: u32,
meta: &ModelMetadata<'_>,
model: &[u8],
) -> Result<Box<dyn Model>, Error>;
fn get_resource(&self, name: &str) -> Option<&[u8]>;
fn log(&self, _record: &Record<'_>);
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct NodeMetadata {
pub kind: String,
pub arguments: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub(crate) struct RuneGraph<'a> {
pub capabilities: &'a HashMap<u32, NodeMetadata>,
pub outputs: &'a HashMap<u32, NodeMetadata>,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct ModelMetadata<'a> {
pub mimetype: &'a str,
pub inputs: &'a [Shape<'a>],
pub outputs: &'a [Shape<'a>],
}
pub trait Model: Send + Sync + 'static {
fn infer(
&mut self,
inputs: &[&[u8]],
outputs: &mut [&mut [u8]],
) -> Result<(), Error>;
fn input_shapes(&self) -> &[Shape<'_>];
fn output_shapes(&self) -> &[Shape<'_>];
}