Skip to content

Commit a3bb762

Browse files
add PlacementLogPrinter class
1 parent d1d5e7f commit a3bb762

File tree

5 files changed

+57
-66
lines changed

5 files changed

+57
-66
lines changed

vpr/src/place/place.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ static bool is_cube_bb(const e_place_bounding_box_mode place_bb_mode,
3939

4040
static void free_placement_structs();
4141

42-
static int count_connections();
43-
4442
/*****************************************************************************/
4543
void try_place(const Netlist<>& net_list,
4644
const t_placer_opts& placer_opts,
@@ -63,8 +61,8 @@ void try_place(const Netlist<>& net_list,
6361
*/
6462
VTR_ASSERT(!is_flat);
6563
const auto& device_ctx = g_vpr_ctx.device();
66-
const auto& timing_ctx = g_vpr_ctx.timing();
67-
auto pre_place_timing_stats = timing_ctx.stats;
64+
// const auto& timing_ctx = g_vpr_ctx.timing();
65+
// auto pre_place_timing_stats = timing_ctx.stats;
6866

6967
/* Placement delay model is independent of the placement and can be shared across
7068
* multiple placers. So, it is created and initialized once. */
@@ -114,23 +112,6 @@ void try_place(const Netlist<>& net_list,
114112
placer.copy_locs_to_global_state();
115113
}
116114

117-
/*only count non-global connections */
118-
static int count_connections() {
119-
auto& cluster_ctx = g_vpr_ctx.clustering();
120-
121-
int count = 0;
122-
123-
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
124-
if (cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
125-
continue;
126-
}
127-
128-
count += cluster_ctx.clb_nlist.net_sinks(net_id).size();
129-
}
130-
131-
return count;
132-
}
133-
134115
static bool is_cube_bb(const e_place_bounding_box_mode place_bb_mode,
135116
const RRGraphView& rr_graph) {
136117
bool cube_bb;

vpr/src/place/place_log_util.cpp

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
#include "tatum/TimingReporter.hpp"
88
#include "VprTimingGraphResolver.h"
99
#include "timing_info.h"
10+
#include "placer.h"
11+
12+
PlacementLogPrinter::PlacementLogPrinter(const Placer& placer)
13+
: placer_(placer) {}
14+
15+
void PlacementLogPrinter::print_place_status_header() const {
16+
const bool noc_enabled = placer_.noc_opts_.noc;
1017

11-
void print_place_status_header(bool noc_enabled) {
1218
VTR_LOG("\n");
1319
if (!noc_enabled) {
1420
VTR_LOG(
@@ -31,28 +37,31 @@ void print_place_status_header(bool noc_enabled) {
3137
}
3238
}
3339

34-
void print_place_status(const t_annealing_state& state,
35-
const t_placer_statistics& stats,
36-
float elapsed_sec,
37-
float cpd,
38-
float sTNS,
39-
float sWNS,
40-
size_t tot_moves,
41-
bool noc_enabled,
42-
const NocCostTerms& noc_cost_terms) {
40+
void PlacementLogPrinter::print_place_status(float elapsed_sec) const {
41+
const t_annealing_state& annealing_state = placer_.annealer_->get_annealing_state();
42+
const auto& [swap_stats, move_type_stats, placer_stats] = placer_.annealer_->get_stats();
43+
const int tot_moves = placer_.annealer_->get_total_iteration();
44+
const bool noc_enabled = placer_.noc_opts_.noc;
45+
const NocCostTerms& noc_cost_terms = placer_.costs_.noc_cost_terms;
46+
47+
const bool is_timing_driven = placer_.placer_opts_.place_algorithm.is_timing_driven();
48+
const float cpd = is_timing_driven ? placer_.critical_path_.delay() : std::numeric_limits<float>::quiet_NaN();
49+
const float sTNS = is_timing_driven ? placer_.timing_info_->setup_total_negative_slack() : std::numeric_limits<float>::quiet_NaN();
50+
const float sWNS = is_timing_driven ? placer_.timing_info_->setup_worst_negative_slack() : std::numeric_limits<float>::quiet_NaN();
51+
4352
VTR_LOG(
4453
"%4zu %6.1f %7.1e "
4554
"%7.3f %10.2f %-10.5g "
4655
"%7.3f % 10.3g % 8.3f "
4756
"%7.3f %7.4f %6.1f %8.2f",
48-
state.num_temps, elapsed_sec, state.t,
49-
stats.av_cost, stats.av_bb_cost, stats.av_timing_cost,
57+
annealing_state.num_temps, elapsed_sec, annealing_state.t,
58+
placer_stats.av_cost, placer_stats.av_bb_cost, placer_stats.av_timing_cost,
5059
1e9 * cpd, 1e9 * sTNS, 1e9 * sWNS,
51-
stats.success_rate, stats.std_dev, state.rlim, state.crit_exponent);
60+
placer_stats.success_rate, placer_stats.std_dev, annealing_state.rlim, annealing_state.crit_exponent);
5261

5362
pretty_print_uint(" ", tot_moves, 9, 3);
5463

55-
VTR_LOG(" %6.3f", state.alpha);
64+
VTR_LOG(" %6.3f", annealing_state.alpha);
5665

5766
if (noc_enabled) {
5867
VTR_LOG(
@@ -66,10 +75,10 @@ void print_place_status(const t_annealing_state& state,
6675
fflush(stdout);
6776
}
6877

69-
void print_resources_utilization(const BlkLocRegistry& blk_loc_registry) {
78+
void PlacementLogPrinter::print_resources_utilization() const {
7079
const auto& cluster_ctx = g_vpr_ctx.clustering();
7180
const auto& device_ctx = g_vpr_ctx.device();
72-
const auto& block_locs = blk_loc_registry.block_locs();
81+
const auto& block_locs = placer_.placer_state_.block_locs();
7382

7483
size_t max_block_name = 0;
7584
size_t max_tile_name = 0;
@@ -103,15 +112,18 @@ void print_resources_utilization(const BlkLocRegistry& blk_loc_registry) {
103112
VTR_LOG("\n");
104113
}
105114

106-
void print_placement_swaps_stats(const t_annealing_state& state, const t_swap_stats& swap_stats) {
115+
void PlacementLogPrinter::print_placement_swaps_stats() const {
116+
const auto& [swap_stats, move_type_stats, placer_stats] = placer_.annealer_->get_stats();
117+
const t_annealing_state& annealing_state = placer_.annealer_->get_annealing_state();
118+
107119
size_t total_swap_attempts = swap_stats.num_swap_rejected + swap_stats.num_swap_accepted + swap_stats.num_swap_aborted;
108120
VTR_ASSERT(total_swap_attempts > 0);
109121

110122
size_t num_swap_print_digits = ceil(log10(total_swap_attempts));
111123
float reject_rate = (float)swap_stats.num_swap_rejected / total_swap_attempts;
112124
float accept_rate = (float)swap_stats.num_swap_accepted / total_swap_attempts;
113125
float abort_rate = (float)swap_stats.num_swap_aborted / total_swap_attempts;
114-
VTR_LOG("Placement number of temperatures: %d\n", state.num_temps);
126+
VTR_LOG("Placement number of temperatures: %d\n", annealing_state.num_temps);
115127
VTR_LOG("Placement total # of swap attempts: %*d\n", num_swap_print_digits,
116128
total_swap_attempts);
117129
VTR_LOG("\tSwaps accepted: %*d (%4.1f %%)\n", num_swap_print_digits,
@@ -141,4 +153,5 @@ void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
141153
timing_reporter.report_timing_setup(
142154
placer_opts.post_place_timing_report_file,
143155
*timing_info.setup_analyzer(), analysis_opts.timing_report_npaths);
144-
}
156+
}
157+

vpr/src/place/place_log_util.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ struct t_analysis_opts;
1414
struct NocCostTerms;
1515
struct t_swap_stats;
1616
class BlkLocRegistry;
17+
class Placer;
1718

18-
void print_place_status_header(bool noc_enabled);
19+
class PlacementLogPrinter {
20+
public:
21+
explicit PlacementLogPrinter(const Placer& placer);
1922

20-
void print_place_status(const t_annealing_state& state,
21-
const t_placer_statistics& stats,
22-
float elapsed_sec,
23-
float cpd,
24-
float sTNS,
25-
float sWNS,
26-
size_t tot_moves,
27-
bool noc_enabled,
28-
const NocCostTerms& noc_cost_terms);
23+
void print_place_status_header() const;
24+
void print_resources_utilization() const;
25+
void print_placement_swaps_stats() const;
26+
void print_place_status(float elapsed_sec) const;
2927

30-
void print_resources_utilization(const BlkLocRegistry& blk_loc_registry);
31-
32-
void print_placement_swaps_stats(const t_annealing_state& state, const t_swap_stats& swap_stats);
28+
private:
29+
const Placer& placer_;
30+
};
3331

3432
void generate_post_place_timing_reports(const t_placer_opts& placer_opts,
3533
const t_analysis_opts& analysis_opts,

vpr/src/place/placer.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "place_timing_update.h"
1515
#include "annealer.h"
1616
#include "RL_agent_util.h"
17-
#include "place_log_util.h"
1817
#include "place_checkpoint.h"
1918

2019
Placer::Placer(const Netlist<>& net_list,
@@ -31,7 +30,8 @@ Placer::Placer(const Netlist<>& net_list,
3130
, placer_state_(placer_opts.place_algorithm.is_timing_driven(), cube_bb)
3231
, rng_(placer_opts.seed)
3332
, net_cost_handler_(placer_opts, placer_state_, cube_bb)
34-
, place_delay_model_(std::move(place_delay_model)){
33+
, place_delay_model_(std::move(place_delay_model))
34+
, log_printer_(*this) {
3535
const auto& cluster_ctx = g_vpr_ctx.clustering();
3636
const auto& device_ctx = g_vpr_ctx.device();
3737
const auto& atom_ctx = g_vpr_ctx.atom();
@@ -322,7 +322,7 @@ void Placer::place() {
322322

323323
if (!skip_anneal) {
324324
//Table header
325-
print_place_status_header(noc_opts_.noc);
325+
log_printer_.print_place_status_header();
326326

327327
// Outer loop of the simulated annealing begins
328328
do {
@@ -346,9 +346,7 @@ void Placer::place() {
346346
// do a complete inner loop iteration
347347
annealer_->placement_inner_loop();
348348

349-
print_place_status(annealing_state, placer_stats, temperature_timer.elapsed_sec(),
350-
critical_path_.delay(), sTNS, sWNS, annealer_->get_total_iteration(),
351-
noc_opts_.noc, costs_.noc_cost_terms);
349+
log_printer_.print_place_status(temperature_timer.elapsed_sec());
352350

353351
// sprintf(msg, "Cost: %g BB Cost %g TD Cost %g Temperature: %g",
354352
// costs_.cost, costs_.bb_cost, costs_.timing_cost, annealing_state.t);
@@ -384,9 +382,7 @@ void Placer::place() {
384382
sWNS = timing_info_->setup_worst_negative_slack();
385383
}
386384

387-
print_place_status(annealing_state, placer_stats, temperature_timer.elapsed_sec(),
388-
critical_path_.delay(), sTNS, sWNS, annealer_->get_total_iteration(),
389-
noc_opts_.noc, costs_.noc_cost_terms);
385+
log_printer_.print_place_status(temperature_timer.elapsed_sec());
390386
}
391387
auto post_quench_timing_stats = timing_ctx.stats;
392388

@@ -431,11 +427,11 @@ void Placer::place() {
431427

432428
check_place_();
433429

430+
print_post_placement_stats_();
434431

435-
// Print out swap statistics
436-
print_resources_utilization(placer_state_.blk_loc_registry());
437-
438-
print_placement_swaps_stats(annealing_state, swap_stats);
432+
// Print out swap statistics and resource utilization
433+
log_printer_.print_resources_utilization();
434+
log_printer_.print_placement_swaps_stats();
439435

440436
move_type_stats.print_placement_move_types_stats();
441437

vpr/src/place/placer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "placer_state.h"
1313
#include "noc_place_utils.h"
1414
#include "net_cost_handler.h"
15+
#include "place_log_util.h"
1516

1617
class PlacementAnnealer;
1718
namespace vtr{
@@ -64,6 +65,8 @@ class Placer {
6465

6566
std::unique_ptr<PlacementAnnealer> annealer_;
6667

68+
PlacementLogPrinter log_printer_;
69+
6770
private:
6871
void alloc_and_init_timing_objects_(const Netlist<>& net_list,
6972
const t_analysis_opts& analysis_opts);

0 commit comments

Comments
 (0)