Skip to content

Commit 7b945a3

Browse files
committed
Fix tests
Signed-off-by: Dusty DeWeese <[email protected]>
1 parent 6cc764c commit 7b945a3

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

vpr/src/place/place.cpp

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ using std::min;
5656
* cost computation. 0.01 means that there is a 1% error tolerance. */
5757
#define ERROR_TOL .01
5858

59+
#define FINAL_RLIM 1
60+
5961
/* This defines the maximum number of swap attempts before invoking the *
6062
* once-in-a-while placement legality check as well as floating point *
6163
* variables round-offs check. */
@@ -100,8 +102,10 @@ struct t_placer_prev_inverse_costs {
100102
struct t_annealing_state {
101103
float t;
102104
float rlim;
105+
float inverse_delta_rlim;
103106
float alpha;
104107
float restart_t;
108+
float crit_exponent;
105109
int move_lim_max;
106110
int move_lim;
107111
};
@@ -325,7 +329,11 @@ static float starting_t(t_placer_costs* costs,
325329
t_pl_blocks_to_be_moved& blocks_affected,
326330
const t_placer_opts& placer_opts);
327331

328-
static bool update_state(t_annealing_state* state, float success_rat, const t_placer_costs& costs, const t_annealing_sched& annealing_sched);
332+
static bool update_state(t_annealing_state* state,
333+
float success_rat,
334+
const t_placer_costs& costs,
335+
const t_placer_opts& placer_opts,
336+
const t_annealing_sched& annealing_sched);
329337

330338
static void update_rlim(float* rlim, float success_rat, const DeviceGrid& grid);
331339

@@ -424,7 +432,7 @@ static void print_place_status(const float t,
424432
size_t tot_moves);
425433
static void print_resources_utilization();
426434

427-
static void init_annealing_state(t_annealing_state* state, const t_annealing_sched& annealing_sched, float t, float rlim, int move_lim_max);
435+
static void init_annealing_state(t_annealing_state* state, const t_annealing_sched& annealing_sched, float t, float rlim, int move_lim_max, float crit_exponent);
428436

429437
/*****************************************************************************/
430438
void try_place(const t_placer_opts& placer_opts,
@@ -443,8 +451,7 @@ void try_place(const t_placer_opts& placer_opts,
443451

444452
int tot_iter, moves_since_cost_recompute, width_fac, num_connections,
445453
outer_crit_iter_count, inner_recompute_limit;
446-
float success_rat, crit_exponent,
447-
first_rlim, final_rlim, inverse_delta_rlim;
454+
float success_rat, first_crit_exponent, first_rlim;
448455

449456
t_placer_costs costs;
450457
t_placer_prev_inverse_costs prev_inverse_costs;
@@ -511,7 +518,7 @@ void try_place(const t_placer_opts& placer_opts,
511518
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE || placer_opts.enable_timing_computations) {
512519
costs.bb_cost = comp_bb_cost(NORMAL);
513520

514-
crit_exponent = placer_opts.td_place_exp_first; /*this will be modified when rlim starts to change */
521+
first_crit_exponent = placer_opts.td_place_exp_first; /*this will be modified when rlim starts to change */
515522

516523
num_connections = count_connections();
517524
VTR_LOG("\n");
@@ -534,7 +541,7 @@ void try_place(const t_placer_opts& placer_opts,
534541
timing_info->set_warn_unconstrained(false); //Don't warn again about unconstrained nodes again during placement
535542

536543
//Initial slack estimates
537-
load_criticalities(*timing_info, crit_exponent, netlist_pin_lookup);
544+
load_criticalities(*timing_info, first_crit_exponent, netlist_pin_lookup);
538545

539546
critical_path = timing_info->least_slack_critical_path();
540547

@@ -565,7 +572,7 @@ void try_place(const t_placer_opts& placer_opts,
565572
costs.timing_cost = 0;
566573
outer_crit_iter_count = 0;
567574
num_connections = 0;
568-
crit_exponent = 0;
575+
first_crit_exponent = 0;
569576

570577
prev_inverse_costs.timing_cost = 0; /*inverses not used */
571578
prev_inverse_costs.bb_cost = 0;
@@ -643,8 +650,6 @@ void try_place(const t_placer_opts& placer_opts,
643650
}
644651

645652
first_rlim = (float)max(device_ctx.grid.width() - 1, device_ctx.grid.height() - 1);
646-
final_rlim = 1;
647-
inverse_delta_rlim = 1 / (first_rlim - final_rlim);
648653

649654
float first_t = starting_t(&costs, &prev_inverse_costs,
650655
annealing_sched, move_lim, first_rlim,
@@ -654,7 +659,7 @@ void try_place(const t_placer_opts& placer_opts,
654659
placer_opts);
655660

656661
t_annealing_state state;
657-
init_annealing_state(&state, annealing_sched, first_t, first_rlim, move_lim);
662+
init_annealing_state(&state, annealing_sched, first_t, first_rlim, move_lim, first_crit_exponent);
658663

659664
if (!placer_opts.move_stats_file.empty()) {
660665
f_move_stats_file = std::unique_ptr<FILE, decltype(&vtr::fclose)>(vtr::fopen(placer_opts.move_stats_file.c_str(), "w"), vtr::fclose);
@@ -676,14 +681,14 @@ void try_place(const t_placer_opts& placer_opts,
676681

677682
outer_loop_recompute_criticalities(placer_opts, &costs, &prev_inverse_costs,
678683
num_connections,
679-
crit_exponent,
684+
state.crit_exponent,
680685
&outer_crit_iter_count,
681686
netlist_pin_lookup,
682687
place_delay_model.get(),
683688
*timing_info);
684689

685690
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
686-
state.move_lim, crit_exponent, inner_recompute_limit, &stats,
691+
state.move_lim, state.crit_exponent, inner_recompute_limit, &stats,
687692
&costs,
688693
&prev_inverse_costs,
689694
&moves_since_cost_recompute,
@@ -708,31 +713,24 @@ void try_place(const t_placer_opts& placer_opts,
708713
print_place_status(state.t, state.alpha,
709714
stats,
710715
critical_path.delay(), sTNS, sWNS,
711-
success_rat, std_dev, state.rlim, crit_exponent, tot_iter);
716+
success_rat, std_dev, state.rlim, state.crit_exponent, tot_iter);
712717

713718
sprintf(msg, "Cost: %g BB Cost %g TD Cost %g Temperature: %g",
714719
costs.cost, costs.bb_cost, costs.timing_cost, state.t);
715720
update_screen(ScreenUpdatePriority::MINOR, msg, PLACEMENT, timing_info);
716-
update_rlim(&state.rlim, success_rat, device_ctx.grid);
717-
718-
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
719-
crit_exponent = (1 - (state.rlim - final_rlim) * inverse_delta_rlim)
720-
* (placer_opts.td_place_exp_last - placer_opts.td_place_exp_first)
721-
+ placer_opts.td_place_exp_first;
722-
}
723721

724722
#ifdef VERBOSE
725723
if (getEchoEnabled()) {
726724
print_clb_placement("first_iteration_clb_placement.echo");
727725
}
728726
#endif
729-
} while (update_state(&state, success_rat, costs, annealing_sched));
727+
} while (update_state(&state, success_rat, costs, placer_opts, annealing_sched));
730728
/* Outer loop of the simmulated annealing ends */
731729

732730
outer_loop_recompute_criticalities(placer_opts, &costs,
733731
&prev_inverse_costs,
734732
num_connections,
735-
crit_exponent,
733+
state.crit_exponent,
736734
&outer_crit_iter_count,
737735
netlist_pin_lookup,
738736
place_delay_model.get(),
@@ -743,7 +741,7 @@ void try_place(const t_placer_opts& placer_opts,
743741
/* Run inner loop again with temperature = 0 so as to accept only swaps
744742
* which reduce the cost of the placement */
745743
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
746-
state.move_lim, crit_exponent, inner_recompute_limit, &stats,
744+
state.move_lim, state.crit_exponent, inner_recompute_limit, &stats,
747745
&costs,
748746
&prev_inverse_costs,
749747
&moves_since_cost_recompute,
@@ -766,7 +764,7 @@ void try_place(const t_placer_opts& placer_opts,
766764

767765
print_place_status(state.t, state.alpha, stats,
768766
critical_path.delay(), sTNS, sWNS,
769-
success_rat, std_dev, state.rlim, crit_exponent, tot_iter);
767+
success_rat, std_dev, state.rlim, state.crit_exponent, tot_iter);
770768

771769
if (placer_opts.placement_saves_per_temperature >= 1) {
772770
std::string filename = vtr::string_fmt("placement_%03d_%03d.place", num_temps + 1, 0);
@@ -1092,21 +1090,25 @@ static void update_rlim(float* rlim, float success_rat, const DeviceGrid& grid)
10921090
}
10931091

10941092
/* Update the temperature according to the annealing schedule selected. */
1095-
static bool update_state(t_annealing_state* state, float success_rat, const t_placer_costs& costs, const t_annealing_sched& annealing_sched) {
1093+
static bool update_state(t_annealing_state* state,
1094+
float success_rat,
1095+
const t_placer_costs& costs,
1096+
const t_placer_opts& placer_opts,
1097+
const t_annealing_sched& annealing_sched) {
10961098
/* Return `false` when the exit criterion is met. */
10971099
if (annealing_sched.type == USER_SCHED) {
10981100
state->t *= annealing_sched.alpha_t;
10991101
return state->t >= annealing_sched.exit_t;
11001102
}
11011103

1104+
auto& device_ctx = g_vpr_ctx.device();
11021105
auto& cluster_ctx = g_vpr_ctx.clustering();
11031106

11041107
/* Automatic annealing schedule */
11051108
float t_exit = 0.005 * costs.cost / cluster_ctx.clb_nlist.nets().size();
11061109

1107-
bool restart_temp = state->t < t_exit || std::isnan(t_exit); //May get nan if there are no nets
1108-
11091110
if (annealing_sched.type == DUSTY_SCHED) {
1111+
bool restart_temp = state->t < t_exit || std::isnan(t_exit); //May get nan if there are no nets
11101112
if (success_rat < annealing_sched.success_min || restart_temp) {
11111113
if (state->alpha > annealing_sched.alpha_max) return false;
11121114
state->t = state->restart_t / sqrt(state->alpha); // Take a half step from the restart temperature.
@@ -1118,7 +1120,6 @@ static bool update_state(t_annealing_state* state, float success_rat, const t_pl
11181120
state->t *= state->alpha;
11191121
}
11201122
state->move_lim = std::max(1, std::min(state->move_lim_max, (int)(state->move_lim_max * (annealing_sched.success_target / success_rat))));
1121-
return true;
11221123
} else { /* annealing_sched.type == AUTO_SCHED */
11231124
if (success_rat > 0.96) {
11241125
state->alpha = 0.5;
@@ -1131,8 +1132,19 @@ static bool update_state(t_annealing_state* state, float success_rat, const t_pl
11311132
}
11321133
state->t *= state->alpha;
11331134

1134-
return !restart_temp;
1135+
// Must be duplicated to retain previous behavior
1136+
if (state->t < t_exit || std::isnan(t_exit)) return false;
11351137
}
1138+
1139+
update_rlim(&state->rlim, success_rat, device_ctx.grid);
1140+
1141+
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
1142+
state->crit_exponent = (1 - (state->rlim - FINAL_RLIM) * state->inverse_delta_rlim)
1143+
* (placer_opts.td_place_exp_last - placer_opts.td_place_exp_first)
1144+
+ placer_opts.td_place_exp_first;
1145+
}
1146+
1147+
return true;
11361148
}
11371149

11381150
static float starting_t(t_placer_costs* costs,
@@ -2662,17 +2674,24 @@ static void print_resources_utilization() {
26622674
VTR_LOG("\n");
26632675
}
26642676

2665-
static void init_annealing_state(t_annealing_state* state, const t_annealing_sched& annealing_sched, float t, float rlim, int move_lim_max) {
2677+
static void init_annealing_state(t_annealing_state* state,
2678+
const t_annealing_sched& annealing_sched,
2679+
float t,
2680+
float rlim,
2681+
int move_lim_max,
2682+
float crit_exponent) {
26662683
state->alpha = annealing_sched.alpha_min;
26672684
state->t = t;
26682685
state->restart_t = t;
26692686
state->rlim = rlim;
2687+
state->inverse_delta_rlim = 1 / (rlim - FINAL_RLIM);
26702688
state->move_lim_max = std::max(1, move_lim_max);
26712689
if (annealing_sched.type == DUSTY_SCHED) {
26722690
state->move_lim = std::max(1, (int)(state->move_lim_max * annealing_sched.success_target));
26732691
} else {
26742692
state->move_lim = state->move_lim_max;
26752693
}
2694+
state->crit_exponent = crit_exponent;
26762695
}
26772696

26782697
bool placer_needs_lookahead(const t_vpr_setup& vpr_setup) {

0 commit comments

Comments
 (0)