From d453bce2bab4841899e40345ce89d44837e1b4a7 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 12:37:39 -0400 Subject: [PATCH 01/12] pass t_chan_width by reference --- vpr/src/route/rr_graph.cpp | 2 +- vpr/src/route/rr_graph2.cpp | 6 +++--- vpr/src/route/rr_graph2.h | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp index 718a21ca9f..a0957a7695 100644 --- a/vpr/src/route/rr_graph.cpp +++ b/vpr/src/route/rr_graph.cpp @@ -1250,7 +1250,7 @@ static void build_rr_graph(e_graph_type graph_type, // Add routing resources to rr_graph lookup table alloc_and_load_rr_node_indices(device_ctx.rr_graph_builder, - &nodes_per_chan, + nodes_per_chan, grid, &num_rr_nodes, chan_details_x, diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 0c716b8dc3..0a304f3b92 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1441,7 +1441,7 @@ static void add_classes_spatial_lookup(RRGraphBuilder& rr_graph_builder, /* As the rr_indices builders modify a local copy of indices, use the local copy in the builder */ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, - const t_chan_width* nodes_per_chan, + const t_chan_width& nodes_per_chan, const DeviceGrid& grid, int* index, const t_chan_details& chan_details_x, @@ -1464,9 +1464,9 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, load_block_rr_indices(rr_graph_builder, grid, index, is_flat); /* Load the data for x and y channels */ - load_chan_rr_indices(nodes_per_chan->x_max, grid, grid.width(), grid.height(), + load_chan_rr_indices(nodes_per_chan.x_max, grid, grid.width(), grid.height(), e_rr_type::CHANX, chan_details_x, rr_graph_builder, index); - load_chan_rr_indices(nodes_per_chan->y_max, grid, grid.height(), grid.width(), + load_chan_rr_indices(nodes_per_chan.y_max, grid, grid.height(), grid.width(), e_rr_type::CHANY, chan_details_y, rr_graph_builder, index); } diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index b783e993d6..4922ec70ba 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -1,5 +1,5 @@ -#ifndef RR_GRAPH2_H -#define RR_GRAPH2_H +#pragma once + #include #include "build_switchblocks.h" @@ -15,7 +15,7 @@ /******************* Subroutines exported by rr_graph2.c *********************/ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, - const t_chan_width* nodes_per_chan, + const t_chan_width& nodes_per_chan, const DeviceGrid& grid, int* index, const t_chan_details& chan_details_x, @@ -252,4 +252,3 @@ void dump_track_to_pin_map(t_track_to_pin_lookup& track_to_pin_map, FILE* fp); inline int get_chan_width(enum e_side side, const t_chan_width& nodes_per_channel); -#endif From b11be1322c6abc1160b7002e4f56b9066a811003 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 12:43:07 -0400 Subject: [PATCH 02/12] doxygen comment for alloc_and_load_rr_node_indices --- vpr/src/route/rr_graph2.cpp | 4 ---- vpr/src/route/rr_graph2.h | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 0a304f3b92..07cc9f4ae9 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1439,7 +1439,6 @@ static void add_classes_spatial_lookup(RRGraphBuilder& rr_graph_builder, } } -/* As the rr_indices builders modify a local copy of indices, use the local copy in the builder */ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const t_chan_width& nodes_per_chan, const DeviceGrid& grid, @@ -1447,9 +1446,6 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const t_chan_details& chan_details_x, const t_chan_details& chan_details_y, bool is_flat) { - /* Allocates and loads all the structures needed for fast lookups of the - * index of an rr_node. rr_node_indices is a matrix containing the index - * of the *first* rr_node at a given (i,j) location. */ /* Alloc the lookup table */ for (e_rr_type rr_type : RR_TYPES) { diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index 4922ec70ba..55bf7304c9 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -14,6 +14,12 @@ /******************* Subroutines exported by rr_graph2.c *********************/ +/** + * @brief Allocates and populates data structures for efficient rr_node index lookups. + * + * This function sets up the `rr_node_indices` structure, which maps a physical location + * and type to the index of the first corresponding rr_node. + */ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const t_chan_width& nodes_per_chan, const DeviceGrid& grid, @@ -22,6 +28,7 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const t_chan_details& chan_details_y, bool is_flat); + /** * @brief allocates extra nodes within the RR graph to support 3D custom switch blocks for multi-die FPGAs * From 1a911ecfdbda28a65889b9a06d290409817fdf83 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 12:57:34 -0400 Subject: [PATCH 03/12] add doxygen comments for load_block_rr_indices() --- libs/librrgraph/src/base/rr_spatial_lookup.cpp | 2 +- vpr/src/route/rr_graph2.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.cpp b/libs/librrgraph/src/base/rr_spatial_lookup.cpp index aa9e17a1d5..7606da19a8 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.cpp +++ b/libs/librrgraph/src/base/rr_spatial_lookup.cpp @@ -338,7 +338,7 @@ void RRSpatialLookup::resize_nodes(int layer, || (x >= int(rr_node_indices_[type].dim_size(1))) || (y >= int(rr_node_indices_[type].dim_size(2))) || (size_t(side) >= rr_node_indices_[type].dim_size(3))) { - rr_node_indices_[type].resize({std::max(rr_node_indices_[type].dim_size(0),size_t(layer)+1), + rr_node_indices_[type].resize({std::max(rr_node_indices_[type].dim_size(0), size_t(layer)+1), std::max(rr_node_indices_[type].dim_size(1), size_t(x) + 1), std::max(rr_node_indices_[type].dim_size(2), size_t(y) + 1), std::max(rr_node_indices_[type].dim_size(3), size_t(side) + 1)}); diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 07cc9f4ae9..63ed87fcb3 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -33,6 +33,18 @@ static void load_chan_rr_indices(const int max_chan_width, RRGraphBuilder& rr_graph_builder, int* index); +/** + * @brief Assigns and loads rr_node indices for block-level routing resources (SOURCE, SINK, IPIN, OPIN). + * + * This function walks through the device grid and assigns unique rr_node indices to the routing resources + * associated with each block (tiles). + * + * For SINKs and SOURCEs, it uses side 0 by convention (since they have no geometric side). For IPINs and OPINs, + * it determines the correct sides based on the tile's position in the grid, following special rules for + * edge and corner tiles. + * + * The index counter is passed and updated as rr_nodes are added. + */ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, int* index, @@ -1347,6 +1359,7 @@ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder, } } } + static void add_pins_spatial_lookup(RRGraphBuilder& rr_graph_builder, t_physical_tile_type_ptr physical_type_ptr, const std::vector& pin_num_vec, From 328efeeffb80d222e095d9f7295d66ca88bd5cce Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 17:03:16 -0400 Subject: [PATCH 04/12] remove unused is_flat argument from alloc_and_load_rr_node_indices() and load_block_rr_indices() --- vpr/src/route/rr_graph.cpp | 3 +-- vpr/src/route/rr_graph2.cpp | 28 +++++++++++----------------- vpr/src/route/rr_graph2.h | 3 +-- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp index a0957a7695..9073fe2415 100644 --- a/vpr/src/route/rr_graph.cpp +++ b/vpr/src/route/rr_graph.cpp @@ -1254,8 +1254,7 @@ static void build_rr_graph(e_graph_type graph_type, grid, &num_rr_nodes, chan_details_x, - chan_details_y, - is_flat); + chan_details_y); size_t expected_node_count = num_rr_nodes; if (clock_modeling == DEDICATED_NETWORK) { diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 63ed87fcb3..32c0401210 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -47,8 +47,8 @@ static void load_chan_rr_indices(const int max_chan_width, */ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, - int* index, - bool is_flat); + int* index); + static void add_pins_spatial_lookup(RRGraphBuilder& rr_graph_builder, t_physical_tile_type_ptr physical_type_ptr, @@ -1091,6 +1091,7 @@ void dump_track_to_pin_map(t_track_to_pin_lookup& track_to_pin_map, } } } + static void load_chan_rr_indices(const int max_chan_width, const DeviceGrid& grid, const int chan_len, @@ -1106,11 +1107,12 @@ static void load_chan_rr_indices(const int max_chan_width, if (!device_ctx.inter_cluster_prog_routing_resources.at(layer)) { continue; } + for (int chan = 0; chan < num_chans - 1; ++chan) { for (int seg = 1; seg < chan_len - 1; ++seg) { /* Assign an inode to the starts of tracks */ - int x = (type == e_rr_type::CHANX ? seg : chan); - int y = (type == e_rr_type::CHANX ? chan : seg); + int x = type == e_rr_type::CHANX ? seg : chan; + int y = type == e_rr_type::CHANX ? chan : seg; const t_chan_seg_details* seg_details = chan_details[x][y].data(); /* Reserve nodes in lookup to save memory */ @@ -1130,8 +1132,7 @@ static void load_chan_rr_indices(const int max_chan_width, std::swap(node_x, node_y); } - /* If the start of the wire doesn't have an inode, - * assign one to it. */ + // If the start of the wire doesn't have an inode, assign one to it. RRNodeId inode = rr_graph_builder.node_lookup().find_node(layer, node_x, node_y, type, track); if (!inode) { inode = RRNodeId(*index); @@ -1268,8 +1269,7 @@ void alloc_and_load_inter_die_rr_node_indices(RRGraphBuilder& rr_graph_builder, */ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, - int* index, - bool /*is_flat*/) { + int* index) { //Walk through the grid assigning indices to SOURCE/SINK IPIN/OPIN for (int layer = 0; layer < grid.get_num_layers(); layer++) { for (int x = 0; x < (int)grid.width(); x++) { @@ -1457,20 +1457,14 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, int* index, const t_chan_details& chan_details_x, - const t_chan_details& chan_details_y, - bool is_flat) { - + const t_chan_details& chan_details_y) { /* Alloc the lookup table */ for (e_rr_type rr_type : RR_TYPES) { - if (rr_type == e_rr_type::CHANX) { - rr_graph_builder.node_lookup().resize_nodes(grid.get_num_layers(), grid.height(), grid.width(), rr_type, NUM_2D_SIDES); - } else { - rr_graph_builder.node_lookup().resize_nodes(grid.get_num_layers(), grid.width(), grid.height(), rr_type, NUM_2D_SIDES); - } + rr_graph_builder.node_lookup().resize_nodes(grid.get_num_layers(), grid.width(), grid.height(), rr_type, NUM_2D_SIDES); } /* Assign indices for block nodes */ - load_block_rr_indices(rr_graph_builder, grid, index, is_flat); + load_block_rr_indices(rr_graph_builder, grid, index); /* Load the data for x and y channels */ load_chan_rr_indices(nodes_per_chan.x_max, grid, grid.width(), grid.height(), diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index 55bf7304c9..066e63af0c 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -25,8 +25,7 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, int* index, const t_chan_details& chan_details_x, - const t_chan_details& chan_details_y, - bool is_flat); + const t_chan_details& chan_details_y); /** From a6c0049ac1630b9456993f10621f431179cf15a7 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 18:05:19 -0400 Subject: [PATCH 05/12] use (x, y) convention for CHANX instead of (y, x) --- libs/librrgraph/src/base/rr_graph_builder.cpp | 14 +++--- .../librrgraph/src/base/rr_spatial_lookup.cpp | 40 ++++------------- vpr/src/route/clock_network_builders.cpp | 3 +- vpr/src/route/rr_graph.cpp | 5 +-- vpr/src/route/rr_graph2.cpp | 44 +++++++++---------- vpr/src/route/rr_graph2.h | 4 +- 6 files changed, 39 insertions(+), 71 deletions(-) diff --git a/libs/librrgraph/src/base/rr_graph_builder.cpp b/libs/librrgraph/src/base/rr_graph_builder.cpp index 48852706c5..4bf9680322 100644 --- a/libs/librrgraph/src/base/rr_graph_builder.cpp +++ b/libs/librrgraph/src/base/rr_graph_builder.cpp @@ -31,31 +31,29 @@ void RRGraphBuilder::add_node_to_all_locs(RRNodeId node) { short node_layer = node_storage_.node_layer(node); short node_twist = node_storage_.node_ptc_twist(node); int node_offset = 0; + for (int ix = node_storage_.node_xlow(node); ix <= node_storage_.node_xhigh(node); ix++) { for (int iy = node_storage_.node_ylow(node); iy <= node_storage_.node_yhigh(node); iy++) { node_ptc_num += node_twist * node_offset; node_offset++; + switch (node_type) { case e_rr_type::SOURCE: case e_rr_type::SINK: case e_rr_type::CHANY: - node_lookup_.add_node(node, node_layer, ix, iy, node_type, node_ptc_num, TOTAL_2D_SIDES[0]); - break; case e_rr_type::CHANX: - /* Currently need to swap x and y for CHANX because of chan, seg convention - * TODO: Once the builders is reworked for use consistent (x, y) convention, - * the following swapping can be removed - */ - node_lookup_.add_node(node, node_layer, iy, ix, node_type, node_ptc_num, TOTAL_2D_SIDES[0]); + node_lookup_.add_node(node, node_layer, ix, iy, node_type, node_ptc_num, TOTAL_2D_SIDES[0]); break; + case e_rr_type::OPIN: case e_rr_type::IPIN: - for (const e_side& side : TOTAL_2D_SIDES) { + for (const e_side side : TOTAL_2D_SIDES) { if (node_storage_.is_node_on_specific_side(node, side)) { node_lookup_.add_node(node,node_layer, ix, iy, node_type, node_ptc_num, side); } } break; + default: VTR_LOG_ERROR("Invalid node type for node '%lu' in the routing resource graph file", size_t(node)); break; diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.cpp b/libs/librrgraph/src/base/rr_spatial_lookup.cpp index 7606da19a8..5faacf182e 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.cpp +++ b/libs/librrgraph/src/base/rr_spatial_lookup.cpp @@ -33,18 +33,6 @@ RRNodeId RRSpatialLookup::find_node(int layer, return RRNodeId::INVALID(); } - /* Currently need to swap x and y for CHANX because of chan, seg convention - * This is due to that the fast look-up builders uses (y, x) coordinate when - * registering a CHANX node in the look-up - * TODO: Once the builders is reworked for use consistent (x, y) convention, - * the following swapping can be removed - */ - size_t node_x = x; - size_t node_y = y; - if (type == e_rr_type::CHANX) { - std::swap(node_x, node_y); - } - VTR_ASSERT_SAFE(4 == rr_node_indices_[type].ndims()); /* Sanity check to ensure the layer, x, y, side and ptc are in range @@ -59,11 +47,11 @@ RRNodeId RRSpatialLookup::find_node(int layer, return RRNodeId::INVALID(); } - if (node_x >= rr_node_indices_[type].dim_size(1)) { + if (x >= rr_node_indices_[type].dim_size(1)) { return RRNodeId::INVALID(); } - if(node_y >= rr_node_indices_[type].dim_size(2)){ + if(y >= rr_node_indices_[type].dim_size(2)){ return RRNodeId::INVALID(); } @@ -71,11 +59,11 @@ RRNodeId RRSpatialLookup::find_node(int layer, return RRNodeId::INVALID(); } - if (size_t(ptc) >= rr_node_indices_[type][layer][node_x][node_y][node_side].size()) { + if (size_t(ptc) >= rr_node_indices_[type][layer][x][y][node_side].size()) { return RRNodeId::INVALID(); } - return rr_node_indices_[type][layer][node_x][node_y][node_side][ptc]; + return rr_node_indices_[type][layer][x][y][node_side][ptc]; } std::vector RRSpatialLookup::find_nodes_in_range(int layer, @@ -114,18 +102,6 @@ std::vector RRSpatialLookup::find_nodes(int layer, return nodes; } - /* Currently need to swap x and y for CHANX because of chan, seg convention - * This is due to that the fast look-up builders uses (y, x) coordinate when - * registering a CHANX node in the look-up - * TODO: Once the builders is reworked for use consistent (x, y) convention, - * the following swapping can be removed - */ - size_t node_x = x; - size_t node_y = y; - if (type == e_rr_type::CHANX) { - std::swap(node_x, node_y); - } - VTR_ASSERT_SAFE(4 == rr_node_indices_[type].ndims()); /* Sanity check to ensure the x, y, side are in range @@ -140,11 +116,11 @@ std::vector RRSpatialLookup::find_nodes(int layer, return nodes; } - if (node_x >= rr_node_indices_[type].dim_size(1)) { + if (x >= rr_node_indices_[type].dim_size(1)) { return nodes; } - if(node_y >= rr_node_indices_[type].dim_size(2)){ + if(y >= rr_node_indices_[type].dim_size(2)){ return nodes; } @@ -154,14 +130,14 @@ std::vector RRSpatialLookup::find_nodes(int layer, /* Reserve space to avoid memory fragmentation */ size_t num_nodes = 0; - for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) { + for (const auto& node : rr_node_indices_[type][layer][x][y][side]) { if (node.is_valid()) { num_nodes++; } } nodes.reserve(num_nodes); - for (const auto& node : rr_node_indices_[type][layer][node_x][node_y][side]) { + for (const auto& node : rr_node_indices_[type][layer][x][y][side]) { if (node.is_valid()) { nodes.emplace_back(node); } diff --git a/vpr/src/route/clock_network_builders.cpp b/vpr/src/route/clock_network_builders.cpp index 9347cf28cd..73932d99f3 100644 --- a/vpr/src/route/clock_network_builders.cpp +++ b/vpr/src/route/clock_network_builders.cpp @@ -372,8 +372,7 @@ int ClockRib::create_chanx_wire(int layer, /* TODO: Will replace these codes with an API add_node_to_all_locs() of RRGraphBuilder */ for (int ix = rr_graph.node_xlow(chanx_node); ix <= rr_graph.node_xhigh(chanx_node); ++ix) { for (int iy = rr_graph.node_ylow(chanx_node); iy <= rr_graph.node_yhigh(chanx_node); ++iy) { - //TODO: CHANX uses odd swapped x/y indices here. Will rework once rr_node_indices is shadowed - rr_graph_builder.node_lookup().add_node(chanx_node, layer, iy, ix, rr_graph.node_type(chanx_node), rr_graph.node_track_num(chanx_node)); + rr_graph_builder.node_lookup().add_node(chanx_node, layer, ix, iy, rr_graph.node_type(chanx_node), rr_graph.node_track_num(chanx_node)); } } diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp index 9073fe2415..3f77949d96 100644 --- a/vpr/src/route/rr_graph.cpp +++ b/vpr/src/route/rr_graph.cpp @@ -1336,11 +1336,10 @@ static void build_rr_graph(e_graph_type graph_type, */ if (grid.get_num_layers() > 1 && sb_type == CUSTOM) { //keep how many nodes each switchblock requires for each x,y location - auto extra_nodes_per_switchblock = get_number_track_to_track_inter_die_conn(sb_conn_map, custom_3d_sb_fanin_fanout, device_ctx.rr_graph_builder); + vtr::NdMatrix extra_nodes_per_switchblock = get_number_track_to_track_inter_die_conn(sb_conn_map, custom_3d_sb_fanin_fanout, device_ctx.rr_graph_builder); //allocate new nodes in each switchblocks - alloc_and_load_inter_die_rr_node_indices(device_ctx.rr_graph_builder, &nodes_per_chan, grid, extra_nodes_per_switchblock, &num_rr_nodes); + alloc_and_load_inter_die_rr_node_indices(device_ctx.rr_graph_builder, nodes_per_chan, grid, extra_nodes_per_switchblock, &num_rr_nodes); device_ctx.rr_graph_builder.resize_nodes(num_rr_nodes); - extra_nodes_per_switchblock.clear(); } /* START IPIN MAP */ diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 32c0401210..74576e692e 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1103,19 +1103,19 @@ static void load_chan_rr_indices(const int max_chan_width, const auto& device_ctx = g_vpr_ctx.device(); for (int layer = 0; layer < grid.get_num_layers(); layer++) { - /* Skip the current die if architecture file specifies that it doesn't require global resource routing */ + // Skip the current die if architecture file specifies that it doesn't require global resource routing if (!device_ctx.inter_cluster_prog_routing_resources.at(layer)) { continue; } for (int chan = 0; chan < num_chans - 1; ++chan) { for (int seg = 1; seg < chan_len - 1; ++seg) { - /* Assign an inode to the starts of tracks */ - int x = type == e_rr_type::CHANX ? seg : chan; - int y = type == e_rr_type::CHANX ? chan : seg; + // Assign an inode to the starts of tracks + const int x = (type == e_rr_type::CHANX) ? seg : chan; + const int y = (type == e_rr_type::CHANX) ? chan : seg; const t_chan_seg_details* seg_details = chan_details[x][y].data(); - /* Reserve nodes in lookup to save memory */ + // Reserve nodes in lookup to save memory rr_graph_builder.node_lookup().reserve_nodes(layer, chan, seg, type, max_chan_width); for (int track = 0; track < max_chan_width; ++track) { @@ -1124,24 +1124,19 @@ static void load_chan_rr_indices(const int max_chan_width, continue; int start = get_seg_start(seg_details, track, chan, seg); + int node_start_x = (type == e_rr_type::CHANX) ? start : chan; + int node_start_y = (type == e_rr_type::CHANX) ? chan : start; - /* TODO: Now we still use the (y, x) convention here for CHANX. Should rework later */ - int node_x = chan; - int node_y = start; - if (e_rr_type::CHANX == type) { - std::swap(node_x, node_y); - } - - // If the start of the wire doesn't have an inode, assign one to it. - RRNodeId inode = rr_graph_builder.node_lookup().find_node(layer, node_x, node_y, type, track); + // If the start of the wire doesn't have an RRNodeId, assign one to it. + RRNodeId inode = rr_graph_builder.node_lookup().find_node(layer, node_start_x, node_start_y, type, track); if (!inode) { inode = RRNodeId(*index); ++(*index); rr_graph_builder.node_lookup().add_node(inode, layer, chan, start, type, track); } - /* Assign inode of start of wire to current position */ - rr_graph_builder.node_lookup().add_node(inode, layer, chan, seg, type, track); + // Assign RRNodeId of start of wire to current position + rr_graph_builder.node_lookup().add_node(inode, layer, x, y, type, track); } } } @@ -1219,7 +1214,7 @@ vtr::NdMatrix get_number_track_to_track_inter_die_conn(t_sb_connection_m } void alloc_and_load_inter_die_rr_node_indices(RRGraphBuilder& rr_graph_builder, - const t_chan_width* nodes_per_chan, + const t_chan_width& nodes_per_chan, const DeviceGrid& grid, const vtr::NdMatrix& extra_nodes_per_switchblock, int* index) { @@ -1232,31 +1227,32 @@ void alloc_and_load_inter_die_rr_node_indices(RRGraphBuilder& rr_graph_builder, * 3) ptc = [max_chanx_width:max_chanx_width+number_of_connection-1] * 4) direction = NONE */ - auto& device_ctx = g_vpr_ctx.device(); + const auto& device_ctx = g_vpr_ctx.device(); for (int layer = 0; layer < grid.get_num_layers(); layer++) { /* Skip the current die if architecture file specifies that it doesn't have global resource routing */ if (!device_ctx.inter_cluster_prog_routing_resources.at(layer)) { continue; } + for (size_t y = 0; y < grid.height() - 1; ++y) { for (size_t x = 1; x < grid.width() - 1; ++x) { - //count how many track-to-track connection go from current layer to other layers + // count how many track-to-track connection go from current layer to other layers int conn_count = extra_nodes_per_switchblock[x][y]; - //skip if no connection is required + // skip if no connection is required if (conn_count == 0) { continue; } - //reserve extra nodes for inter-die track-to-track connection - rr_graph_builder.node_lookup().reserve_nodes(layer, y, x, e_rr_type::CHANX, conn_count + nodes_per_chan->max); + // reserve extra nodes for inter-die track-to-track connection + rr_graph_builder.node_lookup().reserve_nodes(layer, x, y, e_rr_type::CHANX, conn_count + nodes_per_chan.max); for (int rr_node_offset = 0; rr_node_offset < conn_count; rr_node_offset++) { - RRNodeId inode = rr_graph_builder.node_lookup().find_node(layer, x, y, e_rr_type::CHANX, nodes_per_chan->max + rr_node_offset); + RRNodeId inode = rr_graph_builder.node_lookup().find_node(layer, x, y, e_rr_type::CHANX, nodes_per_chan.max + rr_node_offset); if (!inode) { inode = RRNodeId(*index); ++(*index); - rr_graph_builder.node_lookup().add_node(inode, layer, y, x, e_rr_type::CHANX, nodes_per_chan->max + rr_node_offset); + rr_graph_builder.node_lookup().add_node(inode, layer, x, y, e_rr_type::CHANX, nodes_per_chan.max + rr_node_offset); } } } diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index 066e63af0c..2d05825238 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -29,7 +29,7 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, /** - * @brief allocates extra nodes within the RR graph to support 3D custom switch blocks for multi-die FPGAs + * @brief Allocates extra nodes within the RR graph to support 3D custom switch blocks for multi-die FPGAs * * @param rr_graph_builder RRGraphBuilder data structure which allows data modification on a routing resource graph * @param nodes_per_chan number of tracks per channel (x, y) @@ -39,7 +39,7 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, * @param index RRNodeId that should be assigned to add a new RR node to the RR graph */ void alloc_and_load_inter_die_rr_node_indices(RRGraphBuilder& rr_graph_builder, - const t_chan_width* nodes_per_chan, + const t_chan_width& nodes_per_chan, const DeviceGrid& grid, const vtr::NdMatrix& extra_nodes_per_switchblock, int* index); From da5ce31483354ade589ada44aec74ef199262084 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 18:12:04 -0400 Subject: [PATCH 06/12] make format --- vpr/src/route/rr_graph2.cpp | 1 - vpr/src/route/rr_graph2.h | 1 - 2 files changed, 2 deletions(-) diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 74576e692e..a389fbaf15 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -49,7 +49,6 @@ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder, const DeviceGrid& grid, int* index); - static void add_pins_spatial_lookup(RRGraphBuilder& rr_graph_builder, t_physical_tile_type_ptr physical_type_ptr, const std::vector& pin_num_vec, diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index 2d05825238..9948651259 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -27,7 +27,6 @@ void alloc_and_load_rr_node_indices(RRGraphBuilder& rr_graph_builder, const t_chan_details& chan_details_x, const t_chan_details& chan_details_y); - /** * @brief Allocates extra nodes within the RR graph to support 3D custom switch blocks for multi-die FPGAs * From 3f3a5a986a6cdefebdc0bd33d631e2dca81e9cff Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 18:20:46 -0400 Subject: [PATCH 07/12] cast x/y to size_t --- libs/librrgraph/src/base/rr_spatial_lookup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.cpp b/libs/librrgraph/src/base/rr_spatial_lookup.cpp index 5faacf182e..3b661b1eeb 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.cpp +++ b/libs/librrgraph/src/base/rr_spatial_lookup.cpp @@ -47,11 +47,11 @@ RRNodeId RRSpatialLookup::find_node(int layer, return RRNodeId::INVALID(); } - if (x >= rr_node_indices_[type].dim_size(1)) { + if (size_t(x) >= rr_node_indices_[type].dim_size(1)) { return RRNodeId::INVALID(); } - if(y >= rr_node_indices_[type].dim_size(2)){ + if (size_t(y) >= rr_node_indices_[type].dim_size(2)){ return RRNodeId::INVALID(); } From 052461dde10628274f4425727cc2179c5a3d698e Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Wed, 14 May 2025 18:22:45 -0400 Subject: [PATCH 08/12] get rid of warnings in RRSpatialLookup::find_nodes() --- libs/librrgraph/src/base/rr_spatial_lookup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.cpp b/libs/librrgraph/src/base/rr_spatial_lookup.cpp index 3b661b1eeb..d052936eb5 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.cpp +++ b/libs/librrgraph/src/base/rr_spatial_lookup.cpp @@ -116,11 +116,11 @@ std::vector RRSpatialLookup::find_nodes(int layer, return nodes; } - if (x >= rr_node_indices_[type].dim_size(1)) { + if (size_t(x) >= rr_node_indices_[type].dim_size(1)) { return nodes; } - if(y >= rr_node_indices_[type].dim_size(2)){ + if (size_t(y) >= rr_node_indices_[type].dim_size(2)){ return nodes; } From 095087738fc346eb99b1ceea04dfc3762bca790f Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Thu, 15 May 2025 11:03:41 -0400 Subject: [PATCH 09/12] add a closing ) to the text printed by node_coordinate_to_string() --- libs/librrgraph/src/base/rr_graph_view.h | 4 ++-- libs/librrgraph/src/base/rr_spatial_lookup.cpp | 9 +++------ libs/librrgraph/src/base/rr_spatial_lookup.h | 7 ++----- vpr/src/route/rr_graph2.cpp | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/libs/librrgraph/src/base/rr_graph_view.h b/libs/librrgraph/src/base/rr_graph_view.h index e420e46ddd..49a3f92bf9 100644 --- a/libs/librrgraph/src/base/rr_graph_view.h +++ b/libs/librrgraph/src/base/rr_graph_view.h @@ -351,7 +351,7 @@ class RRGraphView { start_x = " (" + std::to_string(node_xhigh(node)) + ","; //start coordinates have large value start_y = std::to_string(node_yhigh(node)) + ","; - start_layer_str = std::to_string(node_layer_num); + start_layer_str = std::to_string(node_layer_num) + ")"; end_x = " (" + std::to_string(node_xlow(node)) + ","; //end coordinates have smaller value end_y = std::to_string(node_ylow(node)) + ","; end_layer_str = std::to_string(node_layer_num) + ")"; @@ -360,7 +360,7 @@ class RRGraphView { else { // signal travels in increasing direction, stays at same point, or can travel both directions start_x = " (" + std::to_string(node_xlow(node)) + ","; //start coordinates have smaller value start_y = std::to_string(node_ylow(node)) + ","; - start_layer_str = std::to_string(node_layer_num); + start_layer_str = std::to_string(node_layer_num) + ")"; end_x = " (" + std::to_string(node_xhigh(node)) + ","; //end coordinates have larger value end_y = std::to_string(node_yhigh(node)) + ","; end_layer_str = std::to_string(node_layer_num) + ")"; //layer number diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.cpp b/libs/librrgraph/src/base/rr_spatial_lookup.cpp index d052936eb5..731dc147fd 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.cpp +++ b/libs/librrgraph/src/base/rr_spatial_lookup.cpp @@ -1,9 +1,6 @@ #include "vtr_assert.h" #include "rr_spatial_lookup.h" -RRSpatialLookup::RRSpatialLookup() { -} - RRNodeId RRSpatialLookup::find_node(int layer, int x, int y, @@ -130,14 +127,14 @@ std::vector RRSpatialLookup::find_nodes(int layer, /* Reserve space to avoid memory fragmentation */ size_t num_nodes = 0; - for (const auto& node : rr_node_indices_[type][layer][x][y][side]) { + for (RRNodeId node : rr_node_indices_[type][layer][x][y][side]) { if (node.is_valid()) { num_nodes++; } } nodes.reserve(num_nodes); - for (const auto& node : rr_node_indices_[type][layer][x][y][side]) { + for (RRNodeId node : rr_node_indices_[type][layer][x][y][side]) { if (node.is_valid()) { nodes.emplace_back(node); } @@ -328,7 +325,7 @@ void RRSpatialLookup::reorder(const vtr::vector& dest_order) for (size_t x = 0; x < grid.dim_size(1); x++) { for (size_t y = 0; y < grid.dim_size(2); y++) { for (size_t s = 0; s < grid.dim_size(3); s++) { - for (auto &node: grid[l][x][y][s]) { + for (RRNodeId &node: grid[l][x][y][s]) { if (node.is_valid()) { node = dest_order[node]; } diff --git a/libs/librrgraph/src/base/rr_spatial_lookup.h b/libs/librrgraph/src/base/rr_spatial_lookup.h index 1af0b6652a..c69f34b791 100644 --- a/libs/librrgraph/src/base/rr_spatial_lookup.h +++ b/libs/librrgraph/src/base/rr_spatial_lookup.h @@ -1,5 +1,4 @@ -#ifndef RR_SPATIAL_LOOKUP_H -#define RR_SPATIAL_LOOKUP_H +#pragma once /** * @file @@ -25,7 +24,7 @@ class RRSpatialLookup { /* -- Constructors -- */ public: /* Explicitly define the only way to create an object */ - explicit RRSpatialLookup(); + explicit RRSpatialLookup() = default; /* Disable copy constructors and copy assignment operator * This is to avoid accidental copy because it could be an expensive operation considering that the @@ -293,5 +292,3 @@ class RRSpatialLookup { /* Fast look-up: TODO: Should rework the data type. Currently it is based on a 3-dimensional array mater where some dimensions must always be accessed with a specific index. Such limitation should be overcome */ t_rr_node_indices rr_node_indices_; }; - -#endif diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index a389fbaf15..37d0a0bf0d 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1547,6 +1547,7 @@ bool verify_rr_node_indices(const DeviceGrid& grid, } else { nodes_from_lookup = rr_graph.node_lookup().find_grid_nodes_at_all_sides(l, x, y, rr_type); } + for (RRNodeId inode : nodes_from_lookup) { rr_node_counts[inode]++; From cb8a3cb715dab5656eda5e95bed92609e8d8eb12 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Thu, 15 May 2025 11:21:19 -0400 Subject: [PATCH 10/12] fix the x/y mismatch for CHANX nodes in rr_nodes and rr_node_indices --- vpr/src/route/rr_graph2.cpp | 11 +---------- vpr/src/route/rr_graph2.h | 9 +++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index 37d0a0bf0d..d015533e0c 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1131,7 +1131,7 @@ static void load_chan_rr_indices(const int max_chan_width, if (!inode) { inode = RRNodeId(*index); ++(*index); - rr_graph_builder.node_lookup().add_node(inode, layer, chan, start, type, track); + rr_graph_builder.node_lookup().add_node(inode, layer, node_start_x, node_start_y, type, track); } // Assign RRNodeId of start of wire to current position @@ -1516,15 +1516,6 @@ void alloc_and_load_intra_cluster_rr_node_indices(RRGraphBuilder& rr_graph_build } } -/** - * Validate the node look-up matches all the node-level information - * in the storage of a routing resource graph - * This function will check the following aspects: - * - The type of each node matches its type that is indexed in the node look-up - * - For bounding box (xlow, ylow, xhigh, yhigh) of each node is indexable in the node look-up - * - The number of unique indexable nodes in the node look up matches the number of nodes in the storage - * This ensures that every node in the storage is indexable and there are no hidden nodes in the look-up - */ bool verify_rr_node_indices(const DeviceGrid& grid, const RRGraphView& rr_graph, const vtr::vector& rr_indexed_data, diff --git a/vpr/src/route/rr_graph2.h b/vpr/src/route/rr_graph2.h index 9948651259..05e723470e 100644 --- a/vpr/src/route/rr_graph2.h +++ b/vpr/src/route/rr_graph2.h @@ -56,6 +56,15 @@ void alloc_and_load_intra_cluster_rr_node_indices(RRGraphBuilder& rr_graph_build const vtr::vector>& pin_chains_num, int* index); +/** + * Validate the node look-up matches all the node-level information + * in the storage of a routing resource graph + * This function will check the following aspects: + * - The type of each node matches its type that is indexed in the node look-up + * - For bounding box (xlow, ylow, xhigh, yhigh) of each node is indexable in the node look-up + * - The number of unique indexable nodes in the node look up matches the number of nodes in the storage + * This ensures that every node in the storage is indexable and there are no hidden nodes in the look-up + */ bool verify_rr_node_indices(const DeviceGrid& grid, const RRGraphView& rr_graph, const vtr::vector& rr_indexed_data, From 9297ad1edd56437f175ce2e9e9ad2dbed857ae80 Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Thu, 15 May 2025 12:36:52 -0400 Subject: [PATCH 11/12] reserve nodes using x/y instead of chan/seg --- vpr/src/route/rr_graph2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp index d015533e0c..7bc71b57a7 100644 --- a/vpr/src/route/rr_graph2.cpp +++ b/vpr/src/route/rr_graph2.cpp @@ -1115,7 +1115,7 @@ static void load_chan_rr_indices(const int max_chan_width, const t_chan_seg_details* seg_details = chan_details[x][y].data(); // Reserve nodes in lookup to save memory - rr_graph_builder.node_lookup().reserve_nodes(layer, chan, seg, type, max_chan_width); + rr_graph_builder.node_lookup().reserve_nodes(layer, x, y, type, max_chan_width); for (int track = 0; track < max_chan_width; ++track) { /* TODO: May let the length() == 0 case go through, to model muxes */ From 9017ac1af8e42d7d1aaec5d0a0ff822385339d3f Mon Sep 17 00:00:00 2001 From: soheilshahrouz Date: Thu, 15 May 2025 14:10:02 -0400 Subject: [PATCH 12/12] resize node lookup for CHANX nodes in RR graph serializer --- libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h b/libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h index 1ee3676dda..fe3f5a6693 100644 --- a/libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h +++ b/libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h @@ -1848,16 +1848,11 @@ class RrGraphSerializer final : public uxsd::RrGraphBase { /* Alloc the lookup table */ for (e_rr_type rr_type : RR_TYPES) { - if (rr_type == e_rr_type::CHANX) { - rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.height(), grid_.width(), rr_type, NUM_2D_SIDES); - } else { - rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.width(), grid_.height(), rr_type, NUM_2D_SIDES); - } + rr_graph_builder.node_lookup().resize_nodes(grid_.get_num_layers(), grid_.width(), grid_.height(), rr_type, NUM_2D_SIDES); } /* Add the correct node into the vector */ - for (size_t inode = 0; inode < rr_nodes_->size(); inode++) { - auto node = (*rr_nodes_)[inode]; + for (const t_rr_node& node : *rr_nodes_) { rr_graph_builder.add_node_to_all_locs(node.id()); } }