Skip to content

Commit 4b7f8fa

Browse files
litghostacomodi
authored andcommitted
Refactor lookahead computation.
Before on the A200T: > Computing connection box lookahead map took 31769.29 seconds (max_rss 45671.6 MiB, delta_rss +14486.3 MiB) After on the A200T: > Computing connection box lookahead map took 16791.79 seconds (max_rss 40113.6 MiB, delta_rss +8895.9 MiB) Signed-off-by: Keith Rothman <[email protected]>
1 parent 1f056de commit 4b7f8fa

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

vpr/src/route/connection_box_lookahead_map.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ struct SampleRegion {
8686

8787
template<typename Entry>
8888
static std::pair<float, int> run_dijkstra(int start_node_ind,
89+
std::vector<bool>* node_expanded,
90+
std::vector<util::Search_Path>* paths,
8991
RoutingCosts* routing_costs);
9092

9193
static std::vector<SampleRegion> find_sample_regions(int num_segments);
@@ -495,7 +497,7 @@ float ConnectionBoxMapLookahead::get_map_cost(int from_node_ind,
495497
template<typename Entry>
496498
static bool add_paths(int start_node_ind,
497499
Entry current,
498-
std::unordered_map<int, util::Search_Path>* paths,
500+
const std::vector<util::Search_Path>& paths,
499501
RoutingCosts* routing_costs) {
500502
auto& device_ctx = g_vpr_ctx.device();
501503
ConnectionBoxId box_id;
@@ -511,7 +513,8 @@ static bool add_paths(int start_node_ind,
511513

512514
// reconstruct the path
513515
std::vector<int> path;
514-
for (int i = (*paths)[node_ind].parent; i != start_node_ind; i = (*paths)[i].parent) {
516+
for (int i = paths[node_ind].parent; i != start_node_ind; i = paths[i].parent) {
517+
VTR_ASSERT(i != -1);
515518
path.push_back(i);
516519
}
517520
path.push_back(start_node_ind);
@@ -538,7 +541,7 @@ static bool add_paths(int start_node_ind,
538541

539542
if (*it != start_node_ind) {
540543
auto& parent_node = device_ctx.rr_nodes[parent];
541-
start_to_here = Entry(*it, parent_node.edge_switch((*paths)[*it].edge), &start_to_here);
544+
start_to_here = Entry(*it, parent_node.edge_switch(paths[*it].edge), &start_to_here);
542545
parent = *it;
543546
}
544547

@@ -573,6 +576,8 @@ static bool add_paths(int start_node_ind,
573576
* the number of paths from start_node_ind stored. */
574577
template<typename Entry>
575578
static std::pair<float, int> run_dijkstra(int start_node_ind,
579+
std::vector<bool>* node_expanded,
580+
std::vector<util::Search_Path>* paths,
576581
RoutingCosts* routing_costs) {
577582
auto& device_ctx = g_vpr_ctx.device();
578583
int path_count = 0;
@@ -584,12 +589,12 @@ static std::pair<float, int> run_dijkstra(int start_node_ind,
584589

585590
/* a list of boolean flags (one for each rr node) to figure out if a
586591
* certain node has already been expanded */
587-
std::vector<bool> node_expanded(device_ctx.rr_nodes.size(), false);
592+
std::fill(node_expanded->begin(), node_expanded->end(), false);
588593
/* For each node keep a list of the cost with which that node has been
589594
* visited (used to determine whether to push a candidate node onto the
590595
* expansion queue.
591596
* Also store the parent node so we can reconstruct a specific path. */
592-
std::unordered_map<int, util::Search_Path> paths;
597+
std::fill(paths->begin(), paths->end(), util::Search_Path{std::numeric_limits<float>::infinity(), -1, -1});
593598
/* a priority queue for expansion */
594599
std::priority_queue<Entry, std::vector<Entry>, std::greater<Entry>> pq;
595600

@@ -607,7 +612,7 @@ static std::pair<float, int> run_dijkstra(int start_node_ind,
607612
int node_ind = current.rr_node_ind;
608613

609614
/* check that we haven't already expanded from this node */
610-
if (node_expanded[node_ind]) {
615+
if ((*node_expanded)[node_ind]) {
611616
continue;
612617
}
613618

@@ -617,11 +622,11 @@ static std::pair<float, int> run_dijkstra(int start_node_ind,
617622
max_cost = current.cost();
618623

619624
path_count++;
620-
add_paths<Entry>(start_node_ind, current, &paths, routing_costs);
625+
add_paths<Entry>(start_node_ind, current, *paths, routing_costs);
621626
} else {
622627
util::expand_dijkstra_neighbours(device_ctx.rr_nodes,
623-
current, paths, node_expanded, pq);
624-
node_expanded[node_ind] = true;
628+
current, paths, node_expanded, &pq);
629+
(*node_expanded)[node_ind] = true;
625630
}
626631
}
627632
return std::make_pair(max_cost, path_count);
@@ -658,6 +663,8 @@ void ConnectionBoxMapLookahead::compute(const std::vector<t_segment_inf>& segmen
658663
RoutingCosts delay_costs;
659664
RoutingCosts base_costs;
660665
int total_path_count = 0;
666+
std::vector<bool> node_expanded(device_ctx.rr_nodes.size());
667+
std::vector<util::Search_Path> paths(device_ctx.rr_nodes.size());
661668

662669
for (auto& point : region.points) {
663670
// statistics
@@ -667,12 +674,12 @@ void ConnectionBoxMapLookahead::compute(const std::vector<t_segment_inf>& segmen
667674
int path_count = 0;
668675
for (auto node_ind : point.nodes) {
669676
{
670-
auto result = run_dijkstra<util::PQ_Entry_Delay>(node_ind, &delay_costs);
677+
auto result = run_dijkstra<util::PQ_Entry_Delay>(node_ind, &node_expanded, &paths, &delay_costs);
671678
max_delay_cost = std::max(max_delay_cost, result.first);
672679
path_count += result.second;
673680
}
674681
{
675-
auto result = run_dijkstra<util::PQ_Entry_Base_Cost>(node_ind, &base_costs);
682+
auto result = run_dijkstra<util::PQ_Entry_Base_Cost>(node_ind, &node_expanded, &paths, &base_costs);
676683
max_base_cost = std::max(max_base_cost, result.first);
677684
path_count += result.second;
678685
}

0 commit comments

Comments
 (0)