Skip to content

Commit 29ef568

Browse files
committed
Initial implementation of node_cost_index() in RRGraphView
Signed-off-by: Ethan Rogers <[email protected]>
1 parent 93f6147 commit 29ef568

15 files changed

+41
-46
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
307307
yhigh = rr_graph.node_yhigh(rr_node);
308308
ptc_num = device_ctx.rr_nodes[inode].ptc_num();
309309
capacity = rr_graph.node_capacity(rr_node);
310-
cost_index = device_ctx.rr_nodes[inode].cost_index();
310+
cost_index = rr_graph.node_cost_index(rr_node);
311311
type = nullptr;
312312

313313
const auto& grid = device_ctx.grid;

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/router_lookahead.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ 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+
int 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];
@@ -120,7 +120,7 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
120120
target_x = rr_graph.node_xlow(target_node);
121121
target_y = rr_graph.node_ylow(target_node);
122122

123-
cost_index = device_ctx.rr_nodes.node_cost_index(inode);
123+
cost_index = rr_graph.node_cost_index(inode);
124124
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
125125
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
126126
ortho_inv_length = device_ctx.rr_indexed_data[ortho_cost_index].inv_length;

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+
int 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool ExtendedMapLookahead::add_paths(RRNodeId start_node,
294294
for (auto it = path.rbegin(); it != path.rend(); it++) {
295295
RRNodeId this_node(*it);
296296
auto& here = device_ctx.rr_nodes[*it];
297-
int seg_index = device_ctx.rr_indexed_data[here.cost_index()].seg_index;
297+
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(this_node)].seg_index;
298298

299299
int from_x = rr_graph.node_xlow(this_node);
300300
int from_y = rr_graph.node_ylow(this_node);

vpr/src/route/router_lookahead_map.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ class PQ_Entry {
146146
this->rr_node = set_rr_node;
147147

148148
auto& device_ctx = g_vpr_ctx.device();
149+
const auto& rr_graph = device_ctx.rr_graph;
149150
this->delay = parent_delay;
150151
this->congestion_upstream = parent_congestion_upstream;
151152
this->R_upstream = parent_R_upstream;
152153
if (!starting_node) {
153-
int cost_index = device_ctx.rr_nodes.node_cost_index(RRNodeId(set_rr_node));
154+
int cost_index = rr_graph.node_cost_index(RRNodeId(set_rr_node));
154155
//this->delay += rr_graph.node_C(RRNodeId(set_rr_node)) * (g_rr_switch_inf[switch_ind].R + 0.5*rr_graph.node_R(RRNodeId(set_rr_node))) +
155156
// g_rr_switch_inf[switch_ind].Tdel;
156157

@@ -335,7 +336,7 @@ std::pair<float, float> MapLookahead::get_expected_delay_and_cong(RRNodeId from_
335336
VTR_ASSERT_SAFE(from_type == CHANX || from_type == CHANY);
336337
//When estimating costs from a wire, we directly look-up the result in the wire lookahead (f_wire_cost_map)
337338

338-
int from_cost_index = rr_graph.node_cost_index(from_node);
339+
int from_cost_index = temp_rr_graph.node_cost_index(from_node);
339340
int from_seg_index = device_ctx.rr_indexed_data[from_cost_index].seg_index;
340341

341342
VTR_ASSERT(from_seg_index >= 0);
@@ -478,7 +479,7 @@ static void compute_router_wire_lookahead(const std::vector<t_segment_inf>& segm
478479
auto rr_type = temp_rr_graph.node_type(rr_node);
479480
if (rr_type != chan_type) continue;
480481

481-
int cost_index = rr_graph.node_cost_index(rr_node);
482+
int cost_index = temp_rr_graph.node_cost_index(rr_node);
482483
VTR_ASSERT(cost_index != OPEN);
483484

484485
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
@@ -544,9 +545,8 @@ static void compute_router_wire_lookahead(const std::vector<t_segment_inf>& segm
544545
/* returns index of a node from which to start routing */
545546
static RRNodeId get_start_node(int start_x, int start_y, int target_x, int target_y, t_rr_type rr_type, int seg_index, int track_offset) {
546547
auto& device_ctx = g_vpr_ctx.device();
547-
const auto& temp_rr_graph = device_ctx.rr_graph; //TODO rename to rr_graph once the rr_graph below is unneeded
548-
auto& rr_graph = device_ctx.rr_nodes;
549-
const auto& node_lookup = device_ctx.rr_graph.node_lookup();
548+
const auto& rr_graph = device_ctx.rr_graph;
549+
const auto& node_lookup = rr_graph.node_lookup();
550550

551551
RRNodeId result = RRNodeId::INVALID();
552552

@@ -565,7 +565,7 @@ static RRNodeId get_start_node(int start_x, int start_y, int target_x, int targe
565565

566566
/* find first node in channel that has specified segment index and goes in the desired direction */
567567
for (const RRNodeId& node_id : node_lookup.find_channel_nodes(start_lookup_x, start_lookup_y, rr_type)) {
568-
VTR_ASSERT(temp_rr_graph.node_type(node_id) == rr_type);
568+
VTR_ASSERT(rr_graph.node_type(node_id) == rr_type);
569569

570570
Direction node_direction = rr_graph.node_direction(node_id);
571571
int node_cost_ind = rr_graph.node_cost_index(node_id);

vpr/src/route/router_lookahead_map_utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static void dijkstra_flood_to_wires(int itile, RRNodeId node, util::t_src_opin_d
469469
int seg_index;
470470
if (curr_rr_type != SINK) {
471471
//It's a wire, figure out its type
472-
int cost_index = rr_graph.node_cost_index(curr.node);
472+
int cost_index = temp_rr_graph.node_cost_index(curr.node);
473473
seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
474474
} else {
475475
//This is a direct-connect path between an IPIN and OPIN,
@@ -493,7 +493,7 @@ static void dijkstra_flood_to_wires(int itile, RRNodeId node, util::t_src_opin_d
493493

494494
} else if (curr_rr_type == SOURCE || curr_rr_type == OPIN || curr_rr_type == IPIN) {
495495
//We allow expansion through SOURCE/OPIN/IPIN types
496-
int cost_index = rr_graph.node_cost_index(curr.node);
496+
int cost_index = temp_rr_graph.node_cost_index(curr.node);
497497
float incr_cong = device_ctx.rr_indexed_data[cost_index].base_cost; //Current nodes congestion cost
498498

499499
for (RREdgeId edge : rr_graph.edge_range(curr.node)) {
@@ -588,7 +588,7 @@ static void dijkstra_flood_to_ipins(RRNodeId node, util::t_chan_ipins_delays& ch
588588
}
589589

590590
//We allow expansion through SOURCE/OPIN/IPIN types
591-
int cost_index = rr_graph.node_cost_index(curr.node);
591+
int cost_index = temp_rr_graph.node_cost_index(curr.node);
592592
float new_cong = device_ctx.rr_indexed_data[cost_index].base_cost; //Current nodes congestion cost
593593

594594
for (RREdgeId edge : rr_graph.edge_range(curr.node)) {

vpr/src/route/router_lookahead_sampling.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,20 @@ static uint64_t interleave(uint32_t x) {
128128
static std::tuple<int, int, int> get_node_info(const t_rr_node& node, int num_segments) {
129129
auto& device_ctx = g_vpr_ctx.device();
130130
const auto& rr_graph = device_ctx.rr_graph;
131+
RRNodeId rr_node = node.id();
131132

132-
if (rr_graph.node_type(node.id()) != CHANX && rr_graph.node_type(node.id()) != CHANY) {
133+
if (rr_graph.node_type(rr_node) != CHANX && rr_graph.node_type(rr_node) != CHANY) {
133134
return std::tuple<int, int, int>(OPEN, OPEN, OPEN);
134135
}
135136

136-
if (rr_graph.node_capacity(node.id()) == 0 || node.num_edges() == 0) {
137+
if (rr_graph.node_capacity(rr_node) == 0 || node.num_edges() == 0) {
137138
return std::tuple<int, int, int>(OPEN, OPEN, OPEN);
138139
}
139140

140-
int x = rr_graph.node_xlow(node.id());
141-
int y = rr_graph.node_ylow(node.id());
141+
int x = rr_graph.node_xlow(rr_node);
142+
int y = rr_graph.node_ylow(rr_node);
142143

143-
int seg_index = device_ctx.rr_indexed_data[node.cost_index()].seg_index;
144+
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(rr_node)].seg_index;
144145

145146
VTR_ASSERT(seg_index != OPEN);
146147
VTR_ASSERT(seg_index < num_segments);
@@ -205,7 +206,7 @@ std::vector<SampleRegion> find_sample_regions(int num_segments) {
205206
for (auto& node : rr_nodes) {
206207
if (rr_graph.node_type(node.id()) != CHANX && rr_graph.node_type(node.id()) != CHANY) continue;
207208
if (rr_graph.node_capacity(node.id()) == 0 || node.num_edges() == 0) continue;
208-
int seg_index = device_ctx.rr_indexed_data[node.cost_index()].seg_index;
209+
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(node.id())].seg_index;
209210

210211
VTR_ASSERT(seg_index != OPEN);
211212
VTR_ASSERT(seg_index < num_segments);

vpr/src/route/rr_graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ std::string describe_rr_node(int inode) {
24312431
auto rr_node = device_ctx.rr_nodes[inode];
24322432

24332433
if (rr_graph.node_type(RRNodeId(inode)) == CHANX || rr_graph.node_type(RRNodeId(inode)) == CHANY) {
2434-
int cost_index = rr_node.cost_index();
2434+
int cost_index = rr_graph.node_cost_index(RRNodeId(inode));
24352435

24362436
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
24372437
std::string rr_node_direction_string = rr_graph.node_direction_string(RRNodeId(inode));

vpr/src/route/rr_graph_indexed_data.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static std::vector<size_t> count_rr_segment_types() {
245245
for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); ++inode) {
246246
if (rr_graph.node_type(RRNodeId(inode)) != CHANX && rr_graph.node_type(RRNodeId(inode)) != CHANY) continue;
247247

248-
int cost_index = device_ctx.rr_nodes[inode].cost_index();
248+
int cost_index = rr_graph.node_cost_index(RRNodeId(inode));
249249

250250
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
251251

@@ -350,7 +350,7 @@ static void load_rr_indexed_data_T_values() {
350350
continue;
351351
}
352352

353-
int cost_index = rr_nodes[inode].cost_index();
353+
int cost_index = rr_graph.node_cost_index(RRNodeId(inode));
354354

355355
/* get average switch parameters */
356356
double avg_switch_R = 0;

vpr/src/route/rr_graph_uxsdcxx_serializer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,23 +706,23 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
706706
node.set_cost_index(0);
707707
} else if (rr_graph.node_type(node.id()) == CHANX) {
708708
node.set_cost_index(CHANX_COST_INDEX_START + segment_id);
709-
seg_index_[node.cost_index()] = segment_id;
709+
seg_index_[rr_graph.node_cost_index(node.id())] = segment_id;
710710
} else if (rr_graph.node_type(node.id()) == CHANY) {
711711
node.set_cost_index(CHANX_COST_INDEX_START + segment_inf_.size() + segment_id);
712-
seg_index_[node.cost_index()] = segment_id;
712+
seg_index_[rr_graph.node_cost_index(node.id())] = segment_id;
713713
}
714714
return inode;
715715
}
716716
inline void finish_node_segment(int& /*inode*/) final {}
717717
inline int get_node_segment_segment_id(const t_rr_node& node) final {
718-
return (*rr_indexed_data_)[node.cost_index()].seg_index;
718+
return (*rr_indexed_data_)[(*rr_graph_).node_cost_index(node.id())].seg_index;
719719
}
720720

721721
inline const t_rr_node get_node_segment(const t_rr_node& node) final {
722722
return node;
723723
}
724724
inline bool has_node_segment(const t_rr_node& node) final {
725-
return (*rr_indexed_data_)[node.cost_index()].seg_index != -1;
725+
return (*rr_indexed_data_)[(*rr_graph_).node_cost_index(node.id())].seg_index != -1;
726726
}
727727

728728
inline MetadataBind init_node_metadata(int& inode) final {

vpr/src/route/rr_node_impl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ inline short t_rr_node::class_num() const {
118118
return storage_->node_class_num(id_);
119119
}
120120

121-
inline short t_rr_node::cost_index() const {
122-
return storage_->node_cost_index(id_);
123-
}
124-
125121
inline bool t_rr_node::is_node_on_specific_side(e_side side) const {
126122
return storage_->is_node_on_specific_side(id_, side);
127123
}

vpr/src/route/segment_stats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void get_segment_usage_stats(std::vector<t_segment_inf>& segment_inf) {
5050

5151
for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
5252
if (rr_graph.node_type(RRNodeId(inode)) == CHANX || rr_graph.node_type(RRNodeId(inode)) == CHANY) {
53-
cost_index = device_ctx.rr_nodes[inode].cost_index();
53+
cost_index = rr_graph.node_cost_index(RRNodeId(inode));
5454
size_t seg_type = device_ctx.rr_indexed_data[cost_index].seg_index;
5555

5656
if (!segment_inf[seg_type].longline)

vpr/src/util/vpr_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ std::string rr_node_arch_name(int inode) {
216216
} else {
217217
VTR_ASSERT(rr_graph.node_type(RRNodeId(inode)) == CHANX || rr_graph.node_type(RRNodeId(inode)) == CHANY);
218218
//Wire segment name
219-
auto cost_index = rr_node.cost_index();
219+
auto cost_index = rr_graph.node_cost_index(RRNodeId(inode));
220220
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
221221

222222
rr_node_arch_name += device_ctx.rr_segments[seg_index].name;

0 commit comments

Comments
 (0)