Skip to content

Commit d307ea0

Browse files
committed
[Router] Refactored t_heap to RTExploredNode
The `t_heap` data structure is no longer needed as the "heap node structure" due to the algorithmic changes in the connection router in commit b11b2eb. However, `t_heap` is used in many places as a holder for the return values of the route routines. This commit refactored the `t_heap`, renamed it to `RTExploredNode`, and combined it with the other similar node info data structure, `node_t`, in the connection router to fit the changes since commit b11b2eb.
1 parent 726294a commit d307ea0

14 files changed

+128
-193
lines changed

doc/src/api/vpr/route_tree.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ RouteTreeNode
2020
.. doxygenclass:: RouteTreeNode
2121
:project: vpr
2222
:members:
23+
24+
RTExploredNode
25+
-------------
26+
27+
.. doxygenclass:: RTExploredNode
28+
:project: vpr
29+
:members:

doc/src/api/vprinternals/router_heap.rst

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,13 @@
22
Router Heap
33
==============
44

5-
t_heap
6-
----------
7-
.. doxygenstruct:: t_heap
8-
:project: vpr
9-
:members:
10-
115
HeapInterface
126
----------
137
.. doxygenclass:: HeapInterface
148
:project: vpr
159
:members:
1610

17-
HeapStorage
18-
----------
19-
.. doxygenclass:: HeapStorage
20-
:project: vpr
21-
:members:
22-
23-
KAryHeap
11+
DAryHeap
2412
----------
25-
.. doxygenclass:: KAryHeap
13+
.. doxygenclass:: DAryHeap
2614
:project: vpr
27-
28-
FourAryHeap
29-
----------
30-
.. doxygenclass:: FourAryHeap
31-
:project: vpr

utils/route_diag/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void do_one_route(const Netlist<>& net_list,
114114
is_flat);
115115
enable_router_debug(router_opts, ParentNetId(), sink_node, 1, &router);
116116
bool found_path;
117-
t_heap cheapest;
117+
RTExploredNode cheapest;
118118
ConnectionParameters conn_params(ParentNetId::INVALID(),
119119
-1,
120120
false,

vpr/src/route/connection_router.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void update_router_stats(RouterStats* router_stats,
2222

2323
/** return tuple <found_path, retry_with_full_bb, cheapest> */
2424
template<typename Heap>
25-
std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_connection_from_route_tree(
25+
std::tuple<bool, bool, RTExploredNode> ConnectionRouter<Heap>::timing_driven_route_connection_from_route_tree(
2626
const RouteTreeNode& rt_root,
2727
RRNodeId sink_node,
2828
const t_conn_cost_params& cost_params,
@@ -37,9 +37,11 @@ std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_conne
3737

3838
if (!std::isinf(rr_node_route_inf_[sink_node].path_cost)) {
3939
rcv_path_manager.update_route_tree_set(rcv_path_data[sink_node]);
40-
t_heap out; // only the `index`, `prev_edge()`, and `path_data` fields of `out` are used after this function returns
40+
// Only the `index`, `prev_edge`, and `rcv_path_backward_delay` fields of `out`
41+
// are used after this function returns.
42+
RTExploredNode out;
4143
out.index = sink_node;
42-
out.set_prev_edge(rr_node_route_inf_[sink_node].prev_edge);
44+
out.prev_edge = rr_node_route_inf_[sink_node].prev_edge;
4345
if (rcv_path_manager.is_enabled()) {
4446
out.rcv_path_backward_delay = rcv_path_data[sink_node]->backward_delay;
4547
}
@@ -51,7 +53,7 @@ std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_conne
5153
clear_modified_rr_node_info();
5254
heap_.empty_heap();
5355
rcv_path_manager.empty_heap();
54-
return std::make_tuple(false, retry, t_heap());
56+
return std::make_tuple(false, retry, RTExploredNode());
5557
}
5658
}
5759

@@ -111,7 +113,7 @@ bool ConnectionRouter<Heap>::timing_driven_route_connection_common_setup(
111113
// which is spatially close to the sink is added to the heap.
112114
// Returns a tuple of <found_path?, retry_with_full_bb?, cheapest> */
113115
template<typename Heap>
114-
std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_connection_from_route_tree_high_fanout(
116+
std::tuple<bool, bool, RTExploredNode> ConnectionRouter<Heap>::timing_driven_route_connection_from_route_tree_high_fanout(
115117
const RouteTreeNode& rt_root,
116118
RRNodeId sink_node,
117119
const t_conn_cost_params& cost_params,
@@ -131,7 +133,7 @@ std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_conne
131133

132134
if (heap_.is_empty_heap()) {
133135
VTR_LOG("No source in route tree: %s\n", describe_unrouteable_connection(source_node, sink_node, is_flat_).c_str());
134-
return std::make_tuple(false, false, t_heap());
136+
return std::make_tuple(false, false, RTExploredNode());
135137
}
136138

137139
VTR_LOGV_DEBUG(router_debug_, " Routing to %d as high fanout net (BB: %d,%d,%d x %d,%d,%d)\n", sink_node,
@@ -164,13 +166,13 @@ std::tuple<bool, bool, t_heap> ConnectionRouter<Heap>::timing_driven_route_conne
164166

165167
heap_.empty_heap();
166168
rcv_path_manager.empty_heap();
167-
return std::make_tuple(false, retry_with_full_bb, t_heap());
169+
return std::make_tuple(false, retry_with_full_bb, RTExploredNode());
168170
}
169171

170172
rcv_path_manager.update_route_tree_set(rcv_path_data[sink_node]);
171-
t_heap out;
173+
RTExploredNode out;
172174
out.index = sink_node;
173-
out.set_prev_edge(rr_node_route_inf_[sink_node].prev_edge);
175+
out.prev_edge = rr_node_route_inf_[sink_node].prev_edge;
174176
if (rcv_path_manager.is_enabled()) {
175177
out.rcv_path_backward_delay = rcv_path_data[sink_node]->backward_delay;
176178
}
@@ -267,7 +269,7 @@ void ConnectionRouter<Heap>::timing_driven_route_connection_from_heap(RRNodeId s
267269

268270
// Find shortest paths from specified route tree to all nodes in the RR graph
269271
template<typename Heap>
270-
vtr::vector<RRNodeId, t_heap> ConnectionRouter<Heap>::timing_driven_find_all_shortest_paths_from_route_tree(
272+
vtr::vector<RRNodeId, RTExploredNode> ConnectionRouter<Heap>::timing_driven_find_all_shortest_paths_from_route_tree(
271273
const RouteTreeNode& rt_root,
272274
const t_conn_cost_params& cost_params,
273275
const t_bb& bounding_box,
@@ -295,10 +297,10 @@ vtr::vector<RRNodeId, t_heap> ConnectionRouter<Heap>::timing_driven_find_all_sho
295297
// Note that to re-use code used for the regular A*-based router we use a
296298
// no-operation lookahead which always returns zero.
297299
template<typename Heap>
298-
vtr::vector<RRNodeId, t_heap> ConnectionRouter<Heap>::timing_driven_find_all_shortest_paths_from_heap(
300+
vtr::vector<RRNodeId, RTExploredNode> ConnectionRouter<Heap>::timing_driven_find_all_shortest_paths_from_heap(
299301
const t_conn_cost_params& cost_params,
300302
const t_bb& bounding_box) {
301-
vtr::vector<RRNodeId, t_heap> cheapest_paths(rr_nodes_.size());
303+
vtr::vector<RRNodeId, RTExploredNode> cheapest_paths(rr_nodes_.size());
302304

303305
VTR_ASSERT_SAFE(heap_.is_valid());
304306

@@ -332,13 +334,13 @@ vtr::vector<RRNodeId, t_heap> ConnectionRouter<Heap>::timing_driven_find_all_sho
332334
bounding_box,
333335
t_bb());
334336

335-
if (cheapest_paths[inode].index == RRNodeId::INVALID() || cheapest_paths[inode].cost >= new_total_cost) {
336-
VTR_LOGV_DEBUG(router_debug_, " Better cost to node %d: %g (was %g)\n", inode, new_total_cost, cheapest_paths[inode].cost);
337-
// Only the `index` and `prev_edge()` fields of `cheapest_paths[inode]` are used after this function returns
337+
if (cheapest_paths[inode].index == RRNodeId::INVALID() || cheapest_paths[inode].total_cost >= new_total_cost) {
338+
VTR_LOGV_DEBUG(router_debug_, " Better cost to node %d: %g (was %g)\n", inode, new_total_cost, cheapest_paths[inode].total_cost);
339+
// Only the `index` and `prev_edge` fields of `cheapest_paths[inode]` are used after this function returns
338340
cheapest_paths[inode].index = inode;
339-
cheapest_paths[inode].set_prev_edge(rr_node_route_inf_[inode].prev_edge);
341+
cheapest_paths[inode].prev_edge = rr_node_route_inf_[inode].prev_edge;
340342
} else {
341-
VTR_LOGV_DEBUG(router_debug_, " Worse cost to node %d: %g (better %g)\n", inode, new_total_cost, cheapest_paths[inode].cost);
343+
VTR_LOGV_DEBUG(router_debug_, " Worse cost to node %d: %g (better %g)\n", inode, new_total_cost, cheapest_paths[inode].total_cost);
342344
}
343345
}
344346

@@ -368,7 +370,8 @@ void ConnectionRouter<Heap>::timing_driven_expand_cheapest(RRNodeId from_node,
368370
// `new_total_cost` is used here as an identifier to detect if the pair
369371
// (from_node or inode, new_total_cost) was the most recently pushed
370372
// element for the corresponding node.
371-
node_t current;
373+
RTExploredNode current;
374+
current.index = from_node;
372375
current.backward_path_cost = rr_node_route_inf_[from_node].backward_path_cost;
373376
current.prev_edge = rr_node_route_inf_[from_node].prev_edge;
374377
current.R_upstream = rr_node_R_upstream[from_node];
@@ -381,8 +384,7 @@ void ConnectionRouter<Heap>::timing_driven_expand_cheapest(RRNodeId from_node,
381384
static_cast<size_t>(rr_graph_->edge_src_node(current.prev_edge)),
382385
static_cast<size_t>(current.prev_edge));
383386

384-
timing_driven_expand_neighbours(current, cost_params, bounding_box, from_node,
385-
target_node, target_bb);
387+
timing_driven_expand_neighbours(current, cost_params, bounding_box, target_node, target_bb);
386388
} else {
387389
// Post-heap prune, do not re-explore from the current/new partial path as it
388390
// has worse cost than the best partial path to this node found so far
@@ -393,16 +395,15 @@ void ConnectionRouter<Heap>::timing_driven_expand_cheapest(RRNodeId from_node,
393395
}
394396

395397
template<typename Heap>
396-
void ConnectionRouter<Heap>::timing_driven_expand_neighbours(const node_t& current,
398+
void ConnectionRouter<Heap>::timing_driven_expand_neighbours(const RTExploredNode& current,
397399
const t_conn_cost_params& cost_params,
398400
const t_bb& bounding_box,
399-
RRNodeId from_node,
400401
RRNodeId target_node,
401402
const t_bb& target_bb) {
402403
/* Puts all the rr_nodes adjacent to current on the heap. */
403404

404405
// For each node associated with the current heap element, expand all of it's neighbors
405-
auto edges = rr_nodes_.edge_range(from_node);
406+
auto edges = rr_nodes_.edge_range(current.index);
406407

407408
// This is a simple prefetch that prefetches:
408409
// - RR node data reachable from this node
@@ -432,7 +433,6 @@ void ConnectionRouter<Heap>::timing_driven_expand_neighbours(const node_t& curre
432433
for (RREdgeId from_edge : edges) {
433434
RRNodeId to_node = rr_nodes_.edge_sink_node(from_edge);
434435
timing_driven_expand_neighbour(current,
435-
from_node,
436436
from_edge,
437437
to_node,
438438
cost_params,
@@ -446,8 +446,7 @@ void ConnectionRouter<Heap>::timing_driven_expand_neighbours(const node_t& curre
446446
// RR nodes outside the expanded bounding box specified in bounding_box are not added
447447
// to the heap.
448448
template<typename Heap>
449-
void ConnectionRouter<Heap>::timing_driven_expand_neighbour(const node_t& current,
450-
RRNodeId from_node,
449+
void ConnectionRouter<Heap>::timing_driven_expand_neighbour(const RTExploredNode& current,
451450
RREdgeId from_edge,
452451
RRNodeId to_node,
453452
const t_conn_cost_params& cost_params,
@@ -456,6 +455,8 @@ void ConnectionRouter<Heap>::timing_driven_expand_neighbour(const node_t& curren
456455
const t_bb& target_bb) {
457456
VTR_ASSERT(bounding_box.layer_max < g_vpr_ctx.device().grid.get_num_layers());
458457

458+
const RRNodeId& from_node = current.index;
459+
459460
// BB-pruning
460461
// Disable BB-pruning if RCV is enabled, as this can make it harder for circuits with high negative hold slack to resolve this
461462
// TODO: Only disable pruning if the net has negative hold slack, maybe go off budgets
@@ -521,7 +522,6 @@ void ConnectionRouter<Heap>::timing_driven_expand_neighbour(const node_t& curren
521522
if (!node_exists || !rcv_path_manager.is_enabled()) {
522523
timing_driven_add_to_heap(cost_params,
523524
current,
524-
from_node,
525525
to_node,
526526
from_edge,
527527
target_node);
@@ -531,15 +531,15 @@ void ConnectionRouter<Heap>::timing_driven_expand_neighbour(const node_t& curren
531531
// Add to_node to the heap, and also add any nodes which are connected by non-configurable edges
532532
template<typename Heap>
533533
void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params& cost_params,
534-
const node_t& current,
535-
RRNodeId from_node,
534+
const RTExploredNode& current,
536535
RRNodeId to_node,
537536
const RREdgeId from_edge,
538537
RRNodeId target_node) {
539538
const auto& device_ctx = g_vpr_ctx.device();
539+
const RRNodeId& from_node = current.index;
540540

541541
// Initialized to current
542-
node_t next;
542+
RTExploredNode next;
543543
next.R_upstream = current.R_upstream;
544544
next.prev_edge = from_edge;
545545
next.total_cost = std::numeric_limits<float>::infinity(); // Not used directly
@@ -566,7 +566,7 @@ void ConnectionRouter<Heap>::timing_driven_add_to_heap(const t_conn_cost_params&
566566
float new_total_cost = next.total_cost;
567567
float new_back_cost = next.backward_path_cost;
568568

569-
if (best_back_cost > new_back_cost) { // TODO: double check the correctness of expansion condition with RCV
569+
if (best_back_cost > new_back_cost) { // TODO: double check the performance of expansion condition
570570
VTR_LOGV_DEBUG(router_debug_, " Expanding to node %d (%s)\n", to_node,
571571
describe_rr_node(device_ctx.rr_graph,
572572
device_ctx.grid,
@@ -682,7 +682,7 @@ void ConnectionRouter<Heap>::set_rcv_enabled(bool enable) {
682682

683683
//Calculates the cost of reaching to_node
684684
template<typename Heap>
685-
void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(node_t* to,
685+
void ConnectionRouter<Heap>::evaluate_timing_driven_node_costs(RTExploredNode* to,
686686
const t_conn_cost_params& cost_params,
687687
RRNodeId from_node,
688688
RRNodeId to_node,

0 commit comments

Comments
 (0)