Skip to content

Commit f0419e2

Browse files
author
Yulang Luo
committed
[vpr][place] ts_nets_to_update now uses size() instead of num_nets
1 parent fe92e6e commit f0419e2

File tree

3 files changed

+88
-96
lines changed

3 files changed

+88
-96
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,10 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
193193
bool is_src_moving);
194194

195195
/**
196-
* @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment num_affected_nets
196+
* @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment the size ofts_nets_to_update.
197197
* @param net ID of a net affected by a move
198-
* @param num_affected_nets Incremented if this is a new net affected, and returned via reference.
199198
*/
200-
static void record_affected_net(const ClusterNetId net, int& num_affected_nets);
199+
static void record_affected_net(const ClusterNetId net);
201200

202201
/**
203202
* @brief Call suitable function based on the bounding box type to update the bounding box of the net connected to pin_id. Also,
@@ -210,19 +209,17 @@ static void record_affected_net(const ClusterNetId net, int& num_affected_nets);
210209
* @param moving_blk_inf Data structure that holds information, e.g., old location and new locatoin, about all moving blocks
211210
* @param affected_pins Netlist pins which are affected, in terms placement cost, by the proposed move.
212211
* @param timing_delta_c Timing cost change based on the proposed move
213-
* @param num_affected_nets A pointer to the first free element of ts_nets_to_update. If a new net is added, the pointer should be increamented.
214212
* @param is_src_moving Is the moving pin the source of a net.
215213
*/
216-
static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algorithm,
217-
const PlaceDelayModel* delay_model,
218-
const PlacerCriticalities* criticalities,
219-
const ClusterBlockId& blk_id,
220-
const ClusterPinId& pin_id,
221-
const t_pl_moved_block& moving_blk_inf,
222-
std::vector<ClusterPinId>& affected_pins,
223-
double& timing_delta_c,
224-
int& num_affected_nets,
225-
bool is_src_moving);
214+
static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm,
215+
const PlaceDelayModel* delay_model,
216+
const PlacerCriticalities* criticalities,
217+
const ClusterBlockId& blk_id,
218+
const ClusterPinId& pin_id,
219+
const t_pl_moved_block& moving_blk_inf,
220+
std::vector<ClusterPinId>& affected_pins,
221+
double& timing_delta_c,
222+
bool is_src_moving);
226223

227224
/**
228225
* @brief Update the 3D bounding box of "net_id" incrementally based on the old and new locations of a pin on that net
@@ -474,10 +471,9 @@ static double wirelength_crossing_count(size_t fanout);
474471
/**
475472
* @brief Calculates and returns the total bb (wirelength) cost change that would result from moving the blocks
476473
* indicated in the blocks_affected data structure.
477-
* @param num_affected_nets Number of valid elements in ts_bb_coord_new
478474
* @param bb_delta_c Cost difference after and before moving the block
479475
*/
480-
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c);
476+
static void set_bb_delta_cost(double& bb_delta_c);
481477

482478
/******************************* End of Function definitions ************************************/
483479
namespace {
@@ -701,29 +697,29 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
701697
}
702698

703699
///@brief Record effected nets.
704-
static void record_affected_net(const ClusterNetId net,
705-
int& num_affected_nets) {
700+
static void record_affected_net(const ClusterNetId net) {
706701
/* Record effected nets. */
707702
if (pl_net_cost.proposed_net_cost[net] < 0.) {
708703
/* Net not marked yet. */
709-
ts_info.ts_nets_to_update[num_affected_nets] = net;
710-
num_affected_nets++;
704+
size_t last_size = ts_info.ts_nets_to_update.size();
705+
VTR_ASSERT(last_size < ts_info.ts_nets_to_update.capacity());
706+
ts_info.ts_nets_to_update.resize(last_size + 1);
707+
ts_info.ts_nets_to_update[last_size] = net;
711708

712709
/* Flag to say we've marked this net. */
713710
pl_net_cost.proposed_net_cost[net] = 1.;
714711
}
715712
}
716713

717-
static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algorithm,
718-
const PlaceDelayModel* delay_model,
719-
const PlacerCriticalities* criticalities,
720-
const ClusterBlockId& blk_id,
721-
const ClusterPinId& pin_id,
722-
const t_pl_moved_block& moving_blk_inf,
723-
std::vector<ClusterPinId>& affected_pins,
724-
double& timing_delta_c,
725-
int& num_affected_nets,
726-
bool is_src_moving) {
714+
static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm,
715+
const PlaceDelayModel* delay_model,
716+
const PlacerCriticalities* criticalities,
717+
const ClusterBlockId& blk_id,
718+
const ClusterPinId& pin_id,
719+
const t_pl_moved_block& moving_blk_inf,
720+
std::vector<ClusterPinId>& affected_pins,
721+
double& timing_delta_c,
722+
bool is_src_moving) {
727723
const auto& cluster_ctx = g_vpr_ctx.clustering();
728724
const ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);
729725
VTR_ASSERT_SAFE_MSG(net_id,
@@ -736,7 +732,7 @@ static void update_pl_net_cost_on_pin_move(const t_place_algorithm& place_algori
736732
}
737733

738734
/* Record effected nets */
739-
record_affected_net(net_id, num_affected_nets);
735+
record_affected_net(net_id);
740736

741737
/* Update the net bounding boxes. */
742738
update_net_bb(net_id, blk_id, pin_id, moving_blk_inf);
@@ -1897,8 +1893,8 @@ static double wirelength_crossing_count(size_t fanout) {
18971893
}
18981894
}
18991895

1900-
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
1901-
for (int inet_affected = 0; inet_affected < num_affected_nets;
1896+
static void set_bb_delta_cost(double& bb_delta_c) {
1897+
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
19021898
inet_affected++) {
19031899
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
19041900

@@ -1908,7 +1904,7 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
19081904
}
19091905
}
19101906

1911-
int find_affected_nets_and_update_costs(
1907+
void find_affected_nets_and_update_costs(
19121908
const t_place_algorithm& place_algorithm,
19131909
const PlaceDelayModel* delay_model,
19141910
const PlacerCriticalities* criticalities,
@@ -1919,7 +1915,7 @@ int find_affected_nets_and_update_costs(
19191915
VTR_ASSERT_SAFE(timing_delta_c == 0.);
19201916
auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist;
19211917

1922-
int num_affected_nets = 0;
1918+
ts_info.ts_nets_to_update.resize(0);
19231919

19241920
/* Go through all the blocks moved. */
19251921
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; iblk++) {
@@ -1936,24 +1932,21 @@ int find_affected_nets_and_update_costs(
19361932
blocks_affected.num_moved_blocks,
19371933
blocks_affected.moved_blocks);
19381934
}
1939-
update_pl_net_cost_on_pin_move(place_algorithm,
1940-
delay_model,
1941-
criticalities,
1942-
blk,
1943-
blk_pin,
1944-
moving_block_inf,
1945-
affected_pins,
1946-
timing_delta_c,
1947-
num_affected_nets,
1948-
is_src_moving);
1935+
update_net_info_on_pin_move(place_algorithm,
1936+
delay_model,
1937+
criticalities,
1938+
blk,
1939+
blk_pin,
1940+
moving_block_inf,
1941+
affected_pins,
1942+
timing_delta_c,
1943+
is_src_moving);
19491944
}
19501945
}
19511946

19521947
/* Now update the bounding box costs (since the net bounding *
19531948
* boxes are up-to-date). The cost is only updated once per net. */
1954-
set_bb_delta_cost(num_affected_nets, bb_delta_c);
1955-
1956-
return num_affected_nets;
1949+
set_bb_delta_cost(bb_delta_c);
19571950
}
19581951

19591952
double comp_bb_cost(e_cost_methods method) {
@@ -2034,12 +2027,12 @@ double comp_layer_bb_cost(e_cost_methods method) {
20342027
return cost;
20352028
}
20362029

2037-
void update_move_nets(int num_nets_affected) {
2030+
void update_move_nets() {
20382031
/* update net cost functions and reset flags. */
20392032
auto& cluster_ctx = g_vpr_ctx.clustering();
20402033
auto& place_move_ctx = g_placer_ctx.mutable_move();
20412034

2042-
for (int inet_affected = 0; inet_affected < num_nets_affected;
2035+
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
20432036
inet_affected++) {
20442037
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
20452038

@@ -2061,9 +2054,9 @@ void update_move_nets(int num_nets_affected) {
20612054
}
20622055
}
20632056

2064-
void reset_move_nets(int num_nets_affected) {
2057+
void reset_move_nets() {
20652058
/* Reset the net cost function flags first. */
2066-
for (int inet_affected = 0; inet_affected < num_nets_affected;
2059+
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
20672060
inet_affected++) {
20682061
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
20692062
pl_net_cost.proposed_net_cost[net_id] = -1;

vpr/src/place/net_cost_handler.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
/**
88
* @brief The method used to calculate palcement cost
9-
* @details For comp_cost. NORMAL means use the method that generates updateable bounding boxes for speed.
10-
* CHECK means compute all bounding boxes from scratch using a very simple routine to allow checks
9+
* @details For comp_cost. NORMAL means use the method that generates updateable bounding boxes for speed.
10+
* CHECK means compute all bounding boxes from scratch using a very simple routine to allow checks
1111
* of the other costs.
1212
* NORMAL: Compute cost efficiently using incremental techniques.
1313
* CHECK: Brute-force cost computation; useful to validate the more complex incremental cost update code.
@@ -36,7 +36,7 @@ enum e_cost_methods {
3636
*
3737
* The change in the bounding box cost is stored in `bb_delta_c`.
3838
* The change in the timing cost is stored in `timing_delta_c`.
39-
*
39+
*
4040
* @param place_algorithm
4141
* @param delay_model
4242
* @param criticalities
@@ -45,7 +45,7 @@ enum e_cost_methods {
4545
* @param timing_delta_c
4646
* @return The number of affected nets.
4747
*/
48-
int find_affected_nets_and_update_costs(
48+
void find_affected_nets_and_update_costs(
4949
const t_place_algorithm& place_algorithm,
5050
const PlaceDelayModel* delay_model,
5151
const PlacerCriticalities* criticalities,
@@ -54,27 +54,27 @@ int find_affected_nets_and_update_costs(
5454
double& timing_delta_c);
5555

5656
/**
57-
* @brief Finds the bb cost from scratch (based on 3D BB).
58-
* Done only when the placement has been radically changed
59-
* (i.e. after initial placement). Otherwise find the cost
60-
* change incrementally. If method check is NORMAL, we find
61-
* bounding boxes that are updatable for the larger nets.
62-
* If method is CHECK, all bounding boxes are found via the
63-
* non_updateable_bb routine, to provide a cost which can be
64-
* used to check the correctness of the other routine.
57+
* @brief Finds the bb cost from scratch (based on 3D BB).
58+
* Done only when the placement has been radically changed
59+
* (i.e. after initial placement). Otherwise find the cost
60+
* change incrementally. If method check is NORMAL, we find
61+
* bounding boxes that are updatable for the larger nets.
62+
* If method is CHECK, all bounding boxes are found via the
63+
* non_updateable_bb routine, to provide a cost which can be
64+
* used to check the correctness of the other routine.
6565
* @param method
6666
* @return The bounding box cost of the placement, computed by the 3D method.
6767
*/
6868
double comp_bb_cost(e_cost_methods method);
6969

7070
/**
71-
* @brief Finds the bb cost from scratch (based on per-layer BB).
72-
* Done only when the placement has been radically changed
73-
* (i.e. after initial placement). Otherwise find the cost change
74-
* incrementally. If method check is NORMAL, we find bounding boxes
75-
* that are updateable for the larger nets. If method is CHECK, all
76-
* bounding boxes are found via the non_updateable_bb routine, to provide
77-
* a cost which can be used to check the correctness of the other routine.
71+
* @brief Finds the bb cost from scratch (based on per-layer BB).
72+
* Done only when the placement has been radically changed
73+
* (i.e. after initial placement). Otherwise find the cost change
74+
* incrementally. If method check is NORMAL, we find bounding boxes
75+
* that are updateable for the larger nets. If method is CHECK, all
76+
* bounding boxes are found via the non_updateable_bb routine, to provide
77+
* a cost which can be used to check the correctness of the other routine.
7878
* @param method
7979
* @return The placement bounding box cost, computed by the per layer method.
8080
*/
@@ -84,17 +84,17 @@ double comp_layer_bb_cost(e_cost_methods method);
8484
* @brief update net cost data structures (in placer context and net_cost in .cpp file) and reset flags (proposed_net_cost and bb_updated_before).
8585
* @param num_nets_affected The number of nets affected by the move. It is used to determine the index up to which elements in ts_nets_to_update are valid.
8686
*/
87-
void update_move_nets(int num_nets_affected);
87+
void update_move_nets();
8888

8989
/**
9090
* @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before)
9191
* @param num_nets_affected
9292
*/
93-
void reset_move_nets(int num_nets_affected);
93+
void reset_move_nets();
9494

9595
/**
9696
* @brief re-calculates different terms of the cost function (wire-length, timing, NoC) and update "costs" accordingly. It is important to note that
97-
* in this function bounding box and connection delays are not calculated from scratch. However, it iterates over all nets and connections and updates
97+
* in this function bounding box and connection delays are not calculated from scratch. However, it iterates over all nets and connections and updates
9898
* their costs by a complete summation, rather than incrementally.
9999
* @param placer_opts
100100
* @param noc_opts
@@ -103,24 +103,24 @@ void reset_move_nets(int num_nets_affected);
103103
* @param costs passed by reference and computed by this routine (i.e. returned by reference)
104104
*/
105105
void recompute_costs_from_scratch(const t_placer_opts& placer_opts,
106-
const t_noc_opts& noc_opts,
107-
const PlaceDelayModel* delay_model,
108-
const PlacerCriticalities* criticalities,
109-
t_placer_costs* costs);
106+
const t_noc_opts& noc_opts,
107+
const PlaceDelayModel* delay_model,
108+
const PlacerCriticalities* criticalities,
109+
t_placer_costs* costs);
110110

111111
/**
112112
* @brief Allocates and loads the chanx_place_cost_fac and chany_place_cost_fac
113113
* arrays with the inverse of the average number of tracks per channel
114114
* between [subhigh] and [sublow].
115-
* @param place_cost_exp It is an exponent to which you take the average inverse channel
115+
* @param place_cost_exp It is an exponent to which you take the average inverse channel
116116
* capacity; a higher value would favour wider channels more over narrower channels during placement (usually we use 1).
117117
*/
118118
void alloc_and_load_chan_w_factors_for_place_cost(float place_cost_exp);
119119

120120
/**
121121
* @brief Frees the chanx_place_cost_fac and chany_place_cost_fac arrays.
122122
*/
123-
void free_chan_w_factors_for_place_cost ();
123+
void free_chan_w_factors_for_place_cost();
124124

125125
/**
126126
* @brief Resize net_cost, proposed_net_cost, and bb_updated_before data structures to accommodate all nets.
@@ -134,8 +134,8 @@ void init_place_move_structs(size_t num_nets);
134134
void free_place_move_structs();
135135

136136
/**
137-
* @brief Resize temporary storage data structures needed to determine which nets are affected by a move and data needed per net
138-
* about where their terminals are in order to quickly (incrementally) update their wirelength costs. These data structures are
137+
* @brief Resize temporary storage data structures needed to determine which nets are affected by a move and data needed per net
138+
* about where their terminals are in order to quickly (incrementally) update their wirelength costs. These data structures are
139139
* (layer_)ts_bb_edge_new, (layer_)ts_bb_coord_new, ts_layer_sink_pin_count, and ts_nets_to_update.
140140
* @param num_nets Number of nets in the netlist used by the placement engine (currently clustered netlist)
141141
* @param cube_bb True if the 3D bounding box should be used, false otherwise.

0 commit comments

Comments
 (0)