Skip to content

Commit ef8007f

Browse files
add get_net_bb_cost_functor_ and get_non_updatable_bb_functor_
1 parent 521c9e3 commit ef8007f

File tree

2 files changed

+65
-82
lines changed

2 files changed

+65
-82
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ NetCostHandler::NetCostHandler(const t_placer_opts& placer_opts,
129129
comp_bb_cost_functor_ = std::bind(&NetCostHandler::comp_cube_bb_cost_, this, std::placeholders::_1);
130130
update_bb_functor_ = std::bind(&NetCostHandler::update_bb_, this, std::placeholders::_1, std::placeholders::_2,
131131
std::placeholders::_3, std::placeholders::_4);
132+
get_net_bb_cost_functor_ = std::bind(&NetCostHandler::get_net_cube_bb_cost_, this, std::placeholders::_1, /*use_ts=*/true);
133+
get_non_updatable_bb_functor_ = std::bind(&NetCostHandler::get_non_updatable_cube_bb_, this, std::placeholders::_1, /*use_ts=*/true);
132134
} else {
133135
layer_ts_bb_edge_new_.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
134136
layer_ts_bb_coord_new_.resize(num_nets, std::vector<t_2D_bb>(num_layers, t_2D_bb()));
135137
comp_bb_cost_functor_ = std::bind(&NetCostHandler::comp_per_layer_bb_cost_, this, std::placeholders::_1);
136138
update_bb_functor_ = std::bind(&NetCostHandler::update_layer_bb_, this, std::placeholders::_1, std::placeholders::_2,
137139
std::placeholders::_3, std::placeholders::_4);
140+
get_net_bb_cost_functor_ = std::bind(&NetCostHandler::get_net_per_layer_bb_cost_, this, std::placeholders::_1, /*use_ts=*/true);
141+
get_non_updatable_bb_functor_ = std::bind(&NetCostHandler::get_non_updatable_per_layer_bb_, this, std::placeholders::_1, /*use_ts=*/true);
138142
}
139143

140144
/* This initializes the whole matrix to OPEN which is an invalid value*/
@@ -262,12 +266,10 @@ double NetCostHandler::comp_cube_bb_cost_(e_cost_methods method) {
262266
place_move_ctx.bb_num_on_edges[net_id],
263267
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
264268
} else {
265-
get_non_updatable_cube_bb_(net_id,
266-
place_move_ctx.bb_coords[net_id],
267-
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
269+
get_non_updatable_cube_bb_(net_id, /*use_ts=*/false);
268270
}
269271

270-
net_cost_[net_id] = get_net_cube_bb_cost_(net_id, place_move_ctx.bb_coords[net_id]);
272+
net_cost_[net_id] = get_net_cube_bb_cost_(net_id, /*use_ts=*/false);
271273
cost += net_cost_[net_id];
272274
if (method == e_cost_methods::CHECK) {
273275
expected_wirelength += get_net_wirelength_estimate(net_id, place_move_ctx.bb_coords[net_id]);
@@ -301,14 +303,10 @@ double NetCostHandler::comp_per_layer_bb_cost_(e_cost_methods method) {
301303
place_move_ctx.layer_bb_coords[net_id],
302304
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
303305
} else {
304-
get_non_updatable_per_layer_bb_(net_id,
305-
place_move_ctx.layer_bb_coords[net_id],
306-
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
306+
get_non_updatable_per_layer_bb_(net_id, /*use_ts=*/false);
307307
}
308308

309-
net_cost_[net_id] = get_net_per_layer_bb_cost_(net_id,
310-
place_move_ctx.layer_bb_coords[net_id],
311-
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
309+
net_cost_[net_id] = get_net_per_layer_bb_cost_(net_id, /*use_ts=*/false);
312310
cost += net_cost_[net_id];
313311
if (method == e_cost_methods::CHECK) {
314312
expected_wirelength += get_net_wirelength_from_layer_bb_(net_id);
@@ -336,7 +334,7 @@ void NetCostHandler::update_net_bb_(const ClusterNetId net,
336334
//For small nets brute-force bounding box update is faster
337335

338336
if (bb_update_status_[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
339-
get_non_updatable_bb_(net);
337+
get_non_updatable_bb_functor_(net);
340338
}
341339
} else {
342340
//For large nets, update bounding box incrementally
@@ -500,13 +498,15 @@ void NetCostHandler::update_net_info_on_pin_move_(const PlaceDelayModel* delay_m
500498
}
501499
}
502500

503-
void NetCostHandler::get_non_updatable_cube_bb_(ClusterNetId net_id,
504-
t_bb& bb_coord_new,
505-
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer) {
501+
void NetCostHandler::get_non_updatable_cube_bb_(ClusterNetId net_id, bool use_ts) {
506502
//TODO: account for multiple physical pin instances per logical pin
507-
auto& cluster_ctx = g_vpr_ctx.clustering();
508-
auto& device_ctx = g_vpr_ctx.device();
509-
auto& block_locs = placer_state_.block_locs();
503+
const auto& cluster_ctx = g_vpr_ctx.clustering();
504+
const auto& device_ctx = g_vpr_ctx.device();
505+
const auto& block_locs = placer_state_.block_locs();
506+
auto& move_ctx = placer_state_.mutable_move();
507+
508+
t_bb& bb_coord_new = use_ts ? ts_bb_coord_new_[net_id] : move_ctx.bb_coords[net_id];
509+
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer = use_ts ? ts_layer_sink_pin_count_[size_t(net_id)] : move_ctx.num_sink_pin_layer[size_t(net_id)];
510510

511511
ClusterBlockId bnum = cluster_ctx.clb_nlist.net_driver_block(net_id);
512512
int pnum = placer_state_.blk_loc_registry().net_pin_to_tile_pin_index(net_id, 0);
@@ -572,13 +572,15 @@ void NetCostHandler::get_non_updatable_cube_bb_(ClusterNetId net_id,
572572
bb_coord_new.layer_max = max(min<int>(layer_max, device_ctx.grid.get_num_layers() - 1), 0);
573573
}
574574

575-
void NetCostHandler::get_non_updatable_per_layer_bb_(ClusterNetId net_id,
576-
std::vector<t_2D_bb>& bb_coord_new,
577-
vtr::NdMatrixProxy<int, 1> num_sink_layer) {
575+
void NetCostHandler::get_non_updatable_per_layer_bb_(ClusterNetId net_id, bool use_ts) {
578576
//TODO: account for multiple physical pin instances per logical pin
579577
auto& device_ctx = g_vpr_ctx.device();
580578
auto& cluster_ctx = g_vpr_ctx.clustering();
581579
auto& block_locs = placer_state_.block_locs();
580+
auto& move_ctx = placer_state_.mutable_move();
581+
582+
std::vector<t_2D_bb>& bb_coord_new = use_ts ? layer_ts_bb_coord_new_[net_id] : move_ctx.layer_bb_coords[net_id];
583+
vtr::NdMatrixProxy<int, 1> num_sink_layer = use_ts ? ts_layer_sink_pin_count_[size_t(net_id)] : move_ctx.num_sink_pin_layer[size_t(net_id)];
582584

583585
const int num_layers = device_ctx.grid.get_num_layers();
584586
VTR_ASSERT_DEBUG(bb_coord_new.size() == num_layers);
@@ -1456,10 +1458,12 @@ void NetCostHandler::get_layer_bb_from_scratch_(ClusterNetId net_id,
14561458
}
14571459
}
14581460

1459-
double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, const t_bb& bb) {
1461+
double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts) {
14601462
// Finds the cost due to one net by looking at its coordinate bounding box.
14611463
auto& cluster_ctx = g_vpr_ctx.clustering();
14621464

1465+
const t_bb& bb = use_ts ? ts_bb_coord_new_[net_id] : placer_state_.move().bb_coords[net_id];
1466+
14631467
double crossing = wirelength_crossing_count(cluster_ctx.clb_nlist.net_pins(net_id).size());
14641468

14651469
/* Could insert a check for xmin == xmax. In that case, assume *
@@ -1476,14 +1480,17 @@ double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, const t_bb& bb
14761480
return ncost;
14771481
}
14781482

1479-
double NetCostHandler::get_net_per_layer_bb_cost_(ClusterNetId /* net_id */,
1480-
const std::vector<t_2D_bb>& bb,
1481-
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count) {
1482-
// Finds the cost due to one net by looking at its coordinate bounding box.
1483+
double NetCostHandler::get_net_per_layer_bb_cost_(ClusterNetId net_id , bool use_ts) {
1484+
const auto& move_ctx = placer_state_.move();
1485+
const std::vector<t_2D_bb>& bb = use_ts ? layer_ts_bb_coord_new_[net_id] : move_ctx.layer_bb_coords[net_id];
1486+
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count = use_ts ? ts_layer_sink_pin_count_[size_t(net_id)] : move_ctx.num_sink_pin_layer[size_t(net_id)];
14831487

1488+
// Finds the cost due to one net by looking at its coordinate bounding box
14841489
double ncost = 0.;
14851490
int num_layers = g_vpr_ctx.device().grid.get_num_layers();
14861491

1492+
1493+
14871494
for (int layer_num = 0; layer_num < num_layers; layer_num++) {
14881495
VTR_ASSERT(layer_pin_sink_count[layer_num] != OPEN);
14891496
if (layer_pin_sink_count[layer_num] == 0) {
@@ -1592,7 +1599,7 @@ void NetCostHandler::set_bb_delta_cost_(double& bb_delta_c) {
15921599
for (const ClusterNetId ts_net: ts_nets_to_update_) {
15931600
ClusterNetId net_id = ts_net;
15941601

1595-
proposed_net_cost_[net_id] = get_net_bb_cost_(net_id);
1602+
proposed_net_cost_[net_id] = get_net_bb_cost_functor_(net_id);
15961603

15971604
bb_delta_c += proposed_net_cost_[net_id] - net_cost_[net_id];
15981605
}
@@ -1734,27 +1741,6 @@ void NetCostHandler::recompute_costs_from_scratch(const t_noc_opts& noc_opts,
17341741
}
17351742
}
17361743

1737-
void NetCostHandler::get_non_updatable_bb_(const ClusterNetId net) {
1738-
if (cube_bb_) {
1739-
get_non_updatable_cube_bb_(net,
1740-
ts_bb_coord_new_[net],
1741-
ts_layer_sink_pin_count_[size_t(net)]);
1742-
}
1743-
else {
1744-
get_non_updatable_per_layer_bb_(net,
1745-
layer_ts_bb_coord_new_[net],
1746-
ts_layer_sink_pin_count_[size_t(net)]);
1747-
}
1748-
}
1749-
1750-
double NetCostHandler::get_net_bb_cost_(const ClusterNetId net_id) {
1751-
if (cube_bb_) {
1752-
return get_net_cube_bb_cost_(net_id, ts_bb_coord_new_[net_id]);
1753-
} else {
1754-
return get_net_per_layer_bb_cost_(net_id, layer_ts_bb_coord_new_[net_id], ts_layer_sink_pin_count_[size_t(net_id)]);
1755-
}
1756-
}
1757-
17581744
void NetCostHandler::set_ts_bb_coord_(const ClusterNetId net_id) {
17591745
auto& place_move_ctx = placer_state_.mutable_move();
17601746
if (cube_bb_) {

vpr/src/place/net_cost_handler.h

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class NetCostHandler {
138138
///@brief Points to the proper method for updating the bounding box of a net.
139139
std::function<void(ClusterNetId net_id, t_physical_tile_loc pin_old_loc, t_physical_tile_loc pin_new_loc, bool is_driver)> update_bb_functor_;
140140

141+
std::function<double(ClusterNetId)> get_net_bb_cost_functor_;
142+
143+
std::function<void(const ClusterNetId net)> get_non_updatable_bb_functor_;
144+
141145
/**
142146
* @brief for the states of the bounding box.
143147
*/
@@ -264,9 +268,7 @@ class NetCostHandler {
264268
double& delta_timing_cost,
265269
bool is_src_moving);
266270

267-
void get_non_updatable_bb_(const ClusterNetId net);
268271

269-
double get_net_bb_cost_(const ClusterNetId net_id);
270272

271273
void set_ts_bb_coord_(const ClusterNetId net_id);
272274

@@ -279,9 +281,7 @@ class NetCostHandler {
279281
* @param bb_coord_new Computed by this function and returned by reference.
280282
* @param num_sink_pin_layer Store the number of sink pins of "net_id" on each layer
281283
*/
282-
void get_non_updatable_cube_bb_(ClusterNetId net_id,
283-
t_bb& bb_coord_new,
284-
vtr::NdMatrixProxy<int, 1> num_sink_pin_layer);
284+
void get_non_updatable_cube_bb_(ClusterNetId net_id, bool use_ts);
285285

286286
/**
287287
* @brief Calculate the per-layer bounding box of "net_id" from scratch (based on the block locations stored in place_ctx) and
@@ -290,9 +290,7 @@ class NetCostHandler {
290290
* @param bb_coord_new Computed by this function and returned by reference.
291291
* @param num_sink_layer Store the number of sink pins of "net_id" on each layer
292292
*/
293-
void get_non_updatable_per_layer_bb_(ClusterNetId net_id,
294-
std::vector<t_2D_bb>& bb_coord_new,
295-
vtr::NdMatrixProxy<int, 1> num_sink_layer);
293+
void get_non_updatable_per_layer_bb_(ClusterNetId net_id, bool use_sink);
296294

297295
/**
298296
* @brief Calculate the 3D BB of a large net from scratch and update coord, edge, and num_sink_pin_layer data structures.
@@ -447,43 +445,42 @@ class NetCostHandler {
447445
double comp_cube_bb_cost_(e_cost_methods method);
448446

449447
/**
450-
* @brief if "net" is not already stored as an affected net, add it in ts_nets_to_update.
451-
* @param net ID of a net affected by a move
452-
*/
448+
* @brief if "net" is not already stored as an affected net, add it in ts_nets_to_update.
449+
* @param net ID of a net affected by a move
450+
*/
453451
void record_affected_net_(const ClusterNetId net);
454452

455453
/**
456-
* @brief To mitigate round-off errors, every once in a while, the costs of nets are summed up from scratch.
457-
* This functions is called to do that for bb cost. It doesn't calculate the BBs from scratch, it would only add the costs again.
458-
* @return Total bb (wirelength) cost for the placement
459-
*/
454+
* @brief To mitigate round-off errors, every once in a while, the costs of nets are summed up from scratch.
455+
* This functions is called to do that for bb cost. It doesn't calculate the BBs from scratch, it would only add the costs again.
456+
* @return Total bb (wirelength) cost for the placement
457+
*/
460458
double recompute_bb_cost_();
461459

462460
/**
463-
* @brief Given the 3D BB, calculate the wire-length cost of the net
464-
* @param net_id ID of the net which cost is requested
465-
* @param bb Bounding box of the net
466-
* @return Wirelength cost of the net
467-
*/
468-
double get_net_cube_bb_cost_(ClusterNetId net_id, const t_bb& bb);
461+
* @brief Given the 3D BB, calculate the wire-length cost of the net
462+
* @param net_id ID of the net which cost is requested.
463+
* @param use_ts Specifies if the bounding box is retrieved from ts data structures
464+
* or move context.
465+
* @return Wirelength cost of the net
466+
*/
467+
double get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts);
469468

470469
/**
471-
* @brief Given the per-layer BB, calculate the wire-length cost of the net on each layer
472-
* and return the sum of the costs
473-
* @param net_id ID of the net which cost is requested. Currently unused
474-
* @param bb Per-layer bounding box of the net
475-
* @return Wirelength cost of the net
476-
*/
477-
double get_net_per_layer_bb_cost_(ClusterNetId net_id,
478-
const std::vector<t_2D_bb>& bb,
479-
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count);
470+
* @brief Given the per-layer BB, calculate the wire-length cost of the net on each layer
471+
* and return the sum of the costs
472+
* @param net_id ID of the net which cost is requested. Currently unused
473+
* @param bb Per-layer bounding box of the net
474+
* @return Wirelength cost of the net
475+
*/
476+
double get_net_per_layer_bb_cost_(ClusterNetId net_id, bool use_ts);
480477

481478
/**
482-
* @brief Given the per-layer BB, calculate the wire-length estimate of the net on each layer
483-
* and return the sum of the lengths
484-
* @param net_id ID of the net which wirelength estimate is requested
485-
* @return Wirelength estimate of the net
486-
*/
479+
* @brief Given the per-layer BB, calculate the wire-length estimate of the net on each layer
480+
* and return the sum of the lengths
481+
* @param net_id ID of the net which wirelength estimate is requested
482+
* @return Wirelength estimate of the net
483+
*/
487484
double get_net_wirelength_from_layer_bb_(ClusterNetId net_id);
488485

489486
};

0 commit comments

Comments
 (0)