@@ -97,7 +97,8 @@ static double wirelength_crossing_count(size_t fanout);
97
97
NetCostHandler::NetCostHandler (const t_placer_opts& placer_opts,
98
98
PlacerState& placer_state,
99
99
bool cube_bb)
100
- : cube_bb_(cube_bb)
100
+ : congestion_modeling_started_(false )
101
+ , cube_bb_(cube_bb)
101
102
, placer_state_(placer_state)
102
103
, placer_opts_(placer_opts) {
103
104
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
279
280
280
281
double bb_cost = 0 .;
281
282
double expected_wirelength = 0 .;
282
- double cong_cost = 0 .;
283
283
284
284
for (ClusterNetId net_id : cluster_ctx.clb_nlist .nets ()) {
285
285
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
299
299
}
300
300
}
301
301
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 .;
305
303
// 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
+ }
310
310
}
311
311
}
312
312
313
-
314
313
return {bb_cost, expected_wirelength, cong_cost};
315
314
}
316
315
@@ -571,11 +570,12 @@ void NetCostHandler::get_non_updatable_cube_bb_(ClusterNetId net_id, bool use_ts
571
570
num_sink_pin_layer[pin_loc.layer_num ]++;
572
571
}
573
572
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
+ }
579
579
}
580
580
581
581
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,
883
883
bb_update_status_[net_id] = NetUpdateState::UPDATED_ONCE;
884
884
}
885
885
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
+ }
891
892
}
892
893
893
894
void NetCostHandler::update_layer_bb_ (ClusterNetId net_id,
@@ -1323,11 +1324,12 @@ void NetCostHandler::get_bb_from_scratch_(ClusterNetId net_id, bool use_ts) {
1323
1324
num_on_edges.layer_min = layer_min_edge;
1324
1325
num_on_edges.layer_max = layer_max_edge;
1325
1326
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
+ }
1331
1333
}
1332
1334
1333
1335
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) {
1423
1425
}
1424
1426
1425
1427
double NetCostHandler::get_net_cube_cong_cost_ (ClusterNetId net_id, bool use_ts) {
1428
+ VTR_ASSERT_SAFE (congestion_modeling_started_);
1426
1429
const auto [x_chan_util, y_chan_util] = use_ts ? ts_avg_chann_util_new_[net_id] : avg_chann_util_[net_id];
1427
1430
1428
1431
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_() {
1562
1565
if (!cluster_ctx.clb_nlist .net_is_ignored (net_id)) {
1563
1566
// Bounding boxes don't have to be recomputed; they're correct.
1564
1567
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
+ }
1566
1572
}
1567
1573
}
1568
1574
@@ -1585,10 +1591,12 @@ void NetCostHandler::set_bb_delta_cost_(double& bb_delta_c, double& congestion_d
1585
1591
ClusterNetId net_id = ts_net;
1586
1592
1587
1593
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
-
1590
1594
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
+ }
1592
1600
}
1593
1601
}
1594
1602
@@ -1600,6 +1608,7 @@ void NetCostHandler::find_affected_nets_and_update_costs(const PlaceDelayModel*
1600
1608
double & congestion_delta_c) {
1601
1609
VTR_ASSERT_DEBUG (bb_delta_c == 0 .);
1602
1610
VTR_ASSERT_DEBUG (timing_delta_c == 0 .);
1611
+ VTR_ASSERT_DEBUG (congestion_delta_c == 0 .);
1603
1612
const auto & clb_nlist = g_vpr_ctx.clustering ().clb_nlist ;
1604
1613
1605
1614
ts_nets_to_update_.resize (0 );
@@ -1649,21 +1658,27 @@ void NetCostHandler::update_move_nets() {
1649
1658
}
1650
1659
1651
1660
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.
1655
1662
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
+
1657
1669
bb_update_status_[net_id] = NetUpdateState::NOT_UPDATED_YET;
1658
1670
}
1659
1671
}
1660
1672
1661
1673
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_) {
1665
1676
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
+
1667
1682
bb_update_status_[net_id] = NetUpdateState::NOT_UPDATED_YET;
1668
1683
}
1669
1684
}
@@ -1682,11 +1697,16 @@ void NetCostHandler::recompute_costs_from_scratch(const PlaceDelayModel* delay_m
1682
1697
}
1683
1698
};
1684
1699
1685
- auto [new_bb_cost, new_cong_cost] = recompute_bb_cong_cost_ ();
1700
+ auto [new_bb_cost, new_cong_cost] = recompute_bb_cong_cost_ ();
1686
1701
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" );
1688
1702
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
+ }
1690
1710
1691
1711
if (placer_opts_.place_algorithm .is_timing_driven ()) {
1692
1712
double new_timing_cost = 0 .;
@@ -1747,8 +1767,6 @@ double NetCostHandler::estimate_routing_chann_util() {
1747
1767
}
1748
1768
}
1749
1769
1750
- // const t_chan_width& chan_width = device_ctx.chan_width;
1751
-
1752
1770
if (chanx_width_.empty ()) {
1753
1771
VTR_ASSERT (chany_width_.empty ());
1754
1772
std::tie (chanx_width_, chany_width_) = calculate_channel_width ();
@@ -1779,6 +1797,8 @@ double NetCostHandler::estimate_routing_chann_util() {
1779
1797
acc_chanx_util_ = vtr::PrefixSum2D<double >(chanx_util_);
1780
1798
acc_chany_util_ = vtr::PrefixSum2D<double >(chany_util_);
1781
1799
1800
+ congestion_modeling_started_ = true ;
1801
+
1782
1802
double cong_cost = 0 .;
1783
1803
// Compute congestion cost using recomputed bounding boxes and channel utilization map
1784
1804
for (ClusterNetId net_id : cluster_ctx.clb_nlist .nets ()) {
0 commit comments