Skip to content

Commit 46a089e

Browse files
add congestion_modeling_started_ flag to NetCostHandler
1 parent f3b49e7 commit 46a089e

File tree

3 files changed

+64
-43
lines changed

3 files changed

+64
-43
lines changed

vpr/src/place/annealer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class PlacementAnnealer {
329329
int tot_iter_;
330330
/// Indicates whether the annealer has entered into the quench stage
331331
bool quench_started_;
332-
332+
/// Indicates whether routing congestion modeling has been started
333333
bool congestion_modeling_started_;
334334

335335
void LOG_MOVE_STATS_HEADER();

vpr/src/place/net_cost_handler.cpp

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ static double wirelength_crossing_count(size_t fanout);
9797
NetCostHandler::NetCostHandler(const t_placer_opts& placer_opts,
9898
PlacerState& placer_state,
9999
bool cube_bb)
100-
: cube_bb_(cube_bb)
100+
: congestion_modeling_started_(false)
101+
, cube_bb_(cube_bb)
101102
, placer_state_(placer_state)
102103
, placer_opts_(placer_opts) {
103104
const auto& device_ctx = g_vpr_ctx.device();
@@ -279,7 +280,6 @@ std::tuple<double, double, double> NetCostHandler::comp_cube_bb_cong_cost_(e_cos
279280

280281
double bb_cost = 0.;
281282
double expected_wirelength = 0.;
282-
double cong_cost = 0.;
283283

284284
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
285285
if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
@@ -299,18 +299,17 @@ std::tuple<double, double, double> NetCostHandler::comp_cube_bb_cong_cost_(e_cos
299299
}
300300
}
301301

302-
// Now that all bounding boxes are computed from scratch, we recompute the channel utilization
303-
// estimate_routing_chann_util();
304-
302+
double cong_cost = 0.;
305303
// Compute congestion cost using recomputed bounding boxes and channel utilization map
306-
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
307-
if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
308-
net_cong_cost_[net_id] = get_net_cube_cong_cost_(net_id, /*use_ts=*/false);
309-
cong_cost += net_cong_cost_[net_id];
304+
if (congestion_modeling_started_) {
305+
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {
306+
if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
307+
net_cong_cost_[net_id] = get_net_cube_cong_cost_(net_id, /*use_ts=*/false);
308+
cong_cost += net_cong_cost_[net_id];
309+
}
310310
}
311311
}
312312

313-
314313
return {bb_cost, expected_wirelength, cong_cost};
315314
}
316315

@@ -571,11 +570,12 @@ void NetCostHandler::get_non_updatable_cube_bb_(ClusterNetId net_id, bool use_ts
571570
num_sink_pin_layer[pin_loc.layer_num]++;
572571
}
573572

574-
// the average channel utilization that is going to be updated by this function
575-
auto& [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
576-
const int total_channels = (bb_coord_new.xmax - bb_coord_new.xmin + 1) * (bb_coord_new.ymax - bb_coord_new.ymin + 1);
577-
x_chan_util = acc_chanx_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
578-
y_chan_util = acc_chany_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
573+
if (congestion_modeling_started_) {
574+
auto& [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
575+
const int total_channels = (bb_coord_new.xmax - bb_coord_new.xmin + 1) * (bb_coord_new.ymax - bb_coord_new.ymin + 1);
576+
x_chan_util = acc_chanx_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
577+
y_chan_util = acc_chany_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
578+
}
579579
}
580580

581581
void NetCostHandler::get_non_updatable_per_layer_bb_(ClusterNetId net_id, bool use_ts) {
@@ -883,11 +883,12 @@ void NetCostHandler::update_bb_(ClusterNetId net_id,
883883
bb_update_status_[net_id] = NetUpdateState::UPDATED_ONCE;
884884
}
885885

886-
// the average channel utilization that is going to be updated by this function
887-
auto& [x_chan_util, y_chan_util] = ts_avg_chann_util_new_[net_id];
888-
const int total_channels = (bb_coord_new.xmax - bb_coord_new.xmin + 1) * (bb_coord_new.ymax - bb_coord_new.ymin + 1);
889-
x_chan_util = acc_chanx_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
890-
y_chan_util = acc_chany_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
886+
if (congestion_modeling_started_) {
887+
auto& [x_chan_util, y_chan_util] = ts_avg_chann_util_new_[net_id];
888+
const int total_channels = (bb_coord_new.xmax - bb_coord_new.xmin + 1) * (bb_coord_new.ymax - bb_coord_new.ymin + 1);
889+
x_chan_util = acc_chanx_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
890+
y_chan_util = acc_chany_util_.get_sum(bb_coord_new.xmin, bb_coord_new.ymin, bb_coord_new.xmax, bb_coord_new.ymax) / total_channels;
891+
}
891892
}
892893

893894
void NetCostHandler::update_layer_bb_(ClusterNetId net_id,
@@ -1323,11 +1324,12 @@ void NetCostHandler::get_bb_from_scratch_(ClusterNetId net_id, bool use_ts) {
13231324
num_on_edges.layer_min = layer_min_edge;
13241325
num_on_edges.layer_max = layer_max_edge;
13251326

1326-
// the average channel utilization that is going to be updated by this function
1327-
auto& [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
1328-
const int total_channels = (coords.xmax - coords.xmin + 1) * (coords.ymax - coords.ymin + 1);
1329-
x_chan_util = acc_chanx_util_.get_sum(coords.xmin, coords.ymin, coords.xmax, coords.ymax) / total_channels;
1330-
y_chan_util = acc_chany_util_.get_sum(coords.xmin, coords.ymin, coords.xmax, coords.ymax) / total_channels;
1327+
if (congestion_modeling_started_) {
1328+
auto& [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
1329+
const int total_channels = (coords.xmax - coords.xmin + 1) * (coords.ymax - coords.ymin + 1);
1330+
x_chan_util = acc_chanx_util_.get_sum(coords.xmin, coords.ymin, coords.xmax, coords.ymax) / total_channels;
1331+
y_chan_util = acc_chany_util_.get_sum(coords.xmin, coords.ymin, coords.xmax, coords.ymax) / total_channels;
1332+
}
13311333
}
13321334

13331335
void NetCostHandler::get_layer_bb_from_scratch_(ClusterNetId net_id,
@@ -1423,6 +1425,7 @@ double NetCostHandler::get_net_cube_bb_cost_(ClusterNetId net_id, bool use_ts) {
14231425
}
14241426

14251427
double NetCostHandler::get_net_cube_cong_cost_(ClusterNetId net_id, bool use_ts) {
1428+
VTR_ASSERT_SAFE(congestion_modeling_started_);
14261429
const auto [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
14271430

14281431
const t_bb& bb = use_ts ? ts_bb_coord_new_[net_id] : bb_coords_[net_id];
@@ -1562,7 +1565,10 @@ std::pair<double, double> NetCostHandler::recompute_bb_cong_cost_() {
15621565
if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) {
15631566
// Bounding boxes don't have to be recomputed; they're correct.
15641567
bb_cost += net_cost_[net_id];
1565-
cong_cost += net_cong_cost_[net_id];
1568+
1569+
if (congestion_modeling_started_) {
1570+
cong_cost += net_cong_cost_[net_id];
1571+
}
15661572
}
15671573
}
15681574

@@ -1585,10 +1591,12 @@ void NetCostHandler::set_bb_delta_cost_(double& bb_delta_c, double& congestion_d
15851591
ClusterNetId net_id = ts_net;
15861592

15871593
proposed_net_cost_[net_id] = get_net_bb_cost_functor_(net_id);
1588-
proposed_net_cong_cost_[net_id] = get_net_cube_cong_cost_(net_id, /*use_ts=*/true);
1589-
15901594
bb_delta_c += proposed_net_cost_[net_id] - net_cost_[net_id];
1591-
congestion_delta_c += proposed_net_cong_cost_[net_id] - net_cong_cost_[net_id];
1595+
1596+
if (congestion_modeling_started_) {
1597+
proposed_net_cong_cost_[net_id] = get_net_cube_cong_cost_(net_id, /*use_ts=*/true);
1598+
congestion_delta_c += proposed_net_cong_cost_[net_id] - net_cong_cost_[net_id];
1599+
}
15921600
}
15931601
}
15941602

@@ -1600,6 +1608,7 @@ void NetCostHandler::find_affected_nets_and_update_costs(const PlaceDelayModel*
16001608
double& congestion_delta_c) {
16011609
VTR_ASSERT_DEBUG(bb_delta_c == 0.);
16021610
VTR_ASSERT_DEBUG(timing_delta_c == 0.);
1611+
VTR_ASSERT_DEBUG(congestion_delta_c == 0.);
16031612
const auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist;
16041613

16051614
ts_nets_to_update_.resize(0);
@@ -1649,21 +1658,27 @@ void NetCostHandler::update_move_nets() {
16491658
}
16501659

16511660
net_cost_[net_id] = proposed_net_cost_[net_id];
1652-
net_cong_cost_[net_id] = proposed_net_cong_cost_[net_id];
1653-
1654-
/* negative proposed_net_cost value is acting as a flag to mean not computed yet. */
1661+
// negative proposed_net_cost value is acting as a flag to mean not computed yet.
16551662
proposed_net_cost_[net_id] = -1;
1656-
proposed_net_cong_cost_[net_id] = -1;
1663+
1664+
if (congestion_modeling_started_) {
1665+
net_cong_cost_[net_id] = proposed_net_cong_cost_[net_id];
1666+
proposed_net_cong_cost_[net_id] = -1;
1667+
}
1668+
16571669
bb_update_status_[net_id] = NetUpdateState::NOT_UPDATED_YET;
16581670
}
16591671
}
16601672

16611673
void NetCostHandler::reset_move_nets() {
1662-
/* Reset the net cost function flags first. */
1663-
for (const ClusterNetId ts_net : ts_nets_to_update_) {
1664-
ClusterNetId net_id = ts_net;
1674+
// Reset the net cost function flags first.
1675+
for (const ClusterNetId net_id : ts_nets_to_update_) {
16651676
proposed_net_cost_[net_id] = -1;
1666-
proposed_net_cong_cost_[net_id] = -1;
1677+
1678+
if (congestion_modeling_started_) {
1679+
proposed_net_cong_cost_[net_id] = -1;
1680+
}
1681+
16671682
bb_update_status_[net_id] = NetUpdateState::NOT_UPDATED_YET;
16681683
}
16691684
}
@@ -1682,11 +1697,16 @@ void NetCostHandler::recompute_costs_from_scratch(const PlaceDelayModel* delay_m
16821697
}
16831698
};
16841699

1685-
auto[new_bb_cost, new_cong_cost] = recompute_bb_cong_cost_();
1700+
auto [new_bb_cost, new_cong_cost] = recompute_bb_cong_cost_();
16861701
check_and_print_cost(new_bb_cost, costs.bb_cost, "bb_cost");
1687-
check_and_print_cost(new_cong_cost, costs.congestion_cost, "cong_cost");
16881702
costs.bb_cost = new_bb_cost;
1689-
costs.congestion_cost = new_cong_cost;
1703+
1704+
if (congestion_modeling_started_) {
1705+
check_and_print_cost(new_cong_cost, costs.congestion_cost, "cong_cost");
1706+
costs.congestion_cost = new_cong_cost;
1707+
} else {
1708+
costs.congestion_cost = 0.;
1709+
}
16901710

16911711
if (placer_opts_.place_algorithm.is_timing_driven()) {
16921712
double new_timing_cost = 0.;
@@ -1747,8 +1767,6 @@ double NetCostHandler::estimate_routing_chann_util() {
17471767
}
17481768
}
17491769

1750-
// const t_chan_width& chan_width = device_ctx.chan_width;
1751-
17521770
if (chanx_width_.empty()) {
17531771
VTR_ASSERT(chany_width_.empty());
17541772
std::tie(chanx_width_, chany_width_) = calculate_channel_width();
@@ -1779,6 +1797,8 @@ double NetCostHandler::estimate_routing_chann_util() {
17791797
acc_chanx_util_ = vtr::PrefixSum2D<double>(chanx_util_);
17801798
acc_chany_util_ = vtr::PrefixSum2D<double>(chany_util_);
17811799

1800+
congestion_modeling_started_ = true;
1801+
17821802
double cong_cost = 0.;
17831803
// Compute congestion cost using recomputed bounding boxes and channel utilization map
17841804
for (ClusterNetId net_id : cluster_ctx.clb_nlist.nets()) {

vpr/src/place/net_cost_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class NetCostHandler {
129129
double estimate_routing_chann_util();
130130

131131
private:
132+
bool congestion_modeling_started_;
132133
///@brief Specifies whether the bounding box is computed using cube method or per-layer method.
133134
bool cube_bb_;
134135
///@brief Determines whether the FPGA has multiple dies (layers)

0 commit comments

Comments
 (0)