44#include < ranges>
55
66#include " device_grid.h"
7+ #include " interposer_types.h"
78#include " rr_graph_builder.h"
89#include " rr_graph_fwd.h"
910#include " rr_graph_view.h"
@@ -143,39 +144,19 @@ std::vector<RREdgeId> mark_interposer_cut_edges_for_removal(const RRGraphView& r
143144}
144145
145146/* *
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);
155-
156- int x_high = rr_graph.node_xhigh (node);
157- int x_low = rr_graph.node_xlow (node);
158-
159- int y_high = rr_graph.node_yhigh (node);
160- int y_low = rr_graph.node_ylow (node);
161-
162- int layer = rr_graph.node_layer_low (node);
163-
164- int ptc_num = rr_graph.node_ptc_num (node);
165-
166- if (!should_cut (y_low, y_high, cut_loc_y)) {
167- return ;
168- }
169-
170- if (rr_graph.node_direction (node) == Direction::INC) {
147+ * @brief Update a CHANY node's bounding box in RRGraph and SpatialLookup entries. This function assumes that the channel node actually crosses the cut location and might not function correctly otherwise.
148+ * This is a low level function, you should use cut_channel_node that wraps this up in a nicer API.
149+ */
150+ static void cut_chan_y_node (RRNodeId node, int x_low, int y_low, int x_high, int y_high, int layer, int ptc_num, int cut_loc_y, Direction node_direction, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
151+ if (node_direction == Direction::INC) {
171152 // Anything above cut_loc_y shouldn't exist
172153 rr_graph_builder.set_node_coordinates (node, x_low, y_low, x_high, cut_loc_y);
173154
174155 // Do a loop from cut_loc_y to y_high and remove node from spatial lookup
175156 for (int y_loc = cut_loc_y + 1 ; y_loc <= y_high; y_loc++) {
176157 spatial_lookup.remove_node (node, layer, x_low, y_loc, e_rr_type::CHANY, ptc_num);
177158 }
178- } else if (rr_graph. node_direction (node) == Direction::DEC) {
159+ } else if (node_direction == Direction::DEC) {
179160 // Anything below cut_loc_y (inclusive) shouldn't exist
180161 rr_graph_builder.set_node_coordinates (node, x_low, cut_loc_y + 1 , x_high, y_high);
181162
@@ -189,39 +170,19 @@ static void cut_chan_y_node(RRNodeId node, int cut_loc_y, const RRGraphView& rr_
189170}
190171
191172/* *
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);
201-
202- int x_high = rr_graph.node_xhigh (node);
203- int x_low = rr_graph.node_xlow (node);
204-
205- int y_high = rr_graph.node_yhigh (node);
206- int y_low = rr_graph.node_ylow (node);
207-
208- int layer = rr_graph.node_layer_low (node);
209-
210- int ptc_num = rr_graph.node_ptc_num (node);
211-
212- if (!should_cut (x_low, x_high, cut_loc_x)) {
213- return ;
214- }
215-
216- if (rr_graph.node_direction (node) == Direction::INC) {
173+ * @brief Update a CHANX node's bounding box in RRGraph and SpatialLookup entries. This function assumes that the channel node actually crosses the cut location and might not function correctly otherwise.
174+ * This is a low level function, you should use cut_channel_node that wraps this up in a nicer API.
175+ */
176+ static void cut_chan_x_node (RRNodeId node, int x_low, int y_low, int x_high, int y_high, int layer, int ptc_num, int cut_loc_x, Direction node_direction, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
177+ if (node_direction == Direction::INC) {
217178 // Anything to the right of cut_loc_x shouldn't exist
218179 rr_graph_builder.set_node_coordinates (node, x_low, y_low, cut_loc_x, y_high);
219180
220181 // Do a loop from cut_loc_x to x_high and remove node from spatial lookup
221182 for (int x_loc = cut_loc_x + 1 ; x_loc <= x_high; x_loc++) {
222183 spatial_lookup.remove_node (node, layer, x_loc, y_low, e_rr_type::CHANX, ptc_num);
223184 }
224- } else if (rr_graph. node_direction (node) == Direction::DEC) {
185+ } else if (node_direction == Direction::DEC) {
225186 // Anything to the left of cut_loc_x (inclusive) shouldn't exist
226187 rr_graph_builder.set_node_coordinates (node, cut_loc_x + 1 , y_low, x_high, y_high);
227188
@@ -234,9 +195,54 @@ static void cut_chan_x_node(RRNodeId node, int cut_loc_x, const RRGraphView& rr_
234195 }
235196}
236197
198+ /* *
199+ * @brief Update a CHANX or CHANY node's bounding box in RRGraph and SpatialLookup entries if it crosses cut_loc
200+ *
201+ * @param node Channel segment RR graph node that might cross the interposer cut line
202+ * @param cut_loc location of vertical interposer cut line
203+ * @param interposer_cut_type Type of the interposer cut line (Horizontal or vertical)
204+ * @param sg_node_indices Sorted list of scatter-gather node IDs. We do not want to cut these nodes as they're allowed to cross an interposer cut line.
205+ * @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.
206+ */
207+ static void cut_channel_node (RRNodeId node, int cut_loc, e_interposer_cut_type interposer_cut_type, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup, const std::vector<std::pair<RRNodeId, int >>& sg_node_indices) {
208+ constexpr auto node_indice_compare = [](RRNodeId l, RRNodeId r) noexcept { return size_t (l) < size_t (r); };
209+ bool is_sg_node = std::ranges::binary_search (std::views::keys (sg_node_indices), node, node_indice_compare);
210+ if (is_sg_node) {
211+ return ;
212+ }
213+
214+ int x_high = rr_graph.node_xhigh (node);
215+ int x_low = rr_graph.node_xlow (node);
216+
217+ int y_high = rr_graph.node_yhigh (node);
218+ int y_low = rr_graph.node_ylow (node);
219+
220+ int layer = rr_graph.node_layer_low (node);
221+ int ptc_num = rr_graph.node_ptc_num (node);
222+ Direction node_direction = rr_graph.node_direction (node);
223+ e_rr_type node_type = rr_graph.node_type (node);
224+
225+ if (interposer_cut_type == e_interposer_cut_type::HORZ) {
226+ VTR_ASSERT (node_type == e_rr_type::CHANY);
227+ if (!should_cut (y_low, y_high, cut_loc)) {
228+ return ;
229+ }
230+ } else if (interposer_cut_type == e_interposer_cut_type::VERT) {
231+ VTR_ASSERT (node_type == e_rr_type::CHANX);
232+ if (!should_cut (x_low, x_high, cut_loc)) {
233+ return ;
234+ }
235+ }
236+
237+ if (interposer_cut_type == e_interposer_cut_type::HORZ) {
238+ cut_chan_y_node (node, x_low, y_low, x_high, y_high, layer, ptc_num, cut_loc, node_direction, rr_graph_builder, spatial_lookup);
239+ } else if (interposer_cut_type == e_interposer_cut_type::VERT) {
240+ cut_chan_x_node (node, x_low, y_low, x_high, y_high, layer, ptc_num, cut_loc, node_direction, rr_graph_builder, spatial_lookup);
241+ }
242+ }
243+
237244void 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) {
238245
239- constexpr auto node_indice_compare = [](RRNodeId l, RRNodeId r) noexcept { return size_t (l) < size_t (r); };
240246 VTR_ASSERT (std::is_sorted (sg_node_indices.begin (), sg_node_indices.end ()));
241247
242248 RRSpatialLookup& spatial_lookup = rr_graph_builder.node_lookup ();
@@ -245,12 +251,7 @@ void update_interposer_crossing_nodes_in_spatial_lookup_and_rr_graph_storage(con
245251 for (size_t x_loc = 0 ; x_loc < grid.width (); x_loc++) {
246252 std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes (layer, x_loc, cut_loc_y, e_rr_type::CHANY);
247253 for (RRNodeId node : channel_nodes) {
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- continue ;
251- }
252-
253- cut_chan_y_node (node, cut_loc_y, rr_graph, rr_graph_builder, spatial_lookup);
254+ cut_channel_node (node, cut_loc_y, e_interposer_cut_type::HORZ, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
254255 }
255256 }
256257 }
@@ -259,12 +260,7 @@ void update_interposer_crossing_nodes_in_spatial_lookup_and_rr_graph_storage(con
259260 for (size_t y_loc = 0 ; y_loc < grid.height (); y_loc++) {
260261 std::vector<RRNodeId> channel_nodes = spatial_lookup.find_channel_nodes (layer, cut_loc_x, y_loc, e_rr_type::CHANX);
261262 for (RRNodeId node : channel_nodes) {
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- continue ;
265- }
266-
267- cut_chan_x_node (node, cut_loc_x, rr_graph, rr_graph_builder, spatial_lookup);
263+ cut_channel_node (node, cut_loc_x, e_interposer_cut_type::VERT, rr_graph, rr_graph_builder, spatial_lookup, sg_node_indices);
268264 }
269265 }
270266 }
0 commit comments