Skip to content

Commit f33c14f

Browse files
author
Nathan Shreve
committed
Merge branch 'improve_map_lookahead' into improve_map_lookahead_exp0
2 parents 581e588 + b1cf295 commit f33c14f

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

libs/librrgraph/src/base/rr_graph_utils.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ vtr::vector<RRNodeId, std::vector<RREdgeId>> get_fan_in_list(const RRGraphView&
9797
return node_fan_in_list;
9898
}
9999

100-
void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder) {
100+
void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid) {
101101
auto node_fanins = get_fan_in_list(rr_graph);
102102

103-
// We could keep track of xy-"offsets" by tile and ptc number; however, this results
104-
// in a ~10% increase in runtime to build the RR graph (on vtr benchmarks)
103+
// Keep track of offsets for SINKs for each tile type, to avoid repeated
104+
// calculations
105+
using Offset = vtr::Point<size_t>;
106+
std::unordered_map<t_physical_tile_type_ptr, std::unordered_map<size_t, Offset>> physical_type_offsets;
105107

106108
// Iterate over all SINK nodes
107109
for (size_t node = 0; node < rr_graph.num_nodes(); ++node) {
@@ -110,17 +112,36 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
110112
if (rr_graph.node_type((RRNodeId)node_id) != e_rr_type::SINK)
111113
continue;
112114

113-
int tile_xlow = rr_graph.node_xlow(node_id);
114-
int tile_xhigh = rr_graph.node_xhigh(node_id);
115-
int tile_ylow = rr_graph.node_ylow(node_id);
116-
int tile_yhigh = rr_graph.node_yhigh(node_id);
115+
// Skip 1x1 tiles
116+
size_t tile_xlow = rr_graph.node_xlow(node_id);
117+
size_t tile_ylow = rr_graph.node_ylow(node_id);
118+
size_t tile_xhigh = rr_graph.node_xhigh(node_id);
119+
size_t tile_yhigh = rr_graph.node_yhigh(node_id);
117120

118-
int tile_width = tile_xhigh - tile_xlow;
119-
int tile_height = tile_yhigh - tile_ylow;
121+
size_t tile_width = tile_xhigh - tile_xlow;
122+
size_t tile_height = tile_yhigh - tile_ylow;
120123

121124
if (tile_width == 0 && tile_height == 0)
122125
continue;
123126

127+
// See if we have encountered this tile type/ptc combo before, and used saved offset if so
128+
size_t tile_layer = rr_graph.node_layer(node_id);
129+
t_physical_tile_type_ptr tile_type = grid.get_physical_type({(int)tile_xlow, (int)tile_ylow, (int)tile_layer});
130+
131+
size_t sink_ptc = rr_graph.node_ptc_num(node_id);
132+
133+
if ((physical_type_offsets.find(tile_type) != physical_type_offsets.end()) && (physical_type_offsets[tile_type].find(sink_ptc) != physical_type_offsets[tile_type].end())) {
134+
auto new_x = (short)((int)tile_xlow + physical_type_offsets[tile_type].at(sink_ptc).x());
135+
auto new_y = (short)((int)tile_ylow + physical_type_offsets[tile_type].at(sink_ptc).y());
136+
137+
// Set new coordinates
138+
rr_graph_builder.set_node_coordinates(node_id, new_x, new_y, new_x, new_y);
139+
140+
continue;
141+
}
142+
143+
/* We have not seen this tile type/ptc combo before */
144+
124145
// The IPINs of the current SINK node
125146
std::unordered_set<RRNodeId> sink_ipins = {};
126147

@@ -132,8 +153,8 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
132153
VTR_ASSERT_SAFE(rr_graph.node_type(pin) == e_rr_type::IPIN);
133154

134155
// Make sure IPIN in the same cluster as origin
135-
int curr_x = rr_graph.node_xlow(pin);
136-
int curr_y = rr_graph.node_ylow(pin);
156+
size_t curr_x = rr_graph.node_xlow(pin);
157+
size_t curr_y = rr_graph.node_ylow(pin);
137158
if ((curr_x < tile_xlow) || (curr_x > tile_xhigh) || (curr_y < tile_ylow) || (curr_y > tile_yhigh))
138159
continue;
139160

@@ -151,8 +172,8 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
151172

152173
// Add coordinates of each "cluster-edge" pin to vectors
153174
for (const auto& pin : sink_ipins) {
154-
int pin_x = rr_graph.node_xlow(pin);
155-
int pin_y = rr_graph.node_ylow(pin);
175+
size_t pin_x = rr_graph.node_xlow(pin);
176+
size_t pin_y = rr_graph.node_ylow(pin);
156177

157178
VTR_ASSERT_SAFE(pin_x == rr_graph.node_xhigh(pin));
158179
VTR_ASSERT_SAFE(pin_y == rr_graph.node_yhigh(pin));
@@ -177,6 +198,13 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
177198
}
178199
}
179200

201+
// Save offset for this tile/ptc combo
202+
if (physical_type_offsets.find(tile_type) == physical_type_offsets.end())
203+
physical_type_offsets[tile_type] = {};
204+
205+
physical_type_offsets[tile_type].insert({sink_ptc, {x_avg - tile_xlow, y_avg - tile_ylow}});
206+
207+
// Set new coordinates
180208
rr_graph_builder.set_node_coordinates(node_id, x_avg, y_avg, x_avg, y_avg);
181209
}
182210
}

libs/librrgraph/src/base/rr_graph_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "rr_graph_fwd.h"
1515
#include "rr_node_types.h"
1616
#include "rr_graph_view.h"
17+
#include "device_grid.h"
1718

1819
struct t_pin_chain_node {
1920
int pin_physical_num = OPEN;
@@ -73,7 +74,7 @@ vtr::vector<RRNodeId, std::vector<RREdgeId>> get_fan_in_list(const RRGraphView&
7374
* determined. However, this is quite a big issue, as choosing to write out the RR graph now significantly increases
7475
* runtime!
7576
*/
76-
void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder);
77+
void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid);
7778

7879
/**
7980
* @brief Returns the segment number (distance along the channel) of the connection box from from_rr_type (CHANX or

vpr/src/route/rr_graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ static void build_rr_graph(const t_graph_type graph_type,
14381438
}
14391439

14401440
// Get better locations for SINK nodes
1441-
set_sink_locs(rr_graph, device_ctx.rr_graph_builder);
1441+
set_sink_locs(rr_graph, device_ctx.rr_graph_builder, device_ctx.grid);
14421442

14431443
// We are done with building the RR Graph. Thus, we can clear the storages only used
14441444
// to build the RR Graph

0 commit comments

Comments
 (0)