Skip to content

Commit 0ac2f30

Browse files
HackerFoovaughnbetz
authored andcommitted
Fix tests
Signed-off-by: Dusty DeWeese <[email protected]>
1 parent c3afdf4 commit 0ac2f30

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

vpr/src/place/place.cpp

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

61+
#define FINAL_RLIM 1
62+
6163
/* This defines the maximum number of swap attempts before invoking the *
6264
* once-in-a-while placement legality check as well as floating point *
6365
* variables round-offs check. */
@@ -106,8 +108,10 @@ struct t_placer_prev_inverse_costs {
106108
struct t_annealing_state {
107109
float t;
108110
float rlim;
111+
float inverse_delta_rlim;
109112
float alpha;
110113
float restart_t;
114+
float crit_exponent;
111115
int move_lim_max;
112116
int move_lim;
113117
};
@@ -353,7 +357,11 @@ static float starting_t(t_placer_costs* costs,
353357
t_pl_blocks_to_be_moved& blocks_affected,
354358
const t_placer_opts& placer_opts);
355359

356-
static bool update_state(t_annealing_state* state, float success_rat, const t_placer_costs& costs, const t_annealing_sched& annealing_sched);
360+
static bool update_state(t_annealing_state* state,
361+
float success_rat,
362+
const t_placer_costs& costs,
363+
const t_placer_opts& placer_opts,
364+
const t_annealing_sched& annealing_sched);
357365

358366
static void update_rlim(float* rlim, float success_rat, const DeviceGrid& grid);
359367

@@ -484,7 +492,7 @@ static void print_place_status(const size_t num_temps,
484492
size_t tot_moves);
485493
static void print_resources_utilization();
486494

487-
static void init_annealing_state(t_annealing_state* state, const t_annealing_sched& annealing_sched, float t, float rlim, int move_lim_max);
495+
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);
488496

489497
/*****************************************************************************/
490498
void try_place(const t_placer_opts& placer_opts,
@@ -509,8 +517,7 @@ void try_place(const t_placer_opts& placer_opts,
509517

510518
int tot_iter, moves_since_cost_recompute, width_fac, num_connections,
511519
outer_crit_iter_count, inner_recompute_limit;
512-
float success_rat, crit_exponent,
513-
first_rlim, final_rlim, inverse_delta_rlim;
520+
float success_rat, first_crit_exponent, first_rlim;
514521

515522
t_placer_costs costs;
516523
t_placer_prev_inverse_costs prev_inverse_costs;
@@ -575,7 +582,7 @@ void try_place(const t_placer_opts& placer_opts,
575582
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
576583
costs.bb_cost = comp_bb_cost(NORMAL);
577584

578-
crit_exponent = placer_opts.td_place_exp_first; /*this will be modified when rlim starts to change */
585+
first_crit_exponent = placer_opts.td_place_exp_first; /*this will be modified when rlim starts to change */
579586

580587
num_connections = count_connections();
581588
VTR_LOG("\n");
@@ -602,7 +609,7 @@ void try_place(const t_placer_opts& placer_opts,
602609
atom_ctx.lookup,
603610
*timing_info->timing_graph());
604611
//Update timing and costs
605-
recompute_criticalities(crit_exponent,
612+
recompute_criticalities(first_crit_exponent,
606613
place_delay_model.get(),
607614
placer_criticalities.get(),
608615
pin_timing_invalidator.get(),
@@ -635,7 +642,7 @@ void try_place(const t_placer_opts& placer_opts,
635642
costs.timing_cost = 0;
636643
outer_crit_iter_count = 0;
637644
num_connections = 0;
638-
crit_exponent = 0;
645+
first_crit_exponent = 0;
639646

640647
prev_inverse_costs.timing_cost = 0; /*inverses not used */
641648
prev_inverse_costs.bb_cost = 0;
@@ -721,8 +728,6 @@ void try_place(const t_placer_opts& placer_opts,
721728
}
722729

723730
first_rlim = (float)max(device_ctx.grid.width() - 1, device_ctx.grid.height() - 1);
724-
final_rlim = 1;
725-
inverse_delta_rlim = 1 / (first_rlim - final_rlim);
726731

727732
float first_t = starting_t(&costs, &prev_inverse_costs,
728733
annealing_sched, move_lim, first_rlim,
@@ -735,7 +740,7 @@ void try_place(const t_placer_opts& placer_opts,
735740
placer_opts);
736741

737742
t_annealing_state state;
738-
init_annealing_state(&state, annealing_sched, first_t, first_rlim, move_lim);
743+
init_annealing_state(&state, annealing_sched, first_t, first_rlim, move_lim, first_crit_exponent);
739744

740745
if (!placer_opts.move_stats_file.empty()) {
741746
f_move_stats_file = std::unique_ptr<FILE, decltype(&vtr::fclose)>(vtr::fopen(placer_opts.move_stats_file.c_str(), "w"), vtr::fclose);
@@ -759,15 +764,15 @@ void try_place(const t_placer_opts& placer_opts,
759764

760765
outer_loop_recompute_criticalities(placer_opts, &costs, &prev_inverse_costs,
761766
num_connections,
762-
crit_exponent,
767+
state.crit_exponent,
763768
&outer_crit_iter_count,
764769
place_delay_model.get(),
765770
placer_criticalities.get(),
766771
pin_timing_invalidator.get(),
767772
timing_info.get());
768773

769774
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
770-
state.move_lim, crit_exponent, inner_recompute_limit, &stats,
775+
state.move_lim, state.crit_exponent, inner_recompute_limit, &stats,
771776
&costs,
772777
&prev_inverse_costs,
773778
&moves_since_cost_recompute,
@@ -795,25 +800,18 @@ void try_place(const t_placer_opts& placer_opts,
795800
state.t, state.alpha,
796801
stats,
797802
critical_path.delay(), sTNS, sWNS,
798-
success_rat, std_dev, state.rlim, crit_exponent, tot_iter);
803+
success_rat, std_dev, state.rlim, state.crit_exponent, tot_iter);
799804

800805
sprintf(msg, "Cost: %g BB Cost %g TD Cost %g Temperature: %g",
801806
costs.cost, costs.bb_cost, costs.timing_cost, state.t);
802807
update_screen(ScreenUpdatePriority::MINOR, msg, PLACEMENT, timing_info);
803-
update_rlim(&state.rlim, success_rat, device_ctx.grid);
804-
805-
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
806-
crit_exponent = (1 - (state.rlim - final_rlim) * inverse_delta_rlim)
807-
* (placer_opts.td_place_exp_last - placer_opts.td_place_exp_first)
808-
+ placer_opts.td_place_exp_first;
809-
}
810808

811809
#ifdef VERBOSE
812810
if (getEchoEnabled()) {
813811
print_clb_placement("first_iteration_clb_placement.echo");
814812
}
815813
#endif
816-
} while (update_state(&state, success_rat, costs, annealing_sched));
814+
} while (update_state(&state, success_rat, costs, placer_opts, annealing_sched));
817815
/* Outer loop of the simmulated annealing ends */
818816

819817
auto pre_quench_timing_stats = timing_ctx.stats;
@@ -823,7 +821,7 @@ void try_place(const t_placer_opts& placer_opts,
823821
outer_loop_recompute_criticalities(placer_opts, &costs,
824822
&prev_inverse_costs,
825823
num_connections,
826-
crit_exponent,
824+
state.crit_exponent,
827825
&outer_crit_iter_count,
828826
place_delay_model.get(),
829827
placer_criticalities.get(),
@@ -835,7 +833,7 @@ void try_place(const t_placer_opts& placer_opts,
835833
/* Run inner loop again with temperature = 0 so as to accept only swaps
836834
* which reduce the cost of the placement */
837835
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
838-
move_lim, crit_exponent, quench_recompute_limit, &stats,
836+
move_lim, state.crit_exponent, quench_recompute_limit, &stats,
839837
&costs,
840838
&prev_inverse_costs,
841839
&moves_since_cost_recompute,
@@ -862,7 +860,7 @@ void try_place(const t_placer_opts& placer_opts,
862860
quench_elapsed_sec,
863861
state.t, state.alpha, stats,
864862
critical_path.delay(), sTNS, sWNS,
865-
success_rat, std_dev, state.rlim, crit_exponent, tot_iter);
863+
success_rat, std_dev, state.rlim, state.crit_exponent, tot_iter);
866864
}
867865
auto post_quench_timing_stats = timing_ctx.stats;
868866

@@ -893,7 +891,7 @@ void try_place(const t_placer_opts& placer_opts,
893891
VTR_ASSERT(timing_info);
894892

895893
//Update timing and costs
896-
recompute_criticalities(crit_exponent,
894+
recompute_criticalities(state.crit_exponent,
897895
place_delay_model.get(),
898896
placer_criticalities.get(),
899897
pin_timing_invalidator.get(),
@@ -1206,21 +1204,25 @@ static void update_rlim(float* rlim, float success_rat, const DeviceGrid& grid)
12061204
}
12071205

12081206
/* Update the temperature according to the annealing schedule selected. */
1209-
static bool update_state(t_annealing_state* state, float success_rat, const t_placer_costs& costs, const t_annealing_sched& annealing_sched) {
1207+
static bool update_state(t_annealing_state* state,
1208+
float success_rat,
1209+
const t_placer_costs& costs,
1210+
const t_placer_opts& placer_opts,
1211+
const t_annealing_sched& annealing_sched) {
12101212
/* Return `false` when the exit criterion is met. */
12111213
if (annealing_sched.type == USER_SCHED) {
12121214
state->t *= annealing_sched.alpha_t;
12131215
return state->t >= annealing_sched.exit_t;
12141216
}
12151217

1218+
auto& device_ctx = g_vpr_ctx.device();
12161219
auto& cluster_ctx = g_vpr_ctx.clustering();
12171220

12181221
/* Automatic annealing schedule */
12191222
float t_exit = 0.005 * costs.cost / cluster_ctx.clb_nlist.nets().size();
12201223

1221-
bool restart_temp = state->t < t_exit || std::isnan(t_exit); //May get nan if there are no nets
1222-
12231224
if (annealing_sched.type == DUSTY_SCHED) {
1225+
bool restart_temp = state->t < t_exit || std::isnan(t_exit); //May get nan if there are no nets
12241226
if (success_rat < annealing_sched.success_min || restart_temp) {
12251227
if (state->alpha > annealing_sched.alpha_max) return false;
12261228
state->t = state->restart_t / sqrt(state->alpha); // Take a half step from the restart temperature.
@@ -1232,7 +1234,6 @@ static bool update_state(t_annealing_state* state, float success_rat, const t_pl
12321234
state->t *= state->alpha;
12331235
}
12341236
state->move_lim = std::max(1, std::min(state->move_lim_max, (int)(state->move_lim_max * (annealing_sched.success_target / success_rat))));
1235-
return true;
12361237
} else { /* annealing_sched.type == AUTO_SCHED */
12371238
if (success_rat > 0.96) {
12381239
state->alpha = 0.5;
@@ -1245,8 +1246,19 @@ static bool update_state(t_annealing_state* state, float success_rat, const t_pl
12451246
}
12461247
state->t *= state->alpha;
12471248

1248-
return !restart_temp;
1249+
// Must be duplicated to retain previous behavior
1250+
if (state->t < t_exit || std::isnan(t_exit)) return false;
12491251
}
1252+
1253+
update_rlim(&state->rlim, success_rat, device_ctx.grid);
1254+
1255+
if (placer_opts.place_algorithm == PATH_TIMING_DRIVEN_PLACE) {
1256+
state->crit_exponent = (1 - (state->rlim - FINAL_RLIM) * state->inverse_delta_rlim)
1257+
* (placer_opts.td_place_exp_last - placer_opts.td_place_exp_first)
1258+
+ placer_opts.td_place_exp_first;
1259+
}
1260+
1261+
return true;
12501262
}
12511263

12521264
static float starting_t(t_placer_costs* costs,
@@ -2958,17 +2970,24 @@ static void print_resources_utilization() {
29582970
VTR_LOG("\n");
29592971
}
29602972

2961-
static void init_annealing_state(t_annealing_state* state, const t_annealing_sched& annealing_sched, float t, float rlim, int move_lim_max) {
2973+
static void init_annealing_state(t_annealing_state* state,
2974+
const t_annealing_sched& annealing_sched,
2975+
float t,
2976+
float rlim,
2977+
int move_lim_max,
2978+
float crit_exponent) {
29622979
state->alpha = annealing_sched.alpha_min;
29632980
state->t = t;
29642981
state->restart_t = t;
29652982
state->rlim = rlim;
2983+
state->inverse_delta_rlim = 1 / (rlim - FINAL_RLIM);
29662984
state->move_lim_max = std::max(1, move_lim_max);
29672985
if (annealing_sched.type == DUSTY_SCHED) {
29682986
state->move_lim = std::max(1, (int)(state->move_lim_max * annealing_sched.success_target));
29692987
} else {
29702988
state->move_lim = state->move_lim_max;
29712989
}
2990+
state->crit_exponent = crit_exponent;
29722991
}
29732992

29742993
bool placer_needs_lookahead(const t_vpr_setup& vpr_setup) {

0 commit comments

Comments
 (0)