From 06d02f4d266f580ddd367e4b45de0280b47acea3 Mon Sep 17 00:00:00 2001 From: Fahrican Kosar Date: Tue, 21 Jan 2025 08:07:38 -0500 Subject: [PATCH 01/18] more fixes for bitstream generation with flat router --- vpr/src/base/netlist_writer.cpp | 5 +- vpr/src/base/vpr_api.cpp | 31 +++++++ vpr/src/pack/post_routing_pb_pin_fixup.cpp | 1 + .../pack/sync_netlists_to_routing_flat.cpp | 84 +++++++++---------- vpr/src/route/annotate_routing.cpp | 14 +++- vpr/src/route/annotate_routing.h | 1 + 6 files changed, 88 insertions(+), 48 deletions(-) diff --git a/vpr/src/base/netlist_writer.cpp b/vpr/src/base/netlist_writer.cpp index d8efdab5b42..e8b1ba333bf 100644 --- a/vpr/src/base/netlist_writer.cpp +++ b/vpr/src/base/netlist_writer.cpp @@ -1245,7 +1245,10 @@ class NetlistWriterVisitor : public NetlistVisitor { //Add the single output connection { - auto atom_net_id = top_pb_route[sink_cluster_pin_idx].atom_net_id; //Connected net in atom netlist + /* Check if the output is connected */ + AtomNetId atom_net_id = AtomNetId::INVALID(); + if (top_pb_route.count(sink_cluster_pin_idx)) + atom_net_id = top_pb_route[sink_cluster_pin_idx].atom_net_id; //Connected net in atom netlist std::string net; if (!atom_net_id) { diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index 1e3a4c390e9..75a4d71e8e0 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -17,6 +17,7 @@ #include "FlatPlacementInfo.h" #include "cluster_util.h" +#include "physical_types.h" #include "verify_placement.h" #include "vpr_context.h" #include "vtr_assert.h" @@ -115,6 +116,13 @@ static void get_intercluster_switch_fanin_estimates(const t_vpr_setup& vpr_setup int* opin_switch_fanin, int* wire_switch_fanin, int* ipin_switch_fanin); + +/** Set all port equivalences in the architecture to NONE. This is used in the + * case of the flat router where port equivalence does not make sense. + * We could just keep it set and ignore it, but that prevents compatibility + * with OpenFPGA which takes it seriously. */ +static void unset_port_equivalences(DeviceContext& device_ctx); + /* Local subroutines end */ ///@brief Display general VPR information @@ -369,6 +377,25 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a device_ctx.pad_loc_type = vpr_setup->PlacerOpts.pad_loc_type; } +/** Port equivalence does not make sense during flat routing. + * Remove port equivalence from all ports in the architecture */ +static void unset_port_equivalences(DeviceContext& device_ctx){ + for(auto& physical_type: device_ctx.physical_tile_types){ + for(auto& sub_tile: physical_type.sub_tiles){ + for(auto& port: sub_tile.ports){ + port.equivalent = PortEquivalence::NONE; + } + } + } + for(auto& logical_type: device_ctx.logical_block_types){ + if(!logical_type.pb_type) + continue; + for(int i=0; inum_ports; i++){ + logical_type.pb_type->ports[i].equivalent = PortEquivalence::NONE; + } + } +} + bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) { if (vpr_setup.exit_before_pack) { VTR_LOG_WARN("Exiting before packing as requested.\n"); @@ -425,6 +452,10 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) { bool is_flat = vpr_setup.RouterOpts.flat_routing; const Netlist<>& router_net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().nlist : (const Netlist<>&)g_vpr_ctx.clustering().clb_nlist; + if (is_flat){ + VTR_LOG_WARN("Disabling port equivalence in the architecture since flat routing is enabled.\n"); + unset_port_equivalences(g_vpr_ctx.mutable_device()); + } RouteStatus route_status; { //Route route_status = vpr_route_flow(router_net_list, vpr_setup, arch, is_flat); diff --git a/vpr/src/pack/post_routing_pb_pin_fixup.cpp b/vpr/src/pack/post_routing_pb_pin_fixup.cpp index 78084d56df3..1d03ca7f74b 100644 --- a/vpr/src/pack/post_routing_pb_pin_fixup.cpp +++ b/vpr/src/pack/post_routing_pb_pin_fixup.cpp @@ -1034,6 +1034,7 @@ void sync_netlists_to_routing(const Netlist<>& net_list, /* Create net-to-rr_node mapping */ vtr::vector rr_node_nets = annotate_rr_node_nets(clustering_ctx, device_ctx, + atom_ctx, verbose); IntraLbPbPinLookup intra_lb_pb_pin_lookup(device_ctx.logical_block_types); diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index 8aa54bb7f1a..403d0a722af 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -47,23 +47,6 @@ static void fixup_atom_pb_graph_pin_mapping(void); /* Function definitions */ -/** Is the clock net found in the routing results? - * (If not, clock_modeling is probably ideal and we should preserve clock routing while rebuilding.) */ -inline bool is_clock_net_routed(void){ - auto& atom_ctx = g_vpr_ctx.atom(); - auto& route_ctx = g_vpr_ctx.routing(); - - for(auto net_id: atom_ctx.nlist.nets()){ - auto& tree = route_ctx.route_trees[net_id]; - if(!tree) - continue; - if(route_ctx.is_clock_net[net_id]) /* Clock net has routing */ - return true; - } - - return false; -} - /** Get the ClusterBlockId for a given RRNodeId. */ inline ClusterBlockId get_cluster_block_from_rr_node(RRNodeId inode){ auto& device_ctx = g_vpr_ctx.device(); @@ -193,18 +176,16 @@ static void sync_pb_routes_to_routing(void){ auto& route_ctx = g_vpr_ctx.routing(); auto& rr_graph = device_ctx.rr_graph; - /* Was the clock net routed? */ - bool clock_net_is_routed = is_clock_net_routed(); - /* Clear out existing pb_routes: they were made by the intra cluster router and are invalid now */ for (ClusterBlockId clb_blk_id : cluster_ctx.clb_nlist.blocks()) { - /* If we don't have routing for the clock net, don't erase entries associated with a clock net. - * Otherwise we won't have data to rebuild them */ + /* Don't erase entries for nets without routing in place (clocks, globals...) */ std::vector pins_to_erase; auto& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; for(auto& [pin, pb_route]: pb_routes){ - if(clock_net_is_routed || !route_ctx.is_clock_net[pb_route.atom_net_id]) - pins_to_erase.push_back(pin); + /* No route tree: no routing in place, it is global or clock */ + if(!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) + continue; + pins_to_erase.push_back(pin); } for(int pin: pins_to_erase){ @@ -286,37 +267,37 @@ static void sync_clustered_netlist_to_routing(void){ auto& atom_ctx = g_vpr_ctx.mutable_atom(); auto& atom_lookup = atom_ctx.lookup; - bool clock_net_is_routed = is_clock_net_routed(); - /* 1. Remove all nets, pins and ports from the clustered netlist. - * If the clock net is not routed, don't remove entries for the clock net - * otherwise we won't have data to rebuild them. */ + * Do not remove entries for nets without an existing route tree, + * since we don't have the information to rebuild those parts. */ std::vector nets_to_remove; std::vector pins_to_remove; std::vector ports_to_remove; for(auto net_id: clb_netlist.nets()){ auto atom_net_id = atom_lookup.atom_net(net_id); - if(!clock_net_is_routed && route_ctx.is_clock_net[atom_net_id]) + if(!route_ctx.route_trees[ParentNetId(int(atom_net_id))]) continue; nets_to_remove.push_back(net_id); } - for(auto pin_id: clb_netlist.pins()){ - ClusterNetId clb_net_id = clb_netlist.pin_net(pin_id); - auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if(!clock_net_is_routed && atom_net_id && route_ctx.is_clock_net[atom_net_id]) - continue; - - pins_to_remove.push_back(pin_id); - } + /* Mark ports and pins for removal. Don't remove a port if + * it has at least one pin remaining */ for(auto port_id: clb_netlist.ports()){ - ClusterNetId clb_net_id = clb_netlist.port_net(port_id, 0); - auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if(!clock_net_is_routed && atom_net_id && route_ctx.is_clock_net[atom_net_id]) - continue; + size_t skipped_pins = 0; + + for(auto pin_id: clb_netlist.port_pins(port_id)){ + ClusterNetId clb_net_id = clb_netlist.pin_net(pin_id); + auto atom_net_id = atom_lookup.atom_net(clb_net_id); + if(atom_net_id && !route_ctx.route_trees[ParentNetId(int(atom_net_id))]){ + skipped_pins++; + }else{ + pins_to_remove.push_back(pin_id); + } + } - ports_to_remove.push_back(port_id); + if(!skipped_pins) // All pins have been removed, remove port + ports_to_remove.push_back(port_id); } /* ClusteredNetlist's iterators rely on internal lookups, so we mark for removal @@ -366,8 +347,7 @@ static void sync_clustered_netlist_to_routing(void){ * Due to how the route tree is traversed, all nodes until the next OPIN on the tile will * be under this OPIN, so this is valid (we don't need to get the branch explicitly) */ if(node_type == OPIN){ - std::string net_name; - net_name = atom_ctx.nlist.net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); + std::string net_name = atom_ctx.nlist.net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); clb_net_id = clb_netlist.create_net(net_name); atom_lookup.add_atom_clb_net(atom_net_id, clb_net_id); clb_nets_so_far++; @@ -375,6 +355,7 @@ static void sync_clustered_netlist_to_routing(void){ t_pb_graph_pin* pb_graph_pin = get_pb_graph_node_pin_from_block_pin(clb, pin_index); + /* Get or create port */ ClusterPortId port_id = clb_netlist.find_port(clb, pb_graph_pin->port->name); if(!port_id){ PortType port_type; @@ -390,6 +371,15 @@ static void sync_clustered_netlist_to_routing(void){ } PinType pin_type = node_type == OPIN ? PinType::DRIVER : PinType::SINK; + /* Pin already exists. This means a global was connected to here. */ + if (clb_netlist.port_pin(port_id, pb_graph_pin->pin_number)) { + VTR_LOG_WARN("Pin %s of block %s has a global or clock net" + " connected and it has a routing clash with the flat router." + " This may cause inconsistent results.\n", + pb_graph_pin->to_string().c_str(), + clb_netlist.block_name(clb).c_str()); + continue; + } ClusterPinId new_pin = clb_netlist.create_pin(port_id, pb_graph_pin->pin_number, clb_net_id, pin_type, pb_graph_pin->pin_count_in_cluster); clb_netlist.set_pin_net(new_pin, pin_type, clb_net_id); } @@ -431,6 +421,12 @@ static void fixup_atom_pb_graph_pin_mapping(void){ /* Find atom port from pbg pin's model port */ AtomPortId atom_port = atom_ctx.nlist.find_atom_port(atb, atom_pbg_pin->port->model_port); + + /* Not an equivalent port, so no need to do fixup */ + if (atom_pbg_pin->port->equivalent != PortEquivalence::FULL) { + continue; + } + for(AtomPinId atom_pin: atom_ctx.nlist.port_pins(atom_port)){ /* Match net IDs from pb_route and atom netlist and connect in lookup */ if(pb_route.atom_net_id == atom_ctx.nlist.pin_net(atom_pin)){ diff --git a/vpr/src/route/annotate_routing.cpp b/vpr/src/route/annotate_routing.cpp index 42b798d4d02..f8f79df68fd 100644 --- a/vpr/src/route/annotate_routing.cpp +++ b/vpr/src/route/annotate_routing.cpp @@ -15,11 +15,13 @@ vtr::vector annotate_rr_node_nets(const ClusteringContext& cluster_ctx, const DeviceContext& device_ctx, + const AtomContext& atom_ctx, const bool& verbose) { size_t counter = 0; vtr::ScopedStartFinishTimer timer("Annotating rr_node with routed nets"); const auto& rr_graph = device_ctx.rr_graph; + auto& atom_lookup = atom_ctx.lookup; auto& netlist = cluster_ctx.clb_nlist; vtr::vector rr_node_nets; @@ -47,11 +49,17 @@ vtr::vector annotate_rr_node_nets(const ClusteringContex * In some routing architectures, node capacity is more than 1 * which allows a node to be mapped by multiple nets * Therefore, the sanity check should focus on the nodes - * whose capacity is 1 - */ + * whose capacity is 1. + * Flat routing may create two clustered nets from a single + * atom net if the atom net ended up exiting the block through + * different pins. Those clustered nets will point to the same + * atom net routing. Ignore clashes if that is the case. */ + AtomNetId my_atom = atom_lookup.atom_net(net_id); + AtomNetId existing_atom = atom_lookup.atom_net(rr_node_nets[rr_node]); if ((rr_node_nets[rr_node]) && (1 == rr_graph.node_capacity(rr_node)) - && (net_id != rr_node_nets[rr_node])) { + && (net_id != rr_node_nets[rr_node]) + && (my_atom != existing_atom)) { VPR_FATAL_ERROR(VPR_ERROR_ANALYSIS, "Detect two nets '%s' and '%s' that are mapped to the same rr_node '%ld'!\n%s\n", netlist.net_name(net_id).c_str(), diff --git a/vpr/src/route/annotate_routing.h b/vpr/src/route/annotate_routing.h index cf548e1e0fe..3d6d87b2575 100644 --- a/vpr/src/route/annotate_routing.h +++ b/vpr/src/route/annotate_routing.h @@ -12,6 +12,7 @@ *******************************************************************/ vtr::vector annotate_rr_node_nets(const ClusteringContext& cluster_ctx, const DeviceContext& device_ctx, + const AtomContext& atom_ctx, const bool& verbose); #endif From ad8bfcef3428873b4e63d06c293ddf8fe3241078 Mon Sep 17 00:00:00 2001 From: Amin Mohaghegh Date: Wed, 23 Apr 2025 08:07:18 -0700 Subject: [PATCH 02/18] [vpr][pack] fix merge issues w/ flat sync list --- .../pack/sync_netlists_to_routing_flat.cpp | 63 +------------------ 1 file changed, 3 insertions(+), 60 deletions(-) diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index 48737693ece..4b23a8cab6b 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -42,26 +42,6 @@ static void fixup_atom_pb_graph_pin_mapping(void); /* Function definitions */ -<<<<<<< HEAD -======= -/** Is the clock net found in the routing results? - * (If not, clock_modeling is probably ideal and we should preserve clock routing while rebuilding.) */ -inline bool is_clock_net_routed(void) { - auto& atom_ctx = g_vpr_ctx.atom(); - auto& route_ctx = g_vpr_ctx.routing(); - - for (auto net_id : atom_ctx.netlist().nets()) { - auto& tree = route_ctx.route_trees[net_id]; - if (!tree) - continue; - if (route_ctx.is_clock_net[net_id]) /* Clock net has routing */ - return true; - } - - return false; -} - ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 /** Get the ClusterBlockId for a given RRNodeId. */ inline ClusterBlockId get_cluster_block_from_rr_node(RRNodeId inode) { auto& device_ctx = g_vpr_ctx.device(); @@ -193,17 +173,11 @@ static void sync_pb_routes_to_routing(void) { /* Don't erase entries for nets without routing in place (clocks, globals...) */ std::vector pins_to_erase; auto& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; -<<<<<<< HEAD for(auto& [pin, pb_route]: pb_routes){ /* No route tree: no routing in place, it is global or clock */ if(!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) continue; pins_to_erase.push_back(pin); -======= - for (auto& [pin, pb_route] : pb_routes) { - if (clock_net_is_routed || !route_ctx.is_clock_net[pb_route.atom_net_id]) - pins_to_erase.push_back(pin); ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 } for (int pin : pins_to_erase) { @@ -292,16 +266,11 @@ static void sync_clustered_netlist_to_routing(void) { for (auto net_id : clb_netlist.nets()) { auto atom_net_id = atom_lookup.atom_net(net_id); -<<<<<<< HEAD if(!route_ctx.route_trees[ParentNetId(int(atom_net_id))]) -======= - if (!clock_net_is_routed && route_ctx.is_clock_net[atom_net_id]) ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 continue; nets_to_remove.push_back(net_id); } -<<<<<<< HEAD /* Mark ports and pins for removal. Don't remove a port if * it has at least one pin remaining */ for(auto port_id: clb_netlist.ports()){ @@ -316,21 +285,6 @@ static void sync_clustered_netlist_to_routing(void) { pins_to_remove.push_back(pin_id); } } -======= - for (auto pin_id : clb_netlist.pins()) { - ClusterNetId clb_net_id = clb_netlist.pin_net(pin_id); - auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if (!clock_net_is_routed && atom_net_id && route_ctx.is_clock_net[atom_net_id]) - continue; - - pins_to_remove.push_back(pin_id); - } - for (auto port_id : clb_netlist.ports()) { - ClusterNetId clb_net_id = clb_netlist.port_net(port_id, 0); - auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if (!clock_net_is_routed && atom_net_id && route_ctx.is_clock_net[atom_net_id]) - continue; ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 if(!skipped_pins) // All pins have been removed, remove port ports_to_remove.push_back(port_id); @@ -380,14 +334,8 @@ static void sync_clustered_netlist_to_routing(void) { /* OPIN on the tile: create a new clb_net_id and add all ports & pins into here * Due to how the route tree is traversed, all nodes until the next OPIN on the tile will * be under this OPIN, so this is valid (we don't need to get the branch explicitly) */ -<<<<<<< HEAD if(node_type == OPIN){ - std::string net_name = atom_ctx.nlist.net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); -======= - if (node_type == OPIN) { - std::string net_name; - net_name = atom_ctx.netlist().net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 + std::string net_name = atom_ctx.netlist().net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); clb_net_id = clb_netlist.create_net(net_name); atom_ctx.mutable_lookup().add_atom_clb_net(atom_net_id, clb_net_id); clb_nets_so_far++; @@ -460,19 +408,14 @@ static void fixup_atom_pb_graph_pin_mapping(void) { continue; /* Find atom port from pbg pin's model port */ -<<<<<<< HEAD - AtomPortId atom_port = atom_ctx.nlist.find_atom_port(atb, atom_pbg_pin->port->model_port); + AtomPortId atom_port = atom_ctx.netlist().find_atom_port(atb, atom_pbg_pin->port->model_port); /* Not an equivalent port, so no need to do fixup */ if (atom_pbg_pin->port->equivalent != PortEquivalence::FULL) { continue; } - for(AtomPinId atom_pin: atom_ctx.nlist.port_pins(atom_port)){ -======= - AtomPortId atom_port = atom_ctx.netlist().find_atom_port(atb, atom_pbg_pin->port->model_port); - for (AtomPinId atom_pin : atom_ctx.netlist().port_pins(atom_port)) { ->>>>>>> 1e479b90837fdc89cbf9089c691ed58200642fe0 + for(AtomPinId atom_pin: atom_ctx.netlist().port_pins(atom_port)){ /* Match net IDs from pb_route and atom netlist and connect in lookup */ if (pb_route.atom_net_id == atom_ctx.netlist().pin_net(atom_pin)) { atom_ctx.mutable_lookup().set_atom_pin_pb_graph_pin(atom_pin, atom_pbg_pin); From fbd20151844c2b1d2cbf41fe32f8ed04bc39ef04 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Wed, 23 Apr 2025 19:08:09 +0000 Subject: [PATCH 03/18] make format --- vpr/src/base/vpr_api.cpp | 16 ++++++------ vpr/src/pack/post_routing_pb_pin_fixup.cpp | 6 ++--- .../pack/sync_netlists_to_routing_flat.cpp | 26 +++++++++---------- vpr/src/route/annotate_routing.cpp | 6 ++--- vpr/src/route/annotate_routing.h | 6 ++--- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index a6564a8ca98..43d5d862bd1 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -373,18 +373,18 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a /** Port equivalence does not make sense during flat routing. * Remove port equivalence from all ports in the architecture */ -static void unset_port_equivalences(DeviceContext& device_ctx){ - for(auto& physical_type: device_ctx.physical_tile_types){ - for(auto& sub_tile: physical_type.sub_tiles){ - for(auto& port: sub_tile.ports){ +static void unset_port_equivalences(DeviceContext& device_ctx) { + for (auto& physical_type : device_ctx.physical_tile_types) { + for (auto& sub_tile : physical_type.sub_tiles) { + for (auto& port : sub_tile.ports) { port.equivalent = PortEquivalence::NONE; } } } - for(auto& logical_type: device_ctx.logical_block_types){ - if(!logical_type.pb_type) + for (auto& logical_type : device_ctx.logical_block_types) { + if (!logical_type.pb_type) continue; - for(int i=0; inum_ports; i++){ + for (int i=0; i < logical_type.pb_type->num_ports; i++) { logical_type.pb_type->ports[i].equivalent = PortEquivalence::NONE; } } @@ -468,7 +468,7 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) { bool is_flat = vpr_setup.RouterOpts.flat_routing; const Netlist<>& router_net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().netlist() : (const Netlist<>&)g_vpr_ctx.clustering().clb_nlist; - if (is_flat){ + if (is_flat) { VTR_LOG_WARN("Disabling port equivalence in the architecture since flat routing is enabled.\n"); unset_port_equivalences(g_vpr_ctx.mutable_device()); } diff --git a/vpr/src/pack/post_routing_pb_pin_fixup.cpp b/vpr/src/pack/post_routing_pb_pin_fixup.cpp index 923bdfe8c3a..5e737724391 100644 --- a/vpr/src/pack/post_routing_pb_pin_fixup.cpp +++ b/vpr/src/pack/post_routing_pb_pin_fixup.cpp @@ -1032,9 +1032,9 @@ void sync_netlists_to_routing(const Netlist<>& net_list, /* Create net-to-rr_node mapping */ vtr::vector rr_node_nets = annotate_rr_node_nets(clustering_ctx, - device_ctx, - atom_ctx, - verbose); + device_ctx, + atom_ctx, + verbose); IntraLbPbPinLookup intra_lb_pb_pin_lookup(device_ctx.logical_block_types); diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index 4b23a8cab6b..d2c9480ea90 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -173,7 +173,7 @@ static void sync_pb_routes_to_routing(void) { /* Don't erase entries for nets without routing in place (clocks, globals...) */ std::vector pins_to_erase; auto& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; - for(auto& [pin, pb_route]: pb_routes){ + for (auto& [pin, pb_route] : pb_routes) { /* No route tree: no routing in place, it is global or clock */ if(!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) continue; @@ -266,27 +266,27 @@ static void sync_clustered_netlist_to_routing(void) { for (auto net_id : clb_netlist.nets()) { auto atom_net_id = atom_lookup.atom_net(net_id); - if(!route_ctx.route_trees[ParentNetId(int(atom_net_id))]) + if (!route_ctx.route_trees[ParentNetId(int(atom_net_id))]) continue; nets_to_remove.push_back(net_id); } /* Mark ports and pins for removal. Don't remove a port if * it has at least one pin remaining */ - for(auto port_id: clb_netlist.ports()){ + for (auto port_id : clb_netlist.ports()) { size_t skipped_pins = 0; - for(auto pin_id: clb_netlist.port_pins(port_id)){ + for (auto pin_id : clb_netlist.port_pins(port_id)) { ClusterNetId clb_net_id = clb_netlist.pin_net(pin_id); auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if(atom_net_id && !route_ctx.route_trees[ParentNetId(int(atom_net_id))]){ + if (atom_net_id && !route_ctx.route_trees[ParentNetId(int(atom_net_id))]) { skipped_pins++; - }else{ + } else { pins_to_remove.push_back(pin_id); } } - if(!skipped_pins) // All pins have been removed, remove port + if (!skipped_pins) // All pins have been removed, remove port ports_to_remove.push_back(port_id); } @@ -334,7 +334,7 @@ static void sync_clustered_netlist_to_routing(void) { /* OPIN on the tile: create a new clb_net_id and add all ports & pins into here * Due to how the route tree is traversed, all nodes until the next OPIN on the tile will * be under this OPIN, so this is valid (we don't need to get the branch explicitly) */ - if(node_type == OPIN){ + if (node_type == OPIN) { std::string net_name = atom_ctx.netlist().net_name(parent_net_id) + "_" + std::to_string(clb_nets_so_far); clb_net_id = clb_netlist.create_net(net_name); atom_ctx.mutable_lookup().add_atom_clb_net(atom_net_id, clb_net_id); @@ -362,10 +362,10 @@ static void sync_clustered_netlist_to_routing(void) { /* Pin already exists. This means a global was connected to here. */ if (clb_netlist.port_pin(port_id, pb_graph_pin->pin_number)) { VTR_LOG_WARN("Pin %s of block %s has a global or clock net" - " connected and it has a routing clash with the flat router." - " This may cause inconsistent results.\n", - pb_graph_pin->to_string().c_str(), - clb_netlist.block_name(clb).c_str()); + " connected and it has a routing clash with the flat router." + " This may cause inconsistent results.\n", + pb_graph_pin->to_string().c_str(), + clb_netlist.block_name(clb).c_str()); continue; } ClusterPinId new_pin = clb_netlist.create_pin(port_id, pb_graph_pin->pin_number, clb_net_id, pin_type, pb_graph_pin->pin_count_in_cluster); @@ -415,7 +415,7 @@ static void fixup_atom_pb_graph_pin_mapping(void) { continue; } - for(AtomPinId atom_pin: atom_ctx.netlist().port_pins(atom_port)){ + for (AtomPinId atom_pin : atom_ctx.netlist().port_pins(atom_port)) { /* Match net IDs from pb_route and atom netlist and connect in lookup */ if (pb_route.atom_net_id == atom_ctx.netlist().pin_net(atom_pin)) { atom_ctx.mutable_lookup().set_atom_pin_pb_graph_pin(atom_pin, atom_pbg_pin); diff --git a/vpr/src/route/annotate_routing.cpp b/vpr/src/route/annotate_routing.cpp index 5dc1d957678..442d7840726 100644 --- a/vpr/src/route/annotate_routing.cpp +++ b/vpr/src/route/annotate_routing.cpp @@ -14,9 +14,9 @@ #include "annotate_routing.h" vtr::vector annotate_rr_node_nets(const ClusteringContext& cluster_ctx, - const DeviceContext& device_ctx, - const AtomContext& atom_ctx, - const bool& verbose) { + const DeviceContext& device_ctx, + const AtomContext& atom_ctx, + const bool& verbose) { size_t counter = 0; vtr::ScopedStartFinishTimer timer("Annotating rr_node with routed nets"); diff --git a/vpr/src/route/annotate_routing.h b/vpr/src/route/annotate_routing.h index 3d6d87b2575..e00be549259 100644 --- a/vpr/src/route/annotate_routing.h +++ b/vpr/src/route/annotate_routing.h @@ -11,8 +11,8 @@ * - Unmapped rr_node will use invalid ids *******************************************************************/ vtr::vector annotate_rr_node_nets(const ClusteringContext& cluster_ctx, - const DeviceContext& device_ctx, - const AtomContext& atom_ctx, - const bool& verbose); + const DeviceContext& device_ctx, + const AtomContext& atom_ctx, + const bool& verbose); #endif From 8b15437939d0b630a20064d04ddd0060def531ef Mon Sep 17 00:00:00 2001 From: amin1377 Date: Wed, 23 Apr 2025 19:15:48 +0000 Subject: [PATCH 04/18] make format 2 --- vpr/src/base/vpr_api.cpp | 2 +- vpr/src/pack/sync_netlists_to_routing_flat.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vpr/src/base/vpr_api.cpp b/vpr/src/base/vpr_api.cpp index 43d5d862bd1..928839410f2 100644 --- a/vpr/src/base/vpr_api.cpp +++ b/vpr/src/base/vpr_api.cpp @@ -384,7 +384,7 @@ static void unset_port_equivalences(DeviceContext& device_ctx) { for (auto& logical_type : device_ctx.logical_block_types) { if (!logical_type.pb_type) continue; - for (int i=0; i < logical_type.pb_type->num_ports; i++) { + for (int i = 0; i < logical_type.pb_type->num_ports; i++) { logical_type.pb_type->ports[i].equivalent = PortEquivalence::NONE; } } diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index d2c9480ea90..9a8f584b966 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -175,7 +175,7 @@ static void sync_pb_routes_to_routing(void) { auto& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; for (auto& [pin, pb_route] : pb_routes) { /* No route tree: no routing in place, it is global or clock */ - if(!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) + if (!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) continue; pins_to_erase.push_back(pin); } @@ -286,7 +286,7 @@ static void sync_clustered_netlist_to_routing(void) { } } - if (!skipped_pins) // All pins have been removed, remove port + if (!skipped_pins) // All pins have been removed, remove port ports_to_remove.push_back(port_id); } From ae07129ae239666f9be3d00b743fbaa9457bc323 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 25 Apr 2025 16:25:20 -0400 Subject: [PATCH 05/18] [vpr][base] fix assigned pb_graph_pin when graph node is not primitive --- vpr/src/base/read_netlist.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/base/read_netlist.cpp b/vpr/src/base/read_netlist.cpp index 9c648607cae..5a39ccfef37 100644 --- a/vpr/src/base/read_netlist.cpp +++ b/vpr/src/base/read_netlist.cpp @@ -823,7 +823,7 @@ static void processPorts(pugi::xml_node Parent, t_pb* pb, t_pb_routes& pb_route, //Why does this not use the output pin used to deterimine the rr node index? pb_route.insert(std::make_pair(rr_node_index, t_pb_route())); pb_route[rr_node_index].driver_pb_pin_id = pin_node[0][0]->pin_count_in_cluster; - pb_route[rr_node_index].pb_graph_pin = pin_node[0][0]; + pb_route[rr_node_index].pb_graph_pin = &pb->pb_graph_node->output_pins[out_port][i]; found = false; for (j = 0; j < pin_node[0][0]->num_output_edges; j++) { From b78b3eb42e9ff86acff4b0599f2505a4fea554cd Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 25 Apr 2025 16:28:03 -0400 Subject: [PATCH 06/18] [vpr][pack] pass logical type to alloc_and_laod_pb_route --- vpr/src/pack/cluster_legalizer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vpr/src/pack/cluster_legalizer.cpp b/vpr/src/pack/cluster_legalizer.cpp index 282b0fe8d1c..1840514a62e 100644 --- a/vpr/src/pack/cluster_legalizer.cpp +++ b/vpr/src/pack/cluster_legalizer.cpp @@ -1571,8 +1571,7 @@ void ClusterLegalizer::clean_cluster(LegalizationClusterId cluster_id) { // Load the pb_route so we can free the cluster router data. // The pb_route is used when creating a netlist from the legalized clusters. std::vector* saved_lb_nets = cluster.router_data->saved_lb_nets; - t_pb_graph_node* pb_graph_node = cluster.pb->pb_graph_node; - cluster.pb->pb_route = alloc_and_load_pb_route(saved_lb_nets, pb_graph_node); + cluster.pb->pb_route = alloc_and_load_pb_route(saved_lb_nets, cluster.type); // Free the router data. free_router_data(cluster.router_data); cluster.router_data = nullptr; From b0d7afc32d938e748da28c27d603eb27332af671 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 25 Apr 2025 16:52:18 -0400 Subject: [PATCH 07/18] [vpr][pack] update alloc_and_load_pb_route header file --- vpr/src/pack/cluster_router.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpr/src/pack/cluster_router.h b/vpr/src/pack/cluster_router.h index 0b40f84c627..717f971f95e 100644 --- a/vpr/src/pack/cluster_router.h +++ b/vpr/src/pack/cluster_router.h @@ -23,7 +23,7 @@ bool try_intra_lb_route(t_lb_router_data* router_data, int verbosity, t_mode_sel void reset_intra_lb_route(t_lb_router_data* router_data); /* Accessor Functions */ -t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_pb_graph_node* pb_graph_head); +t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type); void free_pb_route(t_pb_route* free_pb_route); #endif From 250329ba5baa5bb9d316a845f02c807604b369a4 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Fri, 25 Apr 2025 16:55:25 -0400 Subject: [PATCH 08/18] [vpr][pack] fix pb_graph_pin assignment in load_trace_to_pb_route --- vpr/src/pack/cluster_router.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index 92d4b183dc5..3b4d8ddde7a 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -108,7 +108,12 @@ static bool is_route_success(t_lb_router_data* router_data); static t_lb_trace* find_node_in_rt(t_lb_trace* rt, int rt_index); static void reset_explored_node_tb(t_lb_router_data* router_data); static void save_and_reset_lb_route(t_lb_router_data* router_data); -static void load_trace_to_pb_route(t_pb_routes& pb_route, const int total_pins, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace); +static void load_trace_to_pb_route(t_pb_routes& pb_route, + const int total_pins, + const AtomNetId net_id, + const int prev_pin_id, + const t_lb_trace* trace, + t_logical_block_type_ptr logic_block_type); static std::string describe_lb_type_rr_node(int inode, const t_lb_router_data* router_data); @@ -545,13 +550,14 @@ bool try_intra_lb_route(t_lb_router_data* router_data, /* Creates an array [0..num_pb_graph_pins-1] lookup for intra-logic block routing. Given pb_graph_pin id for clb, lookup atom net that uses that pin. * If pin is not used, stores OPEN at that pin location */ -t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_pb_graph_node* pb_graph_head) { +t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, + t_logical_block_type_ptr logic_block_type) { const std::vector& lb_nets = *intra_lb_nets; - int total_pins = pb_graph_head->total_pb_pins; + int total_pins = logic_block_type->pb_graph_head->total_pb_pins; t_pb_routes pb_route; for (int inet = 0; inet < (int)lb_nets.size(); inet++) { - load_trace_to_pb_route(pb_route, total_pins, lb_nets[inet].atom_net_id, OPEN, lb_nets[inet].rt_tree); + load_trace_to_pb_route(pb_route, total_pins, lb_nets[inet].atom_net_id, OPEN, lb_nets[inet].rt_tree, logic_block_type); } return pb_route; @@ -582,7 +588,12 @@ void free_intra_lb_nets(std::vector* intra_lb_nets) { ****************************************************************************/ /* Recurse through route tree trace to populate pb pin to atom net lookup array */ -static void load_trace_to_pb_route(t_pb_routes& pb_route, const int total_pins, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace) { +static void load_trace_to_pb_route(t_pb_routes& pb_route, + const int total_pins, + const AtomNetId net_id, + const int prev_pin_id, + const t_lb_trace* trace, + t_logical_block_type_ptr logic_block_type) { int ipin = trace->current_node; int driver_pb_pin_id = prev_pin_id; int cur_pin_id = OPEN; @@ -593,12 +604,14 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, const int total_pins, pb_route.insert(std::make_pair(cur_pin_id, t_pb_route())); pb_route[cur_pin_id].atom_net_id = net_id; pb_route[cur_pin_id].driver_pb_pin_id = driver_pb_pin_id; + auto pb_graph_pin = logic_block_type->pin_logical_num_to_pb_pin_mapping.at(cur_pin_id); + pb_route[cur_pin_id].pb_graph_pin = pb_graph_pin; } else { VTR_ASSERT(pb_route[cur_pin_id].atom_net_id == net_id); } } for (int itrace = 0; itrace < (int)trace->next_nodes.size(); itrace++) { - load_trace_to_pb_route(pb_route, total_pins, net_id, cur_pin_id, &trace->next_nodes[itrace]); + load_trace_to_pb_route(pb_route, total_pins, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type); } } From a839dc2710e822a8d3c044555c30dde2f5e3ca28 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Sat, 26 Apr 2025 10:55:17 -0400 Subject: [PATCH 09/18] [vpr][pack] add intra_lb_pb_pin_lookup_ to cluster legalizer --- vpr/src/pack/cluster_legalizer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vpr/src/pack/cluster_legalizer.h b/vpr/src/pack/cluster_legalizer.h index 67bc00a95ec..418bff73d95 100644 --- a/vpr/src/pack/cluster_legalizer.h +++ b/vpr/src/pack/cluster_legalizer.h @@ -23,6 +23,7 @@ #include "vtr_vector.h" #include "vtr_vector_map.h" #include "atom_pb_bimap.h" +#include "vpr_utils.h" // Forward declarations class Prepacker; @@ -524,6 +525,8 @@ class ClusterLegalizer { inline const AtomPBBimap& atom_pb_lookup() const { return atom_pb_lookup_; } inline AtomPBBimap& mutable_atom_pb_lookup() { return atom_pb_lookup_; } + inline const IntraLbPbPinLookup& intra_lb_pb_pin_lookup() const { return intra_lb_pb_pin_lookup_; } + /// @brief Destructor of the class. Frees allocated data. ~ClusterLegalizer(); @@ -595,4 +598,7 @@ class ClusterLegalizer { /// @brief A two way map between AtomBlockIds and pb types. This is a copy /// of the AtomPBBimap in the global context's AtomLookup AtomPBBimap atom_pb_lookup_; + + /// @brief A lookup table for the pin mapping of the intra-lb pb pins. + IntraLbPbPinLookup intra_lb_pb_pin_lookup_; }; From de84b8a82d135da6d01faea351a6cd2a2e968920 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Sat, 26 Apr 2025 10:56:27 -0400 Subject: [PATCH 10/18] [vpr][pack] initializer intra_lb_pb_pin_lookup and pass it to alloc_and_load_pb_route --- vpr/src/pack/cluster_legalizer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vpr/src/pack/cluster_legalizer.cpp b/vpr/src/pack/cluster_legalizer.cpp index 1840514a62e..947fbed2fbd 100644 --- a/vpr/src/pack/cluster_legalizer.cpp +++ b/vpr/src/pack/cluster_legalizer.cpp @@ -1571,7 +1571,7 @@ void ClusterLegalizer::clean_cluster(LegalizationClusterId cluster_id) { // Load the pb_route so we can free the cluster router data. // The pb_route is used when creating a netlist from the legalized clusters. std::vector* saved_lb_nets = cluster.router_data->saved_lb_nets; - cluster.pb->pb_route = alloc_and_load_pb_route(saved_lb_nets, cluster.type); + cluster.pb->pb_route = alloc_and_load_pb_route(saved_lb_nets, cluster.type, intra_lb_pb_pin_lookup_); // Free the router data. free_router_data(cluster.router_data); cluster.router_data = nullptr; @@ -1631,6 +1631,7 @@ ClusterLegalizer::ClusterLegalizer(const AtomNetlist& atom_netlist, log_verbosity_ = log_verbosity; VTR_ASSERT(g_vpr_ctx.atom().lookup().atom_pb_bimap().is_empty()); atom_pb_lookup_ = AtomPBBimap(); + intra_lb_pb_pin_lookup_ = IntraLbPbPinLookup(g_vpr_ctx.device().logical_block_types); } void ClusterLegalizer::reset() { From 8902090e363b9fb5c8b0ab273b505dc4fa39a202 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Sat, 26 Apr 2025 10:58:23 -0400 Subject: [PATCH 11/18] [vpr][pack] use intra_lb_pb_pin_lookup to get pb_pin from pin number --- vpr/src/pack/cluster_router.cpp | 15 +++++++++------ vpr/src/pack/cluster_router.h | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index 3b4d8ddde7a..41685a141f6 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -113,7 +113,8 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace, - t_logical_block_type_ptr logic_block_type); + t_logical_block_type_ptr logic_block_type, + const IntraLbPbPinLookup& intra_lb_pb_pin_lookup); static std::string describe_lb_type_rr_node(int inode, const t_lb_router_data* router_data); @@ -551,13 +552,14 @@ bool try_intra_lb_route(t_lb_router_data* router_data, /* Creates an array [0..num_pb_graph_pins-1] lookup for intra-logic block routing. Given pb_graph_pin id for clb, lookup atom net that uses that pin. * If pin is not used, stores OPEN at that pin location */ t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, - t_logical_block_type_ptr logic_block_type) { + t_logical_block_type_ptr logic_block_type, + const IntraLbPbPinLookup& intra_lb_pb_pin_lookup) { const std::vector& lb_nets = *intra_lb_nets; int total_pins = logic_block_type->pb_graph_head->total_pb_pins; t_pb_routes pb_route; for (int inet = 0; inet < (int)lb_nets.size(); inet++) { - load_trace_to_pb_route(pb_route, total_pins, lb_nets[inet].atom_net_id, OPEN, lb_nets[inet].rt_tree, logic_block_type); + load_trace_to_pb_route(pb_route, total_pins, lb_nets[inet].atom_net_id, OPEN, lb_nets[inet].rt_tree, logic_block_type, intra_lb_pb_pin_lookup); } return pb_route; @@ -593,7 +595,8 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace, - t_logical_block_type_ptr logic_block_type) { + t_logical_block_type_ptr logic_block_type, + const IntraLbPbPinLookup& intra_lb_pb_pin_lookup) { int ipin = trace->current_node; int driver_pb_pin_id = prev_pin_id; int cur_pin_id = OPEN; @@ -604,14 +607,14 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, pb_route.insert(std::make_pair(cur_pin_id, t_pb_route())); pb_route[cur_pin_id].atom_net_id = net_id; pb_route[cur_pin_id].driver_pb_pin_id = driver_pb_pin_id; - auto pb_graph_pin = logic_block_type->pin_logical_num_to_pb_pin_mapping.at(cur_pin_id); + auto pb_graph_pin = intra_lb_pb_pin_lookup.pb_gpin(logic_block_type->index, cur_pin_id); pb_route[cur_pin_id].pb_graph_pin = pb_graph_pin; } else { VTR_ASSERT(pb_route[cur_pin_id].atom_net_id == net_id); } } for (int itrace = 0; itrace < (int)trace->next_nodes.size(); itrace++) { - load_trace_to_pb_route(pb_route, total_pins, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type); + load_trace_to_pb_route(pb_route, total_pins, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type, intra_lb_pb_pin_lookup); } } diff --git a/vpr/src/pack/cluster_router.h b/vpr/src/pack/cluster_router.h index 717f971f95e..a97067c1e76 100644 --- a/vpr/src/pack/cluster_router.h +++ b/vpr/src/pack/cluster_router.h @@ -23,7 +23,9 @@ bool try_intra_lb_route(t_lb_router_data* router_data, int verbosity, t_mode_sel void reset_intra_lb_route(t_lb_router_data* router_data); /* Accessor Functions */ -t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type); +t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, + t_logical_block_type_ptr logic_block_type, + const IntraLbPbPinLookup& intra_lb_pb_pin_lookup); void free_pb_route(t_pb_route* free_pb_route); #endif From 35941246da403c60074d316d9a95b075121335d8 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Sat, 26 Apr 2025 11:05:06 -0400 Subject: [PATCH 12/18] make format --- vpr/src/pack/cluster_router.cpp | 12 ++++++------ vpr/src/pack/cluster_router.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index 41685a141f6..d94a697ee5f 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -108,11 +108,11 @@ static bool is_route_success(t_lb_router_data* router_data); static t_lb_trace* find_node_in_rt(t_lb_trace* rt, int rt_index); static void reset_explored_node_tb(t_lb_router_data* router_data); static void save_and_reset_lb_route(t_lb_router_data* router_data); -static void load_trace_to_pb_route(t_pb_routes& pb_route, - const int total_pins, - const AtomNetId net_id, - const int prev_pin_id, - const t_lb_trace* trace, +static void load_trace_to_pb_route(t_pb_routes& pb_route, + const int total_pins, + const AtomNetId net_id, + const int prev_pin_id, + const t_lb_trace* trace, t_logical_block_type_ptr logic_block_type, const IntraLbPbPinLookup& intra_lb_pb_pin_lookup); @@ -551,7 +551,7 @@ bool try_intra_lb_route(t_lb_router_data* router_data, /* Creates an array [0..num_pb_graph_pins-1] lookup for intra-logic block routing. Given pb_graph_pin id for clb, lookup atom net that uses that pin. * If pin is not used, stores OPEN at that pin location */ -t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, +t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type, const IntraLbPbPinLookup& intra_lb_pb_pin_lookup) { const std::vector& lb_nets = *intra_lb_nets; diff --git a/vpr/src/pack/cluster_router.h b/vpr/src/pack/cluster_router.h index a97067c1e76..b1fd31c2415 100644 --- a/vpr/src/pack/cluster_router.h +++ b/vpr/src/pack/cluster_router.h @@ -23,7 +23,7 @@ bool try_intra_lb_route(t_lb_router_data* router_data, int verbosity, t_mode_sel void reset_intra_lb_route(t_lb_router_data* router_data); /* Accessor Functions */ -t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, +t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type, const IntraLbPbPinLookup& intra_lb_pb_pin_lookup); void free_pb_route(t_pb_route* free_pb_route); From 623132ee3924a8b4cd5934fdb1d5dcf4cf7e3e50 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 08:56:46 -0400 Subject: [PATCH 13/18] [vpr][pack] remove casting net id --- vpr/src/pack/sync_netlists_to_routing_flat.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index 9a8f584b966..6318fb274c8 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -172,11 +172,17 @@ static void sync_pb_routes_to_routing(void) { for (ClusterBlockId clb_blk_id : cluster_ctx.clb_nlist.blocks()) { /* Don't erase entries for nets without routing in place (clocks, globals...) */ std::vector pins_to_erase; - auto& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; + t_pb_routes& pb_routes = cluster_ctx.clb_nlist.block_pb(clb_blk_id)->pb_route; for (auto& [pin, pb_route] : pb_routes) { - /* No route tree: no routing in place, it is global or clock */ - if (!route_ctx.route_trees[ParentNetId(int(pb_route.atom_net_id))]) + /* + * Given that this function is called when flat routing is enabled, + * we can safely assume that the net IDs to index into route_ctx.route_trees + * correspond to the atom net IDs. + */ + if (!route_ctx.route_trees[pb_route.atom_net_id]) { + /* No route tree: no routing in place, it is global or clock */ continue; + } pins_to_erase.push_back(pin); } @@ -266,7 +272,7 @@ static void sync_clustered_netlist_to_routing(void) { for (auto net_id : clb_netlist.nets()) { auto atom_net_id = atom_lookup.atom_net(net_id); - if (!route_ctx.route_trees[ParentNetId(int(atom_net_id))]) + if (!route_ctx.route_trees[atom_net_id]) continue; nets_to_remove.push_back(net_id); @@ -279,7 +285,7 @@ static void sync_clustered_netlist_to_routing(void) { for (auto pin_id : clb_netlist.port_pins(port_id)) { ClusterNetId clb_net_id = clb_netlist.pin_net(pin_id); auto atom_net_id = atom_lookup.atom_net(clb_net_id); - if (atom_net_id && !route_ctx.route_trees[ParentNetId(int(atom_net_id))]) { + if (atom_net_id && !route_ctx.route_trees[atom_net_id]) { skipped_pins++; } else { pins_to_remove.push_back(pin_id); From 2468e8a92595fcc38a3f67247ff6d870e741665a Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 08:59:48 -0400 Subject: [PATCH 14/18] [vpr][pack] add doxygen comment for alloc_and_load_pb_route --- vpr/src/pack/cluster_router.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vpr/src/pack/cluster_router.h b/vpr/src/pack/cluster_router.h index b1fd31c2415..ff7f19bca14 100644 --- a/vpr/src/pack/cluster_router.h +++ b/vpr/src/pack/cluster_router.h @@ -23,6 +23,16 @@ bool try_intra_lb_route(t_lb_router_data* router_data, int verbosity, t_mode_sel void reset_intra_lb_route(t_lb_router_data* router_data); /* Accessor Functions */ +/** + * @brief Creates an array [0..num_pb_graph_pins-1] for intra-logic block routing lookup. + * Given a pb_graph_pin ID for a CLB, this lookup returns t_pb_route corresponding to that + * pin. + * + * @param intra_lb_nets Vector of intra-logic block nets. + * @param logic_block_type Logic block type of the current cluster. + * @param intra_lb_pb_pin_lookup Intra-logic block pin lookup to get t_pb_graph_pin from a pin ID. + * @return t_pb_routes An array [0..num_pb_graph_pins-1] for intra-logic block routing lookup. + */ t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type, const IntraLbPbPinLookup& intra_lb_pb_pin_lookup); From 86491fd56f06052bd28cf05951c827f30766e583 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 09:01:15 -0400 Subject: [PATCH 15/18] [vpr][pack] remove redundant parameters --- vpr/src/pack/cluster_router.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index d94a697ee5f..f971b1919f7 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -109,7 +109,6 @@ static t_lb_trace* find_node_in_rt(t_lb_trace* rt, int rt_index); static void reset_explored_node_tb(t_lb_router_data* router_data); static void save_and_reset_lb_route(t_lb_router_data* router_data); static void load_trace_to_pb_route(t_pb_routes& pb_route, - const int total_pins, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace, @@ -549,17 +548,14 @@ bool try_intra_lb_route(t_lb_router_data* router_data, * Accessor Functions ******************************************************************************************/ -/* Creates an array [0..num_pb_graph_pins-1] lookup for intra-logic block routing. Given pb_graph_pin id for clb, lookup atom net that uses that pin. - * If pin is not used, stores OPEN at that pin location */ t_pb_routes alloc_and_load_pb_route(const std::vector* intra_lb_nets, t_logical_block_type_ptr logic_block_type, const IntraLbPbPinLookup& intra_lb_pb_pin_lookup) { const std::vector& lb_nets = *intra_lb_nets; - int total_pins = logic_block_type->pb_graph_head->total_pb_pins; t_pb_routes pb_route; - for (int inet = 0; inet < (int)lb_nets.size(); inet++) { - load_trace_to_pb_route(pb_route, total_pins, lb_nets[inet].atom_net_id, OPEN, lb_nets[inet].rt_tree, logic_block_type, intra_lb_pb_pin_lookup); + for (const auto& lb_net : lb_nets) { + load_trace_to_pb_route(pb_route, lb_net.atom_net_id, OPEN, lb_net.rt_tree, logic_block_type, intra_lb_pb_pin_lookup); } return pb_route; @@ -591,7 +587,6 @@ void free_intra_lb_nets(std::vector* intra_lb_nets) { /* Recurse through route tree trace to populate pb pin to atom net lookup array */ static void load_trace_to_pb_route(t_pb_routes& pb_route, - const int total_pins, const AtomNetId net_id, const int prev_pin_id, const t_lb_trace* trace, @@ -600,6 +595,7 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, int ipin = trace->current_node; int driver_pb_pin_id = prev_pin_id; int cur_pin_id = OPEN; + const int total_pins = logic_block_type->pb_graph_head->total_pb_pins; if (ipin < total_pins) { /* This routing node corresponds with a pin. This node is virtual (ie. sink or source node) */ cur_pin_id = ipin; @@ -607,14 +603,14 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, pb_route.insert(std::make_pair(cur_pin_id, t_pb_route())); pb_route[cur_pin_id].atom_net_id = net_id; pb_route[cur_pin_id].driver_pb_pin_id = driver_pb_pin_id; - auto pb_graph_pin = intra_lb_pb_pin_lookup.pb_gpin(logic_block_type->index, cur_pin_id); + const t_pb_graph_pin* pb_graph_pin = intra_lb_pb_pin_lookup.pb_gpin(logic_block_type->index, cur_pin_id); pb_route[cur_pin_id].pb_graph_pin = pb_graph_pin; } else { VTR_ASSERT(pb_route[cur_pin_id].atom_net_id == net_id); } } for (int itrace = 0; itrace < (int)trace->next_nodes.size(); itrace++) { - load_trace_to_pb_route(pb_route, total_pins, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type, intra_lb_pb_pin_lookup); + load_trace_to_pb_route(pb_route, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type, intra_lb_pb_pin_lookup); } } From 798055c0df86bf7f188d7c054b42e04c48e1c183 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 09:08:07 -0400 Subject: [PATCH 16/18] [vpr][pack] polish load_trace_to_pb_route --- vpr/src/pack/cluster_router.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index f971b1919f7..068fd4b3391 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -108,6 +108,17 @@ static bool is_route_success(t_lb_router_data* router_data); static t_lb_trace* find_node_in_rt(t_lb_trace* rt, int rt_index); static void reset_explored_node_tb(t_lb_router_data* router_data); static void save_and_reset_lb_route(t_lb_router_data* router_data); + +/** + * @brief Recurse through route tree trace to populate pb pin to atom net lookup array. + * + * @param pb_route Array of pb pin to atom net lookup to be populated in this routine. + * @param net_id Atom net ID of the current net. + * @param prev_pin_id ID of the previous pin in the route tree trace. + * @param trace Current trace node in the route tree. + * @param logic_block_type Logic block type of the current cluster. + * @param intra_lb_pb_pin_lookup Intra-logic block pin lookup to get t_pb_graph_pin from a pin ID. + */ static void load_trace_to_pb_route(t_pb_routes& pb_route, const AtomNetId net_id, const int prev_pin_id, @@ -585,7 +596,6 @@ void free_intra_lb_nets(std::vector* intra_lb_nets) { * Internal Functions ****************************************************************************/ -/* Recurse through route tree trace to populate pb pin to atom net lookup array */ static void load_trace_to_pb_route(t_pb_routes& pb_route, const AtomNetId net_id, const int prev_pin_id, @@ -609,8 +619,8 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, VTR_ASSERT(pb_route[cur_pin_id].atom_net_id == net_id); } } - for (int itrace = 0; itrace < (int)trace->next_nodes.size(); itrace++) { - load_trace_to_pb_route(pb_route, net_id, cur_pin_id, &trace->next_nodes[itrace], logic_block_type, intra_lb_pb_pin_lookup); + for (const auto& trace : trace->next_nodes) { + load_trace_to_pb_route(pb_route, net_id, cur_pin_id, &trace, logic_block_type, intra_lb_pb_pin_lookup); } } From 241589b9f4a9b2d135952e5b243e63d9c9c65e21 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 09:14:11 -0400 Subject: [PATCH 17/18] make format --- vpr/src/pack/cluster_router.h | 1 - vpr/src/pack/sync_netlists_to_routing_flat.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/vpr/src/pack/cluster_router.h b/vpr/src/pack/cluster_router.h index ff7f19bca14..cd68f7eea38 100644 --- a/vpr/src/pack/cluster_router.h +++ b/vpr/src/pack/cluster_router.h @@ -22,7 +22,6 @@ void set_reset_pb_modes(t_lb_router_data* router_data, const t_pb* pb, const boo bool try_intra_lb_route(t_lb_router_data* router_data, int verbosity, t_mode_selection_status* mode_status); void reset_intra_lb_route(t_lb_router_data* router_data); -/* Accessor Functions */ /** * @brief Creates an array [0..num_pb_graph_pins-1] for intra-logic block routing lookup. * Given a pb_graph_pin ID for a CLB, this lookup returns t_pb_route corresponding to that diff --git a/vpr/src/pack/sync_netlists_to_routing_flat.cpp b/vpr/src/pack/sync_netlists_to_routing_flat.cpp index 6318fb274c8..2339f9d2863 100644 --- a/vpr/src/pack/sync_netlists_to_routing_flat.cpp +++ b/vpr/src/pack/sync_netlists_to_routing_flat.cpp @@ -180,7 +180,7 @@ static void sync_pb_routes_to_routing(void) { * correspond to the atom net IDs. */ if (!route_ctx.route_trees[pb_route.atom_net_id]) { - /* No route tree: no routing in place, it is global or clock */ + /* No route tree: no routing in place, it is global or clock */ continue; } pins_to_erase.push_back(pin); @@ -365,7 +365,7 @@ static void sync_clustered_netlist_to_routing(void) { } PinType pin_type = node_type == OPIN ? PinType::DRIVER : PinType::SINK; - /* Pin already exists. This means a global was connected to here. */ + /* Pin already exists. This means a global net that was not routed (i.e. 'ideal' mode). */ if (clb_netlist.port_pin(port_id, pb_graph_pin->pin_number)) { VTR_LOG_WARN("Pin %s of block %s has a global or clock net" " connected and it has a routing clash with the flat router." From f5bb0eb0913b6401de0b000e8bc7f37b7d22eea7 Mon Sep 17 00:00:00 2001 From: amin1377 Date: Mon, 28 Apr 2025 10:23:28 -0400 Subject: [PATCH 18/18] [vpr][pack] fix parameter shadowing --- vpr/src/pack/cluster_router.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vpr/src/pack/cluster_router.cpp b/vpr/src/pack/cluster_router.cpp index 068fd4b3391..db2c58d6da9 100644 --- a/vpr/src/pack/cluster_router.cpp +++ b/vpr/src/pack/cluster_router.cpp @@ -619,8 +619,8 @@ static void load_trace_to_pb_route(t_pb_routes& pb_route, VTR_ASSERT(pb_route[cur_pin_id].atom_net_id == net_id); } } - for (const auto& trace : trace->next_nodes) { - load_trace_to_pb_route(pb_route, net_id, cur_pin_id, &trace, logic_block_type, intra_lb_pb_pin_lookup); + for (const auto& nxt_trace : trace->next_nodes) { + load_trace_to_pb_route(pb_route, net_id, cur_pin_id, &nxt_trace, logic_block_type, intra_lb_pb_pin_lookup); } }