mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-09-16 15:08:27 +00:00
Start ML Coordinator.
Create some common data types and a fake executive. The fake executive can either return an error (emulating execution failing) or a slice of memory (emulating a correct result). Change-Id: Id57f3ea3ee8db64b8921bf7446bcdf143d0daf49 GitOrigin-RevId: e266431d90864c0cd15567221acfa28a02c85a63
This commit is contained in:
committed by
Sam Leffler
parent
31401be481
commit
7e8c603b43
6
apps/system/components/MlCoordinator/Cargo.toml
Normal file
6
apps/system/components/MlCoordinator/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"fake-executive",
|
||||
"ml-common"
|
||||
]
|
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "fake-executive"
|
||||
version = "0.1.0"
|
||||
authors = ["Adam Jesionowski <jesionowski@google.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
ml-common = { path = "../ml-common" }
|
@@ -0,0 +1,44 @@
|
||||
use ml_common as ml;
|
||||
use ml_common::ExecutiveInterface;
|
||||
|
||||
pub struct FakeExecutive {
|
||||
output_memory: [u8; 512],
|
||||
fake_error: Option<ml::ExecutionError>,
|
||||
}
|
||||
|
||||
impl ml::ExecutiveInterface for FakeExecutive {
|
||||
fn run_model(&self, _model: &ml::Model) -> Result<&[u8], ml::ExecutionError> {
|
||||
match self.fake_error {
|
||||
Some(err) => Err(err),
|
||||
None => Ok(&self.output_memory),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_ok() {
|
||||
let exec = FakeExecutive {
|
||||
output_memory: [0xAD; 512],
|
||||
fake_error: None,
|
||||
};
|
||||
let model = ml::Model {
|
||||
output_activations_len: 512,
|
||||
};
|
||||
|
||||
let res = exec.run_model(&model);
|
||||
assert!(res.is_ok());
|
||||
assert_eq!(res.unwrap()[0], 0xAD)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_err() {
|
||||
let exec = FakeExecutive {
|
||||
output_memory: [0; 512],
|
||||
fake_error: Some(ml::ExecutionError::CoreReset),
|
||||
};
|
||||
let model = ml::Model {
|
||||
output_activations_len: 512,
|
||||
};
|
||||
|
||||
assert!(exec.run_model(&model).is_err());
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
[package]
|
||||
name = "ml-common"
|
||||
version = "0.1.0"
|
||||
authors = ["Adam Jesionowski <jesionowski@google.com>"]
|
||||
edition = "2018"
|
17
apps/system/components/MlCoordinator/ml-common/src/lib.rs
Normal file
17
apps/system/components/MlCoordinator/ml-common/src/lib.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
// TODO(jesionowski): What are the actual errors we may encounter?
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum ExecutionError {
|
||||
InvalidInstruction,
|
||||
InvalidFetch,
|
||||
CoreReset
|
||||
}
|
||||
|
||||
// The abstraction layer over the "hardware" of running an execution.
|
||||
// Returns a slice of bytes, which is the output data, or an ExecutionError.
|
||||
pub trait ExecutiveInterface {
|
||||
fn run_model(&self, model: &Model) -> Result<&[u8], ExecutionError>;
|
||||
}
|
||||
|
||||
pub struct Model {
|
||||
pub output_activations_len: usize,
|
||||
}
|
Reference in New Issue
Block a user