pub struct Executor { /* private fields */ }Expand description
Executes a graph against a model and mutable runtime state.
Implementations§
Source§impl Executor
impl Executor
Sourcepub fn new(
model: Arc<ModelLoader>,
graph: Graph,
device: Device,
trace_enabled: bool,
timer_enabled: bool,
) -> Result<Self>
pub fn new( model: Arc<ModelLoader>, graph: Graph, device: Device, trace_enabled: bool, timer_enabled: bool, ) -> Result<Self>
Create a new executor for a graph/model/device configuration.
Sourcepub fn insert_dynamic<T: Into<TensorValue>>(
&mut self,
name: &str,
data: T,
) -> Result<()>
pub fn insert_dynamic<T: Into<TensorValue>>( &mut self, name: &str, data: T, ) -> Result<()>
Insert a dynamic (runtime-provided) tensor value.
§Example
let model = ModelLoader::open("model.oinf")?;
let g = graph! { dynamic { x: f32[1]; } block entry { return; } };
let mut exec = Simulator::new(&model, &g, Device::Cpu)?.make_executor()?;
exec.insert_dynamic("x", Tensor::from_vec(vec![1.0f32])?)?;Sourcepub fn fetch<T: Fetchable>(&mut self, name: &str) -> Result<T>
pub fn fetch<T: Fetchable>(&mut self, name: &str) -> Result<T>
Fetch a named value using a Fetchable adapter.
§Example
let model = ModelLoader::open("model.oinf")?;
let g = graph! { constant { alpha: f32; } block entry { return; } };
let mut exec = Simulator::new(&model, &g, Device::Cpu)?.make_executor()?;
let alpha: f32 = exec.fetch("alpha")?;Sourcepub fn fetch_typed<T: TensorElement>(&mut self, name: &str) -> Result<Tensor<T>>
pub fn fetch_typed<T: TensorElement>(&mut self, name: &str) -> Result<Tensor<T>>
Fetch a tensor and convert it to a concrete element type.
Sourcepub fn fetch_raw(&mut self, name: &str) -> Result<TensorValue>
pub fn fetch_raw(&mut self, name: &str) -> Result<TensorValue>
Fetch a tensor as a raw TensorValue.
Sourcepub fn step(&mut self) -> Result<Option<TraceEvent>>
pub fn step(&mut self) -> Result<Option<TraceEvent>>
Execute the graph to completion, returning the last trace event.
§Example
let model = ModelLoader::open("model.oinf")?;
let g = graph! { block entry { return; } };
let mut exec = Simulator::new(&model, &g, Device::Cpu)?.make_executor()?;
exec.step()?;Sourcepub fn trace(&self) -> Vec<TraceEvent>
pub fn trace(&self) -> Vec<TraceEvent>
Return the accumulated trace events.
Sourcepub fn iterate(&mut self) -> ExecutorIter<'_>
pub fn iterate(&mut self) -> ExecutorIter<'_>
Iterate execution step-by-step, yielding TraceStep values.
§Example
let model = ModelLoader::open("model.oinf")?;
let g = graph! { block entry { return; } };
let mut exec = Simulator::new(&model, &g, Device::Cpu)?.make_executor()?;
for step in exec.iterate() {
let _ = step?;
}Auto Trait Implementations§
impl Freeze for Executor
impl RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnwindSafe for Executor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more