Skip to content

Commit 4bfba43

Browse files
authored
Merge pull request #1742 from ethanroj23/rr_graph_node_type
RRGraphView::node_type() Implementation
2 parents 35d2d59 + b98b952 commit 4bfba43

39 files changed

+306
-210
lines changed

utils/fasm/test/test_fasm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
251251
REQUIRE(flow_succeeded == true);
252252

253253
auto &device_ctx = g_vpr_ctx.mutable_device();
254+
const auto& rr_graph = device_ctx.rr_graph;
254255
for(size_t inode = 0; inode < device_ctx.rr_nodes.size(); ++inode) {
255256
for(t_edge_size iedge = 0; iedge < device_ctx.rr_nodes[inode].num_edges(); ++iedge) {
256257
auto sink_inode = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
@@ -260,7 +261,7 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
260261

261262
// Add additional features to edges that go to CLB.I[11:0] pins
262263
// to correlate them with features of CLB input mux later.
263-
auto sink_type = device_ctx.rr_nodes[sink_inode].type();
264+
auto sink_type = rr_graph.node_type(RRNodeId(sink_inode));
264265
if (sink_type == IPIN) {
265266
auto pin_feature = get_pin_feature(sink_inode);
266267
value = value + "\n" + pin_feature;

vpr/src/base/read_route.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static bool check_rr_graph_connectivity(RRNodeId prev_node, RRNodeId node) {
508508
const auto& switch_info = device_ctx.rr_switch_inf;
509509

510510
// If it's starting a new sub branch this is ok
511-
if (rr_graph.node_type(prev_node) == SINK) return true;
511+
if (device_ctx.rr_graph.node_type(prev_node) == SINK) return true;
512512

513513
for (RREdgeId edge : rr_graph.edge_range(prev_node)) {
514514
//If the sink node is reachable by previous node return true

vpr/src/base/stats.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static void load_channel_occupancies(vtr::Matrix<int>& chanx_occ, vtr::Matrix<in
226226
t_rr_type rr_type;
227227

228228
auto& device_ctx = g_vpr_ctx.device();
229+
const auto& rr_graph = device_ctx.rr_graph;
229230
auto& cluster_ctx = g_vpr_ctx.clustering();
230231
auto& route_ctx = g_vpr_ctx.routing();
231232

@@ -242,7 +243,7 @@ static void load_channel_occupancies(vtr::Matrix<int>& chanx_occ, vtr::Matrix<in
242243
tptr = route_ctx.trace[net_id].head;
243244
while (tptr != nullptr) {
244245
inode = tptr->index;
245-
rr_type = device_ctx.rr_nodes[inode].type();
246+
rr_type = rr_graph.node_type(RRNodeId(inode));
246247

247248
if (rr_type == SINK) {
248249
tptr = tptr->next; /* Skip next segment. */
@@ -274,6 +275,7 @@ static void load_channel_occupancies(vtr::Matrix<int>& chanx_occ, vtr::Matrix<in
274275
void get_num_bends_and_length(ClusterNetId inet, int* bends_ptr, int* len_ptr, int* segments_ptr) {
275276
auto& route_ctx = g_vpr_ctx.routing();
276277
auto& device_ctx = g_vpr_ctx.device();
278+
const auto& rr_graph = device_ctx.rr_graph;
277279

278280
t_trace *tptr, *prevptr;
279281
int inode;
@@ -290,20 +292,20 @@ void get_num_bends_and_length(ClusterNetId inet, int* bends_ptr, int* len_ptr, i
290292
"in get_num_bends_and_length: net #%lu has no traceback.\n", size_t(inet));
291293
}
292294
inode = prevptr->index;
293-
prev_type = device_ctx.rr_nodes[inode].type();
295+
prev_type = rr_graph.node_type(RRNodeId(inode));
294296

295297
tptr = prevptr->next;
296298

297299
while (tptr != nullptr) {
298300
inode = tptr->index;
299-
curr_type = device_ctx.rr_nodes[inode].type();
301+
curr_type = rr_graph.node_type(RRNodeId(inode));
300302

301303
if (curr_type == SINK) { /* Starting a new segment */
302304
tptr = tptr->next; /* Link to existing path - don't add to len. */
303305
if (tptr == nullptr)
304306
break;
305307

306-
curr_type = device_ctx.rr_nodes[tptr->index].type();
308+
curr_type = rr_graph.node_type(RRNodeId(tptr->index));
307309
}
308310

309311
else if (curr_type == CHANX || curr_type == CHANY) {

vpr/src/device/rr_graph_view.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,3 @@ RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage,
55
: node_storage_(node_storage)
66
, node_lookup_(node_lookup) {
77
}
8-
9-
t_rr_type RRGraphView::node_type(RRNodeId node) const {
10-
return node_storage_.node_type(node);
11-
}
12-
13-
const RRSpatialLookup& RRGraphView::node_lookup() const {
14-
return node_lookup_;
15-
}

vpr/src/device/rr_graph_view.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ class RRGraphView {
5252
* kind of accessors
5353
*/
5454
public:
55-
/* Get the type of a routing resource node */
56-
t_rr_type node_type(RRNodeId node) const;
55+
/* Get the type of a routing resource node. This function is inlined for runtime optimization. */
56+
inline t_rr_type node_type(RRNodeId node) const {
57+
return node_storage_.node_type(node);
58+
}
5759

5860
/* Return the fast look-up data structure for queries from client functions */
59-
const RRSpatialLookup& node_lookup() const;
61+
const RRSpatialLookup& node_lookup() const {
62+
return node_lookup_;
63+
}
6064

6165
/* -- Internal data storage -- */
6266
/* Note: only read-only object or data structures are allowed!!! */

vpr/src/draw/draw.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ static void draw_congestion(ezgl::renderer* g) {
11021102
}
11031103

11041104
auto& device_ctx = g_vpr_ctx.device();
1105+
const auto& rr_graph = device_ctx.rr_graph;
11051106
auto& route_ctx = g_vpr_ctx.routing();
11061107

11071108
//Record min/max congestion
@@ -1178,7 +1179,7 @@ static void draw_congestion(ezgl::renderer* g) {
11781179

11791180
ezgl::color color = to_ezgl_color(cmap->color(congestion_ratio));
11801181

1181-
switch (device_ctx.rr_nodes[inode].type()) {
1182+
switch (rr_graph.node_type(RRNodeId(inode))) {
11821183
case CHANX: //fallthrough
11831184
case CHANY:
11841185
draw_rr_chan(inode, color, g);
@@ -1337,6 +1338,7 @@ void draw_rr(ezgl::renderer* g) {
13371338
* them drawn. */
13381339
t_draw_state* draw_state = get_draw_state_vars();
13391340
auto& device_ctx = g_vpr_ctx.device();
1341+
const auto& rr_graph = device_ctx.rr_graph;
13401342

13411343
if (draw_state->draw_rr_toggle == DRAW_NO_RR) {
13421344
g->set_line_width(3);
@@ -1350,7 +1352,7 @@ void draw_rr(ezgl::renderer* g) {
13501352
for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
13511353
if (!draw_state->draw_rr_node[inode].node_highlighted) {
13521354
/* If not highlighted node, assign color based on type. */
1353-
switch (device_ctx.rr_nodes[inode].type()) {
1355+
switch (rr_graph.node_type(RRNodeId(inode))) {
13541356
case CHANX:
13551357
case CHANY:
13561358
draw_state->draw_rr_node[inode].color = DEFAULT_RR_NODE_COLOR;
@@ -1373,7 +1375,7 @@ void draw_rr(ezgl::renderer* g) {
13731375
}
13741376

13751377
/* Now call drawing routines to draw the node. */
1376-
switch (device_ctx.rr_nodes[inode].type()) {
1378+
switch (rr_graph.node_type(RRNodeId(inode))) {
13771379
case SINK:
13781380
draw_rr_src_sink(inode, draw_state->draw_rr_node[inode].color, g);
13791381
break;
@@ -1404,7 +1406,7 @@ void draw_rr(ezgl::renderer* g) {
14041406

14051407
default:
14061408
vpr_throw(VPR_ERROR_OTHER, __FILE__, __LINE__,
1407-
"in draw_rr: Unexpected rr_node type: %d.\n", device_ctx.rr_nodes[inode].type());
1409+
"in draw_rr: Unexpected rr_node type: %d.\n", rr_graph.node_type(RRNodeId(inode)));
14081410
}
14091411
}
14101412

@@ -1413,8 +1415,9 @@ void draw_rr(ezgl::renderer* g) {
14131415

14141416
static void draw_rr_chan(int inode, const ezgl::color color, ezgl::renderer* g) {
14151417
auto& device_ctx = g_vpr_ctx.device();
1418+
const auto& rr_graph = device_ctx.rr_graph;
14161419

1417-
t_rr_type type = device_ctx.rr_nodes[inode].type();
1420+
t_rr_type type = rr_graph.node_type(RRNodeId(inode));
14181421

14191422
VTR_ASSERT(type == CHANX || type == CHANY);
14201423

@@ -1557,12 +1560,13 @@ static void draw_rr_edges(int inode, ezgl::renderer* g) {
15571560
* connects to. inode is assumed to be a CHANX, CHANY, or IPIN. */
15581561
t_draw_state* draw_state = get_draw_state_vars();
15591562
auto& device_ctx = g_vpr_ctx.device();
1563+
const auto& rr_graph = device_ctx.rr_graph;
15601564

15611565
t_rr_type from_type, to_type;
15621566
int to_node, from_ptc_num, to_ptc_num;
15631567
short switch_type;
15641568

1565-
from_type = device_ctx.rr_nodes[inode].type();
1569+
from_type = rr_graph.node_type(RRNodeId(inode));
15661570

15671571
if ((draw_state->draw_rr_toggle == DRAW_NODES_RR)
15681572
|| (draw_state->draw_rr_toggle == DRAW_NODES_SBOX_RR && (from_type == OPIN || from_type == SOURCE || from_type == IPIN))
@@ -1574,7 +1578,7 @@ static void draw_rr_edges(int inode, ezgl::renderer* g) {
15741578

15751579
for (t_edge_size iedge = 0, l = device_ctx.rr_nodes[inode].num_edges(); iedge < l; iedge++) {
15761580
to_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
1577-
to_type = device_ctx.rr_nodes[to_node].type();
1581+
to_type = rr_graph.node_type(RRNodeId(to_node));
15781582
to_ptc_num = device_ctx.rr_nodes[to_node].ptc_num();
15791583
bool edge_configurable = device_ctx.rr_nodes[inode].edge_is_configurable(iedge);
15801584

@@ -2047,8 +2051,9 @@ ezgl::rectangle draw_get_rr_chan_bbox(int inode) {
20472051
double left = 0, right = 0, top = 0, bottom = 0;
20482052
t_draw_coords* draw_coords = get_draw_coords_vars();
20492053
auto& device_ctx = g_vpr_ctx.device();
2054+
const auto& rr_graph = device_ctx.rr_graph;
20502055

2051-
switch (device_ctx.rr_nodes[inode].type()) {
2056+
switch (rr_graph.node_type(RRNodeId(inode))) {
20522057
case CHANX:
20532058
left = draw_coords->tile_x[device_ctx.rr_nodes[inode].xlow()];
20542059
right = draw_coords->tile_x[device_ctx.rr_nodes[inode].xhigh()]
@@ -2332,6 +2337,7 @@ static void draw_routed_net(ClusterNetId net_id, ezgl::renderer* g) {
23322337
void draw_partial_route(const std::vector<int>& rr_nodes_to_draw, ezgl::renderer* g) {
23332338
t_draw_state* draw_state = get_draw_state_vars();
23342339
auto& device_ctx = g_vpr_ctx.device();
2340+
const auto& rr_graph = device_ctx.rr_graph;
23352341

23362342
static vtr::OffsetMatrix<int> chanx_track; /* [1..device_ctx.grid.width() - 2][0..device_ctx.grid.height() - 2] */
23372343
static vtr::OffsetMatrix<int> chany_track; /* [0..device_ctx.grid.width() - 2][1..device_ctx.grid.height() - 2] */
@@ -2358,10 +2364,10 @@ void draw_partial_route(const std::vector<int>& rr_nodes_to_draw, ezgl::renderer
23582364

23592365
for (size_t i = 1; i < rr_nodes_to_draw.size(); ++i) {
23602366
int inode = rr_nodes_to_draw[i];
2361-
auto rr_type = device_ctx.rr_nodes[inode].type();
2367+
auto rr_type = rr_graph.node_type(RRNodeId(inode));
23622368

23632369
int prev_node = rr_nodes_to_draw[i - 1];
2364-
auto prev_type = device_ctx.rr_nodes[prev_node].type();
2370+
auto prev_type = rr_graph.node_type(RRNodeId(prev_node));
23652371

23662372
auto iedge = find_edge(prev_node, inode);
23672373
auto switch_type = device_ctx.rr_nodes[prev_node].edge_switch(iedge);
@@ -2373,7 +2379,7 @@ void draw_partial_route(const std::vector<int>& rr_nodes_to_draw, ezgl::renderer
23732379
}
23742380
case IPIN: {
23752381
draw_rr_pin(inode, draw_state->draw_rr_node[inode].color, g);
2376-
if (device_ctx.rr_nodes[prev_node].type() == OPIN) {
2382+
if (rr_graph.node_type(RRNodeId(prev_node)) == OPIN) {
23772383
draw_pin_to_pin(prev_node, inode, g);
23782384
} else {
23792385
draw_pin_to_chan_edge(inode, prev_node, g);
@@ -2461,13 +2467,14 @@ static int get_track_num(int inode, const vtr::OffsetMatrix<int>& chanx_track, c
24612467
int i, j;
24622468
t_rr_type rr_type;
24632469
auto& device_ctx = g_vpr_ctx.device();
2470+
const auto& rr_graph = device_ctx.rr_graph;
24642471

24652472
if (get_draw_state_vars()->draw_route_type == DETAILED)
24662473
return (device_ctx.rr_nodes[inode].ptc_num());
24672474

24682475
/* GLOBAL route stuff below. */
24692476

2470-
rr_type = device_ctx.rr_nodes[inode].type();
2477+
rr_type = rr_graph.node_type(RRNodeId(inode));
24712478
i = device_ctx.rr_nodes[inode].xlow(); /* NB: Global rr graphs must have only unit */
24722479
j = device_ctx.rr_nodes[inode].ylow(); /* length channel segments. */
24732480

@@ -2585,9 +2592,10 @@ static int draw_check_rr_node_hit(float click_x, float click_y) {
25852592

25862593
t_draw_coords* draw_coords = get_draw_coords_vars();
25872594
auto& device_ctx = g_vpr_ctx.device();
2595+
const auto& rr_graph = device_ctx.rr_graph;
25882596

25892597
for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
2590-
switch (device_ctx.rr_nodes[inode].type()) {
2598+
switch (rr_graph.node_type(RRNodeId(inode))) {
25912599
case IPIN:
25922600
case OPIN: {
25932601
int i = device_ctx.rr_nodes[inode].xlow();
@@ -2957,6 +2965,7 @@ static void draw_pin_to_chan_edge(int pin_node, int chan_node, ezgl::renderer* g
29572965

29582966
t_draw_coords* draw_coords = get_draw_coords_vars();
29592967
auto& device_ctx = g_vpr_ctx.device();
2968+
const auto& rr_graph = device_ctx.rr_graph;
29602969

29612970
const t_rr_node& pin_rr = device_ctx.rr_nodes[pin_node];
29622971
const t_rr_node& chan_rr = device_ctx.rr_nodes[chan_node];
@@ -3012,17 +3021,18 @@ static void draw_pin_to_chan_edge(int pin_node, int chan_node, ezgl::renderer* g
30123021
* Any rr_node of a grid should have at least 1 side!!!
30133022
*/
30143023
e_side pin_side = NUM_SIDES;
3024+
const t_rr_type channel_type = rr_graph.node_type(RRNodeId(chan_node));
30153025
if (1 == pin_candidate_sides.size()) {
30163026
pin_side = pin_candidate_sides[0];
30173027
} else {
30183028
VTR_ASSERT(1 < pin_candidate_sides.size());
3019-
if (CHANX == chan_rr.type() && pin_rr.ylow() <= chan_rr.ylow()) {
3029+
if (CHANX == channel_type && pin_rr.ylow() <= chan_rr.ylow()) {
30203030
pin_side = TOP;
3021-
} else if (CHANX == chan_rr.type() && pin_rr.ylow() - 1 >= chan_rr.ylow()) {
3031+
} else if (CHANX == channel_type && pin_rr.ylow() - 1 >= chan_rr.ylow()) {
30223032
pin_side = BOTTOM;
3023-
} else if (CHANY == chan_rr.type() && pin_rr.xlow() <= chan_rr.xlow()) {
3033+
} else if (CHANY == channel_type && pin_rr.xlow() <= chan_rr.xlow()) {
30243034
pin_side = RIGHT;
3025-
} else if (CHANY == chan_rr.type() && pin_rr.xlow() - 1 >= chan_rr.xlow()) {
3035+
} else if (CHANY == channel_type && pin_rr.xlow() - 1 >= chan_rr.xlow()) {
30263036
pin_side = LEFT;
30273037
}
30283038
/* The inferred side must be in the list of sides of the pin rr_node!!! */
@@ -3069,7 +3079,7 @@ static void draw_pin_to_chan_edge(int pin_node, int chan_node, ezgl::renderer* g
30693079
ezgl::rectangle chan_bbox = draw_get_rr_chan_bbox(chan_node);
30703080

30713081
float x2 = 0, y2 = 0;
3072-
switch (chan_rr.type()) {
3082+
switch (channel_type) {
30733083
case CHANX: {
30743084
y1 += draw_pin_offset;
30753085
y2 = chan_bbox.bottom();
@@ -3116,8 +3126,9 @@ static void draw_pin_to_chan_edge(int pin_node, int chan_node, ezgl::renderer* g
31163126
static void draw_pin_to_pin(int opin_node, int ipin_node, ezgl::renderer* g) {
31173127
/* This routine draws an edge from the opin rr node to the ipin rr node */
31183128
auto& device_ctx = g_vpr_ctx.device();
3119-
VTR_ASSERT(device_ctx.rr_nodes[opin_node].type() == OPIN);
3120-
VTR_ASSERT(device_ctx.rr_nodes[ipin_node].type() == IPIN);
3129+
const auto& rr_graph = device_ctx.rr_graph;
3130+
VTR_ASSERT(rr_graph.node_type(RRNodeId(opin_node)) == OPIN);
3131+
VTR_ASSERT(rr_graph.node_type(RRNodeId(ipin_node)) == IPIN);
31213132

31223133
/* FIXME: May use a smarter strategy
31233134
* Currently, we use the last side found for both OPIN and IPIN
@@ -3876,6 +3887,7 @@ static void draw_rr_costs(ezgl::renderer* g, const std::vector<float>& rr_costs,
38763887
/* Draws routing costs */
38773888

38783889
auto& device_ctx = g_vpr_ctx.device();
3890+
const auto& rr_graph = device_ctx.rr_graph;
38793891

38803892
g->set_line_width(0);
38813893

@@ -3915,7 +3927,7 @@ static void draw_rr_costs(ezgl::renderer* g, const std::vector<float>& rr_costs,
39153927

39163928
ezgl::color color = to_ezgl_color(cmap->color(cost));
39173929

3918-
switch (device_ctx.rr_nodes[inode].type()) {
3930+
switch (rr_graph.node_type(RRNodeId(inode))) {
39193931
case CHANX: //fallthrough
39203932
case CHANY:
39213933
draw_rr_chan(inode, color, g);

vpr/src/draw/search_bar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ bool highlight_rr_nodes(int hit_node) {
180180
void auto_zoom_rr_node(int rr_node_id) {
181181
t_draw_coords* draw_coords = get_draw_coords_vars();
182182
auto& device_ctx = g_vpr_ctx.device();
183+
const auto& rr_graph = device_ctx.rr_graph;
183184
ezgl::rectangle rr_node;
184185

185186
// find the location of the node
186-
switch (device_ctx.rr_nodes[rr_node_id].type()) {
187+
switch (rr_graph.node_type(RRNodeId(rr_node_id))) {
187188
case IPIN:
188189
case OPIN: {
189190
int i = device_ctx.rr_nodes[rr_node_id].xlow();

vpr/src/place/timing_place_lookup.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,20 +1161,20 @@ bool directconnect_exists(int src_rr_node, int sink_rr_node) {
11611161
//This is checked by looking for a SOURCE -> OPIN -> IPIN -> SINK path
11621162
//which starts at src_rr_node and ends at sink_rr_node
11631163
auto& device_ctx = g_vpr_ctx.device();
1164+
const auto& rr_graph = device_ctx.rr_graph;
11641165
auto& rr_nodes = device_ctx.rr_nodes;
11651166

1166-
VTR_ASSERT(rr_nodes[src_rr_node].type() == SOURCE && rr_nodes[sink_rr_node].type() == SINK);
1167+
VTR_ASSERT(rr_graph.node_type(RRNodeId(src_rr_node)) == SOURCE && rr_graph.node_type(RRNodeId(sink_rr_node)) == SINK);
11671168

11681169
//TODO: This is a constant depth search, but still may be too slow
11691170
for (t_edge_size i_src_edge = 0; i_src_edge < rr_nodes[src_rr_node].num_edges(); ++i_src_edge) {
11701171
int opin_rr_node = rr_nodes[src_rr_node].edge_sink_node(i_src_edge);
11711172

1172-
if (rr_nodes[opin_rr_node].type() != OPIN) continue;
1173+
if (rr_graph.node_type(RRNodeId(opin_rr_node)) != OPIN) continue;
11731174

11741175
for (t_edge_size i_opin_edge = 0; i_opin_edge < rr_nodes[opin_rr_node].num_edges(); ++i_opin_edge) {
11751176
int ipin_rr_node = rr_nodes[opin_rr_node].edge_sink_node(i_opin_edge);
1176-
1177-
if (rr_nodes[ipin_rr_node].type() != IPIN) continue;
1177+
if (rr_graph.node_type(RRNodeId(ipin_rr_node)) != IPIN) continue;
11781178

11791179
for (t_edge_size i_ipin_edge = 0; i_ipin_edge < rr_nodes[ipin_rr_node].num_edges(); ++i_ipin_edge) {
11801180
if (sink_rr_node == rr_nodes[ipin_rr_node].edge_sink_node(i_ipin_edge)) {

0 commit comments

Comments
 (0)