Skip to content

Commit 943a140

Browse files
committed
Optimize away some overhead introduced with Router class.
Signed-off-by: Keith Rothman <[email protected]>
1 parent 469d4b5 commit 943a140

File tree

6 files changed

+92
-62
lines changed

6 files changed

+92
-62
lines changed

utils/route_diag/src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static void do_one_route(int source_node, int sink_node,
103103
*router_lookahead,
104104
device_ctx.rr_nodes,
105105
device_ctx.rr_rc_data,
106-
device_ctx.rr_switch_inf);
106+
device_ctx.rr_switch_inf,
107+
g_vpr_ctx.mutable_routing().rr_node_route_inf);
107108
t_heap* cheapest = router.timing_driven_route_connection_from_route_tree(rt_root, sink_node, cost_params, bounding_box, router_stats);
108109

109110
bool found_path = (cheapest != nullptr);

vpr/src/route/route_timing.cpp

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ bool try_timing_driven_route(const t_router_opts& router_opts,
357357
*router_lookahead,
358358
device_ctx.rr_nodes,
359359
device_ctx.rr_rc_data,
360-
device_ctx.rr_switch_inf);
360+
device_ctx.rr_switch_inf,
361+
route_ctx.rr_node_route_inf);
361362

362363
/*
363364
* On the first routing iteration ignore congestion to get reasonable net
@@ -1068,18 +1069,6 @@ bool timing_driven_route_net(Router& router,
10681069
return (true);
10691070
}
10701071

1071-
void Router::update_cheapest(t_heap* cheapest) {
1072-
auto& route_ctx = g_vpr_ctx.mutable_routing();
1073-
1074-
//Record final link to target
1075-
add_to_mod_list(cheapest->index, modified_rr_node_inf_);
1076-
1077-
route_ctx.rr_node_route_inf[cheapest->index].prev_node = cheapest->u.prev.node;
1078-
route_ctx.rr_node_route_inf[cheapest->index].prev_edge = cheapest->u.prev.edge;
1079-
route_ctx.rr_node_route_inf[cheapest->index].path_cost = cheapest->cost;
1080-
route_ctx.rr_node_route_inf[cheapest->index].backward_path_cost = cheapest->backward_path_cost;
1081-
}
1082-
10831072
static bool timing_driven_pre_route_to_clock_root(
10841073
Router& router,
10851074
ClusterNetId net_id,
@@ -1533,7 +1522,7 @@ std::vector<t_heap> Router::timing_driven_find_all_shortest_paths_from_route_tre
15331522
std::vector<t_heap> Router::timing_driven_find_all_shortest_paths_from_heap(
15341523
const t_conn_cost_params cost_params,
15351524
t_bb bounding_box) {
1536-
std::vector<t_heap> cheapest_paths(rr_nodes_.size());
1525+
std::vector<t_heap> cheapest_paths(rr_nodes_->size());
15371526

15381527
VTR_ASSERT_SAFE(heap_::is_valid());
15391528

@@ -1579,12 +1568,11 @@ void Router::timing_driven_expand_cheapest(t_heap* cheapest,
15791568
int target_node,
15801569
const t_conn_cost_params cost_params,
15811570
t_bb bounding_box) {
1582-
auto& route_ctx = g_vpr_ctx.mutable_routing();
1583-
15841571
int inode = cheapest->index;
15851572

1586-
float best_total_cost = route_ctx.rr_node_route_inf[inode].path_cost;
1587-
float best_back_cost = route_ctx.rr_node_route_inf[inode].backward_path_cost;
1573+
t_rr_node_route_inf* route_inf = &rr_node_route_inf_[inode];
1574+
float best_total_cost = route_inf->path_cost;
1575+
float best_back_cost = route_inf->backward_path_cost;
15881576

15891577
float new_total_cost = cheapest->cost;
15901578
float new_back_cost = cheapest->backward_path_cost;
@@ -1605,7 +1593,7 @@ void Router::timing_driven_expand_cheapest(t_heap* cheapest,
16051593
VTR_LOGV_DEBUG(f_router_debug, " New back cost: %g\n", new_back_cost);
16061594
VTR_LOGV_DEBUG(f_router_debug, " Setting path costs for associated node %d (from %d edge %d)\n", cheapest->index, cheapest->u.prev.node, cheapest->u.prev.edge);
16071595

1608-
update_cheapest(cheapest);
1596+
update_cheapest(cheapest, route_inf);
16091597

16101598
timing_driven_expand_neighbours(cheapest, cost_params, bounding_box,
16111599
target_node);
@@ -1958,22 +1946,24 @@ void Router::timing_driven_expand_neighbours(t_heap* current,
19581946
/* Puts all the rr_nodes adjacent to current on the heap.
19591947
*/
19601948

1961-
auto& device_ctx = g_vpr_ctx.device();
1962-
19631949
t_bb target_bb;
19641950
if (target_node != OPEN) {
1965-
target_bb.xmin = device_ctx.rr_nodes[target_node].xlow();
1966-
target_bb.ymin = device_ctx.rr_nodes[target_node].ylow();
1967-
target_bb.xmax = device_ctx.rr_nodes[target_node].xhigh();
1968-
target_bb.ymax = device_ctx.rr_nodes[target_node].yhigh();
1951+
target_bb.xmin = rr_nodes_->xlow(RRNodeId(target_node));
1952+
target_bb.ymin = rr_nodes_->ylow(RRNodeId(target_node));
1953+
target_bb.xmax = rr_nodes_->xhigh(RRNodeId(target_node));
1954+
target_bb.ymax = rr_nodes_->yhigh(RRNodeId(target_node));
19691955
}
19701956

19711957
//For each node associated with the current heap element, expand all of it's neighbors
1972-
int num_edges = device_ctx.rr_nodes[current->index].num_edges();
1958+
int from_node_int = current->index;
1959+
RRNodeId from_node(from_node_int);
1960+
int num_edges = rr_nodes_->num_edges(from_node);
19731961
for (int iconn = 0; iconn < num_edges; iconn++) {
1974-
int to_node = device_ctx.rr_nodes[current->index].edge_sink_node(iconn);
1962+
RRNodeId to_node = rr_nodes_->edge_sink_node(from_node, iconn);
19751963
timing_driven_expand_neighbour(current,
1976-
current->index, iconn, to_node,
1964+
from_node_int,
1965+
iconn,
1966+
size_t(to_node),
19771967
cost_params,
19781968
bounding_box,
19791969
target_node,
@@ -1987,17 +1977,16 @@ void Router::timing_driven_expand_neighbours(t_heap* current,
19871977
void Router::timing_driven_expand_neighbour(t_heap* current,
19881978
const int from_node,
19891979
const t_edge_size from_edge,
1990-
const int to_node,
1980+
const int to_node_int,
19911981
const t_conn_cost_params cost_params,
19921982
const t_bb bounding_box,
19931983
int target_node,
19941984
const t_bb target_bb) {
1995-
auto& device_ctx = g_vpr_ctx.device();
1996-
1997-
int to_xlow = device_ctx.rr_nodes[to_node].xlow();
1998-
int to_ylow = device_ctx.rr_nodes[to_node].ylow();
1999-
int to_xhigh = device_ctx.rr_nodes[to_node].xhigh();
2000-
int to_yhigh = device_ctx.rr_nodes[to_node].yhigh();
1985+
RRNodeId to_node(to_node_int);
1986+
int to_xlow = rr_nodes_->xlow(to_node);
1987+
int to_ylow = rr_nodes_->ylow(to_node);
1988+
int to_xhigh = rr_nodes_->xhigh(to_node);
1989+
int to_yhigh = rr_nodes_->yhigh(to_node);
20011990

20021991
if (to_xhigh < bounding_box.xmin //Strictly left of BB left-edge
20031992
|| to_xlow > bounding_box.xmax //Strictly right of BB right-edge
@@ -2007,7 +1996,7 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20071996
" Pruned expansion of node %d edge %d -> %d"
20081997
" (to node location %d,%dx%d,%d outside of expanded"
20091998
" net bounding box %d,%dx%d,%d)\n",
2010-
from_node, from_edge, to_node,
1999+
from_node, from_edge, to_node_int,
20112000
to_xlow, to_ylow, to_xhigh, to_yhigh,
20122001
bounding_box.xmin, bounding_box.ymin, bounding_box.xmax, bounding_box.ymax);
20132002
return; /* Node is outside (expanded) bounding box. */
@@ -2018,7 +2007,7 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20182007
* more promising routes, but makes route-through (via CLBs) impossible. *
20192008
* Change this if you want to investigate route-throughs. */
20202009
if (target_node != OPEN) {
2021-
t_rr_type to_type = device_ctx.rr_nodes[to_node].type();
2010+
t_rr_type to_type = rr_nodes_->node_type(to_node);
20222011
if (to_type == IPIN) {
20232012
//Check if this IPIN leads to the target block
20242013
// IPIN's of the target block should be contained within it's bounding box
@@ -2030,7 +2019,7 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20302019
" Pruned expansion of node %d edge %d -> %d"
20312020
" (to node is IPIN at %d,%dx%d,%d which does not"
20322021
" lead to target block %d,%dx%d,%d)\n",
2033-
from_node, from_edge, to_node,
2022+
from_node, from_edge, to_node_int,
20342023
to_xlow, to_ylow, to_xhigh, to_yhigh,
20352024
target_bb.xmin, target_bb.ymin, target_bb.xmax, target_bb.ymax);
20362025
return;
@@ -2039,12 +2028,12 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20392028
}
20402029

20412030
VTR_LOGV_DEBUG(f_router_debug, " Expanding node %d edge %d -> %d\n",
2042-
from_node, from_edge, to_node);
2031+
from_node, from_edge, to_node_int);
20432032

20442033
timing_driven_add_to_heap(cost_params,
20452034
current,
20462035
from_node,
2047-
to_node,
2036+
to_node_int,
20482037
from_edge,
20492038
target_node);
20502039
}
@@ -2067,10 +2056,8 @@ void Router::timing_driven_add_to_heap(const t_conn_cost_params cost_params,
20672056
timing_driven_expand_node(cost_params,
20682057
next, from_node, to_node, iconn, target_node);
20692058

2070-
auto& route_ctx = g_vpr_ctx.routing();
2071-
2072-
float best_total_cost = route_ctx.rr_node_route_inf[to_node].path_cost;
2073-
float best_back_cost = route_ctx.rr_node_route_inf[to_node].backward_path_cost;
2059+
float best_total_cost = rr_node_route_inf_[to_node].path_cost;
2060+
float best_back_cost = rr_node_route_inf_[to_node].backward_path_cost;
20742061

20752062
float new_total_cost = next->cost;
20762063
float new_back_cost = next->backward_path_cost;
@@ -2126,20 +2113,20 @@ void Router::evaluate_timing_driven_node_costs(t_heap* to,
21262113
*/
21272114

21282115
//Info for the switch connecting from_node to_node
2129-
int iswitch = rr_nodes_[from_node].edge_switch(iconn);
2116+
int iswitch = rr_nodes_->edge_switch(RRNodeId(from_node), iconn);
21302117
bool switch_buffered = rr_switch_inf_[iswitch].buffered();
21312118
bool reached_configurably = rr_switch_inf_[iswitch].configurable();
21322119
float switch_R = rr_switch_inf_[iswitch].R;
21332120
float switch_Tdel = rr_switch_inf_[iswitch].Tdel;
21342121
float switch_Cinternal = rr_switch_inf_[iswitch].Cinternal;
21352122

21362123
//To node info
2137-
auto rc_index = rr_nodes_[to_node].rc_index();
2124+
auto rc_index = rr_nodes_->node_rc_index(RRNodeId(to_node));
21382125
float node_C = rr_rc_data_[rc_index].C;
21392126
float node_R = rr_rc_data_[rc_index].R;
21402127

21412128
//From node info
2142-
float from_node_R = rr_rc_data_[rr_nodes_[from_node].rc_index()].R;
2129+
float from_node_R = rr_rc_data_[rr_nodes_->node_rc_index(RRNodeId(from_node))].R;
21432130

21442131
//Update R_upstream
21452132
if (switch_buffered) {
@@ -2191,8 +2178,8 @@ void Router::evaluate_timing_driven_node_costs(t_heap* to,
21912178
to->backward_path_cost += cost_params.criticality * Tdel; //Delay cost
21922179

21932180
if (cost_params.bend_cost != 0.) {
2194-
t_rr_type from_type = rr_nodes_[from_node].type();
2195-
t_rr_type to_type = rr_nodes_[to_node].type();
2181+
t_rr_type from_type = rr_nodes_->node_type(RRNodeId(from_node));
2182+
t_rr_type to_type = rr_nodes_->node_type(RRNodeId(to_node));
21962183
if ((from_type == CHANX && to_type == CHANY) || (from_type == CHANY && to_type == CHANX)) {
21972184
to->backward_path_cost += cost_params.bend_cost; //Bend cost
21982185
}

vpr/src/route/route_timing.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ class Router {
2020
const RouterLookahead& router_lookahead,
2121
const t_rr_graph_storage& rr_nodes,
2222
const std::vector<t_rr_rc_data>& rr_rc_data,
23-
const std::vector<t_rr_switch_inf>& rr_switch_inf)
23+
const std::vector<t_rr_switch_inf>& rr_switch_inf,
24+
std::vector<t_rr_node_route_inf>& rr_node_route_inf)
2425
: router_lookahead_(router_lookahead)
25-
, rr_nodes_(rr_nodes)
26-
, rr_rc_data_(rr_rc_data)
27-
, rr_switch_inf_(rr_switch_inf) {}
26+
, rr_nodes_(&rr_nodes)
27+
, rr_rc_data_(rr_rc_data.data())
28+
, rr_switch_inf_(rr_switch_inf.data())
29+
, rr_node_route_inf_(rr_node_route_inf.data()) {}
2830

2931
void clear_modified_rr_node_info() {
3032
modified_rr_node_inf_.clear();
@@ -56,7 +58,26 @@ class Router {
5658
RouterStats& router_stats);
5759

5860
private:
59-
void update_cheapest(t_heap* cheapest);
61+
void add_to_mod_list(int inode) {
62+
if (std::isinf(rr_node_route_inf_[inode].path_cost)) {
63+
modified_rr_node_inf_.push_back(inode);
64+
}
65+
}
66+
67+
void update_cheapest(t_heap* cheapest) {
68+
update_cheapest(cheapest, &rr_node_route_inf_[cheapest->index]);
69+
}
70+
71+
void update_cheapest(t_heap* cheapest, t_rr_node_route_inf* route_inf) {
72+
//Record final link to target
73+
add_to_mod_list(cheapest->index);
74+
75+
route_inf->prev_node = cheapest->u.prev.node;
76+
route_inf->prev_edge = cheapest->u.prev.edge;
77+
route_inf->path_cost = cheapest->cost;
78+
route_inf->backward_path_cost = cheapest->backward_path_cost;
79+
}
80+
6081
t_heap* timing_driven_route_connection_from_route_tree(
6182
t_rt_node* rt_root,
6283
int sink_node,
@@ -111,9 +132,10 @@ class Router {
111132
t_bb bounding_box);
112133

113134
const RouterLookahead& router_lookahead_;
114-
const t_rr_graph_storage& rr_nodes_;
115-
const std::vector<t_rr_rc_data>& rr_rc_data_;
116-
const std::vector<t_rr_switch_inf>& rr_switch_inf_;
135+
const t_rr_graph_storage* rr_nodes_;
136+
const t_rr_rc_data* rr_rc_data_;
137+
const t_rr_switch_inf* rr_switch_inf_;
138+
t_rr_node_route_inf* rr_node_route_inf_;
117139
std::vector<int> modified_rr_node_inf_;
118140
RouterStats* router_stats_;
119141
};

vpr/src/route/router_delay_profiling.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RouterDelayProfiler::RouterDelayProfiler(
1515
*lookahead,
1616
g_vpr_ctx.device().rr_nodes,
1717
g_vpr_ctx.device().rr_rc_data,
18-
g_vpr_ctx.device().rr_switch_inf) {}
18+
g_vpr_ctx.device().rr_switch_inf,
19+
g_vpr_ctx.mutable_routing().rr_node_route_inf) {}
1920

2021
bool RouterDelayProfiler::calculate_delay(int source_node, int sink_node, const t_router_opts& router_opts, float* net_delay) {
2122
/* Returns true as long as found some way to hook up this net, even if that *
@@ -80,6 +81,7 @@ bool RouterDelayProfiler::calculate_delay(int source_node, int sink_node, const
8081
//Returns the shortest path delay from src_node to all RR nodes in the RR graph, or NaN if no path exists
8182
std::vector<float> calculate_all_path_delays_from_rr_node(int src_rr_node, const t_router_opts& router_opts) {
8283
auto& device_ctx = g_vpr_ctx.device();
84+
auto& routing_ctx = g_vpr_ctx.mutable_routing();
8385

8486
std::vector<float> path_delays_to(device_ctx.rr_nodes.size(), std::numeric_limits<float>::quiet_NaN());
8587

@@ -103,7 +105,8 @@ std::vector<float> calculate_all_path_delays_from_rr_node(int src_rr_node, const
103105
*router_lookahead,
104106
device_ctx.rr_nodes,
105107
device_ctx.rr_rc_data,
106-
device_ctx.rr_switch_inf);
108+
device_ctx.rr_switch_inf,
109+
routing_ctx.rr_node_route_inf);
107110
RouterStats router_stats;
108111

109112
init_heap(device_ctx.grid);

vpr/src/route/rr_graph_storage.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ class t_rr_graph_storage {
187187
}
188188
const char* node_type_string(RRNodeId id) const;
189189

190+
int16_t node_rc_index(RRNodeId id) const {
191+
return storage_[id].rc_index_;
192+
}
193+
194+
short xlow(RRNodeId id) const {
195+
return storage_[id].xlow_;
196+
}
197+
short ylow(RRNodeId id) const {
198+
return storage_[id].ylow_;
199+
}
200+
short xhigh(RRNodeId id) const {
201+
return storage_[id].xhigh_;
202+
}
203+
short yhigh(RRNodeId id) const {
204+
return storage_[id].yhigh_;
205+
}
206+
190207
/* PTC set methods */
191208
void set_node_ptc_num(RRNodeId id, short);
192209
void set_node_pin_num(RRNodeId id, short); //Same as set_ptc_num() by checks type() is consistent

vpr/src/route/rr_node_fwd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ struct rr_node_id_tag;
1919
struct rr_edge_id_tag;
2020

2121
//A unique identifier for a node in the rr graph
22-
typedef vtr::StrongId<rr_node_id_tag> RRNodeId;
22+
typedef vtr::StrongId<rr_node_id_tag, unsigned int> RRNodeId;
2323

2424
//A unique identifier for an edge in the rr graph
25-
typedef vtr::StrongId<rr_edge_id_tag> RREdgeId;
25+
typedef vtr::StrongId<rr_edge_id_tag, unsigned int> RREdgeId;
2626

2727
//An iterator that dereferences to an edge index
2828
//

0 commit comments

Comments
 (0)