Skip to content

Commit 4c55bb1

Browse files
Fix integration with scatter-gather patterns
1 parent e83e47c commit 4c55bb1

File tree

2 files changed

+108
-46
lines changed

2 files changed

+108
-46
lines changed

vpr/src/route/rr_graph_generation/interposer_cut.cpp

Lines changed: 98 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -133,59 +133,113 @@ std::vector<RREdgeId> mark_interposer_cut_edges_for_removal(const RRGraphView& r
133133
return edges_to_be_removed;
134134
}
135135

136+
static void cut_chan_y_node(RRNodeId node, int cut_loc_y, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup, const std::vector<std::pair<RRNodeId, int>>& sg_node_indices) {
137+
bool is_sg_node = std::ranges::binary_search(std::views::keys(sg_node_indices), node, [](RRNodeId l, RRNodeId r) {return size_t(l) < size_t(r);});
138+
if (is_sg_node) {
139+
return;
140+
}
141+
142+
int x_high = rr_graph.node_xhigh(node);
143+
int x_low = rr_graph.node_xlow(node);
144+
145+
int y_high = rr_graph.node_yhigh(node);
146+
int y_low = rr_graph.node_ylow(node);
147+
148+
int layer = rr_graph.node_layer_low(node);
149+
150+
int ptc_num = rr_graph.node_ptc_num(node);
151+
152+
// No need to cut 1-length wires
153+
if (y_high == y_low) {
154+
return;
155+
}
156+
157+
if (!should_cut(y_low, y_high, cut_loc_y)) {
158+
return;
159+
}
160+
161+
if (rr_graph.node_direction(node) == Direction::INC) {
162+
// Anything above cut_loc_y shouldn't exist
163+
rr_graph_builder.set_node_coordinates(node, x_low, y_low, x_high, cut_loc_y);
164+
165+
// Do a loop from cut_loc_y to y_high and remove node from spatial lookup
166+
for (int y_loc = cut_loc_y + 1; y_loc <= y_high; y_loc++) {
167+
spatial_lookup.remove_node(node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
168+
}
169+
} else if (rr_graph.node_direction(node) == Direction::DEC) {
170+
// Anything below cut_loc_y shouldn't exist
171+
rr_graph_builder.set_node_coordinates(node, x_low, cut_loc_y + 1, x_high, y_high);
172+
173+
// Do a loop from y_low to cut_loc_y and remove node from spatial lookup
174+
for (int y_loc = y_low; y_loc <= cut_loc_y; y_loc++) {
175+
spatial_lookup.remove_node(node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
176+
}
177+
}
178+
}
179+
180+
static void cut_chan_x_node(RRNodeId node, int cut_loc_x, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup, const std::vector<std::pair<RRNodeId, int>>& sg_node_indices) {
181+
bool is_sg_node = std::ranges::binary_search(std::views::keys(sg_node_indices), node, [](RRNodeId l, RRNodeId r) {return size_t(l) < size_t(r);});
182+
if (is_sg_node) {
183+
return;
184+
}
185+
186+
int x_high = rr_graph.node_xhigh(node);
187+
int x_low = rr_graph.node_xlow(node);
188+
189+
int y_high = rr_graph.node_yhigh(node);
190+
int y_low = rr_graph.node_ylow(node);
191+
192+
int layer = rr_graph.node_layer_low(node);
193+
194+
int ptc_num = rr_graph.node_ptc_num(node);
195+
196+
// No need to cut 1-length wires
197+
if (x_high == x_low) {
198+
return;
199+
}
200+
201+
if (!should_cut(x_low, x_high, cut_loc_x)) {
202+
return;
203+
}
204+
205+
if (rr_graph.node_direction(node) == Direction::INC) {
206+
// Anything to the right of cut_loc_x shouldn't exist
207+
rr_graph_builder.set_node_coordinates(node, x_low, y_low, cut_loc_x, y_high);
208+
209+
// Do a loop from cut_loc_x to x_high and remove node from spatial lookup
210+
for (int x_loc = cut_loc_x + 1; x_loc <= x_high; x_loc++) {
211+
spatial_lookup.remove_node(node, layer, x_loc, y_low, e_rr_type::CHANX, ptc_num);
212+
}
213+
} else if (rr_graph.node_direction(node) == Direction::DEC) {
214+
// Anything to the left of cut_loc_x shouldn't exist
215+
rr_graph_builder.set_node_coordinates(node, cut_loc_x + 1, y_low, x_high, y_high);
216+
217+
// Do a loop from x_low to cut_loc_x - 1 and remove node from spatial lookup
218+
for (int x_loc = x_low; x_loc <= cut_loc_x; x_loc++) {
219+
spatial_lookup.remove_node(node, layer, x_loc, y_low, e_rr_type::CHANX, ptc_num);
220+
}
221+
}
222+
}
223+
136224
// TODO: workshop a better name
137225
void update_interposer_crossing_nodes_in_spatial_lookup_and_rr_graph_storage(const RRGraphView& rr_graph, const DeviceGrid& grid, RRGraphBuilder& rr_graph_builder, const std::vector<std::pair<RRNodeId, int>>& sg_node_indices) {
138226
VTR_ASSERT(std::is_sorted(sg_node_indices.begin(), sg_node_indices.end()));
139-
140227
RRSpatialLookup& spatial_lookup = rr_graph_builder.node_lookup();
141-
size_t num_sg = 0;
142228
for (size_t layer = 0; layer < grid.get_num_layers(); layer++) {
143229
for (int cut_loc_y : grid.get_horizontal_interposer_cuts()[layer]) {
144230
for (size_t x_loc = 0; x_loc < grid.width(); x_loc++) {
145231
std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes(layer, x_loc, cut_loc_y, e_rr_type::CHANY);
146232
for (RRNodeId node : channel_nodes) {
147-
148-
bool is_sg_node = std::ranges::binary_search(std::views::keys(sg_node_indices), node, [](RRNodeId l, RRNodeId r) {return size_t(l) < size_t(r);});
149-
if (is_sg_node) {
150-
num_sg++;
151-
continue;
152-
}
153-
154-
155-
int x_high = rr_graph.node_xhigh(node);
156-
int x_low = rr_graph.node_xlow(node);
157-
VTR_ASSERT(x_high == x_low);
158-
int y_high = rr_graph.node_yhigh(node);
159-
int y_low = rr_graph.node_ylow(node);
160-
int ptc_num = rr_graph.node_ptc_num(node);
161-
162-
163-
// No need to cut 1-length wires
164-
if (y_high == y_low) {
165-
continue;
166-
}
167-
168-
if (!should_cut(y_low, y_high, cut_loc_y)) {
169-
continue;
170-
}
171-
172-
if (rr_graph.node_direction(node) == Direction::INC) {
173-
// Anything above cut_loc_y shouldn't exist
174-
rr_graph_builder.set_node_coordinates(node, x_low, y_low, x_high, cut_loc_y);
175-
176-
// Do a loop from cut_loc_y to y_high and remove node from spatial lookup
177-
for (int y_loc = cut_loc_y + 1; y_loc <= y_high; y_loc++) {
178-
spatial_lookup.remove_node(node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
179-
}
180-
} else if (rr_graph.node_direction(node) == Direction::DEC) {
181-
// Anything below cut_loc_y shouldn't exist
182-
rr_graph_builder.set_node_coordinates(node, x_low, cut_loc_y + 1, x_high, y_high);
183-
184-
// Do a loop from y_low to cut_loc_y and remove node from spatial lookup
185-
for (int y_loc = y_low; y_loc <= cut_loc_y; y_loc++) {
186-
spatial_lookup.remove_node(node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
187-
}
188-
}
233+
cut_chan_y_node(node, cut_loc_y, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
234+
}
235+
}
236+
}
237+
238+
for (int cut_loc_x : grid.get_vertical_interposer_cuts()[layer]) {
239+
for (size_t y_loc = 0; y_loc < grid.height(); y_loc++) {
240+
std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes(layer, cut_loc_x, y_loc, e_rr_type::CHANX);
241+
for (RRNodeId node : channel_nodes) {
242+
cut_chan_x_node(node, cut_loc_x, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
189243
}
190244
}
191245
}

vpr/src/route/rr_graph_generation/rr_graph.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,11 @@ static void add_and_connect_non_3d_sg_links(RRGraphBuilder& rr_graph_builder,
21272127
chan_loc.y,
21282128
gather_chan_type,
21292129
gather_wire.wire_switchpoint.wire);
2130-
VTR_ASSERT(gather_node.is_valid());
2130+
// TODO: Some of the nodes that the scatter-gather patterns want to connect to have been cut because they were crossing the die
2131+
// For now we're ignoring those, but a proper fix should be investigated.
2132+
if (gather_node == RRNodeId::INVALID()) {
2133+
continue;
2134+
}
21312135
// Record deferred edge creation (gather_node --> sg_node)
21322136
non_3d_sg_rr_edges_to_create.emplace_back(gather_node, node_id, link.arch_wire_switch, false);
21332137
}
@@ -2146,7 +2150,11 @@ static void add_and_connect_non_3d_sg_links(RRGraphBuilder& rr_graph_builder,
21462150
scatter_chan_type,
21472151
scatter_wire.wire_switchpoint.wire);
21482152

2149-
VTR_ASSERT(scatter_node.is_valid());
2153+
// TODO: Some of the nodes that the scatter-gather patterns want to connect to have been cut because they were crossing the die
2154+
// For now we're ignoring those, but a proper fix should be investigated.
2155+
if (scatter_node == RRNodeId::INVALID()) {
2156+
continue;
2157+
}
21502158
// Determine which architecture switch this edge should use
21512159
int switch_index = chan_details[chan_loc.x][chan_loc.y][scatter_wire.wire_switchpoint.wire].arch_wire_switch();
21522160
// Record deferred edge creation (sg_node --> scatter_node)

0 commit comments

Comments
 (0)