1414
1515#include " interposer_cut.h"
1616
17- static bool should_cut (int src_start_loc, int sink_start_loc, int cut_loc) {
18- int src_delta = src_start_loc - cut_loc;
19- int sink_delta = sink_start_loc - cut_loc;
17+ /* *
18+ * @brief Takes location of a source and a sink and determines wether it crosses cut_loc or not. For example, the interval (1, 4) is cut by 3, while it is not cut by 5 or 0.
19+ */
20+ static bool should_cut (int src_loc, int sink_loc, int cut_loc) {
21+ int src_delta = src_loc - cut_loc;
22+ int sink_delta = sink_loc - cut_loc;
2023
2124 // Same sign means that both sink and source are on the same side of this cut
2225 if ((src_delta <= 0 && sink_delta <= 0 ) || (src_delta > 0 && sink_delta > 0 )) {
@@ -26,6 +29,9 @@ static bool should_cut(int src_start_loc, int sink_start_loc, int cut_loc) {
2629 }
2730}
2831
32+ /* *
33+ * @brief Calculates the starting x point of node based on it's directionality.
34+ */
2935static short node_xstart (const RRGraphView& rr_graph, RRNodeId node) {
3036 // Return early for OPIN and IPIN types (Some BIDIR pins would trigger the assertion below)
3137 if (rr_graph.node_type (node) == e_rr_type::OPIN || rr_graph.node_type (node) == e_rr_type::IPIN) {
@@ -57,6 +63,9 @@ static short node_xstart(const RRGraphView& rr_graph, RRNodeId node) {
5763 }
5864}
5965
66+ /* *
67+ * @brief Calculates the starting y point of node based on it's directionality.
68+ */
6069static short node_ystart (const RRGraphView& rr_graph, RRNodeId node) {
6170 // Return early for OPIN and IPIN types (Some BIDIR pins would trigger the assertion below)
6271 if (rr_graph.node_type (node) == e_rr_type::OPIN || rr_graph.node_type (node) == e_rr_type::IPIN) {
@@ -133,11 +142,16 @@ std::vector<RREdgeId> mark_interposer_cut_edges_for_removal(const RRGraphView& r
133142 return edges_to_be_removed;
134143}
135144
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- }
145+ /* *
146+ * @brief Update a CHANY node's bounding box in RRGraph and SpatialLookup entries if it crosses cut_loc_y
147+ *
148+ * @param node CHANY RR graph node that might cross the interposer cut line
149+ * @param cut_loc_y Y location of horizontal interposer cut line
150+ * @param sg_node_indices List of scatter-gather node IDs. We do not want to cut these nodes as they're allowed to cross an interposer cut line.
151+ * @note This function is very similar to cut_chan_x_node. If you're modifying this you probably also want to modify that function too.
152+ */
153+ static void cut_chan_y_node (RRNodeId node, int cut_loc_y, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
154+ VTR_ASSERT_SAFE (rr_graph.node_type (node) == e_rr_type::CHANY);
141155
142156 int x_high = rr_graph.node_xhigh (node);
143157 int x_low = rr_graph.node_xlow (node);
@@ -149,11 +163,6 @@ static void cut_chan_y_node(RRNodeId node, int cut_loc_y, const RRGraphView& rr_
149163
150164 int ptc_num = rr_graph.node_ptc_num (node);
151165
152- // No need to cut 1-length wires
153- if (y_high == y_low) {
154- return ;
155- }
156-
157166 if (!should_cut (y_low, y_high, cut_loc_y)) {
158167 return ;
159168 }
@@ -167,21 +176,28 @@ static void cut_chan_y_node(RRNodeId node, int cut_loc_y, const RRGraphView& rr_
167176 spatial_lookup.remove_node (node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
168177 }
169178 } else if (rr_graph.node_direction (node) == Direction::DEC) {
170- // Anything below cut_loc_y shouldn't exist
179+ // Anything below cut_loc_y (inclusive) shouldn't exist
171180 rr_graph_builder.set_node_coordinates (node, x_low, cut_loc_y + 1 , x_high, y_high);
172181
173182 // Do a loop from y_low to cut_loc_y and remove node from spatial lookup
174183 for (int y_loc = y_low; y_loc <= cut_loc_y; y_loc++) {
175184 spatial_lookup.remove_node (node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
176185 }
186+ } else {
187+ VTR_ASSERT_MSG (false , " Bidirectional routing is not supported for interposer architectures." );
177188 }
178189}
179190
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- }
191+ /* *
192+ * @brief Update a CHANX node's bounding box in RRGraph and SpatialLookup entries if it crosses cut_loc_x
193+ *
194+ * @param node CHANX RR graph node that might cross the interposer cut line
195+ * @param cut_loc_y X location of vertical interposer cut line
196+ * @param sg_node_indices List of scatter-gather node IDs. We do not want to cut these nodes as they're allowed to cross an interposer cut line.
197+ * @note This function is very similar to cut_chan_y_node. If you're modifying this you probably also want to modify that function too.
198+ */
199+ static void cut_chan_x_node (RRNodeId node, int cut_loc_x, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
200+ VTR_ASSERT_SAFE (rr_graph.node_type (node) == e_rr_type::CHANX);
185201
186202 int x_high = rr_graph.node_xhigh (node);
187203 int x_low = rr_graph.node_xlow (node);
@@ -193,11 +209,6 @@ static void cut_chan_x_node(RRNodeId node, int cut_loc_x, const RRGraphView& rr_
193209
194210 int ptc_num = rr_graph.node_ptc_num (node);
195211
196- // No need to cut 1-length wires
197- if (x_high == x_low) {
198- return ;
199- }
200-
201212 if (!should_cut (x_low, x_high, cut_loc_x)) {
202213 return ;
203214 }
@@ -211,26 +222,35 @@ static void cut_chan_x_node(RRNodeId node, int cut_loc_x, const RRGraphView& rr_
211222 spatial_lookup.remove_node (node, layer, x_loc, y_low, e_rr_type::CHANX, ptc_num);
212223 }
213224 } else if (rr_graph.node_direction (node) == Direction::DEC) {
214- // Anything to the left of cut_loc_x shouldn't exist
225+ // Anything to the left of cut_loc_x (inclusive) shouldn't exist
215226 rr_graph_builder.set_node_coordinates (node, cut_loc_x + 1 , y_low, x_high, y_high);
216227
217228 // Do a loop from x_low to cut_loc_x - 1 and remove node from spatial lookup
218229 for (int x_loc = x_low; x_loc <= cut_loc_x; x_loc++) {
219230 spatial_lookup.remove_node (node, layer, x_loc, y_low, e_rr_type::CHANX, ptc_num);
220231 }
232+ } else {
233+ VTR_ASSERT_MSG (false , " Bidirectional routing is not supported for interposer architectures." );
221234 }
222235}
223236
224- // TODO: workshop a better name
225237void 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) {
238+
239+ constexpr auto node_indice_compare = [](RRNodeId l, RRNodeId r) noexcept { return size_t (l) < size_t (r); };
226240 VTR_ASSERT (std::is_sorted (sg_node_indices.begin (), sg_node_indices.end ()));
241+
227242 RRSpatialLookup& spatial_lookup = rr_graph_builder.node_lookup ();
228243 for (size_t layer = 0 ; layer < grid.get_num_layers (); layer++) {
229244 for (int cut_loc_y : grid.get_horizontal_interposer_cuts ()[layer]) {
230245 for (size_t x_loc = 0 ; x_loc < grid.width (); x_loc++) {
231246 std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes (layer, x_loc, cut_loc_y, e_rr_type::CHANY);
232247 for (RRNodeId node : channel_nodes) {
233- cut_chan_y_node (node, cut_loc_y, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
248+ bool is_sg_node = std::ranges::binary_search (std::views::keys (sg_node_indices), node, node_indice_compare);
249+ if (is_sg_node) {
250+ return ;
251+ }
252+
253+ cut_chan_y_node (node, cut_loc_y, rr_graph, rr_graph_builder, spatial_lookup);
234254 }
235255 }
236256 }
@@ -239,7 +259,12 @@ void update_interposer_crossing_nodes_in_spatial_lookup_and_rr_graph_storage(con
239259 for (size_t y_loc = 0 ; y_loc < grid.height (); y_loc++) {
240260 std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes (layer, cut_loc_x, y_loc, e_rr_type::CHANX);
241261 for (RRNodeId node : channel_nodes) {
242- cut_chan_x_node (node, cut_loc_x, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
262+ bool is_sg_node = std::ranges::binary_search (std::views::keys (sg_node_indices), node, node_indice_compare);
263+ if (is_sg_node) {
264+ return ;
265+ }
266+
267+ cut_chan_x_node (node, cut_loc_x, rr_graph, rr_graph_builder, spatial_lookup);
243268 }
244269 }
245270 }
0 commit comments