Skip to content

Commit 5102cc8

Browse files
author
Yulang Luo
committed
[vpr][place] refactoring variables in net_cost_handler
inet_cost, proposed_net_cost, and bb_updated_before grouped in a struct. bb_updated_before renamed to bb_update_status.
1 parent 2d7fbf4 commit 5102cc8

File tree

1 file changed

+58
-57
lines changed

1 file changed

+58
-57
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ static vtr::NdMatrix<float, 2> chanx_place_cost_fac({0, 0}); // [0...device_ctx.
5555
static vtr::NdMatrix<float, 2> chany_place_cost_fac({0, 0}); // [0...device_ctx.grid.height()-2]
5656

5757
/**
58-
* @brief Cost of a net, and a temporary cost of a net used during move assessment.
58+
* @brief For the first two element in the struct: Cost of a net, and a temporary cost of a net used during move assessment.
5959
* We also use negative cost values in proposed_net_cost as a flag to indicate that
6060
* the cost of a net has not yet been updated.
61-
*/
62-
static vtr::vector<ClusterNetId, double> net_cost, proposed_net_cost;
63-
64-
/** *
65-
* @brief Flag array to indicate whether the specific bounding box has been updated
61+
* For the last one element in the struct: Flag array to indicate whether the specific bounding box has been updated
6662
* in this particular swap or not. If it has been updated before, the code
6763
* must use the updated data, instead of the out-of-date data passed into the
6864
* subroutine, particularly used in try_swap(). The value NOT_UPDATED_YET
@@ -74,7 +70,12 @@ static vtr::vector<ClusterNetId, double> net_cost, proposed_net_cost;
7470
* bounding box is got from scratch, so the bounding box would definitely be
7571
* right, DO NOT update again.
7672
*/
77-
static vtr::vector<ClusterNetId, NetUpdateState> bb_updated_before; // [0...cluster_ctx.clb_nlist.nets().size()-1]
73+
struct NetInfo {
74+
vtr::vector<ClusterNetId, double> net_cost;
75+
vtr::vector<ClusterNetId, double> proposed_net_cost;
76+
vtr::vector<ClusterNetId, NetUpdateState> bb_update_status; // [0...cluster_ctx.clb_nlist.nets().size()-1]
77+
} NetInfo;
78+
static struct NetInfo net_info;
7879

7980
/* The following arrays are used by the try_swap function for speed. */
8081

@@ -477,7 +478,7 @@ static void update_net_bb(const ClusterNetId& net,
477478
if (cluster_ctx.clb_nlist.net_sinks(net).size() < SMALL_NET) {
478479
//For small nets brute-force bounding box update is faster
479480

480-
if (bb_updated_before[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
481+
if (net_info.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
481482
get_non_updatable_bb(net,
482483
ts_bb_coord_new[net],
483484
ts_layer_sink_pin_count[size_t(net)]);
@@ -515,7 +516,7 @@ static void update_net_layer_bb(const ClusterNetId& net,
515516
if (cluster_ctx.clb_nlist.net_sinks(net).size() < SMALL_NET) {
516517
//For small nets brute-force bounding box update is faster
517518

518-
if (bb_updated_before[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
519+
if (net_info.bb_update_status[net] == NetUpdateState::NOT_UPDATED_YET) { //Only once per-net
519520
get_non_updatable_layer_bb(net,
520521
layer_ts_bb_coord_new[net],
521522
ts_layer_sink_pin_count[size_t(net)]);
@@ -651,13 +652,13 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
651652
static void record_affected_net(const ClusterNetId net,
652653
int& num_affected_nets) {
653654
/* Record effected nets. */
654-
if (proposed_net_cost[net] < 0.) {
655+
if (net_info.proposed_net_cost[net] < 0.) {
655656
/* Net not marked yet. */
656657
ts_nets_to_update[num_affected_nets] = net;
657658
num_affected_nets++;
658659

659660
/* Flag to say we've marked this net. */
660-
proposed_net_cost[net] = 1.;
661+
net_info.proposed_net_cost[net] = 1.;
661662
}
662663
}
663664

@@ -875,18 +876,18 @@ static void update_bb(ClusterNetId net_id,
875876
pin_old_loc.layer_num = max(min<int>(pin_old_loc.layer_num, device_ctx.grid.get_num_layers() - 1), 0);
876877

877878
/* Check if the net had been updated before. */
878-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
879+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
879880
/* The net had been updated from scratch, DO NOT update again! */
880881
return;
881882
}
882883

883-
vtr::NdMatrixProxy<int, 1> curr_num_sink_pin_layer = (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : num_sink_pin_layer_new;
884+
vtr::NdMatrixProxy<int, 1> curr_num_sink_pin_layer = (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : num_sink_pin_layer_new;
884885

885-
if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) {
886+
if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) {
886887
/* The net had NOT been updated before, could use the old values */
887888
curr_bb_edge = &place_move_ctx.bb_num_on_edges[net_id];
888889
curr_bb_coord = &place_move_ctx.bb_coords[net_id];
889-
bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE;
890+
net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE;
890891
} else {
891892
/* The net had been updated before, must use the new values */
892893
curr_bb_coord = &bb_coord_new;
@@ -902,7 +903,7 @@ static void update_bb(ClusterNetId net_id,
902903
if (pin_old_loc.x == curr_bb_coord->xmax) { /* Old position at xmax. */
903904
if (curr_bb_edge->xmax == 1) {
904905
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
905-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
906+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
906907
return;
907908
} else {
908909
bb_edge_new.xmax = curr_bb_edge->xmax - 1;
@@ -934,7 +935,7 @@ static void update_bb(ClusterNetId net_id,
934935
if (pin_old_loc.x == curr_bb_coord->xmin) { /* Old position at xmin. */
935936
if (curr_bb_edge->xmin == 1) {
936937
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
937-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
938+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
938939
return;
939940
} else {
940941
bb_edge_new.xmin = curr_bb_edge->xmin - 1;
@@ -975,7 +976,7 @@ static void update_bb(ClusterNetId net_id,
975976
if (pin_old_loc.y == curr_bb_coord->ymax) { /* Old position at ymax. */
976977
if (curr_bb_edge->ymax == 1) {
977978
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
978-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
979+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
979980
return;
980981
} else {
981982
bb_edge_new.ymax = curr_bb_edge->ymax - 1;
@@ -1007,7 +1008,7 @@ static void update_bb(ClusterNetId net_id,
10071008
if (pin_old_loc.y == curr_bb_coord->ymin) { /* Old position at ymin. */
10081009
if (curr_bb_edge->ymin == 1) {
10091010
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
1010-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
1011+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
10111012
return;
10121013
} else {
10131014
bb_edge_new.ymin = curr_bb_edge->ymin - 1;
@@ -1057,7 +1058,7 @@ static void update_bb(ClusterNetId net_id,
10571058
if (pin_old_loc.layer_num == curr_bb_coord->layer_max) {
10581059
if (curr_bb_edge->layer_max == 1) {
10591060
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
1060-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
1061+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
10611062
return;
10621063
} else {
10631064
bb_edge_new.layer_max = curr_bb_edge->layer_max - 1;
@@ -1086,7 +1087,7 @@ static void update_bb(ClusterNetId net_id,
10861087
if (pin_old_loc.layer_num == curr_bb_coord->layer_min) {
10871088
if (curr_bb_edge->layer_min == 1) {
10881089
get_bb_from_scratch(net_id, bb_coord_new, bb_edge_new, num_sink_pin_layer_new);
1089-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
1090+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
10901091
return;
10911092
} else {
10921093
bb_edge_new.layer_min = curr_bb_edge->layer_min - 1;
@@ -1123,8 +1124,8 @@ static void update_bb(ClusterNetId net_id,
11231124
bb_edge_new.layer_max = curr_bb_edge->layer_max;
11241125
}
11251126

1126-
if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) {
1127-
bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE;
1127+
if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) {
1128+
net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE;
11281129
}
11291130
}
11301131

@@ -1145,19 +1146,19 @@ static void update_layer_bb(ClusterNetId net_id,
11451146
pin_old_loc.y = max(min<int>(pin_old_loc.y, device_ctx.grid.height() - 2), 1); //-2 for no perim channels
11461147

11471148
/* Check if the net had been updated before. */
1148-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1149+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
11491150
/* The net had been updated from scratch, DO NOT update again! */
11501151
return;
11511152
}
11521153

1153-
const vtr::NdMatrixProxy<int, 1> curr_layer_pin_sink_count = (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : bb_pin_sink_count_new;
1154+
const vtr::NdMatrixProxy<int, 1> curr_layer_pin_sink_count = (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) ? place_move_ctx.num_sink_pin_layer[size_t(net_id)] : bb_pin_sink_count_new;
11541155

11551156
const std::vector<t_2D_bb>*curr_bb_edge, *curr_bb_coord;
1156-
if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) {
1157+
if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) {
11571158
/* The net had NOT been updated before, could use the old values */
11581159
curr_bb_edge = &place_move_ctx.layer_bb_num_on_edges[net_id];
11591160
curr_bb_coord = &place_move_ctx.layer_bb_coords[net_id];
1160-
bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE;
1161+
net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE;
11611162
} else {
11621163
/* The net had been updated before, must use the new values */
11631164
curr_bb_edge = &bb_edge_new;
@@ -1199,8 +1200,8 @@ static void update_layer_bb(ClusterNetId net_id,
11991200
bb_coord_new);
12001201
}
12011202

1202-
if (bb_updated_before[net_id] == NetUpdateState::NOT_UPDATED_YET) {
1203-
bb_updated_before[net_id] = NetUpdateState::UPDATED_ONCE;
1203+
if (net_info.bb_update_status[net_id] == NetUpdateState::NOT_UPDATED_YET) {
1204+
net_info.bb_update_status[net_id] = NetUpdateState::UPDATED_ONCE;
12041205
}
12051206
}
12061207

@@ -1231,7 +1232,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id,
12311232
curr_bb_coord[layer_num].xmax,
12321233
bb_edge_new[layer_num].xmax,
12331234
bb_coord_new[layer_num].xmax);
1234-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1235+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
12351236
return;
12361237
}
12371238
}
@@ -1254,7 +1255,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id,
12541255
curr_bb_coord[layer_num].xmin,
12551256
bb_edge_new[layer_num].xmin,
12561257
bb_coord_new[layer_num].xmin);
1257-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1258+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
12581259
return;
12591260
}
12601261
}
@@ -1278,7 +1279,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id,
12781279
curr_bb_coord[layer_num].ymax,
12791280
bb_edge_new[layer_num].ymax,
12801281
bb_coord_new[layer_num].ymax);
1281-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1282+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
12821283
return;
12831284
}
12841285
}
@@ -1301,7 +1302,7 @@ static inline void update_bb_same_layer(ClusterNetId net_id,
13011302
curr_bb_coord[layer_num].ymin,
13021303
bb_edge_new[layer_num].ymin,
13031304
bb_coord_new[layer_num].ymin);
1304-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1305+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
13051306
return;
13061307
}
13071308
}
@@ -1346,7 +1347,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id,
13461347
curr_bb_coord[old_layer_num].xmax,
13471348
bb_edge_new[old_layer_num].xmax,
13481349
bb_coord_new[old_layer_num].xmax);
1349-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1350+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
13501351
return;
13511352
}
13521353
} else if (x_old == curr_bb_coord[old_layer_num].xmin) {
@@ -1358,7 +1359,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id,
13581359
curr_bb_coord[old_layer_num].xmin,
13591360
bb_edge_new[old_layer_num].xmin,
13601361
bb_coord_new[old_layer_num].xmin);
1361-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1362+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
13621363
return;
13631364
}
13641365
}
@@ -1372,7 +1373,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id,
13721373
curr_bb_coord[old_layer_num].ymax,
13731374
bb_edge_new[old_layer_num].ymax,
13741375
bb_coord_new[old_layer_num].ymax);
1375-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1376+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
13761377
return;
13771378
}
13781379
} else if (y_old == curr_bb_coord[old_layer_num].ymin) {
@@ -1384,7 +1385,7 @@ static inline void update_bb_layer_changed(ClusterNetId net_id,
13841385
curr_bb_coord[old_layer_num].ymin,
13851386
bb_edge_new[old_layer_num].ymin,
13861387
bb_coord_new[old_layer_num].ymin);
1387-
if (bb_updated_before[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
1388+
if (net_info.bb_update_status[net_id] == NetUpdateState::GOT_FROM_SCRATCH) {
13881389
return;
13891390
}
13901391
}
@@ -1424,7 +1425,7 @@ static inline void update_bb_edge(ClusterNetId net_id,
14241425
bb_edge_new,
14251426
bb_coord_new,
14261427
bb_layer_pin_sink_count);
1427-
bb_updated_before[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
1428+
net_info.bb_update_status[net_id] = NetUpdateState::GOT_FROM_SCRATCH;
14281429
return;
14291430
} else {
14301431
new_num_block_on_edge = old_num_block_on_edge - 1;
@@ -1838,7 +1839,7 @@ static double recompute_bb_cost() {
18381839
for (auto net_id : cluster_ctx.clb_nlist.nets()) { /* for each net ... */
18391840
if (!cluster_ctx.clb_nlist.net_is_ignored(net_id)) { /* Do only if not ignored. */
18401841
/* Bounding boxes don't have to be recomputed; they're correct. */
1841-
cost += net_cost[net_id];
1842+
cost += net_info.net_cost[net_id];
18421843
}
18431844
}
18441845

@@ -1863,15 +1864,15 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
18631864
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
18641865

18651866
if (cube_bb) {
1866-
proposed_net_cost[net_id] = get_net_cost(net_id,
1867+
net_info.proposed_net_cost[net_id] = get_net_cost(net_id,
18671868
ts_bb_coord_new[net_id]);
18681869
} else {
1869-
proposed_net_cost[net_id] = get_net_layer_bb_wire_cost(net_id,
1870+
net_info.proposed_net_cost[net_id] = get_net_layer_bb_wire_cost(net_id,
18701871
layer_ts_bb_coord_new[net_id],
18711872
ts_layer_sink_pin_count[size_t(net_id)]);
18721873
}
18731874

1874-
bb_delta_c += proposed_net_cost[net_id] - net_cost[net_id];
1875+
bb_delta_c += net_info.proposed_net_cost[net_id] - net_info.net_cost[net_id];
18751876
}
18761877
}
18771878

@@ -1945,8 +1946,8 @@ double comp_bb_cost(e_cost_methods method) {
19451946
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
19461947
}
19471948

1948-
net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]);
1949-
cost += net_cost[net_id];
1949+
net_info.net_cost[net_id] = get_net_cost(net_id, place_move_ctx.bb_coords[net_id]);
1950+
cost += net_info.net_cost[net_id];
19501951
if (method == CHECK)
19511952
expected_wirelength += get_net_wirelength_estimate(net_id, place_move_ctx.bb_coords[net_id]);
19521953
}
@@ -1982,10 +1983,10 @@ double comp_layer_bb_cost(e_cost_methods method) {
19821983
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
19831984
}
19841985

1985-
net_cost[net_id] = get_net_layer_bb_wire_cost(net_id,
1986+
net_info.net_cost[net_id] = get_net_layer_bb_wire_cost(net_id,
19861987
place_move_ctx.layer_bb_coords[net_id],
19871988
place_move_ctx.num_sink_pin_layer[size_t(net_id)]);
1988-
cost += net_cost[net_id];
1989+
cost += net_info.net_cost[net_id];
19891990
if (method == CHECK)
19901991
expected_wirelength += get_net_wirelength_from_layer_bb(net_id,
19911992
place_move_ctx.layer_bb_coords[net_id],
@@ -2029,11 +2030,11 @@ void update_move_nets(int num_nets_affected,
20292030
}
20302031
}
20312032

2032-
net_cost[net_id] = proposed_net_cost[net_id];
2033+
net_info.net_cost[net_id] = net_info.proposed_net_cost[net_id];
20332034

20342035
/* negative proposed_net_cost value is acting as a flag to mean not computed yet. */
2035-
proposed_net_cost[net_id] = -1;
2036-
bb_updated_before[net_id] = NetUpdateState::NOT_UPDATED_YET;
2036+
net_info.proposed_net_cost[net_id] = -1;
2037+
net_info.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET;
20372038
}
20382039
}
20392040

@@ -2042,8 +2043,8 @@ void reset_move_nets(int num_nets_affected) {
20422043
for (int inet_affected = 0; inet_affected < num_nets_affected;
20432044
inet_affected++) {
20442045
ClusterNetId net_id = ts_nets_to_update[inet_affected];
2045-
proposed_net_cost[net_id] = -1;
2046-
bb_updated_before[net_id] = NetUpdateState::NOT_UPDATED_YET;
2046+
net_info.proposed_net_cost[net_id] = -1;
2047+
net_info.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET;
20472048
}
20482049
}
20492050

@@ -2217,18 +2218,18 @@ void free_chan_w_factors_for_place_cost () {
22172218
}
22182219

22192220
void init_place_move_structs(size_t num_nets) {
2220-
net_cost.resize(num_nets, -1.);
2221-
proposed_net_cost.resize(num_nets, -1.);
2221+
net_info.net_cost.resize(num_nets, -1.);
2222+
net_info.proposed_net_cost.resize(num_nets, -1.);
22222223
/* Used to store costs for moves not yet made and to indicate when a net's *
22232224
* cost has been recomputed. proposed_net_cost[inet] < 0 means net's cost hasn't *
22242225
* been recomputed. */
2225-
bb_updated_before.resize(num_nets, NetUpdateState::NOT_UPDATED_YET);
2226+
net_info.bb_update_status.resize(num_nets, NetUpdateState::NOT_UPDATED_YET);
22262227
}
22272228

22282229
void free_place_move_structs() {
2229-
vtr::release_memory(net_cost);
2230-
vtr::release_memory(proposed_net_cost);
2231-
vtr::release_memory(bb_updated_before);
2230+
vtr::release_memory(net_info.net_cost);
2231+
vtr::release_memory(net_info.proposed_net_cost);
2232+
vtr::release_memory(net_info.bb_update_status);
22322233
}
22332234

22342235
void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) {

0 commit comments

Comments
 (0)