Skip to content

Commit 511dbe5

Browse files
author
Yulang Luo
committed
[vpr][place] moved_block uses size() to indicate valid elements
1 parent b778d60 commit 511dbe5

8 files changed

+32
-27
lines changed

vpr/src/place/move_transactions.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#include "move_utils.h"
22

33
#include "globals.h"
4+
// Is this needed?
45
#include "place_util.h"
56

7+
t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){
8+
moved_blocks.reserve(max_blocks);
9+
moved_blocks.resize(0);
10+
}
11+
12+
size_t t_pl_blocks_to_be_moved::get_size_and_increment() {
13+
VTR_ASSERT(moved_blocks.size() < moved_blocks.capacity());
14+
moved_blocks.resize(moved_blocks.size() + 1);
15+
return moved_blocks.size() - 1;
16+
}
17+
618
//Records that block 'blk' should be moved to the specified 'to' location
719
e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected, ClusterBlockId blk, t_pl_loc to) {
820
auto res = blocks_affected.moved_to.emplace(to);
@@ -24,11 +36,10 @@ e_block_move_result record_block_move(t_pl_blocks_to_be_moved& blocks_affected,
2436
VTR_ASSERT_SAFE(to.sub_tile < int(place_ctx.grid_blocks.num_blocks_at_location({to.x, to.y, to.layer})));
2537

2638
// Sets up the blocks moved
27-
int imoved_blk = blocks_affected.num_moved_blocks;
39+
size_t imoved_blk = blocks_affected.get_size_and_increment();
2840
blocks_affected.moved_blocks[imoved_blk].block_num = blk;
2941
blocks_affected.moved_blocks[imoved_blk].old_loc = from;
3042
blocks_affected.moved_blocks[imoved_blk].new_loc = to;
31-
blocks_affected.num_moved_blocks++;
3243

3344
return e_block_move_result::VALID;
3445
}
@@ -40,7 +51,7 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
4051

4152
//Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks
4253
//yet since we don't know whether the swap will be accepted
43-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
54+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
4455
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
4556

4657
const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc;
@@ -67,7 +78,7 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
6778
auto& place_ctx = g_vpr_ctx.mutable_placement();
6879

6980
/* Swap physical location */
70-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
81+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
7182
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
7283

7384
const t_pl_loc& to = blocks_affected.moved_blocks[iblk].new_loc;
@@ -97,7 +108,7 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
97108
auto& device_ctx = g_vpr_ctx.device();
98109

99110
// Swap the blocks back, nets not yet swapped they don't need to be changed
100-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
111+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
101112
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
102113

103114
const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc;
@@ -126,10 +137,10 @@ void clear_move_blocks(t_pl_blocks_to_be_moved& blocks_affected) {
126137
blocks_affected.moved_to.clear();
127138
blocks_affected.moved_from.clear();
128139

129-
//For run-time, we just reset num_moved_blocks to zero, but do not free the blocks_affected
140+
//For run-time, we just reset size of blocks_affected.moved_blocks to zero, but do not free the blocks_affected
130141
//array to avoid memory allocation
131142

132-
blocks_affected.num_moved_blocks = 0;
143+
blocks_affected.moved_blocks.resize(0);
133144

134145
blocks_affected.affected_pins.clear();
135146
}

vpr/src/place/move_transactions.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,21 @@ struct t_pl_moved_block {
2525
* placement, in the form of array of structs instead of struct with *
2626
* arrays for cache effifiency *
2727
*
28-
* num_moved_blocks: total number of blocks moved when *
29-
* swapping two blocks. *
3028
* moved blocks: a list of moved blocks data structure with *
3129
* information on the move. *
3230
* [0...max_blocks-1] *
3331
* affected_pins: pins affected by this move (used to *
3432
* incrementally invalidate parts of the timing *
3533
* graph. */
3634
struct t_pl_blocks_to_be_moved {
37-
explicit t_pl_blocks_to_be_moved(size_t max_blocks)
38-
: moved_blocks(max_blocks) {}
35+
explicit t_pl_blocks_to_be_moved(size_t max_blocks);
3936

40-
int num_moved_blocks = 0;
4137
std::vector<t_pl_moved_block> moved_blocks;
4238
std::unordered_set<t_pl_loc> moved_from;
4339
std::unordered_set<t_pl_loc> moved_to;
4440

4541
std::vector<ClusterPinId> affected_pins;
42+
size_t get_size_and_increment();
4643
};
4744

4845
enum class e_block_move_result {

vpr/src/place/move_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved&
488488
std::set<t_pl_loc> moved_from;
489489
std::set<t_pl_loc> moved_to;
490490

491-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
491+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
492492
//When a block is moved its old location becomes free
493493
moved_from.emplace(blocks_affected.moved_blocks[iblk].old_loc);
494494

vpr/src/place/net_cost_handler.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ static BBUpdater bb_updater;
156156
* @return True if the driver block of the net is among the moving blocks
157157
*/
158158
static bool driven_by_moved_block(const ClusterNetId net,
159-
const int num_blocks,
160159
const std::vector<t_pl_moved_block>& moved_blocks);
161160
/**
162161
* @brief Update the bounding box (3D) of the net connected to blk_pin. The old and new locations of the pin are
@@ -555,14 +554,13 @@ void BBUpdater::set_ts_edge(const ClusterNetId& net_id) {
555554

556555
//Returns true if 'net' is driven by one of the blocks in 'blocks_affected'
557556
static bool driven_by_moved_block(const ClusterNetId net,
558-
const int num_blocks,
559557
const std::vector<t_pl_moved_block>& moved_blocks) {
560558
auto& clb_nlist = g_vpr_ctx.clustering().clb_nlist;
561559
bool is_driven_by_move_blk = false;
562560
ClusterBlockId net_driver_block = clb_nlist.net_driver_block(
563561
net);
564562

565-
for (int block_num = 0; block_num < num_blocks; block_num++) {
563+
for (size_t block_num = 0; block_num < moved_blocks.size(); block_num++) {
566564
if (net_driver_block == moved_blocks[block_num].block_num) {
567565
is_driven_by_move_blk = true;
568566
break;
@@ -1918,7 +1916,7 @@ void find_affected_nets_and_update_costs(
19181916
ts_info.ts_nets_to_update.resize(0);
19191917

19201918
/* Go through all the blocks moved. */
1921-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; iblk++) {
1919+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); iblk++) {
19221920
const auto& moving_block_inf = blocks_affected.moved_blocks[iblk];
19231921
auto& affected_pins = blocks_affected.affected_pins;
19241922
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
@@ -1929,7 +1927,6 @@ void find_affected_nets_and_update_costs(
19291927
if (clb_nlist.pin_type(blk_pin) == PinType::SINK) {
19301928
ClusterNetId net_id = clb_nlist.pin_net(blk_pin);
19311929
is_src_moving = driven_by_moved_block(net_id,
1932-
blocks_affected.num_moved_blocks,
19331930
blocks_affected.moved_blocks);
19341931
}
19351932
update_net_info_on_pin_move(place_algorithm,

vpr/src/place/noc_place_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void find_affected_noc_routers_and_update_noc_costs(const t_pl_blocks_to_be_move
136136
affected_noc_links.clear();
137137

138138
// go through the moved blocks and process them only if they are NoC routers
139-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
139+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
140140
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
141141

142142
// check if the current moved block is a noc router
@@ -291,7 +291,7 @@ void revert_noc_traffic_flow_routes(const t_pl_blocks_to_be_moved& blocks_affect
291291
std::unordered_set<NocTrafficFlowId> reverted_traffic_flows;
292292

293293
// go through the moved blocks and process them only if they are NoC routers
294-
for (int iblk = 0; iblk < blocks_affected.num_moved_blocks; ++iblk) {
294+
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
295295
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
296296

297297
// check if the current moved block is a noc router

vpr/src/place/place.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ std::unique_ptr<FILE, decltype(&vtr::fclose)> f_move_stats_file(nullptr,
150150
t, \
151151
int(b_from), int(b_to), \
152152
from_type->name, (to_type ? to_type->name : "EMPTY"), \
153-
affected_blocks.num_moved_blocks); \
153+
affected_blocks.moved_blocks.size()); \
154154
} \
155155
} while (false)
156156

vpr/src/place/place_constraints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro);
100100
inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) {
101101
bool floorplan_legal;
102102

103-
for (int i = 0; i < blocks_affected.num_moved_blocks; i++) {
103+
for (size_t i = 0; i < blocks_affected.moved_blocks.size(); i++) {
104104
floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num,
105105
blocks_affected.moved_blocks[i].new_loc);
106106
if (!floorplan_legal) {

vpr/test/test_noc_place_utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
748748
} while (swap_router_block_one == swap_router_block_two);
749749

750750
//set up the moved blocks datastructure for the test function
751-
blocks_affected.num_moved_blocks = 2;
751+
blocks_affected.moved_blocks.resize(2);
752752

753753
blocks_affected.moved_blocks[0].block_num = swap_router_block_one;
754754
blocks_affected.moved_blocks[0].old_loc = t_pl_loc(noc_ctx.noc_model.get_single_noc_router(router_where_cluster_is_placed[swap_router_block_one]).get_router_grid_position_x(),
@@ -903,7 +903,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
903903

904904
// now perform the swap
905905
//set up the moved blocks datastructure for the test function
906-
blocks_affected.num_moved_blocks = 2;
906+
blocks_affected.moved_blocks.resize(2);
907907

908908
blocks_affected.moved_blocks[0].block_num = swap_router_block_one;
909909

@@ -1039,7 +1039,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
10391039

10401040
// now perform the swap
10411041
//set up the moved blocks datastructure for the test function
1042-
blocks_affected.num_moved_blocks = 2;
1042+
blocks_affected.moved_blocks.resize(2);
10431043

10441044
blocks_affected.moved_blocks[0].block_num = swap_router_block_one;
10451045

@@ -1142,7 +1142,7 @@ TEST_CASE("test_find_affected_noc_routers_and_update_noc_costs, test_commit_noc_
11421142

11431143
// now perform the swap
11441144
//set up the moved blocks datastructure for the test function
1145-
blocks_affected.num_moved_blocks = 2;
1145+
blocks_affected.moved_blocks.resize(2);
11461146

11471147
blocks_affected.moved_blocks[0].block_num = swap_router_block_one;
11481148

@@ -1584,7 +1584,7 @@ TEST_CASE("test_revert_noc_traffic_flow_routes", "[noc_place_utils]") {
15841584

15851585
//set up the moved blocks datastructure for the test function
15861586
// this is needed for the test function (it needs to know what blocks were swapped, so it can undo it)
1587-
blocks_affected.num_moved_blocks = 2;
1587+
blocks_affected.moved_blocks.resize(2);
15881588

15891589
blocks_affected.moved_blocks[0].block_num = swap_router_block_one;
15901590
blocks_affected.moved_blocks[0].old_loc = t_pl_loc(noc_ctx.noc_model.get_single_noc_router(router_where_cluster_is_placed[swap_router_block_one]).get_router_grid_position_x(),

0 commit comments

Comments
 (0)