pub fn handle_t<TI: TensorInfo>(
    model: &Model<TI>,
    params: &Parameters,
    profiling: ProfilingMode,
    mut display_options: DisplayOptions,
) -> CliResult<()> {
    let (max_iters, max_time) = if let ProfilingMode::Regular { max_iters, max_time } = profiling {
        (max_iters, max_time)
    } else {
        bail!("Expecting regular profile mode")
    };

    info!("Running entire network");
    let plan = SimplePlan::new(model)?;
    let mut iters = 0;
    let start = Instant::now();
    while iters < max_iters && start.elapsed_real() < (max_time as f64 * 1e-3) {
        let _ = plan.run(make_inputs_for_model(model)?)?;
        iters += 1;
    }
    let entire = Duration::since(&start, iters);

    info!("Running {} iterations max. for each node.", max_iters);
    info!("Running for {} ms max. for each node.", max_time);

    let mut state = SimpleState::new(&plan)?;
    state.set_inputs(make_inputs_for_model(model)?)?;
    debug!("Using execution plan: {:?}", plan);

    let mut profile = ProfileData::default();
    let mut progress = ProgressBar::new(plan.order.len() as u64);

    if log_enabled!(Info) {
        println!();
        print_header(format!("Profiling for {}:", params.name), &White.normal());
    }

    // Then execute the plan while profiling each step.
    for &n in &plan.order {
        let node = &model.nodes()[n];

        if atty::is(atty::Stream::Stdout) {
            progress.inc();
        }

        if node.op.name() == "Source" {
            if log_enabled!(Info) {
                print_node(
                    &node,
                    &params.graph,
                    Some(&state),
                    &[Yellow.paint("SKIP").to_string()],
                    vec![],
                );
            }

            continue;
        }

        if !display_options.filter(model, node)? {
            continue;
        }
        state.compute_recursively(n)?;

        let mut iters = 0;
        let start = Instant::now();

        while iters < max_iters && start.elapsed_real() < (max_time as f64 * 1e-3) {
            state.compute_one(n)?;
            iters += 1;
        }

        let measure = Duration::since(&start, iters);
        profile.add(&node, measure)?;
    }

    if display_options == DisplayOptions::default() {
        display_options.node_ids = Some(profile.most_consuming_nodes()?);
    };

    let mut display_graph =
        crate::display_graph::DisplayGraph::from_model_and_options(model, display_options)?
            .with_graph_def(&params.graph)?;

    let sum = profile.summed();
    for (ix, measure) in profile.nodes.iter() {
        display_graph.add_node_label(*ix, dur_avg_oneline_ratio(*measure, sum))?;
    }

    if atty::is(atty::Stream::Stdout) {
        progress.finish_print("");
    }

    display_graph.render()?;
    println!();

    profile.print_most_consuming_ops(model)?;

    println!("Entire network performance: {}", dur_avg_oneline(entire));
    println!("Accounted by ops: {}", dur_avg_oneline_ratio(profile.summed(), entire));

    if log_enabled!(Info) {
        println!(
            "(Real: {} in total, with max_iters={:e} and max_time={:?}ms.)",
            White.paint(format!("{:.3} ms", profile.summed().total_real * 1e3)),
            max_iters as f32,
            max_time,
        );
    }

    Ok(())
}
/// Handles the `profile` subcommand when there are no streaming dimensions.
Handles the `profile` subcommand when there are no streaming dimensions.
Handles the ` profile ` subcommand when there are no streaming dimensions .
pub fn handle_t<TI: TensorInfo>(
    model: &Model<TI>,
    params: &Parameters,
    profiling: ProfilingMode,
    mut display_options: DisplayOptions,
) -> CliResult<()> {
    let (max_iters, max_time) = if let ProfilingMode::Regular { max_iters, max_time } = profiling {
        (max_iters, max_time)
    } else {
        bail!("Expecting regular profile mode")
    };
    info!("Running entire network");
    let plan = SimplePlan::new(model)?;
    let mut iters = 0;
    let start = Instant::now();
    while iters < max_iters && start.elapsed_real() < (max_time as f64 * 1e-3) {
        let _ = plan.run(make_inputs_for_model(model)?)?;
        iters += 1;
    }
    let entire = Duration::since(&start, iters);
    info!("Running {} iterations max. for each node.", max_iters);
    info!("Running for {} ms max. for each node.", max_time);
    let mut state = SimpleState::new(&plan)?;
    state.set_inputs(make_inputs_for_model(model)?)?;
    debug!("Using execution plan: {:?}", plan);
    let mut profile = ProfileData::default();
    let mut progress = ProgressBar::new(plan.order.len() as u64);
    if log_enabled!(Info) {
        println!();
        print_header(format!("Profiling for {}:", params.name), &White.normal());
    }
    // Then execute the plan while profiling each step.
    for &n in &plan.order {
        let node = &model.nodes()[n];
        if atty::is(atty::Stream::Stdout) {
            progress.inc();
        }
        if node.op.name() == "Source" {
            if log_enabled!(Info) {
                print_node(
                    &node,
                    &params.graph,
                    Some(&state),
                    &[Yellow.paint("SKIP").to_string()],
                    vec![],
                );
            }
            continue;
        }
        if !display_options.filter(model, node)? {
            continue;
        }
        state.compute_recursively(n)?;
        let mut iters = 0;
        let start = Instant::now();
        while iters < max_iters && start.elapsed_real() < (max_time as f64 * 1e-3) {
            state.compute_one(n)?;
            iters += 1;
        }
        let measure = Duration::since(&start, iters);
        profile.add(&node, measure)?;
    }
    if display_options == DisplayOptions::default() {
        display_options.node_ids = Some(profile.most_consuming_nodes()?);
    };
    let mut display_graph =
        crate::display_graph::DisplayGraph::from_model_and_options(model, display_options)?
            .with_graph_def(&params.graph)?;
    let sum = profile.summed();
    for (ix, measure) in profile.nodes.iter() {
        display_graph.add_node_label(*ix, dur_avg_oneline_ratio(*measure, sum))?;
    }
    if atty::is(atty::Stream::Stdout) {
        progress.finish_print("");
    }
    display_graph.render()?;
    println!();
    profile.print_most_consuming_ops(model)?;
    println!("Entire network performance: {}", dur_avg_oneline(entire));
    println!("Accounted by ops: {}", dur_avg_oneline_ratio(profile.summed(), entire));
    if log_enabled!(Info) {
        println!(
            "(Real: {} in total, with max_iters={:e} and max_time={:?}ms.)",
            White.paint(format!("{:.3} ms", profile.summed().total_real * 1e3)),
            max_iters as f32,
            max_time,
        );
    }
    Ok(())
}
pub fn handle_t < TI : TensorInfo > ( model : & Model < TI > , params : & Parameters , profiling : ProfilingMode , mut display_options : DisplayOptions , ) -> CliResult < ( ) > { let ( max_iters , max_time ) = if let ProfilingMode :: Regular { max_iters , max_time } = profiling { ( max_iters , max_time ) } else { bail ! ( " " ) } ; info ! ( " " ) ; let plan = SimplePlan :: new ( model ) ? ; let mut iters = 0 ; let start = Instant :: now ( ) ; while iters < max_iters && start . elapsed_real ( ) < ( max_time as f64 * 1e-3 ) { let _ = plan . run ( make_inputs_for_model ( model ) ? ) ? ; iters += 1 ; } let entire = Duration :: since ( & start , iters ) ; info ! ( " " max_iters ) ; info ! ( " " max_time ) ; let mut state = SimpleState :: new ( & plan ) ? ; state . set_inputs ( make_inputs_for_model ( model ) ? ) ? ; debug ! ( " " plan ) ; let mut profile = ProfileData :: default ( ) ; let mut progress = ProgressBar :: new ( plan . order . len ( ) as u64 ) ; if log_enabled ! ( Info ) { println ! ( ) ; print_header ( format ! ( " " params name ) , & White . normal ( ) ) ; } // Then execute the plan while profiling each step. for & n in & plan . order { let node = & model . nodes ( ) [ n ] ; if atty :: is ( atty :: Stream :: Stdout ) { progress . inc ( ) ; } if node . op . name ( ) == " " { if log_enabled ! ( Info ) { print_node ( & node , & params . graph , Some ( & state ) , & [ Yellow . paint ( " " ) . to_string ( ) ] , vec ! [ ] , ) ; } continue ; } if ! display_options . filter ( model , node ) ? { continue ; } state . compute_recursively ( n ) ? ; let mut iters = 0 ; let start = Instant :: now ( ) ; while iters < max_iters && start . elapsed_real ( ) < ( max_time as f64 * 1e-3 ) { state . compute_one ( n ) ? ; iters += 1 ; } let measure = Duration :: since ( & start , iters ) ; profile . add ( & node , measure ) ? ; } if display_options == DisplayOptions :: default ( ) { display_options . node_ids = Some ( profile . most_consuming_nodes ( ) ? ) ; } ; let mut display_graph = crate :: display_graph :: DisplayGraph :: from_model_and_options ( model , display_options ) ? . with_graph_def ( & params . graph ) ? ; let sum = profile . summed ( ) ; for ( ix , measure ) in profile . nodes . iter ( ) { display_graph . add_node_label ( * ix , dur_avg_oneline_ratio ( * measure , sum ) ) ? ; } if atty :: is ( atty :: Stream :: Stdout ) { progress . finish_print ( " " ) ; } display_graph . render ( ) ? ; println ! ( ) ; profile . print_most_consuming_ops ( model ) ? ; println ! ( " " dur_avg_oneline ( entire ) ) ; println ! ( " " dur_avg_oneline_ratio ( profile summed ( ) entire ) ) ; if log_enabled ! ( Info ) { println ! ( " " White paint ( format ( " " profile summed ( ) total_real 1e3 ) ) max_iters as f32 max_time ) ; } Ok ( ( ) ) }
Handles the `profile` subcommand when there are no streaming dimensions.
Handles the ` profile ` subcommand when there are no streaming dimensions .
model
&Model<TI>
params
&Parameters
profiling
ProfilingMode
display_options
DisplayOptions
model
&Model<TI>
params
&Parameters
profiling
ProfilingMode
display_options
DisplayOptions