Skip to content

Commit

Permalink
add print_post_placement_stats() to PlacementLogPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
soheilshahrouz committed Nov 18, 2024
1 parent f2fab38 commit efe43e9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 72 deletions.
56 changes: 56 additions & 0 deletions vpr/src/place/place_log_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "placer.h"
#include "draw.h"
#include "read_place.h"
#include "tatum/echo_writer.hpp"

PlacementLogPrinter::PlacementLogPrinter(const Placer& placer)
: placer_(placer)
Expand Down Expand Up @@ -199,6 +200,61 @@ void PlacementLogPrinter::print_initial_placement_stats() const {
}
}

void PlacementLogPrinter::print_post_placement_stats() const {
const auto& timing_ctx = g_vpr_ctx.timing();
const PlacementAnnealer& annealer = placer_.annealer();
const auto& [swap_stats, move_type_stats, placer_stats] = annealer.get_stats();

VTR_LOG("\n");
VTR_LOG("Swaps called: %d\n", swap_stats.num_ts_called);
// blocks_affected.move_abortion_logger.report_aborted_moves();

if (placer_.placer_opts_.place_algorithm.is_timing_driven()) {
//Final timing estimate
VTR_ASSERT(placer_.timing_info_);

if (isEchoFileEnabled(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH)) {
tatum::write_echo(getEchoFileName(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH),
*timing_ctx.graph, *timing_ctx.constraints,
*placer_.placement_delay_calc_, placer_.timing_info_->analyzer());

tatum::NodeId debug_tnode = id_or_pin_name_to_tnode(placer_.analysis_opts_.echo_dot_timing_graph_node);
write_setup_timing_graph_dot(getEchoFileName(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH) + std::string(".dot"),
*placer_.timing_info_, debug_tnode);
}

generate_post_place_timing_reports(placer_.placer_opts_, placer_.analysis_opts_, *placer_.timing_info_,
*placer_.placement_delay_calc_, /*is_flat=*/false, placer_.placer_state_.blk_loc_registry());

// Print critical path delay metrics
VTR_LOG("\n");
print_setup_timing_summary(*timing_ctx.constraints,
*placer_.timing_info_->setup_analyzer(), "Placement estimated ", "");
}

char msg[vtr::bufsize];
sprintf(msg,
"Placement. Cost: %g bb_cost: %g td_cost: %g Channel Factor: %d",
placer_.costs_.cost, placer_.costs_.bb_cost, placer_.costs_.timing_cost, placer_.placer_opts_.place_chan_width);
VTR_LOG("Placement cost: %g, bb_cost: %g, td_cost: %g, \n", placer_.costs_.cost,
placer_.costs_.bb_cost, placer_.costs_.timing_cost);
update_screen(ScreenUpdatePriority::MAJOR, msg, PLACEMENT, placer_.timing_info_);

// print the noc costs info
if (placer_.noc_opts_.noc) {
VTR_ASSERT(placer_.noc_cost_handler_.has_value());
placer_.noc_cost_handler_->print_noc_costs("\nNoC Placement Costs", placer_.costs_, placer_.noc_opts_);

// TODO: move this to an appropriate file
#ifdef ENABLE_NOC_SAT_ROUTING
if (costs.noc_cost_terms.congestion > 0.0) {
VTR_LOG("NoC routing configuration is congested. Invoking the SAT NoC router.\n");
invoke_sat_router(costs, noc_opts, placer_opts.seed);
}
#endif //ENABLE_NOC_SAT_ROUTING
}
}

void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
const t_analysis_opts& analysis_opts,
const SetupTimingInfo& timing_info,
Expand Down
1 change: 1 addition & 0 deletions vpr/src/place/place_log_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PlacementLogPrinter {
void print_placement_swaps_stats() const;
void print_place_status(float elapsed_sec) const;
void print_initial_placement_stats() const;
void print_post_placement_stats() const;

private:
const Placer& placer_;
Expand Down
80 changes: 14 additions & 66 deletions vpr/src/place/placer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "analytic_placer.h"
#include "initial_placement.h"
#include "concrete_timing_info.h"
#include "tatum/echo_writer.hpp"
#include "verify_placement.h"
#include "place_timing_update.h"
#include "annealer.h"
#include "RL_agent_util.h"
#include "place_checkpoint.h"
#include "tatum/echo_writer.hpp"

Placer::Placer(const Netlist<>& net_list,
const t_placer_opts& placer_opts,
Expand Down Expand Up @@ -179,17 +179,14 @@ void Placer::alloc_and_init_timing_objects_(const Netlist<>& net_list,

// Write out the initial timing echo file
if (isEchoFileEnabled(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH)) {
tatum::write_echo(
getEchoFileName(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH),
*timing_ctx.graph, *timing_ctx.constraints,
*placement_delay_calc_, timing_info_->analyzer());
tatum::write_echo(getEchoFileName(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH),
*timing_ctx.graph, *timing_ctx.constraints,
*placement_delay_calc_, timing_info_->analyzer());

tatum::NodeId debug_tnode = id_or_pin_name_to_tnode(analysis_opts.echo_dot_timing_graph_node);

write_setup_timing_graph_dot(
getEchoFileName(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH)
+ std::string(".dot"),
*timing_info_, debug_tnode);
write_setup_timing_graph_dot(getEchoFileName(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH) + std::string(".dot"),
*timing_info_, debug_tnode);
}

costs_.timing_cost_norm = 1 / costs_.timing_cost;
Expand Down Expand Up @@ -337,8 +334,11 @@ void Placer::place() {
perform_full_timing_update(crit_params, place_delay_model_.get(), placer_criticalities_.get(),
placer_setup_slacks_.get(), pin_timing_invalidator_.get(),
timing_info_.get(), &costs_, placer_state_);

critical_path_ = timing_info_->least_slack_critical_path();

VTR_LOG("post-quench CPD = %g (ns) \n",
1e9 * timing_info_->least_slack_critical_path().delay());
1e9 * critical_path_.delay());
}

// See if our latest checkpoint is better than the current placement solution
Expand Down Expand Up @@ -369,7 +369,7 @@ void Placer::place() {

check_place_();

print_post_placement_stats_();
log_printer_.print_post_placement_stats();

// Print out swap statistics and resource utilization
log_printer_.print_resources_utilization();
Expand All @@ -391,61 +391,6 @@ void Placer::place() {
p_runtime_ctx.f_update_td_costs_total_elapsed_sec);
}

void Placer::print_post_placement_stats_() {
const auto& timing_ctx = g_vpr_ctx.timing();
const auto& [swap_stats, move_type_stats, placer_stats] = annealer_->get_stats();

VTR_LOG("\n");
VTR_LOG("Swaps called: %d\n", swap_stats.num_ts_called);
// blocks_affected.move_abortion_logger.report_aborted_moves();

if (placer_opts_.place_algorithm.is_timing_driven()) {
//Final timing estimate
VTR_ASSERT(timing_info_);

critical_path_ = timing_info_->least_slack_critical_path();

if (isEchoFileEnabled(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH)) {
tatum::write_echo(getEchoFileName(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH),
*timing_ctx.graph, *timing_ctx.constraints,
*placement_delay_calc_, timing_info_->analyzer());

tatum::NodeId debug_tnode = id_or_pin_name_to_tnode(analysis_opts_.echo_dot_timing_graph_node);
write_setup_timing_graph_dot(getEchoFileName(E_ECHO_FINAL_PLACEMENT_TIMING_GRAPH) + std::string(".dot"),
*timing_info_, debug_tnode);
}

generate_post_place_timing_reports(placer_opts_, analysis_opts_, *timing_info_,
*placement_delay_calc_, /*is_flat=*/false, placer_state_.blk_loc_registry());

// Print critical path delay metrics
VTR_LOG("\n");
print_setup_timing_summary(*timing_ctx.constraints,
*timing_info_->setup_analyzer(), "Placement estimated ", "");
}

char msg[vtr::bufsize];
sprintf(msg,
"Placement. Cost: %g bb_cost: %g td_cost: %g Channel Factor: %d",
costs_.cost, costs_.bb_cost, costs_.timing_cost, placer_opts_.place_chan_width);
VTR_LOG("Placement cost: %g, bb_cost: %g, td_cost: %g, \n", costs_.cost,
costs_.bb_cost, costs_.timing_cost);
update_screen(ScreenUpdatePriority::MAJOR, msg, PLACEMENT, timing_info_);

// print the noc costs info
if (noc_opts_.noc) {
VTR_ASSERT(noc_cost_handler_.has_value());
noc_cost_handler_->print_noc_costs("\nNoC Placement Costs", costs_, noc_opts_);

#ifdef ENABLE_NOC_SAT_ROUTING
if (costs.noc_cost_terms.congestion > 0.0) {
VTR_LOG("NoC routing configuration is congested. Invoking the SAT NoC router.\n");
invoke_sat_router(costs, noc_opts, placer_opts.seed);
}
#endif //ENABLE_NOC_SAT_ROUTING
}
}

void Placer::copy_locs_to_global_state() {
auto& place_ctx = g_vpr_ctx.mutable_placement();

Expand Down Expand Up @@ -481,12 +426,15 @@ const t_placer_costs& Placer::costs() const {
const tatum::TimingPathInfo& Placer::critical_path() const {
return critical_path_;
}

std::shared_ptr<const SetupTimingInfo> Placer::timing_info() const {
return timing_info_;
}

const PlacerState& Placer::placer_state() const {
return placer_state_;
}

const std::optional<NocCostHandler>& Placer::noc_cost_handler() const {
return noc_cost_handler_;
}
6 changes: 3 additions & 3 deletions vpr/src/place/placer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class Placer {

std::unique_ptr<PlacementAnnealer> annealer_;

PlacementLogPrinter log_printer_;
const PlacementLogPrinter log_printer_;

friend void PlacementLogPrinter::print_post_placement_stats() const;

private:
void alloc_and_init_timing_objects_(const Netlist<>& net_list,
Expand All @@ -100,8 +102,6 @@ class Placer {
void check_place_();

int check_placement_costs_();

void print_post_placement_stats_();
};

#endif //VTR_PLACER_H
4 changes: 2 additions & 2 deletions vpr/src/timing/timing_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tatum::TimingPathInfo find_least_slack_critical_path_delay(const tatum::TimingCo

auto cpds = tatum::find_critical_paths(*timing_ctx.graph, constraints, setup_analyzer);

//Record the maximum critical path accross all domain pairs
//Record the maximum critical path across all domain pairs
for (const auto& path_info : cpds) {
if (path_info.slack() < crit_path_info.slack() || std::isnan(crit_path_info.slack())) {
crit_path_info = path_info;
Expand Down Expand Up @@ -855,7 +855,7 @@ tatum::NodeId pin_name_to_tnode(std::string pin_name) {
return tnode;
}

void write_setup_timing_graph_dot(std::string filename, SetupTimingInfo& timing_info, tatum::NodeId debug_node) {
void write_setup_timing_graph_dot(std::string filename, const SetupTimingInfo& timing_info, tatum::NodeId debug_node) {
auto& timing_graph = *timing_info.timing_graph();

auto dot_writer = tatum::make_graphviz_dot_writer(timing_graph, *timing_info.delay_calculator());
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/timing/timing_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void print_tatum_cpds(std::vector<tatum::TimingPathInfo> cpds);
tatum::NodeId id_or_pin_name_to_tnode(std::string name_or_id);
tatum::NodeId pin_name_to_tnode(std::string name);

void write_setup_timing_graph_dot(std::string filename, SetupTimingInfo& timing_info, tatum::NodeId debug_node = tatum::NodeId::INVALID());
void write_setup_timing_graph_dot(std::string filename, const SetupTimingInfo& timing_info, tatum::NodeId debug_node = tatum::NodeId::INVALID());
void write_hold_timing_graph_dot(std::string filename, HoldTimingInfo& timing_info, tatum::NodeId debug_node = tatum::NodeId::INVALID());

struct TimingStats {
Expand Down

0 comments on commit efe43e9

Please sign in to comment.