@@ -370,6 +370,7 @@ std::vector<std::pair<RRNodeId, int>> alloc_and_load_non_3d_sg_pattern_rr_node_i
370370 const DeviceContext& device_ctx = g_vpr_ctx.device ();
371371 const DeviceGrid& grid = device_ctx.grid ;
372372
373+ // Initialize matrices tracking the next free track number (ptc)
373374 vtr::NdMatrix<int , 3 > chanx_ptc ({grid.get_num_layers (), grid.width (), grid.height ()}, chan_width_inf.x_max );
374375 vtr::NdMatrix<int , 3 > chany_ptc ({grid.get_num_layers (), grid.width (), grid.height ()}, chan_width_inf.y_max );
375376
@@ -385,6 +386,7 @@ std::vector<std::pair<RRNodeId, int>> alloc_and_load_non_3d_sg_pattern_rr_node_i
385386 VTR_ASSERT_SAFE (src_loc.layer_num == dst_loc.layer_num );
386387 const int layer = src_loc.layer_num ;
387388
389+ // Step 1: Determine the channel type (CHANX/CHANY) and span coordinates
388390 if (dst_loc.x > src_loc.x ) {
389391 chan_type = e_rr_type::CHANX;
390392 ylow = yhigh = dst_loc.y ;
@@ -409,21 +411,29 @@ std::vector<std::pair<RRNodeId, int>> alloc_and_load_non_3d_sg_pattern_rr_node_i
409411 VTR_ASSERT (false );
410412 }
411413
414+ // Select the appropriate ptc matrix for this channel type
412415 vtr::NdMatrix<int , 3 >& ptc_matrix = (chan_type == e_rr_type::CHANX) ? chanx_ptc : chany_ptc;
413416
417+ // Step 2: Find the maximum next-free ptc value across all (x,y) cells
418+ // spanned by this SG link. We use the max to ensure that the chosen
419+ // ptc number is free along the entire length of the node
414420 int ptc = 0 ;
415421 for (int x = xlow; x <= xhigh; x++) {
416422 for (int y = ylow; y <= yhigh; y++) {
417423 ptc = std::max (ptc, ptc_matrix[layer][x][y]);
418424 }
419425 }
420426
427+ // Step 3: Sanity check: no existing node should occupy this (layer,x,y,ptc)
421428 VTR_ASSERT (rr_graph_builder.node_lookup ().find_nodes_in_range (layer, xlow, ylow, xhigh, yhigh, chan_type, ptc).empty ());
422429
430+ // Step 4: Allocate a new RR node ID and record its (inode, ptc)
423431 const RRNodeId inode = RRNodeId (index);
424432 node_indices.push_back ({inode, ptc});
425433 index++;
426434
435+ // Step 5: Register this node in the spatial lookup for every (x,y)
436+ // location it spans, and update ptc_matrix to mark this track as used.
427437 for (int x = xlow; x <= xhigh; x++) {
428438 for (int y = ylow; y <= yhigh; y++) {
429439 rr_graph_builder.node_lookup ().add_node (inode, layer, x, y, chan_type, ptc);
@@ -432,6 +442,7 @@ std::vector<std::pair<RRNodeId, int>> alloc_and_load_non_3d_sg_pattern_rr_node_i
432442 }
433443 }
434444
445+ // Later, another routine will use this info to add nodes and edges to RR graph
435446 return node_indices;
436447}
437448
0 commit comments