Skip to content

Commit 70985e4

Browse files
[Place] Updated the Equlibrium Code Based on Feedback
1 parent a7bc5a9 commit 70985e4

File tree

6 files changed

+40
-47
lines changed

6 files changed

+40
-47
lines changed

doc/src/vpr/command_line_usage.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,17 +840,17 @@ If any of init_t, exit_t or alpha_t is specified, the user schedule, with a fixe
840840

841841
**Default:** ``1.0``
842842

843-
.. option:: ----anneal_auto_init_t_estimator {cost_variance, equilibrium_est}
843+
.. option:: --anneal_auto_init_t_estimator {cost_variance, equilibrium}
844844

845845
Controls which estimation method is used when selecting the starting temperature
846846
for the automatic annealing schedule.
847847

848848
The options for estimators are:
849849

850-
* ``cost_variance``: Estimates the initial temperature using the variance of cost after a set of trial swaps.
851-
* ``equilibrium_est``: Estimates the initial temperature by trying to predict the equilibrium temperature for the initial placement (i.e. the temperature that would result in no change in cost).
850+
* ``cost_variance``: Estimates the initial temperature using the variance of cost after a set of trial swaps. The initial temperature is set to a value proportional to the variance.
851+
* ``equilibrium``: Estimates the initial temperature by trying to predict the equilibrium temperature for the initial placement (i.e. the temperature that would result in no change in cost).
852852

853-
**Default** ``equilibrium_est``
853+
**Default** ``cost_variance``
854854

855855
.. option:: --init_t <float>
856856

vpr/src/base/read_options.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,8 @@ struct ParsePlaceInitTEstimator {
696696
ConvertedValue<e_anneal_init_t_estimator> conv_value;
697697
if (str == "cost_variance")
698698
conv_value.set_value(e_anneal_init_t_estimator::COST_VARIANCE);
699-
else if (str == "equilibrium_est")
700-
conv_value.set_value(e_anneal_init_t_estimator::EQUILIBRIUM_EST);
699+
else if (str == "equilibrium")
700+
conv_value.set_value(e_anneal_init_t_estimator::EQUILIBRIUM);
701701
else {
702702
std::stringstream msg;
703703
msg << "Invalid conversion from '" << str << "' to e_anneal_init_t_estimator (expected one of: " << argparse::join(default_choices(), ", ") << ")";
@@ -712,8 +712,8 @@ struct ParsePlaceInitTEstimator {
712712
case e_anneal_init_t_estimator::COST_VARIANCE:
713713
conv_value.set_value("cost_variance");
714714
break;
715-
case e_anneal_init_t_estimator::EQUILIBRIUM_EST:
716-
conv_value.set_value("equilibrium_est");
715+
case e_anneal_init_t_estimator::EQUILIBRIUM:
716+
conv_value.set_value("equilibrium");
717717
break;
718718
default: {
719719
std::stringstream msg;
@@ -725,7 +725,7 @@ struct ParsePlaceInitTEstimator {
725725
}
726726

727727
std::vector<std::string> default_choices() {
728-
return {"cost_variance", "equilibrium_est"};
728+
return {"cost_variance", "equilibrium"};
729729
}
730730
};
731731

@@ -2320,7 +2320,7 @@ argparse::ArgumentParser create_arg_parser(const std::string& prog_name, t_optio
23202320
"The options for estimators are:\n"
23212321
"\tcost_variance: Estimates the initial temperature using the variance "
23222322
"of cost after a set of trial swaps.\n"
2323-
"\tequilibrium_est: Estimates the initial temperature by trying to "
2323+
"\tequilibrium: Estimates the initial temperature by trying to "
23242324
"predict the equilibrium temperature for the initial placement "
23252325
"(i.e. the temperature that would result in no change in cost).")
23262326
.default_value("cost_variance")

vpr/src/base/vpr_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ enum class e_place_delta_delay_algorithm {
973973
*/
974974
enum class e_anneal_init_t_estimator {
975975
COST_VARIANCE, ///<Estimate the initial temperature using the variance in cost of a set of trial swaps.
976-
EQUILIBRIUM_EST, ///<Estimate the initial temperature by predicting the equilibrium temperature for the initial placement.
976+
EQUILIBRIUM, ///<Estimate the initial temperature by predicting the equilibrium temperature for the initial placement.
977977
};
978978

979979
enum class e_move_type;

vpr/src/place/annealer.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ float PlacementAnnealer::estimate_starting_temperature_() {
302302
switch (placer_opts_.anneal_init_t_estimator) {
303303
case e_anneal_init_t_estimator::COST_VARIANCE:
304304
return estimate_starting_temp_using_cost_variance_();
305-
case e_anneal_init_t_estimator::EQUILIBRIUM_EST:
305+
case e_anneal_init_t_estimator::EQUILIBRIUM:
306306
return estimate_equilibrium_temp_();
307307
default:
308308
VPR_FATAL_ERROR(VPR_ERROR_PLACE,
@@ -328,18 +328,9 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
328328
accepted_swaps.reserve(move_lim);
329329
rejected_swaps.reserve(move_lim);
330330
for (int i = 0; i < move_lim; i++) {
331-
bool manual_move_enabled = false;
332-
#ifndef NO_GRAPHICS
333-
// Checks manual move flag for manual move feature
334-
t_draw_state* draw_state = get_draw_state_vars();
335-
if (draw_state->show_graphics) {
336-
manual_move_enabled = manual_move_is_selected();
337-
}
338-
#endif /*NO_GRAPHICS*/
339-
340331
t_swap_result swap_result = try_swap_(*move_generator_1_,
341332
placer_opts_.place_algorithm,
342-
manual_move_enabled);
333+
false /*manual_move_enabled*/);
343334

344335
if (swap_result.move_result == e_move_result::ACCEPTED) {
345336
accepted_swaps.push_back(swap_result.delta_c);
@@ -361,6 +352,14 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
361352
total_accepted_cost += accepted_cost;
362353
}
363354

355+
// Find the magnitude of the largest reject swap cost. This is useful for
356+
// picking a worst-case initial temperature.
357+
double max_rejected_swap_cost = 0.0;
358+
for (double rejected_cost : rejected_swaps) {
359+
max_rejected_swap_cost = std::max(max_rejected_swap_cost,
360+
std::abs(rejected_cost));
361+
}
362+
364363
// Perform a binary search to try and find the equilibrium temperature for
365364
// this placement. This is the temperature that we expect would lead to no
366365
// overall change in temperature. We do this by computing the expected
@@ -372,43 +371,46 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
372371
// Initialize the lower bound temperature to 0. The temperature cannot
373372
// be less than 0.
374373
double lower_bound_temp = 0.0;
375-
// Initialize the upper bound temperature to 1e10. It is possible for
374+
// Initialize the upper bound temperature. It is possible for
376375
// the equilibrium temperature to be infinite if the initial placement
377376
// is so bad that no swaps are accepted. In that case this value will
378377
// be returned instead of infinity.
379-
// TODO: Find what a reasonable value for this should be.
380-
double upper_bound_temp = 1e10;
378+
// At this temperature, the probability of accepting this worst rejected
379+
// swap would be 71.655% (e^(-1/3)).
380+
// TODO: Investigate if this is a good initial temperature for these
381+
// cases.
382+
double upper_bound_temp = 3.0 * max_rejected_swap_cost;
381383
// The max search iterations should never be hit, but it is here as an
382384
// exit condition to prevent infinite loops.
383385
constexpr unsigned max_search_iters = 100;
384386
for (unsigned binary_search_iter = 0; binary_search_iter < max_search_iters; binary_search_iter++) {
385387
// Exit condition for binary search. Could be hit if the lower and upper
386388
// bounds are arbitrarily close.
387-
if (lower_bound_temp > upper_bound_temp)
389+
if (lower_bound_temp >= upper_bound_temp)
388390
break;
389391

390392
// Try the temperature in the middle of the lower and upper bounds.
391393
double trial_temp = (lower_bound_temp + upper_bound_temp) / 2.0;
392394

395+
// Return the trial temperature if it is within 6 decimal-points of precision.
396+
// NOTE: This is arbitrary.
397+
// TODO: We could stop this early and then use Newton's Method to quickly
398+
// touch it up to a more accurate value.
399+
if (std::abs(upper_bound_temp - lower_bound_temp) / trial_temp < 1e-6)
400+
return trial_temp;
401+
393402
// Calculate the expected change in cost at this temperature (which we
394403
// call the residual here).
395404
double expected_total_post_rejected_cost = 0.0;
396405
for (double rejected_cost : rejected_swaps) {
397406
// Expected change in cost after a rejected swap is the change in
398407
// cost multiplied by the probability that this swap is accepted at
399408
// this temperature.
400-
double accpetance_prob = std::exp((-1.0 * rejected_cost) / trial_temp);
401-
expected_total_post_rejected_cost += rejected_cost * accpetance_prob;
409+
double acceptance_prob = std::exp((-1.0 * rejected_cost) / trial_temp);
410+
expected_total_post_rejected_cost += rejected_cost * acceptance_prob;
402411
}
403412
double residual = expected_total_post_rejected_cost + total_accepted_cost;
404413

405-
// Return the trial temperature if it is within 6 decimal-points of precision.
406-
// NOTE: This is arbitrary.
407-
// TODO: We could stop this early and then use Newton's Method to quickly
408-
// touch it up to a more accurate value.
409-
if (std::abs(upper_bound_temp - lower_bound_temp) / trial_temp < 1e-6)
410-
return trial_temp;
411-
412414
if (residual < 0) {
413415
// Since the function is monotonically increasing, if the residual
414416
// is negative, then the lower bound should be raised to the trial

vtr_flow/tasks/regression_tests/vtr_reg_strong/strong_place_init_t_est/config/config.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ arch_list_add=k6_frac_N10_40nm.xml
99

1010
# Add circuits to list to sweep
1111
circuit_list_add=alu4.pre-vpr.blif
12-
circuit_list_add=apex4.pre-vpr.blif
13-
circuit_list_add=ex5p.pre-vpr.blif
14-
circuit_list_add=misex3.pre-vpr.blif
1512

1613
# Parse info and how to parse
1714
parse_file=vpr_fixed_chan_width.txt
@@ -24,5 +21,5 @@ pass_requirements_file=pass_requirements_fixed_chan_width.txt
2421

2522
script_params_common=-starting_stage vpr --pack --place
2623
script_params_list_add=--anneal_auto_init_t_estimator cost_variance
27-
script_params_list_add=--anneal_auto_init_t_estimator equilibrium_est
24+
script_params_list_add=--anneal_auto_init_t_estimator equilibrium
2825

0 commit comments

Comments
 (0)