Skip to content

Commit 45a4af4

Browse files
remove static chanx_place_cost_fac and chany_place_cost_fac from net_cost_handler
1 parent 22c4ea8 commit 45a4af4

File tree

3 files changed

+66
-90
lines changed

3 files changed

+66
-90
lines changed

vpr/src/place/net_cost_handler.cpp

+30-78
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include "noc_place_utils.h"
3535
#include "vtr_math.h"
3636

37-
#include <optional>
38-
#include <functional>
39-
4037
using std::max;
4138
using std::min;
4239

@@ -58,23 +55,6 @@ static const float cross_count[MAX_FANOUT_CROSSING_COUNT] = {/* [0..49] */ 1.0,
5855
2.5610, 2.5864, 2.6117, 2.6371, 2.6625, 2.6887, 2.7148, 2.7410, 2.7671,
5956
2.7933};
6057

61-
/**
62-
* @brief Matrices below are used to precompute the inverse of the average
63-
* number of tracks per channel between [subhigh] and [sublow]. Access
64-
* them as chan?_place_cost_fac[subhigh][sublow]. They are used to
65-
* speed up the computation of the cost function that takes the length
66-
* of the net bounding box in each dimension, divided by the average
67-
* number of tracks in that direction; for other cost functions they
68-
* will never be used.
69-
*/
70-
static vtr::NdMatrix<float, 2> chanx_place_cost_fac({0, 0}); // [0...device_ctx.grid.width()-2]
71-
static vtr::NdMatrix<float, 2> chany_place_cost_fac({0, 0}); // [0...device_ctx.grid.height()-2]
72-
73-
namespace {
74-
75-
76-
} // namespace
77-
7858
/**
7959
* @param net
8060
* @param moved_blocks
@@ -83,17 +63,6 @@ namespace {
8363
static bool driven_by_moved_block(const ClusterNetId net,
8464
const std::vector<t_pl_moved_block>& moved_blocks);
8565

86-
/**
87-
* @brief Given the per-layer BB, calculate the wire-length cost of the net on each layer
88-
* and return the sum of the costs
89-
* @param net_id ID of the net which cost is requested
90-
* @param bb Per-layer bounding box of the net
91-
* @return Wirelength cost of the net
92-
*/
93-
static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */,
94-
const std::vector<t_2D_bb>& bb,
95-
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count);
96-
9766
/**
9867
* @brief Given the per-layer BB, calculate the wire-length estimate of the net on each layer
9968
* and return the sum of the lengths
@@ -138,13 +107,7 @@ static void add_block_to_bb(const t_physical_tile_loc& new_pin_loc,
138107
t_2D_bb& bb_edge_new,
139108
t_2D_bb& bb_coord_new);
140109

141-
/**
142-
* @brief Given the 3D BB, calculate the wire-length cost of the net
143-
* @param net_id ID of the net which cost is requested
144-
* @param bb Bounding box of the net
145-
* @return Wirelength cost of the net
146-
*/
147-
static double get_net_cost(ClusterNetId net_id, const t_bb& bb);
110+
148111

149112
/**
150113
* @brief Given the 3D BB, calculate the wire-length estimate of the net
@@ -621,7 +584,7 @@ void NetCostHandler::update_bb_(ClusterNetId net_id,
621584
bb_edge_new.ymax = curr_bb_edge->ymax - 1;
622585
bb_coord_new.ymax = curr_bb_coord->ymax;
623586
}
624-
} else { /* Move down, old postion was not at ymax. */
587+
} else { /* Move down, old position was not at ymax. */
625588
bb_coord_new.ymax = curr_bb_coord->ymax;
626589
bb_edge_new.ymax = curr_bb_edge->ymax;
627590
}
@@ -1340,7 +1303,7 @@ void NetCostHandler::get_layer_bb_from_scratch_(ClusterNetId net_id,
13401303
}
13411304
}
13421305

1343-
static double get_net_cost(ClusterNetId net_id, const t_bb& bb) {
1306+
double NetCostHandler::get_net_cost_(ClusterNetId net_id, const t_bb& bb) {
13441307
/* Finds the cost due to one net by looking at its coordinate bounding *
13451308
* box. */
13461309
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -1355,15 +1318,15 @@ static double get_net_cost(ClusterNetId net_id, const t_bb& bb) {
13551318
* channel capacity. Do this for x, then y direction and add. */
13561319

13571320
double ncost;
1358-
ncost = (bb.xmax - bb.xmin + 1) * crossing * chanx_place_cost_fac[bb.ymax][bb.ymin - 1];
1359-
ncost += (bb.ymax - bb.ymin + 1) * crossing * chany_place_cost_fac[bb.xmax][bb.xmin - 1];
1321+
ncost = (bb.xmax - bb.xmin + 1) * crossing * chanx_place_cost_fac_[bb.ymax][bb.ymin - 1];
1322+
ncost += (bb.ymax - bb.ymin + 1) * crossing * chany_place_cost_fac_[bb.xmax][bb.xmin - 1];
13601323

13611324
return (ncost);
13621325
}
13631326

1364-
static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */,
1365-
const std::vector<t_2D_bb>& bb,
1366-
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count) {
1327+
double NetCostHandler::get_net_layer_bb_wire_cost_(ClusterNetId /* net_id */,
1328+
const std::vector<t_2D_bb>& bb,
1329+
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count) {
13671330
/* Finds the cost due to one net by looking at its coordinate bounding *
13681331
* box. */
13691332

@@ -1391,10 +1354,10 @@ static double get_net_layer_bb_wire_cost(ClusterNetId /* net_id */,
13911354
* channel capacity. Do this for x, then y direction and add. */
13921355

13931356
ncost += (bb[layer_num].xmax - bb[layer_num].xmin + 1) * crossing
1394-
* chanx_place_cost_fac[bb[layer_num].ymax][bb[layer_num].ymin - 1];
1357+
* chanx_place_cost_fac_[bb[layer_num].ymax][bb[layer_num].ymin - 1];
13951358

13961359
ncost += (bb[layer_num].ymax - bb[layer_num].ymin + 1) * crossing
1397-
* chany_place_cost_fac[bb[layer_num].xmax][bb[layer_num].xmin - 1];
1360+
* chany_place_cost_fac_[bb[layer_num].xmax][bb[layer_num].xmin - 1];
13981361
}
13991362

14001363
return (ncost);
@@ -1414,7 +1377,6 @@ static double get_net_wirelength_estimate(ClusterNetId net_id, const t_bb& bb) {
14141377

14151378
double ncost;
14161379
ncost = (bb.xmax - bb.xmin + 1) * crossing;
1417-
14181380
ncost += (bb.ymax - bb.ymin + 1) * crossing;
14191381

14201382
return ncost;
@@ -1555,7 +1517,7 @@ double NetCostHandler::comp_3d_bb_cost_(e_cost_methods method) {
15551517
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
15561518
}
15571519

1558-
net_cost_[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]);
1520+
net_cost_[net_id] = get_net_cost_(net_id, place_move_ctx.bb_coords[net_id]);
15591521
cost += net_cost_[net_id];
15601522
if (method == e_cost_methods::CHECK)
15611523
expected_wirelength += get_net_wirelength_estimate(net_id, place_move_ctx.bb_coords[net_id]);
@@ -1591,7 +1553,7 @@ double NetCostHandler::comp_per_layer_bb_cost_(e_cost_methods method) {
15911553
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
15921554
}
15931555

1594-
net_cost_[net_id] = get_net_layer_bb_wire_cost(net_id,
1556+
net_cost_[net_id] = get_net_layer_bb_wire_cost_(net_id,
15951557
place_move_ctx.layer_bb_coords[net_id],
15961558
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
15971559
cost += net_cost_[net_id];
@@ -1730,18 +1692,18 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_c
17301692
for simplicity so we can use the vtr utility matrix functions.
17311693
*/
17321694

1733-
chanx_place_cost_fac.resize({device_ctx.grid.height(), device_ctx.grid.height() + 1});
1734-
chany_place_cost_fac.resize({device_ctx.grid.width(), device_ctx.grid.width() + 1});
1695+
chanx_place_cost_fac_.resize({device_ctx.grid.height(), device_ctx.grid.height() + 1});
1696+
chany_place_cost_fac_.resize({device_ctx.grid.width(), device_ctx.grid.width() + 1});
17351697

17361698
/* First compute the number of tracks between channel high and channel *
17371699
* low, inclusive, in an efficient manner. */
17381700

1739-
chanx_place_cost_fac[0][0] = device_ctx.chan_width.x_list[0];
1701+
chanx_place_cost_fac_[0][0] = device_ctx.chan_width.x_list[0];
17401702

17411703
for (size_t high = 1; high < device_ctx.grid.height(); high++) {
1742-
chanx_place_cost_fac[high][high] = device_ctx.chan_width.x_list[high];
1704+
chanx_place_cost_fac_[high][high] = device_ctx.chan_width.x_list[high];
17431705
for (size_t low = 0; low < high; low++) {
1744-
chanx_place_cost_fac[high][low] = chanx_place_cost_fac[high - 1][low] + device_ctx.chan_width.x_list[high];
1706+
chanx_place_cost_fac_[high][low] = chanx_place_cost_fac_[high - 1][low] + device_ctx.chan_width.x_list[high];
17451707
}
17461708
}
17471709

@@ -1760,27 +1722,24 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_c
17601722
* will result in infinite wiring capacity normalization *
17611723
* factor, and extremely bad placer behaviour. Hence we change *
17621724
* this to a small (1 track) channel capacity instead. */
1763-
if (chanx_place_cost_fac[high][low] == 0.0f) {
1725+
if (chanx_place_cost_fac_[high][low] == 0.0f) {
17641726
VTR_LOG_WARN("CHANX place cost fac is 0 at %d %d\n", high, low);
1765-
chanx_place_cost_fac[high][low] = 1.0f;
1727+
chanx_place_cost_fac_[high][low] = 1.0f;
17661728
}
17671729

1768-
chanx_place_cost_fac[high][low] = (high - low + 1.)
1769-
/ chanx_place_cost_fac[high][low];
1770-
chanx_place_cost_fac[high][low] = pow(
1771-
(double)chanx_place_cost_fac[high][low],
1772-
(double)place_cost_exp);
1730+
chanx_place_cost_fac_[high][low] = (high - low + 1.) / chanx_place_cost_fac_[high][low];
1731+
chanx_place_cost_fac_[high][low] = pow((double)chanx_place_cost_fac_[high][low], (double)place_cost_exp);
17731732
}
17741733

17751734
/* Now do the same thing for the y-directed channels. First get the *
17761735
* number of tracks between channel high and channel low, inclusive. */
17771736

1778-
chany_place_cost_fac[0][0] = device_ctx.chan_width.y_list[0];
1737+
chany_place_cost_fac_[0][0] = device_ctx.chan_width.y_list[0];
17791738

17801739
for (size_t high = 1; high < device_ctx.grid.width(); high++) {
1781-
chany_place_cost_fac[high][high] = device_ctx.chan_width.y_list[high];
1740+
chany_place_cost_fac_[high][high] = device_ctx.chan_width.y_list[high];
17821741
for (size_t low = 0; low < high; low++) {
1783-
chany_place_cost_fac[high][low] = chany_place_cost_fac[high - 1][low] + device_ctx.chan_width.y_list[high];
1742+
chany_place_cost_fac_[high][low] = chany_place_cost_fac_[high - 1][low] + device_ctx.chan_width.y_list[high];
17841743
}
17851744
}
17861745

@@ -1794,23 +1753,16 @@ void NetCostHandler::alloc_and_load_chan_w_factors_for_place_cost_(float place_c
17941753
* will result in infinite wiring capacity normalization *
17951754
* factor, and extremely bad placer behaviour. Hence we change *
17961755
* this to a small (1 track) channel capacity instead. */
1797-
if (chany_place_cost_fac[high][low] == 0.0f) {
1756+
if (chany_place_cost_fac_[high][low] == 0.0f) {
17981757
VTR_LOG_WARN("CHANY place cost fac is 0 at %d %d\n", high, low);
1799-
chany_place_cost_fac[high][low] = 1.0f;
1758+
chany_place_cost_fac_[high][low] = 1.0f;
18001759
}
18011760

1802-
chany_place_cost_fac[high][low] = (high - low + 1.) / chany_place_cost_fac[high][low];
1803-
chany_place_cost_fac[high][low] = pow(
1804-
(double)chany_place_cost_fac[high][low],
1805-
(double)place_cost_exp);
1761+
chany_place_cost_fac_[high][low] = (high - low + 1.) / chany_place_cost_fac_[high][low];
1762+
chany_place_cost_fac_[high][low] = pow((double)chany_place_cost_fac_[high][low], (double)place_cost_exp);
18061763
}
18071764
}
18081765

1809-
void NetCostHandler::free_chan_w_factors_for_place_cost() {
1810-
chanx_place_cost_fac.clear();
1811-
chany_place_cost_fac.clear();
1812-
}
1813-
18141766
NetCostHandler::NetCostHandler(PlacerContext& placer_ctx, size_t num_nets, bool cube_bb, float place_cost_exp)
18151767
: cube_bb_(cube_bb)
18161768
, placer_ctx_(placer_ctx) {
@@ -1879,10 +1831,10 @@ void NetCostHandler::update_bb_(ClusterNetId net_id, t_physical_tile_loc pin_old
18791831

18801832
double NetCostHandler::get_net_cost_(const ClusterNetId net_id) {
18811833
if (cube_bb_) {
1882-
return ::get_net_cost(net_id, ts_bb_coord_new_[net_id]);
1834+
return get_net_cost_(net_id, ts_bb_coord_new_[net_id]);
18831835
}
18841836
else {
1885-
return ::get_net_layer_bb_wire_cost(net_id, layer_ts_bb_coord_new_[net_id], ts_layer_sink_pin_count_[size_t(net_id)]);
1837+
return get_net_layer_bb_wire_cost_(net_id, layer_ts_bb_coord_new_[net_id], ts_layer_sink_pin_count_[size_t(net_id)]);
18861838
}
18871839
}
18881840

vpr/src/place/net_cost_handler.h

+33-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "move_transactions.h"
55
#include "place_util.h"
66

7+
#include <functional>
8+
79
class PlacerContext;
810

911
/**
@@ -115,11 +117,6 @@ class NetCostHandler {
115117
const PlacerCriticalities* criticalities,
116118
t_placer_costs* costs);
117119

118-
/**
119-
* @brief Frees the chanx_place_cost_fac and chany_place_cost_fac arrays.
120-
*/
121-
void free_chan_w_factors_for_place_cost();
122-
123120
private:
124121
bool cube_bb_ = false;
125122
PlacerContext& placer_ctx_;
@@ -176,6 +173,18 @@ class NetCostHandler {
176173
vtr::vector<ClusterNetId, double> proposed_net_cost_;
177174
vtr::vector<ClusterNetId, NetUpdateState> bb_update_status_;
178175

176+
/**
177+
* @brief Matrices below are used to precompute the inverse of the average
178+
* number of tracks per channel between [subhigh] and [sublow]. Access
179+
* them as chan?_place_cost_fac[subhigh][sublow]. They are used to
180+
* speed up the computation of the cost function that takes the length
181+
* of the net bounding box in each dimension, divided by the average
182+
* number of tracks in that direction; for other cost functions they
183+
* will never be used.
184+
*/
185+
vtr::NdMatrix<float, 2> chanx_place_cost_fac_; // [0...device_ctx.grid.width()-2]
186+
vtr::NdMatrix<float, 2> chany_place_cost_fac_; // [0...device_ctx.grid.height()-2]
187+
179188

180189
private:
181190
/**
@@ -439,4 +448,23 @@ class NetCostHandler {
439448
*/
440449
double recompute_bb_cost_();
441450

451+
/**
452+
* @brief Given the 3D BB, calculate the wire-length cost of the net
453+
* @param net_id ID of the net which cost is requested
454+
* @param bb Bounding box of the net
455+
* @return Wirelength cost of the net
456+
*/
457+
double get_net_cost_(ClusterNetId net_id, const t_bb& bb);
458+
459+
/**
460+
* @brief Given the per-layer BB, calculate the wire-length cost of the net on each layer
461+
* and return the sum of the costs
462+
* @param net_id ID of the net which cost is requested
463+
* @param bb Per-layer bounding box of the net
464+
* @return Wirelength cost of the net
465+
*/
466+
double get_net_layer_bb_wire_cost_(ClusterNetId /* net_id */,
467+
const std::vector<t_2D_bb>& bb,
468+
const vtr::NdMatrixProxy<int, 1> layer_pin_sink_count);
469+
442470
};

vpr/src/place/place.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ static void free_try_swap_structs();
199199

200200
static void free_placement_structs(const t_placer_opts& placer_opts,
201201
const t_noc_opts& noc_opts,
202-
PlacerContext& placer_ctx,
203-
NetCostHandler& net_cost_handler);
202+
PlacerContext& placer_ctx);
204203

205204
static e_move_result try_swap(const t_annealing_state* state,
206205
t_placer_costs* costs,
@@ -976,7 +975,7 @@ void try_place(const Netlist<>& net_list,
976975
write_noc_placement_file(noc_opts.noc_placement_file_name, blk_loc_registry.block_locs());
977976
}
978977

979-
free_placement_structs(placer_opts, noc_opts, placer_ctx, net_cost_handler);
978+
free_placement_structs(placer_opts, noc_opts, placer_ctx);
980979
free_try_swap_arrays();
981980

982981
print_timing_stats("Placement Quench", post_quench_timing_stats,
@@ -1918,8 +1917,7 @@ static NetCostHandler alloc_and_load_placement_structs(const t_placer_opts& plac
19181917
* elsewhere). */
19191918
static void free_placement_structs(const t_placer_opts& placer_opts,
19201919
const t_noc_opts& noc_opts,
1921-
PlacerContext& placer_ctx,
1922-
NetCostHandler& net_cost_handler) {
1920+
PlacerContext& placer_ctx) {
19231921
auto& place_move_ctx = placer_ctx.mutable_move();
19241922

19251923
if (placer_opts.place_algorithm.is_timing_driven()) {
@@ -1944,8 +1942,6 @@ static void free_placement_structs(const t_placer_opts& placer_opts,
19441942

19451943
place_move_ctx.num_sink_pin_layer.clear();
19461944

1947-
net_cost_handler.free_chan_w_factors_for_place_cost();
1948-
19491945
free_try_swap_structs();
19501946

19511947
if (noc_opts.noc) {

0 commit comments

Comments
 (0)