Skip to content

Commit 7554512

Browse files
authored
Merge pull request #1843 from ethanroj23/rr_graph_node_cost_index
RRGraphView node_cost_index() Implementation
2 parents e82ecbb + e1058cb commit 7554512

28 files changed

+173
-173
lines changed

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct DeviceContext : public Context {
149149
*/
150150
t_rr_graph_storage rr_nodes; // autogenerated in build_rr_graph
151151

152-
std::vector<t_rr_indexed_data> rr_indexed_data; // [0 .. num_rr_indexed_data-1]
152+
vtr::vector<RRIndexedDataId, t_rr_indexed_data> rr_indexed_data; // [0 .. num_rr_indexed_data-1]
153153

154154
///@brief Fly-weighted Resistance/Capacitance data for RR Nodes
155155
std::vector<t_rr_rc_data> rr_rc_data;

vpr/src/device/rr_graph_fwd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ class RRGraph;
1515

1616
struct rr_node_id_tag;
1717
struct rr_edge_id_tag;
18+
struct rr_indexed_data_id_tag;
1819
struct rr_switch_id_tag;
1920
struct rr_segment_id_tag;
2021

2122
typedef vtr::StrongId<rr_node_id_tag, unsigned int> RRNodeId;
2223
typedef vtr::StrongId<rr_edge_id_tag, unsigned int> RREdgeId;
24+
typedef vtr::StrongId<rr_indexed_data_id_tag, unsigned int> RRIndexedDataId;
2325
typedef vtr::StrongId<rr_switch_id_tag, short> RRSwitchId;
2426
typedef vtr::StrongId<rr_segment_id_tag, short> RRSegmentId;
2527

vpr/src/device/rr_graph_obj.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ short RRGraph::node_class_num(const RRNodeId& node) const {
151151
return node_ptc_num(node);
152152
}
153153

154-
short RRGraph::node_cost_index(const RRNodeId& node) const {
154+
RRIndexedDataId RRGraph::node_cost_index(const RRNodeId& node) const {
155155
VTR_ASSERT_SAFE(valid_node_id(node));
156-
return node_cost_indices_[node];
156+
return RRIndexedDataId(node_cost_indices_[node]);
157157
}
158158

159159
Direction RRGraph::node_direction(const RRNodeId& node) const {
@@ -990,9 +990,9 @@ void RRGraph::set_node_class_num(const RRNodeId& node, const short& class_id) {
990990
set_node_ptc_num(node, class_id);
991991
}
992992

993-
void RRGraph::set_node_cost_index(const RRNodeId& node, const short& cost_index) {
993+
void RRGraph::set_node_cost_index(const RRNodeId& node, const RRIndexedDataId& cost_index) {
994994
VTR_ASSERT(valid_node_id(node));
995-
node_cost_indices_[node] = cost_index;
995+
node_cost_indices_[node] = (size_t)cost_index;
996996
}
997997

998998
void RRGraph::set_node_direction(const RRNodeId& node, const Direction& direction) {

vpr/src/device/rr_graph_obj.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class RRGraph {
410410
* when used in evaluate different routing paths
411411
* See cross-reference section in this header file for more details
412412
*/
413-
short node_cost_index(const RRNodeId& node) const;
413+
RRIndexedDataId node_cost_index(const RRNodeId& node) const;
414414

415415
/* Get the directionality of a node
416416
* see node coordinate for details
@@ -669,7 +669,7 @@ class RRGraph {
669669

670670
/* Set the routing cost index for node, see node_cost_index() for details */
671671
/* TODO: the cost index should be changed to a StrongId!!! */
672-
void set_node_cost_index(const RRNodeId& node, const short& cost_index);
672+
void set_node_cost_index(const RRNodeId& node, const RRIndexedDataId& cost_index);
673673

674674
/* Set the directionality for a node, only applicable to CHANX and CHANY */
675675
void set_node_direction(const RRNodeId& node, const Direction& direction);

vpr/src/device/rr_graph_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "rr_node.h"
33
#include "physical_types.h"
44

5-
RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage, const RRSpatialLookup& node_lookup, const std::vector<t_rr_indexed_data>& rr_indexed_data, const std::vector<t_segment_inf>& rr_segments)
5+
RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage, const RRSpatialLookup& node_lookup, const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, const std::vector<t_segment_inf>& rr_segments)
66
: node_storage_(node_storage)
77
, node_lookup_(node_lookup)
88
, rr_indexed_data_(rr_indexed_data)

vpr/src/device/rr_graph_view.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RRGraphView {
3737
/* See detailed comments about the data structures in the internal data storage section of this file */
3838
RRGraphView(const t_rr_graph_storage& node_storage,
3939
const RRSpatialLookup& node_lookup,
40-
const std::vector<t_rr_indexed_data>& rr_indexed_data,
40+
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
4141
const std::vector<t_segment_inf>& rr_segments);
4242

4343
/* Disable copy constructors and copy assignment operator
@@ -207,7 +207,7 @@ class RRGraphView {
207207
arrow = "";
208208
}
209209
if (node_type(node) == CHANX || node_type(node) == CHANY) { //for channels, we would like to describe the component with segment specific information
210-
int cost_index = node_cost_index(node);
210+
RRIndexedDataId cost_index = node_cost_index(node);
211211
int seg_index = rr_indexed_data_[cost_index].seg_index;
212212
coordinate_string += rr_segments_[seg_index].name; //Write the segment name
213213
coordinate_string += " length:" + std::to_string(node_length(node)); //add the length of the segment
@@ -245,7 +245,7 @@ class RRGraphView {
245245
}
246246

247247
/** @brief Get the cost index of a routing resource node. This function is inlined for runtime optimization. */
248-
inline short node_cost_index(RRNodeId node) const {
248+
RRIndexedDataId node_cost_index(RRNodeId node) const {
249249
return node_storage_.node_cost_index(node);
250250
}
251251

@@ -263,7 +263,7 @@ class RRGraphView {
263263
const RRSpatialLookup& node_lookup_;
264264

265265
/* rr_indexed_data_ and rr_segments_ are needed to lookup the segment information in node_coordinate_to_string() */
266-
const std::vector<t_rr_indexed_data>& rr_indexed_data_;
266+
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;
267267

268268
/* Segment info for rr nodes */
269269
const std::vector<t_segment_inf>& rr_segments_;

vpr/src/power/power.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,17 @@ static void power_usage_routing(t_power_usage* power_usage,
858858
for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
859859
t_power_usage sub_power_usage;
860860
auto node = device_ctx.rr_nodes[rr_node_idx];
861+
RRNodeId rr_node = RRNodeId(rr_node_idx);
861862
t_rr_node_power* node_power = &rr_node_power[rr_node_idx];
862863
float C_wire;
863864
float buffer_size;
864865
int connectionbox_fanout;
865866
int switchbox_fanout;
866867
//float C_per_seg_split;
867868
int wire_length;
868-
const t_edge_size node_fan_in = rr_graph.node_fan_in(RRNodeId(rr_node_idx));
869+
const t_edge_size node_fan_in = rr_graph.node_fan_in(rr_node);
869870

870-
switch (rr_graph.node_type(RRNodeId(rr_node_idx))) {
871+
switch (rr_graph.node_type(rr_node)) {
871872
case SOURCE:
872873
case SINK:
873874
case OPIN:
@@ -905,12 +906,12 @@ static void power_usage_routing(t_power_usage* power_usage,
905906
VTR_ASSERT(node_power->in_prob);
906907

907908
wire_length = 0;
908-
if (rr_graph.node_type(RRNodeId(rr_node_idx)) == CHANX) {
909-
wire_length = rr_graph.node_xhigh(node.id()) - rr_graph.node_xlow(node.id()) + 1;
910-
} else if (rr_graph.node_type(RRNodeId(rr_node_idx)) == CHANY) {
911-
wire_length = rr_graph.node_yhigh(node.id()) - rr_graph.node_ylow(node.id()) + 1;
909+
if (rr_graph.node_type(rr_node) == CHANX) {
910+
wire_length = rr_graph.node_xhigh(rr_node) - rr_graph.node_xlow(rr_node) + 1;
911+
} else if (rr_graph.node_type(rr_node) == CHANY) {
912+
wire_length = rr_graph.node_yhigh(rr_node) - rr_graph.node_ylow(rr_node) + 1;
912913
}
913-
int seg_index = device_ctx.rr_indexed_data[node.cost_index()].seg_index;
914+
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(rr_node)].seg_index;
914915
C_wire = wire_length * device_ctx.rr_segments[seg_index].Cmetal;
915916
//(double)power_ctx.commonly_used->tile_length);
916917
VTR_ASSERT(node_power->selected_input < node_fan_in);

vpr/src/route/check_rr_graph.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
295295
int xlow, ylow, xhigh, yhigh, ptc_num, capacity;
296296
t_rr_type rr_type;
297297
t_physical_tile_type_ptr type;
298-
int nodes_per_chan, tracks_per_node, num_edges, cost_index;
298+
int nodes_per_chan, tracks_per_node, num_edges;
299+
RRIndexedDataId cost_index;
299300
float C, R;
300301
const auto& rr_graph = device_ctx.rr_graph;
301302
RRNodeId rr_node = RRNodeId(inode);
@@ -307,7 +308,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
307308
yhigh = rr_graph.node_yhigh(rr_node);
308309
ptc_num = device_ctx.rr_nodes[inode].ptc_num();
309310
capacity = rr_graph.node_capacity(rr_node);
310-
cost_index = device_ctx.rr_nodes[inode].cost_index();
311+
cost_index = rr_graph.node_cost_index(rr_node);
311312
type = nullptr;
312313

313314
const auto& grid = device_ctx.grid;
@@ -326,7 +327,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
326327
"in check_rr_node: inode %d (type %d) had a ptc_num of %d.\n", inode, rr_type, ptc_num);
327328
}
328329

329-
if (cost_index < 0 || cost_index >= (int)device_ctx.rr_indexed_data.size()) {
330+
if (!cost_index || (size_t)cost_index >= (size_t)device_ctx.rr_indexed_data.size()) {
330331
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
331332
"in check_rr_node: node %d cost index (%d) is out of range.\n", inode, cost_index);
332333
}

vpr/src/route/clock_connection_builders.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ RRNodeId RoutingToClockConnection::create_virtual_clock_network_sink_node(int x,
109109
rr_graph.set_node_ptc_num(node_index, ptc);
110110
rr_graph_builder.set_node_coordinates(node_index, x, y, x, y);
111111
rr_graph_builder.set_node_capacity(node_index, 1);
112-
rr_graph.set_node_cost_index(node_index, SINK_COST_INDEX);
112+
rr_graph.set_node_cost_index(node_index, RRIndexedDataId(SINK_COST_INDEX));
113113
rr_graph.set_node_type(node_index, SINK);
114+
114115
float R = 0.;
115116
float C = 0.;
116117
rr_graph.set_node_rc_index(node_index, find_create_rr_rc_data(R, C));

vpr/src/route/clock_network_builders.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ int ClockRib::create_chanx_wire(int x_start,
342342
VTR_ASSERT_MSG(false, "Unidentified direction type for clock rib");
343343
break;
344344
}
345-
node.set_cost_index(CHANX_COST_INDEX_START + seg_index); // Actual value set later
345+
node.set_cost_index(RRIndexedDataId(CHANX_COST_INDEX_START + seg_index)); // Actual value set later
346346

347347
/* Add the node to spatial lookup */
348348
auto& rr_graph = (*rr_nodes);
@@ -648,7 +648,7 @@ int ClockSpine::create_chany_wire(int y_start,
648648
VTR_ASSERT_MSG(false, "Unidentified direction type for clock rib");
649649
break;
650650
}
651-
node.set_cost_index(CHANX_COST_INDEX_START + num_segments + seg_index);
651+
node.set_cost_index(RRIndexedDataId(CHANX_COST_INDEX_START + num_segments + seg_index));
652652

653653
/* Add the node to spatial lookup */
654654
auto& rr_graph = (*rr_nodes);

vpr/src/route/route_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ float get_rr_cong_cost(int inode, float pres_fac);
3434
/* Returns the base cost of using this rr_node */
3535
inline float get_single_rr_cong_base_cost(int inode) {
3636
auto& device_ctx = g_vpr_ctx.device();
37-
auto cost_index = device_ctx.rr_nodes[inode].cost_index();
37+
auto cost_index = device_ctx.rr_graph.node_cost_index(RRNodeId(inode));
3838

3939
return device_ctx.rr_indexed_data[cost_index].base_cost;
4040
}
@@ -78,7 +78,7 @@ inline float get_single_rr_cong_cost(int inode, float pres_fac) {
7878
pres_cost = 1.;
7979
}
8080

81-
auto cost_index = device_ctx.rr_nodes[inode].cost_index();
81+
auto cost_index = rr_graph.node_cost_index(RRNodeId(inode));
8282

8383
float cost = device_ctx.rr_indexed_data[cost_index].base_cost * route_ctx.rr_node_route_inf[inode].acc_cost * pres_cost;
8484

vpr/src/route/route_timing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,10 +1550,10 @@ void update_rr_base_costs(int fanout) {
15501550
factor = sqrt(fanout);
15511551

15521552
for (index = CHANX_COST_INDEX_START; index < device_ctx.rr_indexed_data.size(); index++) {
1553-
if (device_ctx.rr_indexed_data[index].T_quadratic > 0.) { /* pass transistor */
1554-
device_ctx.rr_indexed_data[index].base_cost = device_ctx.rr_indexed_data[index].saved_base_cost * factor;
1553+
if (device_ctx.rr_indexed_data[RRIndexedDataId(index)].T_quadratic > 0.) { /* pass transistor */
1554+
device_ctx.rr_indexed_data[RRIndexedDataId(index)].base_cost = device_ctx.rr_indexed_data[RRIndexedDataId(index)].saved_base_cost * factor;
15551555
} else {
1556-
device_ctx.rr_indexed_data[index].base_cost = device_ctx.rr_indexed_data[index].saved_base_cost;
1556+
device_ctx.rr_indexed_data[RRIndexedDataId(index)].base_cost = device_ctx.rr_indexed_data[RRIndexedDataId(index)].saved_base_cost;
15571557
}
15581558
}
15591559
}

vpr/src/route/router_lookahead.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
6161
int num_segs_ortho_dir = 0;
6262
int num_segs_same_dir = get_expected_segs_to_target(node, target_node, &num_segs_ortho_dir);
6363

64-
int cost_index = device_ctx.rr_nodes.node_cost_index(node);
64+
auto cost_index = rr_graph.node_cost_index(node);
6565
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
6666

6767
const auto& same_data = device_ctx.rr_indexed_data[cost_index];
68-
const auto& ortho_data = device_ctx.rr_indexed_data[ortho_cost_index];
69-
const auto& ipin_data = device_ctx.rr_indexed_data[IPIN_COST_INDEX];
70-
const auto& sink_data = device_ctx.rr_indexed_data[SINK_COST_INDEX];
68+
const auto& ortho_data = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)];
69+
const auto& ipin_data = device_ctx.rr_indexed_data[RRIndexedDataId(IPIN_COST_INDEX)];
70+
const auto& sink_data = device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)];
7171

7272
float cong_cost = num_segs_same_dir * same_data.base_cost
7373
+ num_segs_ortho_dir * ortho_data.base_cost
@@ -83,7 +83,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
8383

8484
return std::make_pair(params.criticality * Tdel, (1 - params.criticality) * cong_cost);
8585
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
86-
return std::make_pair(0., device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost);
86+
return std::make_pair(0., device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost);
8787

8888
} else { /* Change this if you want to investigate route-throughs */
8989
return std::make_pair(0., 0.);
@@ -113,17 +113,18 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
113113
const auto& rr_graph = device_ctx.rr_graph;
114114

115115
t_rr_type rr_type;
116-
int target_x, target_y, num_segs_same_dir, cost_index, ortho_cost_index;
116+
int target_x, target_y, num_segs_same_dir, ortho_cost_index;
117+
RRIndexedDataId cost_index;
117118
int no_need_to_pass_by_clb;
118119
float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;
119120

120121
target_x = rr_graph.node_xlow(target_node);
121122
target_y = rr_graph.node_ylow(target_node);
122123

123-
cost_index = device_ctx.rr_nodes.node_cost_index(inode);
124+
cost_index = rr_graph.node_cost_index(inode);
124125
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
125126
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
126-
ortho_inv_length = device_ctx.rr_indexed_data[ortho_cost_index].inv_length;
127+
ortho_inv_length = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)].inv_length;
127128
rr_type = rr_graph.node_type(inode);
128129

129130
if (rr_type == CHANX) {

vpr/src/route/router_lookahead_cost_map.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ void CostMap::set_counts(size_t seg_count) {
5959
*/
6060
int CostMap::node_to_segment(int from_node_ind) const {
6161
const auto& device_ctx = g_vpr_ctx.device();
62-
63-
auto& from_node = device_ctx.rr_nodes[from_node_ind];
64-
65-
int from_cost_index = from_node.cost_index();
62+
auto from_cost_index = device_ctx.rr_graph.node_cost_index(RRNodeId(from_node_ind));
6663
return device_ctx.rr_indexed_data[from_cost_index].seg_index;
6764
}
6865

vpr/src/route/router_lookahead_extended_map.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ bool ExtendedMapLookahead::add_paths(RRNodeId start_node,
293293
auto parent = start_node;
294294
for (auto it = path.rbegin(); it != path.rend(); it++) {
295295
RRNodeId this_node(*it);
296-
auto& here = device_ctx.rr_nodes[*it];
297-
int seg_index = device_ctx.rr_indexed_data[here.cost_index()].seg_index;
296+
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(this_node)].seg_index;
298297

299298
int from_x = rr_graph.node_xlow(this_node);
300299
int from_y = rr_graph.node_ylow(this_node);
@@ -587,7 +586,7 @@ float ExtendedMapLookahead::get_expected_cost(
587586
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
588587
// This is to return only the cost between the IPIN and SINK. No need to
589588
// query the cost map, as the routing of this connection is almost done.
590-
return device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost;
589+
return device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost;
591590
} else { /* Change this if you want to investigate route-throughs */
592591
return 0.;
593592
}

0 commit comments

Comments
 (0)