Skip to content

Commit 2e19dc4

Browse files
author
Yulang Luo
committed
[vpr][place] rebased all branch and fixed PR comments
1 parent 4c5d897 commit 2e19dc4

7 files changed

+45
-73
lines changed

vpr/src/place/move_transactions.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include "move_utils.h"
22

33
#include "globals.h"
4+
#include "vtr_assert.h"
45

56
t_pl_blocks_to_be_moved::t_pl_blocks_to_be_moved(size_t max_blocks){
67
moved_blocks.reserve(max_blocks);
78
moved_blocks.resize(0);
89
}
910

1011
size_t t_pl_blocks_to_be_moved::get_size_and_increment() {
11-
VTR_ASSERT(moved_blocks.size() < moved_blocks.capacity());
12+
VTR_ASSERT_SAFE(moved_blocks.size() < moved_blocks.capacity());
1213
moved_blocks.resize(moved_blocks.size() + 1);
1314
return moved_blocks.size() - 1;
1415
}
@@ -49,11 +50,11 @@ void apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
4950

5051
//Swap the blocks, but don't swap the nets or update place_ctx.grid_blocks
5152
//yet since we don't know whether the swap will be accepted
52-
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
53-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
53+
for (const auto& block : blocks_affected.moved_blocks) {
54+
ClusterBlockId blk = block.block_num;
5455

55-
const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc;
56-
const t_pl_loc& new_loc = blocks_affected.moved_blocks[iblk].new_loc;
56+
const t_pl_loc& old_loc = block.old_loc;
57+
const t_pl_loc& new_loc = block.new_loc;
5758

5859
// move the block to its new location
5960
place_ctx.block_locs[blk].loc = new_loc;
@@ -76,11 +77,11 @@ void commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
7677
auto& place_ctx = g_vpr_ctx.mutable_placement();
7778

7879
/* Swap physical location */
79-
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
80-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
80+
for (const auto& block : blocks_affected.moved_blocks) {
81+
ClusterBlockId blk = block.block_num;
8182

82-
const t_pl_loc& to = blocks_affected.moved_blocks[iblk].new_loc;
83-
const t_pl_loc& from = blocks_affected.moved_blocks[iblk].old_loc;
83+
const t_pl_loc& to = block.new_loc;
84+
const t_pl_loc& from = block.old_loc;
8485

8586
//Remove from old location only if it hasn't already been updated by a previous block update
8687
if (place_ctx.grid_blocks.block_at_location(from) == blk) {
@@ -106,11 +107,11 @@ void revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
106107
auto& device_ctx = g_vpr_ctx.device();
107108

108109
// Swap the blocks back, nets not yet swapped they don't need to be changed
109-
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
110-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
110+
for (const auto& block : blocks_affected.moved_blocks) {
111+
ClusterBlockId blk = block.block_num;
111112

112-
const t_pl_loc& old_loc = blocks_affected.moved_blocks[iblk].old_loc;
113-
const t_pl_loc& new_loc = blocks_affected.moved_blocks[iblk].new_loc;
113+
const t_pl_loc& old_loc = block.old_loc;
114+
const t_pl_loc& new_loc = block.new_loc;
114115

115116
// return the block to where it was before the swap
116117
place_ctx.block_locs[blk].loc = old_loc;

vpr/src/place/move_utils.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#include "move_utils.h"
2-
3-
#include "place_util.h"
42
#include "globals.h"
5-
63
#include "vtr_random.h"
7-
8-
#include "draw_debug.h"
9-
#include "draw.h"
10-
114
#include "place_constraints.h"
125
#include "placer_globals.h"
136

@@ -488,12 +481,12 @@ std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved&
488481
std::set<t_pl_loc> moved_from;
489482
std::set<t_pl_loc> moved_to;
490483

491-
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
484+
for (const auto& block : blocks_affected.moved_blocks) {
492485
//When a block is moved its old location becomes free
493-
moved_from.emplace(blocks_affected.moved_blocks[iblk].old_loc);
486+
moved_from.emplace(block.old_loc);
494487

495488
//But any block later moved to a position fills it
496-
moved_to.emplace(blocks_affected.moved_blocks[iblk].new_loc);
489+
moved_to.emplace(block.new_loc);
497490
}
498491

499492
std::set<t_pl_loc> empty_locs;

vpr/src/place/net_cost_handler.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void update_td_delta_costs(const PlaceDelayModel* delay_model,
192192
bool is_src_moving);
193193

194194
/**
195-
* @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.
195+
* @brief if "net" is not already stored as an affected net, add it in ts_nets_to_update.
196196
* @param net ID of a net affected by a move
197197
*/
198198
static void record_affected_net(const ClusterNetId net);
@@ -560,8 +560,8 @@ static bool driven_by_moved_block(const ClusterNetId net,
560560
ClusterBlockId net_driver_block = clb_nlist.net_driver_block(
561561
net);
562562

563-
for (size_t block_num = 0; block_num < moved_blocks.size(); block_num++) {
564-
if (net_driver_block == moved_blocks[block_num].block_num) {
563+
for (const auto& block : moved_blocks) {
564+
if (net_driver_block == block.block_num) {
565565
is_driven_by_move_blk = true;
566566
break;
567567
}
@@ -1892,9 +1892,8 @@ static double wirelength_crossing_count(size_t fanout) {
18921892
}
18931893

18941894
static void set_bb_delta_cost(double& bb_delta_c) {
1895-
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
1896-
inet_affected++) {
1897-
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
1895+
for (const auto& ts_net: ts_info.ts_nets_to_update) {
1896+
ClusterNetId net_id = ts_net;
18981897

18991898
pl_net_cost.proposed_net_cost[net_id] = bb_updater.get_net_cost(net_id);
19001899

@@ -1916,10 +1915,10 @@ void find_affected_nets_and_update_costs(
19161915
ts_info.ts_nets_to_update.resize(0);
19171916

19181917
/* Go through all the blocks moved. */
1919-
for (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); iblk++) {
1920-
const auto& moving_block_inf = blocks_affected.moved_blocks[iblk];
1918+
for (const auto& block : blocks_affected.moved_blocks) {
1919+
const auto& moving_block_inf = block;
19211920
auto& affected_pins = blocks_affected.affected_pins;
1922-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
1921+
ClusterBlockId blk = block.block_num;
19231922

19241923
/* Go through all the pins in the moved block. */
19251924
for (ClusterPinId blk_pin : clb_nlist.block_pins(blk)) {
@@ -2029,9 +2028,8 @@ void update_move_nets() {
20292028
auto& cluster_ctx = g_vpr_ctx.clustering();
20302029
auto& place_move_ctx = g_placer_ctx.mutable_move();
20312030

2032-
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
2033-
inet_affected++) {
2034-
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
2031+
for (const auto& ts_net : ts_info.ts_nets_to_update) {
2032+
ClusterNetId net_id = ts_net;
20352033

20362034
bb_updater.set_ts_bb_coord(net_id);
20372035

@@ -2053,9 +2051,8 @@ void update_move_nets() {
20532051

20542052
void reset_move_nets() {
20552053
/* Reset the net cost function flags first. */
2056-
for (size_t inet_affected = 0; inet_affected < ts_info.ts_nets_to_update.size();
2057-
inet_affected++) {
2058-
ClusterNetId net_id = ts_info.ts_nets_to_update[inet_affected];
2054+
for (const auto& ts_net : ts_info.ts_nets_to_update) {
2055+
ClusterNetId net_id = ts_net;
20592056
pl_net_cost.proposed_net_cost[net_id] = -1;
20602057
pl_net_cost.bb_update_status[net_id] = NetUpdateState::NOT_UPDATED_YET;
20612058
}

vpr/src/place/net_cost_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +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+
* ts_nets_to_update is also extended with the latest net.
3940
*
4041
* @param place_algorithm
4142
* @param delay_model

vpr/src/place/noc_place_utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ 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 (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
140-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
139+
for (const auto& block : blocks_affected.moved_blocks) {
140+
ClusterBlockId blk = block.block_num;
141141

142142
// check if the current moved block is a noc router
143143
if (noc_traffic_flows_storage.check_if_cluster_block_has_traffic_flows(blk)) {
@@ -291,8 +291,8 @@ 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 (size_t iblk = 0; iblk < blocks_affected.moved_blocks.size(); ++iblk) {
295-
ClusterBlockId blk = blocks_affected.moved_blocks[iblk].block_num;
294+
for (const auto& block : blocks_affected.moved_blocks) {
295+
ClusterBlockId blk = block.block_num;
296296

297297
// check if the current moved block is a noc router
298298
if (noc_traffic_flows_storage.check_if_cluster_block_has_traffic_flows(blk)) {
@@ -323,7 +323,7 @@ void re_route_traffic_flow(NocTrafficFlowId traffic_flow_id,
323323
// get the current traffic flow info
324324
const t_noc_traffic_flow& curr_traffic_flow = noc_traffic_flows_storage.get_single_noc_traffic_flow(traffic_flow_id);
325325

326-
/* since the current traffic flow route will be
326+
/* since the current traffic flow route will be
327327
* changed, first we need to decrement the bandwidth
328328
* usage of all links that are part of
329329
* the existing traffic flow route
@@ -994,4 +994,4 @@ static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<No
994994
std::back_inserter(unique_links));
995995

996996
return unique_links;
997-
}
997+
}

vpr/src/place/place.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
#include <cstdio>
22
#include <cmath>
33
#include <memory>
4-
#include <fstream>
5-
#include <iostream>
6-
#include <numeric>
7-
#include <chrono>
8-
#include <optional>
9-
10-
#include "NetPinTimingInvalidator.h"
114
#include "vtr_assert.h"
125
#include "vtr_log.h"
136
#include "vtr_util.h"
147
#include "vtr_random.h"
15-
#include "vtr_geometry.h"
168
#include "vtr_time.h"
17-
#include "vtr_math.h"
189
#include "vtr_ndmatrix.h"
1910

2011
#include "vpr_types.h"
@@ -27,11 +18,6 @@
2718
#include "placer_globals.h"
2819
#include "read_place.h"
2920
#include "draw.h"
30-
#include "place_and_route.h"
31-
#include "net_delay.h"
32-
#include "timing_place_lookup.h"
33-
#include "timing_place.h"
34-
#include "read_xml_arch_file.h"
3521
#include "echo_files.h"
3622
#include "place_macro.h"
3723
#include "histogram.h"
@@ -45,10 +31,7 @@
4531
#include "read_place.h"
4632
#include "place_constraints.h"
4733
#include "manual_moves.h"
48-
#include "buttons.h"
4934

50-
#include "static_move_generator.h"
51-
#include "simpleRL_move_generator.h"
5235
#include "manual_move_generator.h"
5336

5437
#include "PlacementDelayCalculator.h"
@@ -59,13 +42,11 @@
5942
#include "tatum/echo_writer.hpp"
6043
#include "tatum/TimingReporter.hpp"
6144

62-
#include "placer_breakpoint.h"
6345
#include "RL_agent_util.h"
6446
#include "place_checkpoint.h"
6547

6648
#include "clustered_netlist_utils.h"
6749

68-
#include "cluster_placement.h"
6950

7051
#include "noc_place_utils.h"
7152

@@ -150,7 +131,7 @@ std::unique_ptr<FILE, decltype(&vtr::fclose)> f_move_stats_file(nullptr,
150131
t, \
151132
int(b_from), int(b_to), \
152133
from_type->name, (to_type ? to_type->name : "EMPTY"), \
153-
affected_blocks.moved_blocks.size()); \
134+
affected_blocks.moved_blocks.size()); \
154135
} \
155136
} while (false)
156137

@@ -1325,7 +1306,7 @@ static e_move_result try_swap(const t_annealing_state* state,
13251306
if (manual_move_enabled) {
13261307
#ifndef NO_GRAPHICS
13271308
create_move_outcome = manual_move_display_and_propose(manual_move_generator, blocks_affected, proposed_action.move_type, rlim, placer_opts, criticalities);
1328-
#else //NO_GRAPHICS \
1309+
#else //NO_GRAPHICS
13291310
//Cast to void to explicitly avoid warning.
13301311
(void)manual_move_generator;
13311312
#endif //NO_GRAPHICS

vpr/src/place/place_constraints.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111
#include "move_transactions.h"
1212
#include "region.h"
13-
#include "clustered_netlist_utils.h"
1413
#include "partition_region.h"
1514
#include "place_macro.h"
1615
#include "grid_tile_lookup.h"
@@ -100,16 +99,16 @@ void print_macro_constraint_error(const t_pl_macro& pl_macro);
10099
inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) {
101100
bool floorplan_legal;
102101

103-
for (size_t i = 0; i < blocks_affected.moved_blocks.size(); i++) {
104-
floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num,
105-
blocks_affected.moved_blocks[i].new_loc);
102+
for (const auto& block : blocks_affected.moved_blocks) {
103+
floorplan_legal = cluster_floorplanning_legal(block.block_num,
104+
block.new_loc);
106105
if (!floorplan_legal) {
107106
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug,
108107
"\tMove aborted for block %zu, location tried was x: %d, y: %d, subtile: %d \n",
109-
size_t(blocks_affected.moved_blocks[i].block_num),
110-
blocks_affected.moved_blocks[i].new_loc.x,
111-
blocks_affected.moved_blocks[i].new_loc.y,
112-
blocks_affected.moved_blocks[i].new_loc.sub_tile);
108+
size_t(block.block_num),
109+
block.new_loc.x,
110+
block.new_loc.y,
111+
block.new_loc.sub_tile);
113112
return false;
114113
}
115114
}

0 commit comments

Comments
 (0)