Skip to content

Commit 999961a

Browse files
authored
Merge pull request #2724 from verilog-to-routing/temp_remove_static_vars_noc
NocCostHandler class
2 parents 286105a + 169b31c commit 999961a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1758
-1550
lines changed

vpr/src/analytical_place/full_legalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class APClusterPlacer {
104104
// to share the code.
105105

106106
// Clear the grid locations (stolen from initial_placement)
107-
clear_all_grid_locs(blk_loc_registry);
107+
blk_loc_registry.clear_all_grid_locs();
108108

109109
// Deal with the placement constraints.
110110
propagate_place_constraints();

vpr/src/base/blk_loc_registry.cpp

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int BlkLocRegistry::tile_pin_index(const ClusterPinId pin) const {
3636
}
3737

3838
int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const {
39-
auto& cluster_ctx = g_vpr_ctx.clustering();
39+
const auto& cluster_ctx = g_vpr_ctx.clustering();
4040

4141
// Get the logical pin index of pin within its logical block type
4242
ClusterPinId pin_id = cluster_ctx.clb_nlist.net_pin(net_id, net_pin_index);
@@ -45,22 +45,22 @@ int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net
4545
}
4646

4747
void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& location) {
48-
auto& device_ctx = g_vpr_ctx.device();
49-
auto& cluster_ctx = g_vpr_ctx.clustering();
48+
const auto& device_ctx = g_vpr_ctx.device();
49+
const auto& cluster_ctx = g_vpr_ctx.clustering();
5050

5151
const std::string& block_name = cluster_ctx.clb_nlist.block_name(blk_id);
5252

53-
//Check if block location is out of range of grid dimensions
53+
// Check if block location is out of range of grid dimensions
5454
if (location.x < 0 || location.x > int(device_ctx.grid.width() - 1)
5555
|| location.y < 0 || location.y > int(device_ctx.grid.height() - 1)) {
5656
VPR_THROW(VPR_ERROR_PLACE, "Block %s with ID %d is out of range at location (%d, %d). \n",
5757
block_name.c_str(), blk_id, location.x, location.y);
5858
}
5959

60-
//Set the location of the block
60+
// Set the location of the block
6161
block_locs_[blk_id].loc = location;
6262

63-
//Check if block is at an illegal location
63+
// Check if block is at an illegal location
6464
auto physical_tile = device_ctx.grid.get_physical_type({location.x, location.y, location.layer});
6565
auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id);
6666

@@ -77,13 +77,71 @@ void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& l
7777
location.layer);
7878
}
7979

80-
//Mark the grid location and usage of the block
80+
// Mark the grid location and usage of the block
8181
grid_blocks_.set_block_at_location(location, blk_id);
8282
grid_blocks_.increment_usage({location.x, location.y, location.layer});
8383

8484
place_sync_external_block_connections(blk_id);
8585
}
8686

87+
void BlkLocRegistry::clear_all_grid_locs() {
88+
const auto& device_ctx = g_vpr_ctx.device();
89+
90+
std::unordered_set<int> blk_types_to_be_cleared;
91+
const auto& logical_block_types = device_ctx.logical_block_types;
92+
93+
// Insert all the logical block types into the set except the empty type
94+
// clear_block_type_grid_locs does not expect empty type to be among given types
95+
for (const t_logical_block_type& logical_type : logical_block_types) {
96+
if (!is_empty_type(&logical_type)) {
97+
blk_types_to_be_cleared.insert(logical_type.index);
98+
}
99+
}
100+
101+
clear_block_type_grid_locs(blk_types_to_be_cleared);
102+
}
103+
104+
void BlkLocRegistry::clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index) {
105+
const auto& device_ctx = g_vpr_ctx.device();
106+
const auto& cluster_ctx = g_vpr_ctx.clustering();
107+
108+
bool clear_all_block_types = false;
109+
110+
/* check if all types should be cleared
111+
* logical_block_types contain empty type, needs to be ignored.
112+
* Not having any type in unplaced_blk_types_index means that it is the first iteration, hence all grids needs to be cleared
113+
*/
114+
if (unplaced_blk_types_index.size() == device_ctx.logical_block_types.size() - 1) {
115+
clear_all_block_types = true;
116+
}
117+
118+
/* We'll use the grid to record where everything goes. Initialize to the grid has no
119+
* blocks placed anywhere.
120+
*/
121+
for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
122+
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
123+
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
124+
const t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({i, j, layer_num});
125+
int itype = type->index;
126+
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
127+
grid_blocks_.set_usage({i, j, layer_num}, 0);
128+
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
129+
grid_blocks_.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
130+
}
131+
}
132+
}
133+
}
134+
}
135+
136+
// Similarly, mark all blocks as not being placed yet.
137+
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
138+
int blk_type = cluster_ctx.clb_nlist.block_type(blk_id)->index;
139+
if (clear_all_block_types || unplaced_blk_types_index.count(blk_type)) {
140+
block_locs_[blk_id].loc = t_pl_loc();
141+
}
142+
}
143+
}
144+
87145
void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk) {
88146
const auto& cluster_ctx = g_vpr_ctx.clustering();
89147
const auto& clb_nlist = cluster_ctx.clb_nlist;
@@ -119,7 +177,7 @@ void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk)
119177
}
120178

121179
void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
122-
auto& device_ctx = g_vpr_ctx.device();
180+
const auto& device_ctx = g_vpr_ctx.device();
123181

124182
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::APPLY);
125183

@@ -177,7 +235,7 @@ void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
177235
}
178236

179237
void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
180-
auto& device_ctx = g_vpr_ctx.device();
238+
const auto& device_ctx = g_vpr_ctx.device();
181239

182240
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT);
183241

vpr/src/base/blk_loc_registry.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ class BlkLocRegistry {
6161
*/
6262
void set_block_location(ClusterBlockId blk_id, const t_pl_loc& location);
6363

64+
/**
65+
* @brief Initializes the grid to empty. It also initializes the location for
66+
* all blocks to unplaced.
67+
*/
68+
void clear_all_grid_locs();
69+
70+
/**
71+
* @brief Set chosen grid locations to EMPTY block id before each placement iteration
72+
*
73+
* @param unplaced_blk_types_index Block types that their grid locations must be cleared.
74+
*/
75+
void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index);
76+
6477
/**
6578
* @brief Syncs the logical block pins corresponding to the input iblk with the corresponding chosen physical tile
6679
* @param iblk cluster block ID to sync within the assigned physical tile

vpr/src/base/setup_noc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void create_noc_routers(const t_noc_inf& noc_info,
133133
const vtr::vector<int, t_noc_router_tile_position>& noc_router_tiles) {
134134
// keep track of the router assignments (store the user router id that was assigned to each physical router tile)
135135
// this is used in error checking, after determining the closest physical router for a user described router in the arch file,
136-
// the datastructure below can be used to check if that physical router was already assigned previously
136+
// the data structure below can be used to check if that physical router was already assigned previously
137137
std::vector<int> router_assignments;
138138
router_assignments.resize(noc_router_tiles.size(), PHYSICAL_ROUTER_NOT_ASSIGNED);
139139

vpr/src/base/setup_noc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct t_noc_router_tile_position {
5858
* @brief Based on the NoC information provided by the user in the architecture
5959
* description file, a NoC model is created. The model defines the
6060
* constraints of the NoC as well as its layout on the FPGA device.
61-
* The datastructure used to define the model is "NocStorage" and that
61+
* The data structure used to define the model is "NocStorage" and that
6262
* is created here and stored within the noc_ctx.
6363
*
6464
* @param arch Contains the parsed information from the architecture

vpr/src/base/vpr_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void vpr_setup_clock_networks(t_vpr_setup& vpr_setup, const t_arch& Arch) {
554554
* constraints. Additionally, the graphics state is updated
555555
* to include a NoC button to display it.
556556
*
557-
* @param vpr_setup A datastructure that stores all the user provided option
557+
* @param vpr_setup A data structure that stores all the user provided option
558558
* to vpr.
559559
* @param arch Contains the parsed information from the architecture
560560
* description file.
@@ -1327,7 +1327,7 @@ static void free_routing() {
13271327
}
13281328

13291329
/**
1330-
* @brief handles the deletion of NoC related datastructures.
1330+
* @brief handles the deletion of NoC related data structures.
13311331
*/
13321332
static void free_noc() {}
13331333

vpr/src/draw/draw.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ void init_draw_coords(float clb_width, const BlkLocRegistry& blk_loc_registry) {
580580
/* Store a reference to block location variables so that other drawing
581581
* functions can access block location information without accessing
582582
* the global placement state, which is inaccessible during placement.*/
583-
set_graphics_blk_loc_registry_ref(blk_loc_registry);
583+
draw_state->set_graphics_blk_loc_registry_ref(blk_loc_registry);
584584

585585
if (!draw_state->show_graphics && !draw_state->save_graphics
586586
&& draw_state->graphics_commands.empty())
@@ -1004,8 +1004,8 @@ static void highlight_blocks(double x, double y) {
10041004
return; /* Nothing was found on any layer*/
10051005
}
10061006

1007-
auto& cluster_ctx = g_vpr_ctx.clustering();
1008-
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
1007+
const auto& cluster_ctx = g_vpr_ctx.clustering();
1008+
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
10091009

10101010
VTR_ASSERT(clb_index != ClusterBlockId::INVALID());
10111011

@@ -1046,14 +1046,15 @@ static void highlight_blocks(double x, double y) {
10461046
ClusterBlockId get_cluster_block_id_from_xy_loc(double x, double y) {
10471047
t_draw_coords* draw_coords = get_draw_coords_vars();
10481048
t_draw_state* draw_state = get_draw_state_vars();
1049-
auto clb_index = ClusterBlockId::INVALID();
1050-
auto& device_ctx = g_vpr_ctx.device();
1051-
auto& cluster_ctx = g_vpr_ctx.clustering();
1052-
const auto& grid_blocks = get_graphics_blk_loc_registry_ref().grid_blocks();
1049+
const auto& device_ctx = g_vpr_ctx.device();
1050+
const auto& cluster_ctx = g_vpr_ctx.clustering();
1051+
const auto& grid_blocks = draw_state->get_graphics_blk_loc_registry_ref().grid_blocks();
10531052

10541053
/// determine block ///
10551054
ezgl::rectangle clb_bbox;
10561055

1056+
auto clb_index = ClusterBlockId::INVALID();
1057+
10571058
//iterate over grid z (layers) first. Start search of the block at the top layer to prioritize highlighting of blocks at higher levels during overlapping of layers.
10581059
for (int layer_num = device_ctx.grid.get_num_layers() - 1; layer_num >= 0; layer_num--) {
10591060
if (!draw_state->draw_layer_display[layer_num].visible) {

vpr/src/draw/draw_basic.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ const std::vector<ezgl::color> kelly_max_contrast_colors = {
101101
void drawplace(ezgl::renderer* g) {
102102
t_draw_state* draw_state = get_draw_state_vars();
103103
t_draw_coords* draw_coords = get_draw_coords_vars();
104-
auto& device_ctx = g_vpr_ctx.device();
105-
auto& cluster_ctx = g_vpr_ctx.clustering();
106-
const auto& grid_blocks = get_graphics_blk_loc_registry_ref().grid_blocks();
104+
const auto& device_ctx = g_vpr_ctx.device();
105+
const auto& cluster_ctx = g_vpr_ctx.clustering();
106+
const auto& grid_blocks = draw_state->get_graphics_blk_loc_registry_ref().grid_blocks();
107107

108108
ClusterBlockId bnum;
109109
int num_sub_tiles;
@@ -224,12 +224,9 @@ void drawplace(ezgl::renderer* g) {
224224
void drawnets(ezgl::renderer* g) {
225225
t_draw_state* draw_state = get_draw_state_vars();
226226
t_draw_coords* draw_coords = get_draw_coords_vars();
227+
const auto& cluster_ctx = g_vpr_ctx.clustering();
228+
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
227229

228-
ClusterBlockId b1, b2;
229-
auto& cluster_ctx = g_vpr_ctx.clustering();
230-
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
231-
232-
float transparency_factor;
233230
float NET_ALPHA = draw_state->net_alpha;
234231

235232
g->set_line_dash(ezgl::line_dash::none);
@@ -250,7 +247,7 @@ void drawnets(ezgl::renderer* g) {
250247
continue;
251248
}
252249

253-
b1 = cluster_ctx.clb_nlist.net_driver_block(net_id);
250+
ClusterBlockId b1 = cluster_ctx.clb_nlist.net_driver_block(net_id);
254251

255252
//The layer of the net driver block
256253
driver_block_layer_num = block_locs[b1].loc.layer;
@@ -262,7 +259,7 @@ void drawnets(ezgl::renderer* g) {
262259

263260
ezgl::point2d driver_center = draw_coords->get_absolute_clb_bbox(b1, cluster_ctx.clb_nlist.block_type(b1)).center();
264261
for (ClusterPinId pin_id : cluster_ctx.clb_nlist.net_sinks(net_id)) {
265-
b2 = cluster_ctx.clb_nlist.pin_block(pin_id);
262+
ClusterBlockId b2 = cluster_ctx.clb_nlist.pin_block(pin_id);
266263

267264
//the layer of the pin block (net sinks)
268265
sink_block_layer_num =block_locs[b2].loc.layer;
@@ -272,7 +269,7 @@ void drawnets(ezgl::renderer* g) {
272269
if (!element_visibility.visible) {
273270
continue; /* Don't Draw */
274271
}
275-
transparency_factor = element_visibility.alpha;
272+
float transparency_factor = element_visibility.alpha;
276273

277274
//Take the highest of the 2 transparency values that the user can select from the UI
278275
// Compare the current cross layer transparency to the overall Net transparency set by the user.
@@ -800,8 +797,8 @@ void draw_placement_macros(ezgl::renderer* g) {
800797
}
801798
t_draw_coords* draw_coords = get_draw_coords_vars();
802799

803-
auto& place_ctx = g_vpr_ctx.placement();
804-
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
800+
const auto& place_ctx = g_vpr_ctx.placement();
801+
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
805802

806803
for (const t_pl_macro& pl_macro : place_ctx.pl_macros) {
807804

@@ -1184,8 +1181,9 @@ void draw_crit_path_elements(const std::vector<tatum::TimingPath>& paths, const
11841181
}
11851182

11861183
int get_timing_path_node_layer_num(tatum::NodeId node) {
1187-
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
1188-
auto& atom_ctx = g_vpr_ctx.atom();
1184+
t_draw_state* draw_state = get_draw_state_vars();
1185+
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
1186+
const auto& atom_ctx = g_vpr_ctx.atom();
11891187

11901188
AtomPinId atom_pin = atom_ctx.lookup.tnode_atom_pin(node);
11911189
AtomBlockId atom_block = atom_ctx.nlist.pin_block(atom_pin);
@@ -1415,9 +1413,9 @@ void draw_block_pin_util() {
14151413
if (draw_state->show_blk_pin_util == DRAW_NO_BLOCK_PIN_UTIL)
14161414
return;
14171415

1418-
auto& device_ctx = g_vpr_ctx.device();
1419-
auto& cluster_ctx = g_vpr_ctx.clustering();
1420-
auto& block_locs = get_graphics_blk_loc_registry_ref().block_locs();
1416+
const auto& device_ctx = g_vpr_ctx.device();
1417+
const auto& cluster_ctx = g_vpr_ctx.clustering();
1418+
const auto& block_locs = draw_state->get_graphics_blk_loc_registry_ref().block_locs();
14211419

14221420
std::map<t_physical_tile_type_ptr, size_t> total_input_pins;
14231421
std::map<t_physical_tile_type_ptr, size_t> total_output_pins;
@@ -1475,9 +1473,8 @@ void draw_block_pin_util() {
14751473
}
14761474

14771475
void draw_reset_blk_colors() {
1478-
auto& cluster_ctx = g_vpr_ctx.clustering();
1479-
auto blks = cluster_ctx.clb_nlist.blocks();
1480-
for (auto blk : blks) {
1476+
const auto& cluster_ctx = g_vpr_ctx.clustering();
1477+
for (auto blk : cluster_ctx.clb_nlist.blocks()) {
14811478
draw_reset_blk_color(blk);
14821479
}
14831480
}

vpr/src/draw/draw_global.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ static t_draw_state draw_state;
2626
*/
2727
static t_draw_coords draw_coords;
2828

29-
/**
30-
* @brief Stores a reference to a PlaceLocVars to be used in the graphics code.
31-
* @details This reference let us pass in a currently-being-optimized placement state,
32-
* rather than using the global placement state in placement context that is valid only once placement is done
33-
*/
34-
static std::optional<std::reference_wrapper<const BlkLocRegistry>> blk_loc_registry_ref;
35-
3629
/*********************** Accessor Subroutines Definition ********************/
3730

3831
/* This accessor function returns pointer to the global variable
@@ -47,12 +40,4 @@ t_draw_state* get_draw_state_vars() {
4740
return &draw_state;
4841
}
4942

50-
void set_graphics_blk_loc_registry_ref(const BlkLocRegistry& blk_loc_registry) {
51-
blk_loc_registry_ref = std::ref(blk_loc_registry);
52-
}
53-
54-
const BlkLocRegistry& get_graphics_blk_loc_registry_ref() {
55-
return blk_loc_registry_ref->get();
56-
}
57-
5843
#endif // NO_GRAPHICS

vpr/src/draw/draw_global.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,6 @@ t_draw_coords* get_draw_coords_vars();
2727

2828
t_draw_state* get_draw_state_vars();
2929

30-
/**
31-
* @brief Set the reference to placement location variable.
32-
*
33-
* During the placement stage, this reference should point to a local object
34-
* in the placement stage because the placement stage does not change the
35-
* global stage in place_ctx until the end of placement. After the placement is
36-
* done, the reference should point to the global state stored in place_ctx.
37-
*
38-
* @param blk_loc_registry The PlaceLocVars that the reference will point to.
39-
*/
40-
void set_graphics_blk_loc_registry_ref(const BlkLocRegistry& blk_loc_registry);
41-
42-
/**
43-
* @brief Returns the reference to placement block location variables.
44-
* @return A const reference to placement block location variables.
45-
*/
46-
const BlkLocRegistry& get_graphics_blk_loc_registry_ref();
47-
4830
#endif // NO_GRAPHICS
4931

5032
#endif

0 commit comments

Comments
 (0)