Skip to content

Commit 7b956b6

Browse files
committed
Add flat version of sync_netlists_to_routing
1 parent a574c73 commit 7b956b6

20 files changed

+649
-150
lines changed

libs/libarchfpga/src/physical_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,9 @@ constexpr std::array<const char*, size_t(SwitchType::NUM_SWITCH_TYPES)> SWITCH_T
16891689
*/
16901690
constexpr const char* VPR_DELAYLESS_SWITCH_NAME = "__vpr_delayless_switch__";
16911691

1692+
/* An intracluster switch automatically added to the RRG by the flat router. */
1693+
constexpr const char* VPR_INTERNAL_SWITCH_NAME = "__vpr_intra_cluster_switch__";
1694+
16921695
enum class BufferSize {
16931696
AUTO,
16941697
ABSOLUTE

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
526526
bool found_arch_name = false;
527527
std::string string_name = std::string(name);
528528
// The string name has the format of "Internal Switch/delay". So, I have to use compare to specify the portion I want to be compared.
529-
bool is_internal_sw = string_name.compare(0, 15, "Internal Switch") == 0;
529+
bool is_internal_sw = string_name.compare(0, strlen(VPR_INTERNAL_SWITCH_NAME), VPR_INTERNAL_SWITCH_NAME) == 0;
530530
for (const auto& arch_sw_inf: arch_switch_inf_) {
531531
if (string_name == arch_sw_inf.name || is_internal_sw) {
532532
found_arch_name = true;

utils/fasm/src/main.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ using namespace std;
2323
#include "fasm.h"
2424

2525
#include "post_routing_pb_pin_fixup.h"
26+
#include "sync_netlists_to_routing_flat.h"
2627

2728
/*
2829
* Exit codes to signal success/failure to scripts
@@ -87,25 +88,14 @@ int main(int argc, const char **argv) {
8788
bool is_flat = vpr_setup.RouterOpts.flat_routing;
8889
if (flow_succeeded) {
8990
if(is_flat) {
90-
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.atom().nlist,
91-
g_vpr_ctx.device(),
92-
g_vpr_ctx.mutable_atom(),
93-
g_vpr_ctx.atom().lookup,
94-
g_vpr_ctx.mutable_clustering(),
95-
g_vpr_ctx.placement(),
96-
g_vpr_ctx.routing(),
97-
vpr_setup.PackerOpts.pack_verbosity > 2,
98-
is_flat);
91+
sync_netlists_to_routing_flat();
9992
} else {
10093
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
10194
g_vpr_ctx.device(),
10295
g_vpr_ctx.mutable_atom(),
103-
g_vpr_ctx.atom().lookup,
10496
g_vpr_ctx.mutable_clustering(),
10597
g_vpr_ctx.placement(),
106-
g_vpr_ctx.routing(),
107-
vpr_setup.PackerOpts.pack_verbosity > 2,
108-
is_flat);
98+
vpr_setup.PackerOpts.pack_verbosity > 2);
10999
}
110100
}
111101

utils/fasm/test/test_fasm.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#include "fasm_utils.h"
1010
#include "arch_util.h"
1111
#include "rr_graph_writer.h"
12-
#include "post_routing_pb_pin_fixup.h"
1312
#include <sstream>
1413
#include <fstream>
1514
#include <regex>
1615
#include <cmath>
1716
#include <algorithm>
1817

18+
#include "post_routing_pb_pin_fixup.h"
19+
#include "sync_netlists_to_routing_flat.h"
20+
1921
static constexpr const char kArchFile[] = "test_fasm_arch.xml";
2022
static constexpr const char kRrGraphFile[] = "test_fasm_rrgraph.xml";
2123

@@ -328,15 +330,16 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
328330
/* Sync netlist to the actual routing (necessary if there are block
329331
ports with equivalent pins) */
330332
if (flow_succeeded) {
331-
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
332-
g_vpr_ctx.device(),
333-
g_vpr_ctx.mutable_atom(),
334-
g_vpr_ctx.atom().lookup,
335-
g_vpr_ctx.mutable_clustering(),
336-
g_vpr_ctx.placement(),
337-
g_vpr_ctx.routing(),
338-
vpr_setup.PackerOpts.pack_verbosity > 2,
339-
is_flat);
333+
if (is_flat) {
334+
sync_netlists_to_routing_flat();
335+
} else {
336+
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
337+
g_vpr_ctx.device(),
338+
g_vpr_ctx.mutable_atom(),
339+
g_vpr_ctx.mutable_clustering(),
340+
g_vpr_ctx.placement(),
341+
vpr_setup.PackerOpts.pack_verbosity > 2);
342+
}
340343
}
341344

342345
std::stringstream fasm_string;

vpr/src/base/atom_lookup.cpp

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include "clustered_netlist_fwd.h"
12
#include "vtr_assert.h"
23
#include "vtr_log.h"
4+
#include "vtr_optional.h"
35

46
#include "atom_lookup.h"
57
/*
@@ -85,36 +87,51 @@ void AtomLookup::set_atom_clb(const AtomBlockId blk_id, const ClusterBlockId clb
8587
* Nets
8688
*/
8789
AtomNetId AtomLookup::atom_net(const ClusterNetId clb_net_index) const {
88-
auto iter = atom_net_to_clb_net_.find(clb_net_index);
89-
if (iter == atom_net_to_clb_net_.inverse_end()) {
90+
auto iter = clb_net_to_atom_net_.find(clb_net_index);
91+
if (iter == clb_net_to_atom_net_.end()) {
9092
//Not found
9193
return AtomNetId::INVALID();
9294
}
9395
return iter->second;
9496
}
9597

96-
ClusterNetId AtomLookup::clb_net(const AtomNetId net_id) const {
97-
auto iter = atom_net_to_clb_net_.find(net_id);
98-
if (iter == atom_net_to_clb_net_.end()) {
98+
vtr::optional<const std::vector<ClusterNetId>&> AtomLookup::clb_nets(const AtomNetId atom_net) const {
99+
auto iter = atom_net_to_clb_nets_.find(atom_net);
100+
if (iter == atom_net_to_clb_nets_.end()) {
99101
//Not found
100-
return ClusterNetId::INVALID();
102+
return vtr::nullopt;
101103
}
102104
return iter->second;
103105
}
104106

105-
void AtomLookup::set_atom_clb_net(const AtomNetId net_id, const ClusterNetId clb_net_index) {
106-
VTR_ASSERT(net_id);
107-
//If either are invalid remove any mapping
108-
if (!net_id && clb_net_index != ClusterNetId::INVALID()) {
109-
//Remove
110-
atom_net_to_clb_net_.erase(clb_net_index);
111-
} else if (net_id && clb_net_index == ClusterNetId::INVALID()) {
112-
//Remove
113-
atom_net_to_clb_net_.erase(net_id);
114-
} else if (net_id && clb_net_index != ClusterNetId::INVALID()) {
115-
//Store
116-
atom_net_to_clb_net_.update(net_id, clb_net_index);
107+
void AtomLookup::add_atom_clb_net(const AtomNetId atom_net, const ClusterNetId clb_net) {
108+
VTR_ASSERT(atom_net && clb_net);
109+
110+
/* Use the default behavior of [] operator */
111+
atom_net_to_clb_nets_[atom_net].push_back(clb_net);
112+
clb_net_to_atom_net_[clb_net] = atom_net;
113+
}
114+
115+
void AtomLookup::remove_clb_net(const ClusterNetId clb_net){
116+
if(!clb_net_to_atom_net_.count(clb_net))
117+
return;
118+
119+
auto atom_net = clb_net_to_atom_net_[clb_net];
120+
auto& all_clb_nets = atom_net_to_clb_nets_[atom_net];
121+
/* This is o(n), but an AtomNetId rarely has >5 ClusterNetIds */
122+
all_clb_nets.erase(std::remove(all_clb_nets.begin(), all_clb_nets.end(), clb_net), all_clb_nets.end());
123+
}
124+
125+
/* Remove mapping for given atom net */
126+
void AtomLookup::remove_atom_net(const AtomNetId atom_net) {
127+
if(!atom_net_to_clb_nets_.count(atom_net))
128+
return;
129+
130+
auto cluster_nets = atom_net_to_clb_nets_[atom_net];
131+
for(auto c: cluster_nets){
132+
clb_net_to_atom_net_.erase(c);
117133
}
134+
atom_net_to_clb_nets_.erase(atom_net);
118135
}
119136

120137
/*

vpr/src/base/atom_lookup.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "vpr_types.h"
1414
#include "tatum/TimingGraphFwd.hpp"
1515

16+
#include "vtr_optional.h"
17+
1618
/**
1719
* @brief The AtomLookup class describes the mapping between components in the AtomNetlist
1820
* and other netlists/entities (i.e. atom block <-> t_pb, atom block <-> clb)
@@ -76,17 +78,21 @@ class AtomLookup {
7678
*/
7779

7880
///@brief Returns the atom net id associated with the clb_net_index
79-
AtomNetId atom_net(const ClusterNetId clb_net_index) const;
81+
AtomNetId atom_net(const ClusterNetId cluster_net_id) const;
8082

81-
///@brief Returns the clb net index associated with net_id
82-
ClusterNetId clb_net(const AtomNetId net_id) const;
83+
///@brief Returns the clb net indices associated with atom_net_id
84+
vtr::optional<const std::vector<ClusterNetId>&> clb_nets(const AtomNetId atom_net_id) const;
8385

8486
/**
8587
* @brief Sets the bidirectional mapping between an atom net and a clb net
86-
*
87-
* If either net_id or clb_net_index are not valid any existing mapping is removed
8888
*/
89-
void set_atom_clb_net(const AtomNetId net_id, const ClusterNetId clb_net_index);
89+
void add_atom_clb_net(const AtomNetId atom_net, const ClusterNetId clb_net);
90+
91+
/** Remove given clb net from the mapping */
92+
void remove_clb_net(const ClusterNetId clb_net);
93+
94+
/** Remove given atom net from the mapping */
95+
void remove_atom_net(const AtomNetId atom_net);
9096

9197
/*
9298
* Timing Nodes
@@ -112,7 +118,8 @@ class AtomLookup {
112118

113119
vtr::vector_map<AtomBlockId, ClusterBlockId> atom_to_clb_;
114120

115-
vtr::bimap<AtomNetId, ClusterNetId, vtr::linear_map, vtr::linear_map> atom_net_to_clb_net_;
121+
vtr::linear_map<AtomNetId, std::vector<ClusterNetId>> atom_net_to_clb_nets_;
122+
vtr::linear_map<ClusterNetId, AtomNetId> clb_net_to_atom_net_;
116123

117124
vtr::linear_map<AtomPinId, tatum::NodeId> atom_pin_tnode_external_;
118125
vtr::linear_map<AtomPinId, tatum::NodeId> atom_pin_tnode_internal_;

vpr/src/base/read_netlist.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ ClusteredNetlist read_netlist(const char* net_file,
218218

219219
/* load mapping between external nets and all nets */
220220
for (auto net_id : atom_ctx.nlist.nets()) {
221-
atom_ctx.lookup.set_atom_clb_net(net_id, ClusterNetId::INVALID());
221+
atom_ctx.lookup.remove_atom_net(net_id);
222222
}
223223

224224
//Save the mapping between clb and atom nets
225225
for (auto clb_net_id : clb_nlist.nets()) {
226226
AtomNetId net_id = atom_ctx.nlist.find_net(clb_nlist.net_name(clb_net_id));
227227
VTR_ASSERT(net_id);
228-
atom_ctx.lookup.set_atom_clb_net(net_id, clb_net_id);
228+
atom_ctx.lookup.add_atom_clb_net(net_id, clb_net_id);
229229
}
230230

231231
// Mark ignored and global atom nets

vpr/src/base/vpr_api.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#include "arch_util.h"
8787

8888
#include "post_routing_pb_pin_fixup.h"
89-
89+
#include "sync_netlists_to_routing_flat.h"
9090

9191
#include "load_flat_place.h"
9292

@@ -1477,27 +1477,26 @@ bool vpr_analysis_flow(const Netlist<>& net_list,
14771477
* - Turn on verbose output when users require verbose output
14781478
* for packer (default verbosity is set to 2 for compact logs)
14791479
*/
1480-
if (!is_flat) {
1481-
if (route_status.success()) {
1480+
if (route_status.success()) {
1481+
if (is_flat) {
1482+
sync_netlists_to_routing_flat();
1483+
} else {
14821484
sync_netlists_to_routing(net_list,
14831485
g_vpr_ctx.device(),
14841486
g_vpr_ctx.mutable_atom(),
1485-
g_vpr_ctx.atom().lookup,
14861487
g_vpr_ctx.mutable_clustering(),
14871488
g_vpr_ctx.placement(),
1488-
g_vpr_ctx.routing(),
1489-
vpr_setup.PackerOpts.pack_verbosity > 2,
1490-
is_flat);
1491-
1492-
std::string post_routing_packing_output_file_name = vpr_setup.PackerOpts.output_file + ".post_routing";
1493-
write_packing_results_to_xml(vpr_setup.PackerOpts.global_clocks,
1494-
Arch.architecture_id,
1495-
post_routing_packing_output_file_name.c_str());
1496-
} else {
1497-
VTR_LOG_WARN("Synchronization between packing and routing results is not applied due to illegal circuit implementation\n");
1489+
vpr_setup.PackerOpts.pack_verbosity > 2);
14981490
}
1499-
VTR_LOG("\n");
1491+
1492+
std::string post_routing_packing_output_file_name = vpr_setup.PackerOpts.output_file + ".post_routing";
1493+
write_packing_results_to_xml(vpr_setup.PackerOpts.global_clocks,
1494+
Arch.architecture_id,
1495+
post_routing_packing_output_file_name.c_str());
1496+
} else {
1497+
VTR_LOG_WARN("Synchronization between packing and routing results is not applied due to illegal circuit implementation\n");
15001498
}
1499+
VTR_LOG("\n");
15011500

15021501
vpr_analysis(net_list,
15031502
vpr_setup,

vpr/src/base/vpr_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ struct RoutingContext : public Context {
466466
* @brief User specified routing constraints
467467
*/
468468
UserRouteConstraints constraints;
469+
470+
/** Is flat routing enabled? */
471+
bool is_flat;
469472
};
470473

471474
/**

vpr/src/draw/search_bar.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
167167
warning_dialog_box("Invalid Net Name");
168168
return; //name not exist
169169
}
170-
ClusterNetId clb_net_id = atom_ctx.lookup.clb_net(atom_net_id);
171-
highlight_nets(clb_net_id);
170+
for(auto clb_net_id: atom_ctx.lookup.clb_nets(atom_net_id).value()){
171+
highlight_nets(clb_net_id);
172+
}
172173
}
173174

174175
else

vpr/src/pack/pack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool try_pack(t_packer_opts* packer_opts,
232232
g_vpr_ctx.mutable_atom().lookup.set_atom_pb(blk, nullptr);
233233
}
234234
for (auto net : g_vpr_ctx.atom().nlist.nets()) {
235-
g_vpr_ctx.mutable_atom().lookup.set_atom_clb_net(net, ClusterNetId::INVALID());
235+
g_vpr_ctx.mutable_atom().lookup.remove_atom_net(net);
236236
}
237237
g_vpr_ctx.mutable_floorplanning().cluster_constraints.clear();
238238
//attraction_groups.reset_attraction_groups();

0 commit comments

Comments
 (0)