Skip to content

Commit ad9ece7

Browse files
committed
Reduce computation in edge loop.
Signed-off-by: Keith Rothman <[email protected]>
1 parent 943a140 commit ad9ece7

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

vpr/src/route/route_timing.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,11 +1957,15 @@ void Router::timing_driven_expand_neighbours(t_heap* current,
19571957
//For each node associated with the current heap element, expand all of it's neighbors
19581958
int from_node_int = current->index;
19591959
RRNodeId from_node(from_node_int);
1960-
int num_edges = rr_nodes_->num_edges(from_node);
1960+
RREdgeId first_edge = rr_nodes_->first_edge(from_node);
1961+
RREdgeId last_edge = rr_nodes_->last_edge(from_node);
1962+
int num_edges = size_t(last_edge) - size_t(first_edge);
19611963
for (int iconn = 0; iconn < num_edges; iconn++) {
1962-
RRNodeId to_node = rr_nodes_->edge_sink_node(from_node, iconn);
1964+
RREdgeId from_edge(size_t(first_edge) + iconn);
1965+
RRNodeId to_node = rr_nodes_->edge_sink_node(from_edge);
19631966
timing_driven_expand_neighbour(current,
19641967
from_node_int,
1968+
from_edge,
19651969
iconn,
19661970
size_t(to_node),
19671971
cost_params,
@@ -1976,7 +1980,8 @@ void Router::timing_driven_expand_neighbours(t_heap* current,
19761980
//to the heap.
19771981
void Router::timing_driven_expand_neighbour(t_heap* current,
19781982
const int from_node,
1979-
const t_edge_size from_edge,
1983+
const RREdgeId from_edge,
1984+
const t_edge_size from_edge_int,
19801985
const int to_node_int,
19811986
const t_conn_cost_params cost_params,
19821987
const t_bb bounding_box,
@@ -1996,7 +2001,7 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
19962001
" Pruned expansion of node %d edge %d -> %d"
19972002
" (to node location %d,%dx%d,%d outside of expanded"
19982003
" net bounding box %d,%dx%d,%d)\n",
1999-
from_node, from_edge, to_node_int,
2004+
from_node, from_edge_int, to_node_int,
20002005
to_xlow, to_ylow, to_xhigh, to_yhigh,
20012006
bounding_box.xmin, bounding_box.ymin, bounding_box.xmax, bounding_box.ymax);
20022007
return; /* Node is outside (expanded) bounding box. */
@@ -2019,7 +2024,7 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20192024
" Pruned expansion of node %d edge %d -> %d"
20202025
" (to node is IPIN at %d,%dx%d,%d which does not"
20212026
" lead to target block %d,%dx%d,%d)\n",
2022-
from_node, from_edge, to_node_int,
2027+
from_node, from_edge_int, to_node_int,
20232028
to_xlow, to_ylow, to_xhigh, to_yhigh,
20242029
target_bb.xmin, target_bb.ymin, target_bb.xmax, target_bb.ymax);
20252030
return;
@@ -2028,13 +2033,14 @@ void Router::timing_driven_expand_neighbour(t_heap* current,
20282033
}
20292034

20302035
VTR_LOGV_DEBUG(f_router_debug, " Expanding node %d edge %d -> %d\n",
2031-
from_node, from_edge, to_node_int);
2036+
from_node, from_edge_int, to_node_int);
20322037

20332038
timing_driven_add_to_heap(cost_params,
20342039
current,
20352040
from_node,
20362041
to_node_int,
20372042
from_edge,
2043+
from_edge_int,
20382044
target_node);
20392045
}
20402046

@@ -2043,65 +2049,59 @@ void Router::timing_driven_add_to_heap(const t_conn_cost_params cost_params,
20432049
const t_heap* current,
20442050
const int from_node,
20452051
const int to_node,
2052+
const RREdgeId from_edge,
20462053
const int iconn,
20472054
const int target_node) {
2048-
t_heap* next = alloc_heap_data();
2049-
next->index = to_node;
2055+
t_heap next;
20502056

20512057
//Costs initialized to current
2052-
next->cost = std::numeric_limits<float>::infinity(); //Not used directly
2053-
next->backward_path_cost = current->backward_path_cost;
2054-
next->R_upstream = current->R_upstream;
2058+
next.cost = std::numeric_limits<float>::infinity(); //Not used directly
2059+
next.backward_path_cost = current->backward_path_cost;
2060+
next.R_upstream = current->R_upstream;
20552061

2056-
timing_driven_expand_node(cost_params,
2057-
next, from_node, to_node, iconn, target_node);
2062+
2063+
VTR_LOGV_DEBUG(f_router_debug, " Expanding to node %d (%s)\n", to_node, describe_rr_node(to_node).c_str());
2064+
2065+
evaluate_timing_driven_node_costs(&next,
2066+
cost_params,
2067+
from_node,
2068+
to_node,
2069+
from_edge,
2070+
target_node);
20582071

20592072
float best_total_cost = rr_node_route_inf_[to_node].path_cost;
20602073
float best_back_cost = rr_node_route_inf_[to_node].backward_path_cost;
20612074

2062-
float new_total_cost = next->cost;
2063-
float new_back_cost = next->backward_path_cost;
2064-
2065-
VTR_ASSERT_SAFE(next->index == to_node);
2075+
float new_total_cost = next.cost;
2076+
float new_back_cost = next.backward_path_cost;
20662077

20672078
if (new_total_cost < best_total_cost && new_back_cost < best_back_cost) {
20682079
//Add node to the heap only if the cost via the current partial path is less than the
20692080
//best known cost, since there is no reason for the router to expand more expensive paths.
20702081
//
20712082
//Pre-heap prune to keep the heap small, by not putting paths which are known to be
20722083
//sub-optimal (at this point in time) into the heap.
2073-
add_to_heap(next);
2074-
++router_stats_->heap_pushes;
2075-
} else {
2076-
free_heap_data(next);
2077-
}
2078-
}
2084+
t_heap* next_ptr = alloc_heap_data();
20792085

2080-
//Updates current (path step and costs) to account for the step taken to reach to_node
2081-
void Router::timing_driven_expand_node(const t_conn_cost_params cost_params,
2082-
t_heap* current,
2083-
const int from_node,
2084-
const int to_node,
2085-
const int iconn,
2086-
const int target_node) {
2087-
VTR_LOGV_DEBUG(f_router_debug, " Expanding to node %d (%s)\n", to_node, describe_rr_node(to_node).c_str());
2086+
//Record how we reached this node
2087+
next_ptr->cost = next.cost;
2088+
next_ptr->R_upstream = next.R_upstream;
2089+
next_ptr->backward_path_cost = next.backward_path_cost;
2090+
next_ptr->index = to_node;
2091+
next_ptr->u.prev.edge = iconn;
2092+
next_ptr->u.prev.node = from_node;
20882093

2089-
evaluate_timing_driven_node_costs(current,
2090-
cost_params,
2091-
from_node, to_node, iconn, target_node);
2092-
2093-
//Record how we reached this node
2094-
current->index = to_node;
2095-
current->u.prev.edge = iconn;
2096-
current->u.prev.node = from_node;
2094+
add_to_heap(next_ptr);
2095+
++router_stats_->heap_pushes;
2096+
}
20972097
}
20982098

20992099
//Calculates the cost of reaching to_node
21002100
void Router::evaluate_timing_driven_node_costs(t_heap* to,
21012101
const t_conn_cost_params cost_params,
21022102
const int from_node,
21032103
const int to_node,
2104-
const int iconn,
2104+
const RREdgeId from_edge,
21052105
const int target_node) {
21062106
/* new_costs.backward_cost: is the "known" part of the cost to this node -- the
21072107
* congestion cost of all the routing resources back to the existing route
@@ -2113,7 +2113,7 @@ void Router::evaluate_timing_driven_node_costs(t_heap* to,
21132113
*/
21142114

21152115
//Info for the switch connecting from_node to_node
2116-
int iswitch = rr_nodes_->edge_switch(RRNodeId(from_node), iconn);
2116+
int iswitch = rr_nodes_->edge_switch(from_edge);
21172117
bool switch_buffered = rr_switch_inf_[iswitch].buffered();
21182118
bool reached_configurably = rr_switch_inf_[iswitch].configurable();
21192119
float switch_R = rr_switch_inf_[iswitch].R;

vpr/src/route/route_timing.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class Router {
100100
void timing_driven_expand_neighbour(
101101
t_heap* current,
102102
const int from_node,
103-
const t_edge_size from_edge,
103+
const RREdgeId from_edge,
104+
const t_edge_size from_edge_int,
104105
const int to_node,
105106
const t_conn_cost_params cost_params,
106107
const t_bb bounding_box,
@@ -111,21 +112,15 @@ class Router {
111112
const t_heap* current,
112113
const int from_node,
113114
const int to_node,
114-
const int iconn,
115-
const int target_node);
116-
void timing_driven_expand_node(
117-
const t_conn_cost_params cost_params,
118-
t_heap* current,
119-
const int from_node,
120-
const int to_node,
115+
const RREdgeId from_edge,
121116
const int iconn,
122117
const int target_node);
123118
void evaluate_timing_driven_node_costs(
124119
t_heap* to,
125120
const t_conn_cost_params cost_params,
126121
const int from_node,
127122
const int to_node,
128-
const int iconn,
123+
const RREdgeId from_edge,
129124
const int target_node);
130125
std::vector<t_heap> timing_driven_find_all_shortest_paths_from_heap(
131126
const t_conn_cost_params cost_params,

vpr/src/route/rr_graph_storage.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,23 @@ class t_rr_graph_storage {
316316
}
317317

318318
t_edge_size num_edges(const RRNodeId& id) const {
319-
RREdgeId first_id = first_edge_[id];
320-
RREdgeId last_id = (&first_edge_[id])[1];
321-
return size_t(last_id) - size_t(first_id);
319+
return size_t(last_edge(id)) - size_t(first_edge(id));
320+
}
321+
322+
RREdgeId first_edge(const RRNodeId& id) const {
323+
return first_edge_[id];
324+
}
325+
RREdgeId last_edge(const RRNodeId& id) const {
326+
return (&first_edge_[id])[1];
322327
}
323328

324329
t_edge_size num_configurable_edges(const RRNodeId& id) const;
325330
t_edge_size num_non_configurable_edges(const RRNodeId& id) const;
326331

327332
RREdgeId edge_id(const RRNodeId& id, t_edge_size iedge) const {
328-
RREdgeId first_edge = first_edge_[id];
333+
RREdgeId first_edge = this->first_edge(id);
329334
RREdgeId ret(size_t(first_edge) + iedge);
330-
VTR_ASSERT_SAFE(ret < (&first_edge_[id])[1]);
335+
VTR_ASSERT_SAFE(ret < last_edge(id));
331336
return ret;
332337
}
333338
RRNodeId edge_sink_node(const RREdgeId& edge) const {

0 commit comments

Comments
 (0)