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:
Adam Jesionowski
2021-04-09 15:18:55 -07:00
committed by Sam Leffler
parent 31401be481
commit 7e8c603b43
5 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
[workspace]
members = [
"fake-executive",
"ml-common"
]

View File

@@ -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" }

View File

@@ -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());
}

View File

@@ -0,0 +1,5 @@
[package]
name = "ml-common"
version = "0.1.0"
authors = ["Adam Jesionowski <jesionowski@google.com>"]
edition = "2018"

View 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,
}