Skip to content

Commit

Permalink
Merge pull request verilog-to-routing#2493 from verilog-to-routing/pe…
Browse files Browse the repository at this point in the history
…r_iteration

Parallelize cost updates & wirelength computation
  • Loading branch information
duck2 authored Feb 21, 2024
2 parents bcc45db + 02460a1 commit 109c5ad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions vpr/src/route/route_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@ void pathfinder_update_acc_cost_and_overuse_info(float acc_fac, OveruseInfo& ove
auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;
auto& route_ctx = g_vpr_ctx.mutable_routing();

#ifdef VPR_USE_TBB
tbb::combinable<size_t> overused_nodes(0), total_overuse(0), worst_overuse(0);
tbb::parallel_for_each(rr_graph.nodes().begin(), rr_graph.nodes().end(), [&](RRNodeId rr_id) {
int overuse = route_ctx.rr_node_route_inf[rr_id].occ() - rr_graph.node_capacity(rr_id);

// If overused, update the acc_cost and add this node to the overuse info
// If not, do nothing
if (overuse > 0) {
route_ctx.rr_node_route_inf[rr_id].acc_cost += overuse * acc_fac;

++overused_nodes.local();
total_overuse.local() += overuse;
worst_overuse.local() = std::max(worst_overuse.local(), size_t(overuse));
}
});

// Update overuse info
overuse_info.overused_nodes = overused_nodes.combine(std::plus<size_t>());
overuse_info.total_overuse = total_overuse.combine(std::plus<size_t>());
overuse_info.worst_overuse = worst_overuse.combine([](size_t a, size_t b) { return std::max(a, b); });
#else
size_t overused_nodes = 0, total_overuse = 0, worst_overuse = 0;

for (const RRNodeId& rr_id : rr_graph.nodes()) {
Expand All @@ -210,6 +232,7 @@ void pathfinder_update_acc_cost_and_overuse_info(float acc_fac, OveruseInfo& ove
overuse_info.overused_nodes = overused_nodes;
overuse_info.total_overuse = total_overuse;
overuse_info.worst_overuse = worst_overuse;
#endif
}

/** Update pathfinder cost of all nodes rooted at rt_node, including rt_node itself */
Expand Down
18 changes: 18 additions & 0 deletions vpr/src/route/route_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ WirelengthInfo calculate_wirelength_info(const Netlist<>& net_list, size_t avail

auto& route_ctx = g_vpr_ctx.routing();

#ifdef VPR_USE_TBB
tbb::combinable<size_t> thread_used_wirelength(0);

tbb::parallel_for_each(net_list.nets().begin(), net_list.nets().end(), [&](ParentNetId net_id) {
if (!net_list.net_is_ignored(net_id)
&& net_list.net_sinks(net_id).size() != 0 /* Globals don't count. */
&& route_ctx.route_trees[net_id]) {
int bends, wirelength, segments;
bool is_absorbed;
get_num_bends_and_length(net_id, &bends, &wirelength, &segments, &is_absorbed);

thread_used_wirelength.local() += wirelength;
}
});

used_wirelength = thread_used_wirelength.combine(std::plus<size_t>());
#else
for (auto net_id : net_list.nets()) {
if (!net_list.net_is_ignored(net_id)
&& net_list.net_sinks(net_id).size() != 0 /* Globals don't count. */
Expand All @@ -262,6 +279,7 @@ WirelengthInfo calculate_wirelength_info(const Netlist<>& net_list, size_t avail
used_wirelength += wirelength;
}
}
#endif

return WirelengthInfo(available_wirelength, used_wirelength);
}
Expand Down

0 comments on commit 109c5ad

Please sign in to comment.