Struct tract_libcli::annotations::Annotations
source · pub struct Annotations {
pub tags: HashMap<NodeQId, NodeTags>,
pub profile_summary: Option<ProfileSummary>,
}Fields§
§profile_summary: Option<ProfileSummary>Implementations§
source§impl Annotations
impl Annotations
sourcepub fn node_mut(&mut self, qid: NodeQId) -> &mut NodeTags
pub fn node_mut(&mut self, qid: NodeQId) -> &mut NodeTags
Examples found in repository?
src/profile.rs (line 38)
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
pub fn profile(
model: &TypedModel,
bench_limits: &BenchLimits,
dg: &mut Annotations,
run_params: &RunParams,
) -> TractResult<()> {
info!("Running entire network");
let plan = SimplePlan::new(model)?;
let mut state = SimpleState::new(&plan)?;
let mut iters = 0usize;
let start = Instant::now();
while iters < bench_limits.max_iters && start.elapsed() < bench_limits.max_time {
let input = retrieve_or_make_inputs(model, run_params)?;
let _ =
state.run_plan_with_eval(input[0].clone(), |session_state, state, node, input| {
let start = Instant::now();
let r = tract_core::plan::eval(session_state, state, node, input);
let elapsed = start.elapsed();
*dg.node_mut(NodeQId(tvec!(), node.id))
.profile
.get_or_insert(Duration::default()) += elapsed;
r
})?;
iters += 1;
}
let entire = start.elapsed();
info!("Running {} iterations max. for each node.", bench_limits.max_iters);
info!("Running for {} ms max. for each node.", bench_limits.max_time.as_millis());
for &outer_node in &plan.order {
if let Some(m) = (model as &dyn Model).downcast_ref::<Graph<TypedFact, Box<dyn TypedOp>>>()
{
let outer_node = m.node(outer_node);
let inputs: TVec<TypedFact> = model
.node_input_facts(outer_node.id)?
.iter()
.map(|&i| i.to_typed_fact().map(|f| f.into_owned()))
.collect::<TractResult<_>>()?;
let ref_inputs: TVec<&TypedFact> = inputs.iter().collect();
for ((inner_model_name, inner_model), multiplier) in model
.nested_models(outer_node.id)
.iter()
.zip(model.nested_models_iters(outer_node.id, &ref_inputs).iter())
{
let multi = multiplier.as_ref().unwrap().to_isize().unwrap();
let prefix = tvec!((outer_node.id, inner_model_name.to_string()));
if let Some(inner_model) = inner_model.downcast_ref::<TypedModel>() {
for _ in 0..iters {
let inner_plan = SimplePlan::new(inner_model)?;
let mut state = SimpleState::new(inner_plan)?;
let _ = state.run_plan_with_eval(
make_inputs_for_model(inner_model)?,
|session_state, state, node, input| {
let start = Instant::now();
let r = tract_core::plan::eval(session_state, state, node, input);
let elapsed = start.elapsed().mul_f32(multi as _);
*dg.node_mut(NodeQId(prefix.clone(), node.id))
.profile
.get_or_insert(Duration::default()) += elapsed;
let parent = dg
.node_mut(NodeQId(tvec!(), outer_node.id))
.profile
.get_or_insert(Duration::default());
*parent -= elapsed.min(*parent);
r
},
)?;
}
}
}
}
}
let denum = (iters as f32).recip();
let entire = entire.mul_f32(denum);
for d in dg.tags.values_mut() {
if let Some(d) = d.profile.as_mut() {
*d = d.mul_f32(denum);
}
}
let max = dg.tags.values().filter_map(|t| t.profile).max().unwrap();
let sum = dg.tags.values().filter_map(|t| t.profile).sum::<Duration>();
dg.profile_summary = Some(ProfileSummary { max, sum, entire, iters });
Ok(())
}pub fn track_axes(
&mut self,
model: &dyn Model,
hints: &HashMap<OutletId, TVec<String>>
) -> TractResult<()>
pub fn from_model(model: &dyn Model) -> TractResult<Annotations>
Trait Implementations§
source§impl Clone for Annotations
impl Clone for Annotations
source§fn clone(&self) -> Annotations
fn clone(&self) -> Annotations
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for Annotations
impl Debug for Annotations
source§impl Default for Annotations
impl Default for Annotations
source§fn default() -> Annotations
fn default() -> Annotations
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl RefUnwindSafe for Annotations
impl Send for Annotations
impl Sync for Annotations
impl Unpin for Annotations
impl UnwindSafe for Annotations
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.