@@ -302,7 +302,7 @@ float PlacementAnnealer::estimate_starting_temperature_() {
302
302
switch (placer_opts_.anneal_init_t_estimator ) {
303
303
case e_anneal_init_t_estimator::COST_VARIANCE:
304
304
return estimate_starting_temp_using_cost_variance_ ();
305
- case e_anneal_init_t_estimator::EQUILIBRIUM_EST :
305
+ case e_anneal_init_t_estimator::EQUILIBRIUM :
306
306
return estimate_equilibrium_temp_ ();
307
307
default :
308
308
VPR_FATAL_ERROR (VPR_ERROR_PLACE,
@@ -328,18 +328,9 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
328
328
accepted_swaps.reserve (move_lim);
329
329
rejected_swaps.reserve (move_lim);
330
330
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
-
340
331
t_swap_result swap_result = try_swap_ (*move_generator_1_,
341
332
placer_opts_.place_algorithm ,
342
- manual_move_enabled);
333
+ false /* manual_move_enabled*/ );
343
334
344
335
if (swap_result.move_result == e_move_result::ACCEPTED) {
345
336
accepted_swaps.push_back (swap_result.delta_c );
@@ -361,6 +352,14 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
361
352
total_accepted_cost += accepted_cost;
362
353
}
363
354
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
+
364
363
// Perform a binary search to try and find the equilibrium temperature for
365
364
// this placement. This is the temperature that we expect would lead to no
366
365
// overall change in temperature. We do this by computing the expected
@@ -372,43 +371,46 @@ float PlacementAnnealer::estimate_equilibrium_temp_() {
372
371
// Initialize the lower bound temperature to 0. The temperature cannot
373
372
// be less than 0.
374
373
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
376
375
// the equilibrium temperature to be infinite if the initial placement
377
376
// is so bad that no swaps are accepted. In that case this value will
378
377
// 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;
381
383
// The max search iterations should never be hit, but it is here as an
382
384
// exit condition to prevent infinite loops.
383
385
constexpr unsigned max_search_iters = 100 ;
384
386
for (unsigned binary_search_iter = 0 ; binary_search_iter < max_search_iters; binary_search_iter++) {
385
387
// Exit condition for binary search. Could be hit if the lower and upper
386
388
// bounds are arbitrarily close.
387
- if (lower_bound_temp > upper_bound_temp)
389
+ if (lower_bound_temp >= upper_bound_temp)
388
390
break ;
389
391
390
392
// Try the temperature in the middle of the lower and upper bounds.
391
393
double trial_temp = (lower_bound_temp + upper_bound_temp) / 2.0 ;
392
394
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
+
393
402
// Calculate the expected change in cost at this temperature (which we
394
403
// call the residual here).
395
404
double expected_total_post_rejected_cost = 0.0 ;
396
405
for (double rejected_cost : rejected_swaps) {
397
406
// Expected change in cost after a rejected swap is the change in
398
407
// cost multiplied by the probability that this swap is accepted at
399
408
// 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 ;
402
411
}
403
412
double residual = expected_total_post_rejected_cost + total_accepted_cost;
404
413
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
-
412
414
if (residual < 0 ) {
413
415
// Since the function is monotonically increasing, if the residual
414
416
// is negative, then the lower bound should be raised to the trial
0 commit comments