Struct tract_core::optim::OptimizerSession
source · pub struct OptimizerSession<'o> { /* private fields */ }Implementations§
source§impl<'o> OptimizerSession<'o>
impl<'o> OptimizerSession<'o>
sourcepub fn optimize(&mut self, model: &mut TypedModel) -> TractResult<()>
pub fn optimize(&mut self, model: &mut TypedModel) -> TractResult<()>
Examples found in repository?
More examples
src/ops/scan/mir.rs (line 69)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
fn declutter_body(
&self,
session: &mut OptimizerSession,
model: &TypedModel,
node: &TypedNode,
) -> TractResult<Option<TypedModelPatch>> {
if !self.decluttered {
let mut new = self.clone();
let mut body = self.body.clone();
session.optimize(&mut body)?;
new.body = body;
new.decluttered = true;
Ok(Some(TypedModelPatch::replace_single_op(model, node, &node.inputs, new)?))
} else {
Ok(None)
}
}sourcepub fn run_all_passes(
&mut self,
i: usize,
model: &mut TypedModel
) -> TractResult<()>
pub fn run_all_passes(
&mut self,
i: usize,
model: &mut TypedModel
) -> TractResult<()>
Examples found in repository?
src/optim/mod.rs (line 94)
89 90 91 92 93 94 95 96 97 98 99 100 101
pub fn optimize(&mut self, model: &mut TypedModel) -> TractResult<()> {
model.check_consistency().context("during optimizer preflight check")?;
model.compact().context("during optimizer preflight compaction")?;
for i in 0.. {
let old = self.counter;
self.run_all_passes(i, model)?;
if old == self.counter {
return Ok(());
}
model.compact()?;
}
unreachable!()
}sourcepub fn run_one_pass_outer(
&mut self,
i: usize,
p: &mut dyn TypedPass,
model: &mut TypedModel
) -> TractResult<()>
pub fn run_one_pass_outer(
&mut self,
i: usize,
p: &mut dyn TypedPass,
model: &mut TypedModel
) -> TractResult<()>
Examples found in repository?
src/optim/mod.rs (line 106)
103 104 105 106 107 108 109 110 111 112 113 114
pub fn run_all_passes(&mut self, i: usize, model: &mut TypedModel) -> TractResult<()> {
let mut passes = self.optimizer.passes.clone();
for p in passes.iter_mut() {
self.run_one_pass_outer(i, p.as_mut(), model)
.with_context(|| format!("running pass {:?}", p))?;
model.compact()?;
model
.check_consistency()
.with_context(|| format!("consistency check after pass {:?}", p))?;
}
Ok(())
}sourcepub fn run_one_pass_inner(
&mut self,
i: usize,
p: &mut dyn TypedPass,
model: &mut TypedModel
) -> TractResult<()>
pub fn run_one_pass_inner(
&mut self,
i: usize,
p: &mut dyn TypedPass,
model: &mut TypedModel
) -> TractResult<()>
Examples found in repository?
src/optim/mod.rs (line 124)
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
pub fn run_one_pass_outer(
&mut self,
i: usize,
p: &mut dyn TypedPass,
model: &mut TypedModel,
) -> TractResult<()> {
loop {
let old_counter = self.counter;
self.run_one_pass_inner(i, p, model)?;
if self.counter == old_counter {
return Ok(());
}
model.compact().with_context(|| format!("after pass {:?}", p))?;
}
}Trait Implementations§
Auto Trait Implementations§
impl<'o> !RefUnwindSafe for OptimizerSession<'o>
impl<'o> Send for OptimizerSession<'o>
impl<'o> Sync for OptimizerSession<'o>
impl<'o> Unpin for OptimizerSession<'o>
impl<'o> !UnwindSafe for OptimizerSession<'o>
Blanket Implementations§
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.