Skip to content

Commit 29dcbf1

Browse files
committed
Merged t_placer_costs and t_placer_prev_inverse_costs. Provided more detailed documentation on the new combined structure t_placer_costs.
1 parent 2f1b25d commit 29dcbf1

File tree

3 files changed

+95
-56
lines changed

3 files changed

+95
-56
lines changed

vpr/src/place/place.cpp

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ struct t_placer_statistics {
9696
};
9797

9898
constexpr float INVALID_DELAY = std::numeric_limits<float>::quiet_NaN();
99-
100-
constexpr double MAX_INV_TIMING_COST = 1.e9;
101-
/* Stops inverse timing cost from going to infinity with very lax timing constraints,
102-
* which avoids multiplying by a gigantic prev_inverse.timing_cost when auto-normalizing.
103-
* The exact value of this cost has relatively little impact, but should not be
104-
* large enough to be on the order of timing costs for normal constraints. */
99+
constexpr float INVALID_COST = std::numeric_limits<double>::quiet_NaN();
105100

106101
/********************** Variables local to place.c ***************************/
107102

@@ -265,7 +260,6 @@ static void reset_move_nets(int num_nets_affected);
265260
static e_move_result try_swap(float t,
266261
float crit_exponent,
267262
t_placer_costs* costs,
268-
t_placer_prev_inverse_costs* prev_inverse_costs,
269263
float rlim,
270264
MoveGenerator& move_generator,
271265
SetupTimingInfo* timing_info,
@@ -293,7 +287,6 @@ static int check_macro_placement_consistency();
293287

294288
static float starting_t(float crit_exponent,
295289
t_placer_costs* costs,
296-
t_placer_prev_inverse_costs* prev_inverse_costs,
297290
t_annealing_sched annealing_sched,
298291
int max_moves,
299292
float rlim,
@@ -369,7 +362,6 @@ static void free_try_swap_arrays();
369362

370363
static void outer_loop_update_timing_info(const t_placer_opts& placer_opts,
371364
t_placer_costs* costs,
372-
t_placer_prev_inverse_costs* prev_inverse_costs,
373365
int num_connections,
374366
float crit_exponent,
375367
int* outer_crit_iter_count,
@@ -388,7 +380,6 @@ static void placement_inner_loop(float t,
388380
int inner_recompute_limit,
389381
t_placer_statistics* stats,
390382
t_placer_costs* costs,
391-
t_placer_prev_inverse_costs* prev_inverse_costs,
392383
int* moves_since_cost_recompute,
393384
ClusteredPinTimingInvalidator* pin_timing_invalidator,
394385
const PlaceDelayModel* delay_model,
@@ -458,8 +449,7 @@ void try_place(const t_placer_opts& placer_opts,
458449
outer_crit_iter_count, inner_recompute_limit;
459450
float success_rat, first_crit_exponent, first_rlim;
460451

461-
t_placer_costs costs;
462-
t_placer_prev_inverse_costs prev_inverse_costs;
452+
t_placer_costs costs(placer_opts.place_algorithm);
463453

464454
tatum::TimingPathInfo critical_path;
465455
float sTNS = NAN;
@@ -573,7 +563,7 @@ void try_place(const t_placer_opts& placer_opts,
573563

574564
critical_path = timing_info->least_slack_critical_path();
575565

576-
//Write out the initial timing echo file
566+
/* Write out the initial timing echo file */
577567
if (isEchoFileEnabled(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH)) {
578568
tatum::write_echo(getEchoFileName(E_ECHO_INITIAL_PLACEMENT_TIMING_GRAPH),
579569
*timing_ctx.graph, *timing_ctx.constraints, *placement_delay_calc, timing_info->analyzer());
@@ -585,20 +575,27 @@ void try_place(const t_placer_opts& placer_opts,
585575

586576
outer_crit_iter_count = 1;
587577

588-
prev_inverse_costs.timing_cost = 1 / costs.timing_cost;
589-
prev_inverse_costs.bb_cost = 1 / costs.bb_cost;
590-
costs.cost = 1; /*our new cost function uses normalized values of */
591-
/*bb_cost and timing_cost, the value of cost will be reset */
592-
/*to 1 at each temperature when *_TIMING_DRIVEN_PLACE is true */
593-
} else { /*BOUNDING_BOX_PLACE */
594-
costs.cost = costs.bb_cost = comp_bb_cost(NORMAL);
595-
costs.timing_cost = 0;
578+
/* Initialize the normalization factors. Calling costs.update_norm_factors() *
579+
* here would fail the golden results of strong_sdc benchmark */
580+
costs.timing_cost_norm = 1 / costs.timing_cost;
581+
costs.bb_cost_norm = 1 / costs.bb_cost;
582+
costs.cost = 1;
583+
} else {
584+
VTR_ASSERT(placer_opts.place_algorithm == BOUNDING_BOX_PLACE);
585+
586+
/* Total cost is the same as wirelength cost */
587+
costs.bb_cost = comp_bb_cost(NORMAL);
588+
costs.cost = costs.bb_cost;
589+
590+
/* Timing cost and normalization factors are not used */
591+
costs.timing_cost = INVALID_COST;
592+
costs.timing_cost_norm = INVALID_COST;
593+
costs.bb_cost_norm = INVALID_COST;
594+
595+
/* Other initializations */
596596
outer_crit_iter_count = 0;
597597
num_connections = 0;
598598
first_crit_exponent = 0;
599-
600-
prev_inverse_costs.timing_cost = 0; /*inverses not used */
601-
prev_inverse_costs.bb_cost = 0;
602599
}
603600

604601
//Sanity check that initial placement is legal
@@ -683,7 +680,7 @@ void try_place(const t_placer_opts& placer_opts,
683680
first_rlim = (float)max(device_ctx.grid.width() - 1, device_ctx.grid.height() - 1);
684681

685682
float first_t = starting_t(first_crit_exponent,
686-
&costs, &prev_inverse_costs,
683+
&costs,
687684
annealing_sched, move_lim, first_rlim,
688685
place_delay_model.get(),
689686
placer_criticalities.get(),
@@ -720,12 +717,9 @@ void try_place(const t_placer_opts& placer_opts,
720717
/* Outer loop of the simulated annealing begins */
721718
do {
722719
vtr::Timer temperature_timer;
723-
if (placer_opts.place_algorithm.is_timing_driven()) {
724-
costs.cost = 1;
725-
}
726720

727721
outer_loop_update_timing_info(placer_opts,
728-
&costs, &prev_inverse_costs,
722+
&costs,
729723
num_connections,
730724
state.crit_exponent,
731725
&outer_crit_iter_count,
@@ -737,7 +731,7 @@ void try_place(const t_placer_opts& placer_opts,
737731

738732
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
739733
state.move_lim, state.crit_exponent, inner_recompute_limit, &stats,
740-
&costs, &prev_inverse_costs,
734+
&costs,
741735
&moves_since_cost_recompute,
742736
pin_timing_invalidator.get(),
743737
place_delay_model.get(),
@@ -789,7 +783,7 @@ void try_place(const t_placer_opts& placer_opts,
789783
vtr::ScopedFinishTimer temperature_timer("Placement Quench");
790784

791785
outer_loop_update_timing_info(placer_opts,
792-
&costs, &prev_inverse_costs,
786+
&costs,
793787
num_connections,
794788
state.crit_exponent,
795789
&outer_crit_iter_count,
@@ -805,7 +799,7 @@ void try_place(const t_placer_opts& placer_opts,
805799
* which reduce the cost of the placement */
806800
placement_inner_loop(state.t, num_temps, state.rlim, placer_opts,
807801
move_lim, state.crit_exponent, quench_recompute_limit, &stats,
808-
&costs, &prev_inverse_costs,
802+
&costs,
809803
&moves_since_cost_recompute,
810804
pin_timing_invalidator.get(),
811805
place_delay_model.get(),
@@ -928,7 +922,6 @@ void try_place(const t_placer_opts& placer_opts,
928922
/* Function to update the setup slacks and criticalities before the inner loop of the annealing/quench */
929923
static void outer_loop_update_timing_info(const t_placer_opts& placer_opts,
930924
t_placer_costs* costs,
931-
t_placer_prev_inverse_costs* prev_inverse_costs,
932925
int num_connections,
933926
float crit_exponent,
934927
int* outer_crit_iter_count,
@@ -964,11 +957,8 @@ static void outer_loop_update_timing_info(const t_placer_opts& placer_opts,
964957
}
965958
(*outer_crit_iter_count)++;
966959

967-
/*at each temperature change we update these values to be used */
968-
/*for normalizing the tradeoff between timing and wirelength (bb) */
969-
prev_inverse_costs->bb_cost = 1 / costs->bb_cost;
970-
/*Prevent inverse timing cost from going to infinity */
971-
prev_inverse_costs->timing_cost = min(1 / costs->timing_cost, MAX_INV_TIMING_COST);
960+
/* Update the cost normalization factors */
961+
costs->update_norm_factors();
972962
}
973963

974964
/* Function which contains the inner loop of the simulated annealing */
@@ -981,7 +971,6 @@ static void placement_inner_loop(float t,
981971
int inner_recompute_limit,
982972
t_placer_statistics* stats,
983973
t_placer_costs* costs,
984-
t_placer_prev_inverse_costs* prev_inverse_costs,
985974
int* moves_since_cost_recompute,
986975
ClusteredPinTimingInvalidator* pin_timing_invalidator,
987976
const PlaceDelayModel* delay_model,
@@ -1008,7 +997,6 @@ static void placement_inner_loop(float t,
1008997
e_move_result swap_result = try_swap(t,
1009998
crit_exponent,
1010999
costs,
1011-
prev_inverse_costs,
10121000
rlim,
10131001
move_generator,
10141002
timing_info,
@@ -1239,7 +1227,6 @@ static bool update_annealing_state(t_annealing_state* state,
12391227

12401228
static float starting_t(float crit_exponent,
12411229
t_placer_costs* costs,
1242-
t_placer_prev_inverse_costs* prev_inverse_costs,
12431230
t_annealing_sched annealing_sched,
12441231
int max_moves,
12451232
float rlim,
@@ -1275,7 +1262,6 @@ static float starting_t(float crit_exponent,
12751262
e_move_result swap_result = try_swap(t,
12761263
crit_exponent,
12771264
costs,
1278-
prev_inverse_costs,
12791265
rlim,
12801266
move_generator,
12811267
timing_info,
@@ -1350,7 +1336,6 @@ static void reset_move_nets(int num_nets_affected) {
13501336
static e_move_result try_swap(float t,
13511337
float crit_exponent,
13521338
t_placer_costs* costs,
1353-
t_placer_prev_inverse_costs* prev_inverse_costs,
13541339
float rlim,
13551340
MoveGenerator& move_generator,
13561341
SetupTimingInfo* timing_info,
@@ -1472,8 +1457,8 @@ static e_move_result try_swap(float t,
14721457
/*in this case we redefine delta_c as a combination of timing and bb. *
14731458
*additionally, we normalize all values, therefore delta_c is in *
14741459
*relation to 1*/
1475-
delta_c = (1 - timing_tradeoff) * bb_delta_c * prev_inverse_costs->bb_cost
1476-
+ timing_tradeoff * timing_delta_c * prev_inverse_costs->timing_cost;
1460+
delta_c = (1 - timing_tradeoff) * bb_delta_c * costs->bb_cost_norm
1461+
+ timing_tradeoff * timing_delta_c * costs->timing_cost_norm;
14771462

14781463
} else {
14791464
VTR_ASSERT(place_algorithm == BOUNDING_BOX_PLACE);
@@ -1559,8 +1544,8 @@ static e_move_result try_swap(float t,
15591544
}
15601545

15611546
move_outcome_stats.delta_cost_norm = delta_c;
1562-
move_outcome_stats.delta_bb_cost_norm = bb_delta_c * prev_inverse_costs->bb_cost;
1563-
move_outcome_stats.delta_timing_cost_norm = timing_delta_c * prev_inverse_costs->timing_cost;
1547+
move_outcome_stats.delta_bb_cost_norm = bb_delta_c * costs->bb_cost_norm;
1548+
move_outcome_stats.delta_timing_cost_norm = timing_delta_c * costs->timing_cost_norm;
15641549

15651550
move_outcome_stats.delta_bb_cost_abs = bb_delta_c;
15661551
move_outcome_stats.delta_timing_cost_abs = timing_delta_c;

vpr/src/place/place_util.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,21 @@ static vtr::Matrix<t_grid_blocks> init_grid_blocks() {
3434

3535
return grid_blocks;
3636
}
37+
38+
/**
39+
* @brief Mutator: updates the norm factors in the outer loop iteration.
40+
*
41+
* At each temperature change we update these values to be used
42+
* for normalizing the trade-off between timing and wirelength (bb)
43+
*/
44+
void t_placer_costs::update_norm_factors() {
45+
if (place_algorithm.is_timing_driven()) {
46+
bb_cost_norm = 1 / bb_cost;
47+
//Prevent the norm factor from going to infinity
48+
timing_cost_norm = std::min(1 / timing_cost, MAX_INV_TIMING_COST);
49+
cost = 1; //The value of cost will be reset to 1 if timing driven
50+
} else {
51+
VTR_ASSERT_SAFE(place_algorithm == BOUNDING_BOX_PLACE);
52+
cost = bb_cost; //The cost value should be identical to the wirelength cost
53+
}
54+
}

vpr/src/place/place_util.h

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,56 @@
55
*/
66

77
#pragma once
8+
#include "vpr_types.h"
89

9-
struct t_placer_costs {
10-
//Although we do nost cost calculations with float's we
11-
//use doubles for the accumulated costs to avoid round-off,
12-
//particularly on large designs where the magnitude of a single
13-
//move's delta cost is small compared to the overall cost.
10+
/**
11+
* @brief Data structure that stores different cost values in the placer.
12+
*
13+
* Although we do cost calculations with float values, we use doubles
14+
* for the accumulated costs to avoid round-off, particularly on large
15+
* designs where the magnitude of a single move's delta cost is small
16+
* compared to the overall cost.
17+
*
18+
* The cost normalization factors are updated upon every temperature change
19+
* in the outer_loop_update_timing_info routine. They are the multiplicative
20+
* inverses of their respective cost values when the routine is called. They
21+
* serve to normalize the trade-off between timing and wirelength (bb).
22+
*
23+
* @param cost The weighted average of the wiring cost and the timing cost.
24+
* @param bb_cost The bounding box cost, aka the wiring cost.
25+
* @param timing_cost The timing cost, which is connection delay * criticality.
26+
*
27+
* @param bb_cost_norm The normalization factor for the wiring cost.
28+
* @param timing_cost_norm The normalization factor for the timing cost, which
29+
* is upper-bounded by the value of MAX_INV_TIMING_COST.
30+
*
31+
* @param MAX_INV_TIMING_COST Stops inverse timing cost from going to infinity
32+
* with very lax timing constraints, which avoids multiplying by a
33+
* gigantic timing_cost_norm when auto-normalizing. The exact value
34+
* of this cost has relatively little impact, but should not be large
35+
* enough to be on the order of timing costs for normal constraints.
36+
*
37+
* @param place_algorithm Determines how the member values are updated upon
38+
* each temperature change during the placer annealing process.
39+
*/
40+
class t_placer_costs {
41+
public: //members
1442
double cost;
1543
double bb_cost;
1644
double timing_cost;
17-
};
45+
double bb_cost_norm;
46+
double timing_cost_norm;
1847

19-
struct t_placer_prev_inverse_costs {
20-
double bb_cost;
21-
double timing_cost;
48+
public: //Constructor
49+
t_placer_costs(t_place_algorithm algo)
50+
: place_algorithm(algo) {}
51+
52+
public: //Mutator
53+
void update_norm_factors();
54+
55+
private:
56+
double MAX_INV_TIMING_COST = 1.e9;
57+
t_place_algorithm place_algorithm;
2258
};
2359

2460
// Used by update_annealing_state()

0 commit comments

Comments
 (0)