From 7bc80ac6149e4a4886bc0c8631014f9371fd2bc3 Mon Sep 17 00:00:00 2001 From: Nathan Shreve Date: Wed, 3 Jul 2024 19:33:44 -0400 Subject: [PATCH] set_sink_locs() now keeps track of tile types to avoid repeated calculations --- libs/librrgraph/src/base/rr_graph_utils.cpp | 31 ++++++++++++++++++++- libs/librrgraph/src/base/rr_graph_utils.h | 3 +- vpr/src/route/rr_graph.cpp | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libs/librrgraph/src/base/rr_graph_utils.cpp b/libs/librrgraph/src/base/rr_graph_utils.cpp index fec0dbdb1dd..c609ce92112 100644 --- a/libs/librrgraph/src/base/rr_graph_utils.cpp +++ b/libs/librrgraph/src/base/rr_graph_utils.cpp @@ -97,9 +97,13 @@ vtr::vector> get_fan_in_list(const RRGraphView& return node_fan_in_list; } -void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder) { +void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid) { auto node_fanins = get_fan_in_list(rr_graph); + // Keep track of offsets for SINKs for each tile type, to avoid repeated + // calculations + std::unordered_map>> physical_type_offsets; + // Iterate over all SINK nodes for (size_t node = 0; node < rr_graph.num_nodes(); ++node) { auto node_id = RRNodeId(node); @@ -113,6 +117,24 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder if (tile_width == 0 && tile_height == 0) continue; + // See if we have encountered this tile before + size_t tile_layer = rr_graph.node_layer(node_id); + size_t node_x = rr_graph.node_xhigh(node_id); + size_t node_y = rr_graph.node_yhigh(node_id); + std::string tile_name = grid.get_physical_type({(int)node_x, (int)node_y, (int)tile_layer})->name; + + size_t sink_ptc = rr_graph.node_ptc_num(node_id); + + if ((physical_type_offsets.find(tile_name) != physical_type_offsets.end()) && (physical_type_offsets[tile_name].find(sink_ptc) != physical_type_offsets[tile_name].end())) { /* We have seen this tile before */ + auto new_x = (short)((int)node_x + physical_type_offsets[tile_name].at(sink_ptc).x()); + auto new_y = (short)((int)node_y + physical_type_offsets[tile_name].at(sink_ptc).y()); + + // Set new coordinates + rr_graph_builder.set_node_coordinates(node_id, new_x, new_y, new_x, new_y); + + continue; + } + // The IPINs of the current SINK node std::unordered_set sink_ipins = {}; @@ -156,6 +178,13 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder auto x_avg = (short)round(std::accumulate(x_coords.begin(), x_coords.end(), 0.f) / (double)x_coords.size()); auto y_avg = (short)round(std::accumulate(y_coords.begin(), y_coords.end(), 0.f) / (double)y_coords.size()); + // Save offset for this tile type + if (physical_type_offsets.find(tile_name) == physical_type_offsets.end()) + physical_type_offsets[tile_name] = {}; + + physical_type_offsets[tile_name].insert({sink_ptc, {x_avg - (int)node_x, y_avg - (int)node_y}}); + + // Set new coordinates rr_graph_builder.set_node_coordinates(node_id, x_avg, y_avg, x_avg, y_avg); } } diff --git a/libs/librrgraph/src/base/rr_graph_utils.h b/libs/librrgraph/src/base/rr_graph_utils.h index 2f063201503..0222e8d06b9 100644 --- a/libs/librrgraph/src/base/rr_graph_utils.h +++ b/libs/librrgraph/src/base/rr_graph_utils.h @@ -14,6 +14,7 @@ #include "rr_graph_fwd.h" #include "rr_node_types.h" #include "rr_graph_view.h" +#include "device_grid.h" struct t_pin_chain_node { int pin_physical_num = OPEN; @@ -73,7 +74,7 @@ vtr::vector> get_fan_in_list(const RRGraphView& * determined. However, this is quite a big issue, as choosing to write out the RR graph now significantly increases * runtime! */ -void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder); +void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid); /** * @brief Returns the segment number (distance along the channel) of the connection box from from_rr_type (CHANX or diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp index 93cda957bfb..3ae69a6ca8f 100644 --- a/vpr/src/route/rr_graph.cpp +++ b/vpr/src/route/rr_graph.cpp @@ -1438,7 +1438,7 @@ static void build_rr_graph(const t_graph_type graph_type, } // Get better locations for SINK nodes - set_sink_locs(rr_graph, device_ctx.rr_graph_builder); + set_sink_locs(rr_graph, device_ctx.rr_graph_builder, device_ctx.grid); // We are done with building the RR Graph. Thus, we can clear the storages only used // to build the RR Graph