@@ -378,6 +378,22 @@ static void build_rr_graph(e_graph_type graph_type,
378378static int get_delayless_switch_id (const t_det_routing_arch& det_routing_arch,
379379 bool load_rr_graph);
380380
381+ /* *
382+ * @brief Adds and connects non-3D scatter–gather (SG) links to the RR graph.
383+ *
384+ * For each bottleneck link, this function creates a corresponding RR node
385+ * representing the non-3D SG link, and records edges between the node and
386+ * gather and scatter wires. The edges are stored in `non_3d_sg_rr_edges_to_create`
387+ * for deferred creation.
388+ *
389+ * @param rr_graph_builder Reference to the RR graph builder.
390+ * @param sg_links List of scatter–gather bottleneck links.
391+ * @param sg_node_indices RR node IDs and track numbers for SG links.
392+ * @param chan_details_x Channel details for CHANX segments.
393+ * @param chan_details_y Channel details for CHANY segments.
394+ * @param num_seg_types_x Number of segment types in the X direction.
395+ * @param non_3d_sg_rr_edges_to_create Set collecting RR edges to create later.
396+ */
381397static void add_and_connect_non_3d_sg_links (RRGraphBuilder& rr_graph_builder,
382398 const std::vector<t_bottleneck_link>& sg_links,
383399 const std::vector<std::pair<RRNodeId, int >>& sg_node_indices,
@@ -2048,6 +2064,7 @@ static void add_and_connect_non_3d_sg_links(RRGraphBuilder& rr_graph_builder,
20482064 const t_chan_details& chan_details_y,
20492065 size_t num_seg_types_x,
20502066 t_rr_edge_info_set& non_3d_sg_rr_edges_to_create) {
2067+ // Each SG link should have a corresponding RR node index
20512068 VTR_ASSERT (sg_links.size () == sg_node_indices.size ());
20522069 const size_t num_links = sg_links.size ();
20532070
@@ -2060,6 +2077,8 @@ static void add_and_connect_non_3d_sg_links(RRGraphBuilder& rr_graph_builder,
20602077 const t_physical_tile_loc& src_loc = link.gather_loc ;
20612078 const t_physical_tile_loc& dst_loc = link.scatter_loc ;
20622079
2080+ // Step 1: Determine the link’s direction and its spatial span.
2081+ // SG links are confined to one layer (non-3D), but can run in X or Y.
20632082 VTR_ASSERT_SAFE (src_loc.layer_num == dst_loc.layer_num );
20642083 const int layer = src_loc.layer_num ;
20652084
@@ -2087,40 +2106,61 @@ static void add_and_connect_non_3d_sg_links(RRGraphBuilder& rr_graph_builder,
20872106 VTR_ASSERT (false );
20882107 }
20892108
2109+ // Retrieve the node ID and track number allocated earlier
20902110 const RRNodeId node_id = sg_node_indices[i].first ;
20912111 const int track_num = sg_node_indices[i].second ;
20922112
2113+ // Step 2: Assign coordinates
20932114 rr_graph_builder.set_node_layer (node_id, layer, layer);
20942115 rr_graph_builder.set_node_coordinates (node_id, xlow, ylow, xhigh, yhigh);
20952116 rr_graph_builder.set_node_capacity (node_id, 1 );
20962117
2118+ // Step 3: Set cost index based on segment type and orientation
20972119 const size_t cons_index = link.chan_type == e_rr_type::CHANX ? CHANX_COST_INDEX_START + link.parallel_segment_index
20982120 : CHANX_COST_INDEX_START + num_seg_types_x + link.parallel_segment_index ;
20992121 rr_graph_builder.set_node_cost_index (node_id, RRIndexedDataId (cons_index));
21002122
2123+ // Step 4: Assign electrical characteristics
21012124 float R = 0 ;
21022125 float C = 0 ;
21032126 rr_graph_builder.set_node_rc_index (node_id, NodeRCIndex (find_create_rr_rc_data (R, C, g_vpr_ctx.mutable_device ().rr_rc_data )));
2127+ // Step 5: Set node type, track number, and direction
21042128 rr_graph_builder.set_node_type (node_id, link.chan_type );
21052129 rr_graph_builder.set_node_track_num (node_id, track_num);
2106-
21072130 rr_graph_builder.set_node_direction (node_id, direction);
21082131
2132+ // Step 6: Add incoming edges from gather (fanin) channel wires
2133+ // Each gather wire connects to this SG link node using the SG wire switch.
21092134 for (const t_sg_candidate& gather_wire : link.gather_fanin_connections ) {
21102135 const t_physical_tile_loc& chan_loc = gather_wire.chan_loc .location ;
21112136 e_rr_type gather_chan_type = gather_wire.chan_loc .chan_type ;
2112- RRNodeId gather_node = rr_graph_builder.node_lookup ().find_node (chan_loc.layer_num , chan_loc.x , chan_loc.y , gather_chan_type, gather_wire.wire_switchpoint .wire );
21132137
2138+ // Locate the source RR node for this gather wire
2139+ RRNodeId gather_node = rr_graph_builder.node_lookup ().find_node (chan_loc.layer_num ,
2140+ chan_loc.x ,
2141+ chan_loc.y ,
2142+ gather_chan_type,
2143+ gather_wire.wire_switchpoint .wire );
2144+ // Record deferred edge creation (gather_node --> sg_node)
21142145 non_3d_sg_rr_edges_to_create.emplace_back (gather_node, node_id, link.arch_wire_switch , false );
21152146 }
21162147
2148+ // Step 7: Add outgoing edges to scatter (fanout) channel wires
2149+ // Each scatter wire connects from this SG link node outward.
21172150 for (const t_sg_candidate& scatter_wire : link.scatter_fanout_connections ) {
21182151 const t_physical_tile_loc& chan_loc = scatter_wire.chan_loc .location ;
21192152 e_rr_type scatter_chan_type = scatter_wire.chan_loc .chan_type ;
21202153 const t_chan_details& chan_details = (scatter_chan_type == e_rr_type::CHANX) ? chan_details_x : chan_details_y;
2121- RRNodeId scatter_node = rr_graph_builder.node_lookup ().find_node (chan_loc.layer_num , chan_loc.x , chan_loc.y , scatter_chan_type, scatter_wire.wire_switchpoint .wire );
21222154
2155+ // Locate the destination RR node for this scatter wire
2156+ RRNodeId scatter_node = rr_graph_builder.node_lookup ().find_node (chan_loc.layer_num ,
2157+ chan_loc.x ,
2158+ chan_loc.y ,
2159+ scatter_chan_type,
2160+ scatter_wire.wire_switchpoint .wire );
2161+ // Determine which architecture switch this edge should use
21232162 int switch_index = chan_details[chan_loc.x ][chan_loc.y ][scatter_wire.wire_switchpoint .wire ].arch_wire_switch ();
2163+ // Record deferred edge creation (sg_node --> scatter_node)
21242164 non_3d_sg_rr_edges_to_create.emplace_back (node_id, scatter_node, switch_index, false );
21252165 }
21262166 }
0 commit comments