Skip to content

Commit 54ba0fd

Browse files
author
Yulang Luo
committed
[vpr][place] ts_nets_to_update now uses size() instead of num_nets
1 parent 3f1f8e2 commit 54ba0fd

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

vpr/src/place/net_cost_handler.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
140140
bool is_src_moving);
141141

142142
/**
143-
* @brief if "net" is not already stored as an affected net, mark it in ts_nets_to_update and increment num_affected_nets
143+
* @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.
144144
* @param net ID of a net affected by a move
145-
* @param num_affected_nets Incremented if this is a new net affected, and returned via reference.
146145
*/
147-
static void record_affected_net(const ClusterNetId net, int& num_affected_nets);
146+
static void record_affected_net(const ClusterNetId net);
148147

149148
/**
150149
* @brief Call suitable function based on the bounding box type to update the bounding box of the net connected to pin_id. Also,
@@ -157,7 +156,6 @@ static void record_affected_net(const ClusterNetId net, int& num_affected_nets);
157156
* @param moving_blk_inf Data structure that holds information, e.g., old location and new locatoin, about all moving blocks
158157
* @param affected_pins Netlist pins which are affected, in terms placement cost, by the proposed move.
159158
* @param timing_delta_c Timing cost change based on the proposed move
160-
* @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.
161159
* @param is_src_moving Is the moving pin the source of a net.
162160
*/
163161
static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm,
@@ -168,7 +166,6 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm
168166
const t_pl_moved_block& moving_blk_inf,
169167
std::vector<ClusterPinId>& affected_pins,
170168
double& timing_delta_c,
171-
int& num_affected_nets,
172169
bool is_src_moving);
173170

174171
/**
@@ -446,10 +443,9 @@ static double wirelength_crossing_count(size_t fanout);
446443
/**
447444
* @brief Calculates and returns the total bb (wirelength) cost change that would result from moving the blocks
448445
* indicated in the blocks_affected data structure.
449-
* @param num_affected_nets Number of valid elements in ts_bb_coord_new
450446
* @param bb_delta_c Cost difference after and before moving the block
451447
*/
452-
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c);
448+
static void set_bb_delta_cost(double& bb_delta_c);
453449

454450
/******************************* End of Function definitions ************************************/
455451

@@ -642,13 +638,14 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
642638
}
643639

644640
///@brief Record effected nets.
645-
static void record_affected_net(const ClusterNetId net,
646-
int& num_affected_nets) {
641+
static void record_affected_net(const ClusterNetId net) {
647642
/* Record effected nets. */
648643
if (proposed_net_cost[net] < 0.) {
649644
/* Net not marked yet. */
650-
ts_nets_to_update[num_affected_nets] = net;
651-
num_affected_nets++;
645+
size_t last_size = ts_nets_to_update.size();
646+
VTR_ASSERT(last_size < ts_nets_to_update.capacity());
647+
ts_nets_to_update.resize(last_size + 1);
648+
ts_nets_to_update[last_size] = net;
652649

653650
/* Flag to say we've marked this net. */
654651
proposed_net_cost[net] = 1.;
@@ -663,7 +660,6 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm
663660
const t_pl_moved_block& moving_blk_inf,
664661
std::vector<ClusterPinId>& affected_pins,
665662
double& timing_delta_c,
666-
int& num_affected_nets,
667663
bool is_src_moving) {
668664
const auto& cluster_ctx = g_vpr_ctx.clustering();
669665
const ClusterNetId net_id = cluster_ctx.clb_nlist.pin_net(pin_id);
@@ -677,7 +673,7 @@ static void update_net_info_on_pin_move(const t_place_algorithm& place_algorithm
677673
}
678674

679675
/* Record effected nets */
680-
record_affected_net(net_id, num_affected_nets);
676+
record_affected_net(net_id);
681677

682678
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
683679

@@ -1852,8 +1848,8 @@ static double wirelength_crossing_count(size_t fanout) {
18521848
}
18531849
}
18541850

1855-
static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
1856-
for (int inet_affected = 0; inet_affected < num_affected_nets;
1851+
static void set_bb_delta_cost(double& bb_delta_c) {
1852+
for (size_t inet_affected = 0; inet_affected < ts_nets_to_update.size();
18571853
inet_affected++) {
18581854
ClusterNetId net_id = ts_nets_to_update[inet_affected];
18591855
const auto& cube_bb = g_vpr_ctx.placement().cube_bb;
@@ -1871,7 +1867,7 @@ static void set_bb_delta_cost(const int num_affected_nets, double& bb_delta_c) {
18711867
}
18721868
}
18731869

1874-
int find_affected_nets_and_update_costs(
1870+
void find_affected_nets_and_update_costs(
18751871
const t_place_algorithm& place_algorithm,
18761872
const PlaceDelayModel* delay_model,
18771873
const PlacerCriticalities* criticalities,
@@ -1882,7 +1878,7 @@ int find_affected_nets_and_update_costs(
18821878
VTR_ASSERT_SAFE(timing_delta_c == 0.);
18831879
auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist;
18841880

1885-
int num_affected_nets = 0;
1881+
ts_nets_to_update.resize(0);
18861882

18871883
/* Go through all the blocks moved. */
18881884
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; iblk++) {
@@ -1907,16 +1903,13 @@ int find_affected_nets_and_update_costs(
19071903
moving_block_inf,
19081904
affected_pins,
19091905
timing_delta_c,
1910-
num_affected_nets,
19111906
is_src_moving);
19121907
}
19131908
}
19141909

19151910
/* Now update the bounding box costs (since the net bounding *
19161911
* boxes are up-to-date). The cost is only updated once per net. */
1917-
set_bb_delta_cost(num_affected_nets, bb_delta_c);
1918-
1919-
return num_affected_nets;
1912+
set_bb_delta_cost(bb_delta_c);
19201913
}
19211914

19221915
double comp_bb_cost(e_cost_methods method) {
@@ -1997,13 +1990,12 @@ double comp_layer_bb_cost(e_cost_methods method) {
19971990
return cost;
19981991
}
19991992

2000-
void update_move_nets(int num_nets_affected,
2001-
const bool cube_bb) {
1993+
void update_move_nets(const bool cube_bb) {
20021994
/* update net cost functions and reset flags. */
20031995
auto& cluster_ctx = g_vpr_ctx.clustering();
20041996
auto& place_move_ctx = g_placer_ctx.mutable_move();
20051997

2006-
for (int inet_affected = 0; inet_affected < num_nets_affected;
1998+
for (size_t inet_affected = 0; inet_affected < ts_nets_to_update.size();
20071999
inet_affected++) {
20082000
ClusterNetId net_id = ts_nets_to_update[inet_affected];
20092001

@@ -2033,9 +2025,9 @@ void update_move_nets(int num_nets_affected,
20332025
}
20342026
}
20352027

2036-
void reset_move_nets(int num_nets_affected) {
2028+
void reset_move_nets() {
20372029
/* Reset the net cost function flags first. */
2038-
for (int inet_affected = 0; inet_affected < num_nets_affected;
2030+
for (size_t inet_affected = 0; inet_affected < ts_nets_to_update.size();
20392031
inet_affected++) {
20402032
ClusterNetId net_id = ts_nets_to_update[inet_affected];
20412033
proposed_net_cost[net_id] = -1;
@@ -2242,7 +2234,8 @@ void init_try_swap_net_cost_structs(size_t num_nets, bool cube_bb) {
22422234
/*This initialize the whole matrix to OPEN which is an invalid value*/
22432235
ts_layer_sink_pin_count.resize({num_nets, size_t(num_layers)}, OPEN);
22442236

2245-
ts_nets_to_update.resize(num_nets, ClusterNetId::INVALID());
2237+
ts_nets_to_update.reserve(num_nets);
2238+
ts_nets_to_update.resize(0);
22462239
}
22472240

22482241
void free_try_swap_net_cost_structs() {

vpr/src/place/net_cost_handler.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
@@ -85,14 +85,13 @@ double comp_layer_bb_cost(e_cost_methods method);
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
* @param cube_bb True if we should use the 3D bounding box (cube_bb), false otherwise.
8787
*/
88-
void update_move_nets(int num_nets_affected,
89-
const bool cube_bb);
88+
void update_move_nets(const bool cube_bb);
9089

9190
/**
9291
* @brief Reset the net cost function flags (proposed_net_cost and bb_updated_before)
9392
* @param num_nets_affected
9493
*/
95-
void reset_move_nets(int num_nets_affected);
94+
void reset_move_nets();
9695

9796
/**
9897
* @brief re-calculates different terms of the cost function (wire-length, timing, NoC) and update "costs" accordingly. It is important to note that

vpr/src/place/place.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ static e_move_result try_swap(const t_annealing_state* state,
13781378
//
13791379
//Also find all the pins affected by the swap, and calculates new connection
13801380
//delays and timing costs and store them in proposed_* data structures.
1381-
int num_nets_affected = find_affected_nets_and_update_costs(
1381+
find_affected_nets_and_update_costs(
13821382
place_algorithm, delay_model, criticalities, blocks_affected,
13831383
bb_delta_c, timing_delta_c);
13841384

@@ -1481,8 +1481,7 @@ static e_move_result try_swap(const t_annealing_state* state,
14811481
}
14821482

14831483
/* Update net cost functions and reset flags. */
1484-
update_move_nets(num_nets_affected,
1485-
g_vpr_ctx.placement().cube_bb);
1484+
update_move_nets(g_vpr_ctx.placement().cube_bb);
14861485

14871486
/* Update clb data structures since we kept the move. */
14881487
commit_move_blocks(blocks_affected);
@@ -1506,7 +1505,7 @@ static e_move_result try_swap(const t_annealing_state* state,
15061505
VTR_ASSERT_SAFE(move_outcome == REJECTED);
15071506

15081507
/* Reset the net cost function flags first. */
1509-
reset_move_nets(num_nets_affected);
1508+
reset_move_nets();
15101509

15111510
/* Restore the place_ctx.block_locs data structures to their state before the move. */
15121511
revert_move_blocks(blocks_affected);

0 commit comments

Comments
 (0)