From 02460a1a4c3cc781c1bf640431162f71fd7933ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fahrican=20Ko=C5=9Far?= Date: Wed, 21 Feb 2024 01:45:15 -0500 Subject: [PATCH] add parallel cost updates --- vpr/src/route/route_common.cpp | 23 +++++++++++++++++++++++ vpr/src/route/route_net.cpp | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/vpr/src/route/route_common.cpp b/vpr/src/route/route_common.cpp index ccc179320fb..6b5be2d9edf 100644 --- a/vpr/src/route/route_common.cpp +++ b/vpr/src/route/route_common.cpp @@ -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 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()); + overuse_info.total_overuse = total_overuse.combine(std::plus()); + 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()) { @@ -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 */ diff --git a/vpr/src/route/route_net.cpp b/vpr/src/route/route_net.cpp index 39ff6d06742..9be057ad983 100644 --- a/vpr/src/route/route_net.cpp +++ b/vpr/src/route/route_net.cpp @@ -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 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()); +#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. */ @@ -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); }