@@ -92,7 +92,7 @@ static void get_switchblocks_edges(RRGraphBuilder& rr_graph_builder,
9292 const int switch_override,
9393 const int custom_3d_sb_fanin_fanout,
9494 const int delayless_switch,
95- t_sb_connection_map* sb_conn_map,
95+ const t_sb_connection_map& sb_conn_map,
9696 vtr::NdMatrix<int , 2 >& num_of_3d_conns_custom_SB,
9797 t_rr_edge_info_set& rr_edges_to_create,
9898 t_rr_edge_info_set& des_3d_rr_edges_to_create,
@@ -130,7 +130,7 @@ static int get_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
130130 const int swtich_override,
131131 const int custom_3d_sb_fanin_fanout,
132132 const int delayless_switch,
133- t_sb_connection_map* sb_conn_map,
133+ const t_sb_connection_map& sb_conn_map,
134134 vtr::NdMatrix<int , 2 >& num_of_3d_conns_custom_SB,
135135 RRNodeId from_rr_node,
136136 t_rr_edge_info_set& rr_edges_to_create,
@@ -1245,15 +1245,15 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
12451245 const int custom_3d_sb_fanin_fanout,
12461246 const int delayless_switch,
12471247 const vtr::NdMatrix<std::vector<int >, 3 >& switch_block_conn,
1248- t_sb_connection_map* sb_conn_map) {
1248+ const t_sb_connection_map* sb_conn_map) {
12491249 int to_chan, to_sb;
12501250 std::vector<int > conn_tracks;
12511251 bool from_is_sblock, is_behind, Fs_clipped;
12521252 enum e_side to_side;
12531253
12541254 /* check whether a custom switch block will be used */
12551255 bool custom_switch_block = false ;
1256- if (sb_conn_map) {
1256+ if (sb_conn_map != nullptr ) {
12571257 custom_switch_block = true ;
12581258 VTR_ASSERT (switch_block_conn.empty ());
12591259 }
@@ -1375,7 +1375,7 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
13751375 num_conn += get_track_to_chan_seg (rr_graph_builder, layer, max_chan_width, from_track, to_chan, to_seg,
13761376 to_type, from_side_a, to_side,
13771377 switch_override, custom_3d_sb_fanin_fanout, delayless_switch,
1378- sb_conn_map, num_of_3d_conns_custom_SB, from_rr_node, rr_edges_to_create, des_3d_rr_edges_to_create);
1378+ * sb_conn_map, num_of_3d_conns_custom_SB, from_rr_node, rr_edges_to_create, des_3d_rr_edges_to_create);
13791379 }
13801380 } else {
13811381 if (BI_DIRECTIONAL == directionality) {
@@ -1413,7 +1413,7 @@ int get_track_to_tracks(RRGraphBuilder& rr_graph_builder,
14131413 num_conn += get_track_to_chan_seg (rr_graph_builder, layer, max_chan_width, from_track, to_chan, to_seg,
14141414 to_type, from_side_b, to_side,
14151415 switch_override, custom_3d_sb_fanin_fanout, delayless_switch,
1416- sb_conn_map, num_of_3d_conns_custom_SB, from_rr_node, rr_edges_to_create, des_3d_rr_edges_to_create);
1416+ * sb_conn_map, num_of_3d_conns_custom_SB, from_rr_node, rr_edges_to_create, des_3d_rr_edges_to_create);
14171417 }
14181418 } else {
14191419 if (BI_DIRECTIONAL == directionality) {
@@ -1527,38 +1527,39 @@ static void get_switchblocks_edges(RRGraphBuilder& rr_graph_builder,
15271527 const int switch_override,
15281528 const int custom_3d_sb_fanin_fanout,
15291529 const int delayless_switch,
1530- t_sb_connection_map* sb_conn_map,
1530+ const t_sb_connection_map& sb_conn_map,
15311531 vtr::NdMatrix<int , 2 >& num_of_3d_conns_custom_SB,
15321532 t_rr_edge_info_set& rr_edges_to_create,
15331533 t_rr_edge_info_set& des_3d_rr_edges_to_create,
15341534 int & edge_count) {
1535- auto & device_ctx = g_vpr_ctx.device ();
1535+ const auto & device_ctx = g_vpr_ctx.device ();
15361536
1537- /* get coordinate to index into the SB map */
1537+ // Coordinate to index into the SB map
15381538 SwitchblockLookupKey sb_coord (tile_x, tile_y, layer, from_side, to_side);
1539- if (sb_conn_map-> count (sb_coord) > 0 ) {
1540- /* get reference to the connections vector which lists all destination wires for a given source wire
1541- * at a specific coordinate sb_coord */
1542- std::vector<t_switchblock_edge>& conn_vector = (* sb_conn_map)[ sb_coord] ;
1543-
1544- /* go through the connections... */
1545- for (int iconn = 0 ; iconn < ( int )conn_vector. size (); ++iconn ) {
1546- if (conn_vector. at (iconn) .from_wire != from_wire) continue ;
1547-
1548- int to_wire = conn_vector. at (iconn) .to_wire ;
1549- int to_layer = conn_vector. at (iconn) .to_wire_layer ;
1550- /* Get the index of the switch connecting the two wires */
1551- int src_switch = conn_vector[iconn] .switch_ind ;
1552- /* Get the index of the switch connecting the two wires in two layers */
1553- int src_switch_betwen_layers = conn_vector[iconn] .switch_ind_between_layers ;
1554-
1555- if (to_layer == layer) { // track-to-track connection within the same layer
1539+ if (sb_conn_map. count (sb_coord) > 0 ) {
1540+ // Reference to the connections vector which lists all destination wires for a given source wire
1541+ // at a specific coordinate sb_coord
1542+ const std::vector<t_switchblock_edge>& sb_edges = sb_conn_map. at ( sb_coord) ;
1543+
1544+ // Go through the connections...
1545+ for (const t_switchblock_edge& sb_edge : sb_edges ) {
1546+ if (sb_edge .from_wire != from_wire) continue ;
1547+
1548+ int to_wire = sb_edge .to_wire ;
1549+ int to_layer = sb_edge .to_wire_layer ;
1550+ // Get the index of the switch connecting the two wires
1551+ int src_switch = sb_edge .switch_ind ;
1552+ // Get the index of the switch connecting the two wires in two layers
1553+ int src_switch_betwen_layers = sb_edge .switch_ind_between_layers ;
1554+
1555+ if (to_layer == layer) { // track-to-track connection within the same layer
15561556 RRNodeId to_node = rr_graph_builder.node_lookup ().find_node (to_layer, to_x, to_y, to_chan_type, to_wire);
15571557
15581558 if (!to_node) {
15591559 continue ;
15601560 }
1561- // Apply any switch overrides
1561+
1562+ // Apply any switch overrides
15621563 if (should_apply_switch_override (switch_override)) {
15631564 src_switch = switch_override;
15641565 }
@@ -1567,34 +1568,32 @@ static void get_switchblocks_edges(RRGraphBuilder& rr_graph_builder,
15671568 ++edge_count;
15681569
15691570 if (device_ctx.arch_switch_inf [src_switch].directionality () == BI_DIRECTIONAL) {
1570- // Add reverse edge since bi-directional
1571+ // Add reverse edge since bidirectional
15711572 rr_edges_to_create.emplace_back (to_node, from_rr_node, src_switch, false );
15721573 ++edge_count;
15731574 }
1574- } else { // track-to_track connection crossing layer
1575+ } else { // track-to_track connection crossing layer
15751576 VTR_ASSERT (to_layer != layer);
1576- // check if current connection is valid, since switch block pattern is very general,
1577- // we might see invalid layer in connection, so we just skip those
1578- if ((layer < 0 || layer >= device_ctx.grid .get_num_layers ()) || (to_layer < 0 || to_layer >= device_ctx.grid .get_num_layers ())) {
1577+ // Check if current connection is valid, since switch block pattern is very general,
1578+ // we might see invalid layer in connection, so we just skip those
1579+ if ((layer < 0 || layer >= device_ctx.grid .get_num_layers ())
1580+ || (to_layer < 0 || to_layer >= device_ctx.grid .get_num_layers ())) {
15791581 continue ;
15801582 }
15811583
15821584 if (tile_x != to_x || tile_y != to_y) {
15831585 continue ;
15841586 }
15851587
1586- /*
1587- * In order to connect two tracks in different layers, we need to follow these three steps:
1588- * 1) connect "from_tracks" to extra "chanx" node in the same switch blocks
1589- * 2) connect extra "chanx" node located in from_layer to another extra "chanx" node located in to_layer
1590- * 3) connect "chanx" node located in to_layer to "to_track"
1591- *
1592- * +-------------+ +-------------+ +--------------+ +--------------+
1593- * | from_wire | -----> | extra_chanx | ------> | extra_chanx | ------> | to_wire |
1594- * | (src_layer) | | (src_layer) | | (dest_layer) | | (dest_layer) |
1595- * +-------------+ +-------------+ +--------------+ +--------------+
1596- *
1597- * */
1588+ // In order to connect two tracks in different layers, we need to follow these three steps:
1589+ // 1) connect "from_tracks" to extra "chanx" node in the same switch blocks
1590+ // 2) connect extra "chanx" node located in from_layer to another extra "chanx" node located in to_layer
1591+ // 3) connect "chanx" node located in to_layer to "to_track"
1592+ // +-------------+ +-------------+ +--------------+ +--------------+
1593+ // | from_wire | -----> | extra_chanx | ------> | extra_chanx | ------> | to_wire |
1594+ // | (src_layer) | | (src_layer) | | (dest_layer) | | (dest_layer) |
1595+ // +-------------+ +-------------+ +--------------+ +--------------+
1596+
15981597 int offset = num_of_3d_conns_custom_SB[tile_x][tile_y] / custom_3d_sb_fanin_fanout;
15991598 RRNodeId track_to_chanx_node = rr_graph_builder.node_lookup ().find_node (layer, tile_x, tile_y, e_rr_type::CHANX, max_chan_width + offset);
16001599 RRNodeId diff_layer_chanx_node = rr_graph_builder.node_lookup ().find_node (to_layer, tile_x, tile_y, e_rr_type::CHANX, max_chan_width + offset);
@@ -1604,21 +1603,21 @@ static void get_switchblocks_edges(RRGraphBuilder& rr_graph_builder,
16041603 continue ;
16051604 }
16061605
1607- // Apply any switch overrides
1606+ // Apply any switch overrides
16081607 if (should_apply_switch_override (switch_override)) {
16091608 src_switch = switch_override;
16101609 }
16111610
1612- // add edge between source node at from layer to intermediate node
1611+ // Add edge between source node at from layer to intermediate node
16131612 rr_edges_to_create.emplace_back (from_rr_node, track_to_chanx_node, delayless_switch, false );
16141613 ++edge_count;
16151614
1616- // add edge between intermediate node to destination node at to layer
1617- // might add the same edge more than once
1615+ // Add edge between intermediate node to destination node at to layer
1616+ // might add the same edge more than once, but redundant edges will be removed before updating the RR graph
16181617 des_3d_rr_edges_to_create.emplace_back (diff_layer_chanx_node, chanx_to_track_node, src_switch_betwen_layers, false );
16191618 ++edge_count;
16201619
1621- // we only add the following edge between intermediate nodes once for the first 3D connection for each pair of intermediate nodes
1620+ // We only add the following edge between intermediate nodes once for the first 3D connection for each pair of intermediate nodes
16221621 if (num_of_3d_conns_custom_SB[tile_x][tile_y] % custom_3d_sb_fanin_fanout == 0 ) {
16231622 rr_edges_to_create.emplace_back (track_to_chanx_node, diff_layer_chanx_node, delayless_switch, false );
16241623 ++edge_count;
@@ -1642,7 +1641,7 @@ static int get_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
16421641 const int switch_override,
16431642 const int custom_3d_sb_fanin_fanout,
16441643 const int delayless_switch,
1645- t_sb_connection_map* sb_conn_map,
1644+ const t_sb_connection_map& sb_conn_map,
16461645 vtr::NdMatrix<int , 2 >& num_of_3d_conns_custom_SB,
16471646 RRNodeId from_rr_node,
16481647 t_rr_edge_info_set& rr_edges_to_create,
@@ -1651,7 +1650,7 @@ static int get_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
16511650 int to_x, to_y;
16521651 int tile_x, tile_y;
16531652
1654- /* get x/y coordinates from seg/chan coordinates */
1653+ // Get x/y coordinates from seg/chan coordinates
16551654 if (e_rr_type::CHANX == to_chan_type) {
16561655 to_x = tile_x = to_seg;
16571656 to_y = tile_y = to_chan;
@@ -1688,7 +1687,7 @@ static int get_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
16881687 des_3d_rr_edges_to_create,
16891688 edge_count);
16901689
1691- // check sb_conn_map for connections between two layers
1690+ // Check sb_conn_map for connections between two layers
16921691 for (e_side to_another_die_side : {ABOVE, UNDER}) {
16931692 get_switchblocks_edges (rr_graph_builder,
16941693 tile_x,
@@ -1798,9 +1797,9 @@ static int get_unidir_track_to_chan_seg(RRGraphBuilder& rr_graph_builder,
17981797 rr_edges_to_create.emplace_back (from_rr_node, to_node, iswitch, false );
17991798 ++count;
18001799
1801- auto & device_ctx = g_vpr_ctx.device ();
1800+ const auto & device_ctx = g_vpr_ctx.device ();
18021801 if (device_ctx.arch_switch_inf [iswitch].directionality () == BI_DIRECTIONAL) {
1803- // Add reverse edge since bi-directional
1802+ // Add reverse edge since bidirectional
18041803 rr_edges_to_create.emplace_back (to_node, from_rr_node, iswitch, false );
18051804 ++count;
18061805 }
0 commit comments