Skip to content

Commit 2517149

Browse files
authored
Merge pull request #3042 from verilog-to-routing/temp_fix_rr_node_lookup_xy
Clean up confusing rr-node lookup convention for x/y location of CHANX nodes
2 parents aabed10 + 9017ac1 commit 2517149

9 files changed

+94
-131
lines changed

libs/librrgraph/src/base/rr_graph_builder.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,29 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) {
3131
short node_layer = node_storage_.node_layer(node);
3232
short node_twist = node_storage_.node_ptc_twist(node);
3333
int node_offset = 0;
34+
3435
for (int ix = node_storage_.node_xlow(node); ix <= node_storage_.node_xhigh(node); ix++) {
3536
for (int iy = node_storage_.node_ylow(node); iy <= node_storage_.node_yhigh(node); iy++) {
3637
node_ptc_num += node_twist * node_offset;
3738
node_offset++;
39+
3840
switch (node_type) {
3941
case e_rr_type::SOURCE:
4042
case e_rr_type::SINK:
4143
case e_rr_type::CHANY:
42-
node_lookup_.add_node(node, node_layer, ix, iy, node_type, node_ptc_num, TOTAL_2D_SIDES[0]);
43-
break;
4444
case e_rr_type::CHANX:
45-
/* Currently need to swap x and y for CHANX because of chan, seg convention
46-
* TODO: Once the builders is reworked for use consistent (x, y) convention,
47-
* the following swapping can be removed
48-
*/
49-
node_lookup_.add_node(node, node_layer, iy, ix, node_type, node_ptc_num, TOTAL_2D_SIDES[0]);
45+
node_lookup_.add_node(node, node_layer, ix, iy, node_type, node_ptc_num, TOTAL_2D_SIDES[0]);
5046
break;
47+
5148
case e_rr_type::OPIN:
5249
case e_rr_type::IPIN:
53-
for (const e_side& side : TOTAL_2D_SIDES) {
50+
for (const e_side side : TOTAL_2D_SIDES) {
5451
if (node_storage_.is_node_on_specific_side(node, side)) {
5552
node_lookup_.add_node(node,node_layer, ix, iy, node_type, node_ptc_num, side);
5653
}
5754
}
5855
break;
56+
5957
default:
6058
VTR_LOG_ERROR("Invalid node type for node '%lu' in the routing resource graph file", size_t(node));
6159
break;

libs/librrgraph/src/base/rr_graph_view.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class RRGraphView {
351351

352352
start_x = " (" + std::to_string(node_xhigh(node)) + ","; //start coordinates have large value
353353
start_y = std::to_string(node_yhigh(node)) + ",";
354-
start_layer_str = std::to_string(node_layer_num);
354+
start_layer_str = std::to_string(node_layer_num) + ")";
355355
end_x = " (" + std::to_string(node_xlow(node)) + ","; //end coordinates have smaller value
356356
end_y = std::to_string(node_ylow(node)) + ",";
357357
end_layer_str = std::to_string(node_layer_num) + ")";
@@ -360,7 +360,7 @@ class RRGraphView {
360360
else { // signal travels in increasing direction, stays at same point, or can travel both directions
361361
start_x = " (" + std::to_string(node_xlow(node)) + ","; //start coordinates have smaller value
362362
start_y = std::to_string(node_ylow(node)) + ",";
363-
start_layer_str = std::to_string(node_layer_num);
363+
start_layer_str = std::to_string(node_layer_num) + ")";
364364
end_x = " (" + std::to_string(node_xhigh(node)) + ","; //end coordinates have larger value
365365
end_y = std::to_string(node_yhigh(node)) + ",";
366366
end_layer_str = std::to_string(node_layer_num) + ")"; //layer number

libs/librrgraph/src/base/rr_spatial_lookup.cpp

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "vtr_assert.h"
22
#include "rr_spatial_lookup.h"
33

4-
RRSpatialLookup::RRSpatialLookup() {
5-
}
6-
74
RRNodeId RRSpatialLookup::find_node(int layer,
85
int x,
96
int y,
@@ -33,18 +30,6 @@ RRNodeId RRSpatialLookup::find_node(int layer,
3330
return RRNodeId::INVALID();
3431
}
3532

36-
/* Currently need to swap x and y for CHANX because of chan, seg convention
37-
* This is due to that the fast look-up builders uses (y, x) coordinate when
38-
* registering a CHANX node in the look-up
39-
* TODO: Once the builders is reworked for use consistent (x, y) convention,
40-
* the following swapping can be removed
41-
*/
42-
size_t node_x = x;
43-
size_t node_y = y;
44-
if (type == e_rr_type::CHANX) {
45-
std::swap(node_x, node_y);
46-
}
47-
4833
VTR_ASSERT_SAFE(4 == rr_node_indices_[type].ndims());
4934

5035
/* Sanity check to ensure the layer, x, y, side and ptc are in range
@@ -59,23 +44,23 @@ RRNodeId RRSpatialLookup::find_node(int layer,
5944
return RRNodeId::INVALID();
6045
}
6146

62-
if (node_x >= rr_node_indices_[type].dim_size(1)) {
47+
if (size_t(x) >= rr_node_indices_[type].dim_size(1)) {
6348
return RRNodeId::INVALID();
6449
}
6550

66-
if(node_y >= rr_node_indices_[type].dim_size(2)){
51+
if (size_t(y) >= rr_node_indices_[type].dim_size(2)){
6752
return RRNodeId::INVALID();
6853
}
6954

7055
if (node_side >= rr_node_indices_[type].dim_size(3)) {
7156
return RRNodeId::INVALID();
7257
}
7358

74-
if (size_t(ptc) >= rr_node_indices_[type][layer][node_x][node_y][node_side].size()) {
59+
if (size_t(ptc) >= rr_node_indices_[type][layer][x][y][node_side].size()) {
7560
return RRNodeId::INVALID();
7661
}
7762

78-
return rr_node_indices_[type][layer][node_x][node_y][node_side][ptc];
63+
return rr_node_indices_[type][layer][x][y][node_side][ptc];
7964
}
8065

8166
std::vector<RRNodeId> RRSpatialLookup::find_nodes_in_range(int layer,
@@ -114,18 +99,6 @@ std::vector<RRNodeId> RRSpatialLookup::find_nodes(int layer,
11499
return nodes;
115100
}
116101

117-
/* Currently need to swap x and y for CHANX because of chan, seg convention
118-
* This is due to that the fast look-up builders uses (y, x) coordinate when
119-
* registering a CHANX node in the look-up
120-
* TODO: Once the builders is reworked for use consistent (x, y) convention,
121-
* the following swapping can be removed
122-
*/
123-
size_t node_x = x;
124-
size_t node_y = y;
125-
if (type == e_rr_type::CHANX) {
126-
std::swap(node_x, node_y);
127-
}
128-
129102
VTR_ASSERT_SAFE(4 == rr_node_indices_[type].ndims());
130103

131104
/* Sanity check to ensure the x, y, side are in range
@@ -140,11 +113,11 @@ std::vector<RRNodeId> RRSpatialLookup::find_nodes(int layer,
140113
return nodes;
141114
}
142115

143-
if (node_x >= rr_node_indices_[type].dim_size(1)) {
116+
if (size_t(x) >= rr_node_indices_[type].dim_size(1)) {
144117
return nodes;
145118
}
146119

147-
if(node_y >= rr_node_indices_[type].dim_size(2)){
120+
if (size_t(y) >= rr_node_indices_[type].dim_size(2)){
148121
return nodes;
149122
}
150123

@@ -154,14 +127,14 @@ std::vector<RRNodeId> RRSpatialLookup::find_nodes(int layer,
154127

155128
/* Reserve space to avoid memory fragmentation */
156129
size_t num_nodes = 0;
157-
for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) {
130+
for (RRNodeId node : rr_node_indices_[type][layer][x][y][side]) {
158131
if (node.is_valid()) {
159132
num_nodes++;
160133
}
161134
}
162135

163136
nodes.reserve(num_nodes);
164-
for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) {
137+
for (RRNodeId node : rr_node_indices_[type][layer][x][y][side]) {
165138
if (node.is_valid()) {
166139
nodes.emplace_back(node);
167140
}
@@ -338,7 +311,7 @@ void RRSpatialLookup::resize_nodes(int layer,
338311
|| (x >= int(rr_node_indices_[type].dim_size(1)))
339312
|| (y >= int(rr_node_indices_[type].dim_size(2)))
340313
|| (size_t(side) >= rr_node_indices_[type].dim_size(3))) {
341-
rr_node_indices_[type].resize({std::max(rr_node_indices_[type].dim_size(0),size_t(layer)+1),
314+
rr_node_indices_[type].resize({std::max(rr_node_indices_[type].dim_size(0), size_t(layer)+1),
342315
std::max(rr_node_indices_[type].dim_size(1), size_t(x) + 1),
343316
std::max(rr_node_indices_[type].dim_size(2), size_t(y) + 1),
344317
std::max(rr_node_indices_[type].dim_size(3), size_t(side) + 1)});
@@ -352,7 +325,7 @@ void RRSpatialLookup::reorder(const vtr::vector<RRNodeId, RRNodeId>& dest_order)
352325
for (size_t x = 0; x < grid.dim_size(1); x++) {
353326
for (size_t y = 0; y < grid.dim_size(2); y++) {
354327
for (size_t s = 0; s < grid.dim_size(3); s++) {
355-
for (auto &node: grid[l][x][y][s]) {
328+
for (RRNodeId &node: grid[l][x][y][s]) {
356329
if (node.is_valid()) {
357330
node = dest_order[node];
358331
}

libs/librrgraph/src/base/rr_spatial_lookup.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef RR_SPATIAL_LOOKUP_H
2-
#define RR_SPATIAL_LOOKUP_H
1+
#pragma once
32

43
/**
54
* @file
@@ -25,7 +24,7 @@ class RRSpatialLookup {
2524
/* -- Constructors -- */
2625
public:
2726
/* Explicitly define the only way to create an object */
28-
explicit RRSpatialLookup();
27+
explicit RRSpatialLookup() = default;
2928

3029
/* Disable copy constructors and copy assignment operator
3130
* This is to avoid accidental copy because it could be an expensive operation considering that the
@@ -293,5 +292,3 @@ class RRSpatialLookup {
293292
/* Fast look-up: TODO: Should rework the data type. Currently it is based on a 3-dimensional array mater where some dimensions must always be accessed with a specific index. Such limitation should be overcome */
294293
t_rr_node_indices rr_node_indices_;
295294
};
296-
297-
#endif

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,16 +1848,11 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
18481848

18491849
/* Alloc the lookup table */
18501850
for (e_rr_type rr_type : RR_TYPES) {
1851-
if (rr_type == e_rr_type::CHANX) {
1852-
rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.height(), grid_.width(), rr_type, NUM_2D_SIDES);
1853-
} else {
1854-
rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.width(), grid_.height(), rr_type, NUM_2D_SIDES);
1855-
}
1851+
rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.width(), grid_.height(), rr_type, NUM_2D_SIDES);
18561852
}
18571853

18581854
/* Add the correct node into the vector */
1859-
for (size_t inode = 0; inode < rr_nodes_->size(); inode++) {
1860-
auto node = (*rr_nodes_)[inode];
1855+
for (const t_rr_node& node : *rr_nodes_) {
18611856
rr_graph_builder.add_node_to_all_locs(node.id());
18621857
}
18631858
}

vpr/src/route/clock_network_builders.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ int ClockRib::create_chanx_wire(int layer,
372372
/* TODO: Will replace these codes with an API add_node_to_all_locs() of RRGraphBuilder */
373373
for (int ix = rr_graph.node_xlow(chanx_node); ix <= rr_graph.node_xhigh(chanx_node); ++ix) {
374374
for (int iy = rr_graph.node_ylow(chanx_node); iy <= rr_graph.node_yhigh(chanx_node); ++iy) {
375-
//TODO: CHANX uses odd swapped x/y indices here. Will rework once rr_node_indices is shadowed
376-
rr_graph_builder.node_lookup().add_node(chanx_node, layer, iy, ix, rr_graph.node_type(chanx_node), rr_graph.node_track_num(chanx_node));
375+
rr_graph_builder.node_lookup().add_node(chanx_node, layer, ix, iy, rr_graph.node_type(chanx_node), rr_graph.node_track_num(chanx_node));
377376
}
378377
}
379378

vpr/src/route/rr_graph.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,12 +1250,11 @@ static void build_rr_graph(e_graph_type graph_type,
12501250

12511251
// Add routing resources to rr_graph lookup table
12521252
alloc_and_load_rr_node_indices(device_ctx.rr_graph_builder,
1253-
&nodes_per_chan,
1253+
nodes_per_chan,
12541254
grid,
12551255
&num_rr_nodes,
12561256
chan_details_x,
1257-
chan_details_y,
1258-
is_flat);
1257+
chan_details_y);
12591258

12601259
size_t expected_node_count = num_rr_nodes;
12611260
if (clock_modeling == DEDICATED_NETWORK) {
@@ -1337,11 +1336,10 @@ static void build_rr_graph(e_graph_type graph_type,
13371336
*/
13381337
if (grid.get_num_layers() > 1 && sb_type == CUSTOM) {
13391338
//keep how many nodes each switchblock requires for each x,y location
1340-
auto extra_nodes_per_switchblock = get_number_track_to_track_inter_die_conn(sb_conn_map, custom_3d_sb_fanin_fanout, device_ctx.rr_graph_builder);
1339+
vtr::NdMatrix<int, 2> extra_nodes_per_switchblock = get_number_track_to_track_inter_die_conn(sb_conn_map, custom_3d_sb_fanin_fanout, device_ctx.rr_graph_builder);
13411340
//allocate new nodes in each switchblocks
1342-
alloc_and_load_inter_die_rr_node_indices(device_ctx.rr_graph_builder, &nodes_per_chan, grid, extra_nodes_per_switchblock, &num_rr_nodes);
1341+
alloc_and_load_inter_die_rr_node_indices(device_ctx.rr_graph_builder, nodes_per_chan, grid, extra_nodes_per_switchblock, &num_rr_nodes);
13431342
device_ctx.rr_graph_builder.resize_nodes(num_rr_nodes);
1344-
extra_nodes_per_switchblock.clear();
13451343
}
13461344

13471345
/* START IPIN MAP */

0 commit comments

Comments
 (0)