Skip to content

Commit 57cf345

Browse files
remove direct calls to comp_layer_bb_cost
1 parent 5651cbe commit 57cf345

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,10 @@ void NetCostHandler::find_affected_nets_and_update_costs(const t_place_algorithm
16091609
}
16101610

16111611
double NetCostHandler::comp_bb_cost(e_cost_methods method) {
1612+
return comp_bb_cost_functor_(method);
1613+
}
1614+
1615+
double NetCostHandler::comp_3d_bb_cost_(e_cost_methods method) {
16121616
double cost = 0;
16131617
double expected_wirelength = 0.0;
16141618
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -1644,7 +1648,7 @@ double NetCostHandler::comp_bb_cost(e_cost_methods method) {
16441648
return cost;
16451649
}
16461650

1647-
double NetCostHandler::comp_layer_bb_cost(e_cost_methods method) {
1651+
double NetCostHandler::comp_per_layer_bb_cost_(e_cost_methods method) {
16481652
double cost = 0;
16491653
double expected_wirelength = 0.0;
16501654
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -1910,9 +1914,11 @@ NetCostHandler::NetCostHandler(PlacerContext& placer_ctx, size_t num_nets, bool
19101914
if (cube_bb_) {
19111915
ts_info.ts_bb_edge_new.resize(num_nets, t_bb());
19121916
ts_info.ts_bb_coord_new.resize(num_nets, t_bb());
1917+
comp_bb_cost_functor_ = std::bind(&NetCostHandler::comp_3d_bb_cost_, this, std::placeholders::_1);
19131918
} else {
19141919
ts_info.layer_ts_bb_edge_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
19151920
ts_info.layer_ts_bb_coord_new.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
1921+
comp_bb_cost_functor_ = std::bind(&NetCostHandler::comp_per_layer_bb_cost_, this, std::placeholders::_1);
19161922
}
19171923

19181924
/* This initializes the whole matrix to OPEN which is an invalid value*/

vpr/src/place/net_cost_handler.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class NetCostHandler {
7575
double& timing_delta_c);
7676

7777
/**
78-
* @brief Finds the bb cost from scratch (based on 3D BB).
78+
* @brief Finds the bb cost from scratch.
7979
* Done only when the placement has been radically changed
8080
* (i.e. after initial placement). Otherwise find the cost
8181
* change incrementally. If method check is NORMAL, we find
@@ -84,23 +84,10 @@ class NetCostHandler {
8484
* non_updateable_bb routine, to provide a cost which can be
8585
* used to check the correctness of the other routine.
8686
* @param method The method used to calculate placement cost.
87-
* @return The bounding box cost of the placement, computed by the 3D method.
87+
* @return The bounding box cost of the placement.
8888
*/
8989
double comp_bb_cost(e_cost_methods method);
9090

91-
/**
92-
* @brief Finds the bb cost from scratch (based on per-layer BB).
93-
* Done only when the placement has been radically changed
94-
* (i.e. after initial placement). Otherwise find the cost change
95-
* incrementally. If method check is NORMAL, we find bounding boxes
96-
* that are updateable for the larger nets. If method is CHECK, all
97-
* bounding boxes are found via the non_updateable_bb routine, to provide
98-
* a cost which can be used to check the correctness of the other routine.
99-
* @param method The method used to calculate placement cost.
100-
* @return The placement bounding box cost, computed by the per layer method.
101-
*/
102-
double comp_layer_bb_cost(e_cost_methods method);
103-
10491
/**
10592
* @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before)
10693
*/
@@ -169,6 +156,8 @@ class NetCostHandler {
169156
bool cube_bb_ = false;
170157
PlacerContext& placer_ctx_;
171158

159+
std::function<double(e_cost_methods method)> comp_bb_cost_functor_;
160+
172161
private:
173162
/**
174163
* @brief Update the bounding box (3D) of the net connected to blk_pin. The old and new locations of the pin are
@@ -415,4 +404,7 @@ class NetCostHandler {
415404
std::vector<t_2D_bb>& bb_edge_new,
416405
std::vector<t_2D_bb>& bb_coord_new);
417406

407+
double comp_per_layer_bb_cost_(e_cost_methods method);
408+
double comp_3d_bb_cost_(e_cost_methods method);
409+
418410
};

vpr/src/place/place.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,7 @@ void try_place(const Netlist<>& net_list,
497497
/* Gets initial cost and loads bounding boxes. */
498498

499499
if (placer_opts.place_algorithm.is_timing_driven()) {
500-
if (cube_bb) {
501-
costs.bb_cost = net_cost_handler.comp_bb_cost(e_cost_methods::NORMAL);
502-
} else {
503-
VTR_ASSERT_SAFE(!cube_bb);
504-
costs.bb_cost = net_cost_handler.comp_layer_bb_cost(e_cost_methods::NORMAL);
505-
}
500+
costs.bb_cost = net_cost_handler.comp_bb_cost(e_cost_methods::NORMAL);
506501

507502
first_crit_exponent = placer_opts.td_place_exp_first; /*this will be modified when rlim starts to change */
508503

@@ -578,12 +573,7 @@ void try_place(const Netlist<>& net_list,
578573
VTR_ASSERT(placer_opts.place_algorithm == BOUNDING_BOX_PLACE);
579574

580575
/* Total cost is the same as wirelength cost normalized*/
581-
if (cube_bb) {
582-
costs.bb_cost = net_cost_handler.comp_bb_cost(e_cost_methods::NORMAL);
583-
} else {
584-
VTR_ASSERT_SAFE(!cube_bb);
585-
costs.bb_cost = net_cost_handler.comp_layer_bb_cost(e_cost_methods::NORMAL);
586-
}
576+
costs.bb_cost = net_cost_handler.comp_bb_cost(e_cost_methods::NORMAL);
587577
costs.bb_cost_norm = 1 / costs.bb_cost;
588578

589579
/* Timing cost and normalization factors are not used */
@@ -2029,17 +2019,9 @@ static int check_placement_costs(const t_placer_costs& costs,
20292019
PlacerContext& placer_ctx,
20302020
NetCostHandler& net_cost_handler) {
20312021
int error = 0;
2032-
double bb_cost_check;
20332022
double timing_cost_check;
20342023

2035-
const bool cube_bb = g_vpr_ctx.placement().cube_bb;
2036-
2037-
if (cube_bb) {
2038-
bb_cost_check = net_cost_handler.comp_bb_cost(e_cost_methods::CHECK);
2039-
} else {
2040-
VTR_ASSERT_SAFE(!cube_bb);
2041-
bb_cost_check = net_cost_handler.comp_layer_bb_cost(e_cost_methods::CHECK);
2042-
}
2024+
double bb_cost_check = net_cost_handler.comp_bb_cost(e_cost_methods::CHECK);
20432025

20442026
if (fabs(bb_cost_check - costs.bb_cost) > costs.bb_cost * ERROR_TOL) {
20452027
VTR_LOG_ERROR(

0 commit comments

Comments
 (0)