Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flat version of sync_netlists_to_routing #2691

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/libarchfpga/src/physical_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,9 @@ constexpr std::array<const char*, size_t(SwitchType::NUM_SWITCH_TYPES)> SWITCH_T
*/
constexpr const char* VPR_DELAYLESS_SWITCH_NAME = "__vpr_delayless_switch__";

/* An intracluster switch automatically added to the RRG by the flat router. */
constexpr const char* VPR_INTERNAL_SWITCH_NAME = "__vpr_intra_cluster_switch__";

enum class BufferSize {
AUTO,
ABSOLUTE
Expand Down
2 changes: 1 addition & 1 deletion libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
bool found_arch_name = false;
std::string string_name = std::string(name);
// 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.
bool is_internal_sw = string_name.compare(0, 15, "Internal Switch") == 0;
bool is_internal_sw = string_name.compare(0, strlen(VPR_INTERNAL_SWITCH_NAME), VPR_INTERNAL_SWITCH_NAME) == 0;
for (const auto& arch_sw_inf: arch_switch_inf_) {
if (string_name == arch_sw_inf.name || is_internal_sw) {
found_arch_name = true;
Expand Down
16 changes: 3 additions & 13 deletions utils/fasm/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ using namespace std;
#include "fasm.h"

#include "post_routing_pb_pin_fixup.h"
#include "sync_netlists_to_routing_flat.h"

/*
* Exit codes to signal success/failure to scripts
Expand Down Expand Up @@ -87,25 +88,14 @@ int main(int argc, const char **argv) {
bool is_flat = vpr_setup.RouterOpts.flat_routing;
if (flow_succeeded) {
if(is_flat) {
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.atom().nlist,
g_vpr_ctx.device(),
g_vpr_ctx.mutable_atom(),
g_vpr_ctx.atom().lookup,
g_vpr_ctx.mutable_clustering(),
g_vpr_ctx.placement(),
g_vpr_ctx.routing(),
vpr_setup.PackerOpts.pack_verbosity > 2,
is_flat);
sync_netlists_to_routing_flat();
} else {
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.device(),
g_vpr_ctx.mutable_atom(),
g_vpr_ctx.atom().lookup,
g_vpr_ctx.mutable_clustering(),
g_vpr_ctx.placement(),
g_vpr_ctx.routing(),
vpr_setup.PackerOpts.pack_verbosity > 2,
is_flat);
vpr_setup.PackerOpts.pack_verbosity > 2);
}
}

Expand Down
23 changes: 13 additions & 10 deletions utils/fasm/test/test_fasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#include "fasm_utils.h"
#include "arch_util.h"
#include "rr_graph_writer.h"
#include "post_routing_pb_pin_fixup.h"
#include <sstream>
#include <fstream>
#include <regex>
#include <cmath>
#include <algorithm>

#include "post_routing_pb_pin_fixup.h"
#include "sync_netlists_to_routing_flat.h"

static constexpr const char kArchFile[] = "test_fasm_arch.xml";
static constexpr const char kRrGraphFile[] = "test_fasm_rrgraph.xml";

Expand Down Expand Up @@ -328,15 +330,16 @@ TEST_CASE("fasm_integration_test", "[fasm]") {
/* Sync netlist to the actual routing (necessary if there are block
ports with equivalent pins) */
if (flow_succeeded) {
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.device(),
g_vpr_ctx.mutable_atom(),
g_vpr_ctx.atom().lookup,
g_vpr_ctx.mutable_clustering(),
g_vpr_ctx.placement(),
g_vpr_ctx.routing(),
vpr_setup.PackerOpts.pack_verbosity > 2,
is_flat);
if (is_flat) {
sync_netlists_to_routing_flat();
} else {
sync_netlists_to_routing((const Netlist<>&) g_vpr_ctx.clustering().clb_nlist,
g_vpr_ctx.device(),
g_vpr_ctx.mutable_atom(),
g_vpr_ctx.mutable_clustering(),
g_vpr_ctx.placement(),
vpr_setup.PackerOpts.pack_verbosity > 2);
}
}

std::stringstream fasm_string;
Expand Down
53 changes: 35 additions & 18 deletions vpr/src/base/atom_lookup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "clustered_netlist_fwd.h"
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_optional.h"

#include "atom_lookup.h"
/*
Expand Down Expand Up @@ -85,36 +87,51 @@ void AtomLookup::set_atom_clb(const AtomBlockId blk_id, const ClusterBlockId clb
* Nets
*/
AtomNetId AtomLookup::atom_net(const ClusterNetId clb_net_index) const {
auto iter = atom_net_to_clb_net_.find(clb_net_index);
if (iter == atom_net_to_clb_net_.inverse_end()) {
auto iter = clb_net_to_atom_net_.find(clb_net_index);
if (iter == clb_net_to_atom_net_.end()) {
//Not found
return AtomNetId::INVALID();
}
return iter->second;
}

ClusterNetId AtomLookup::clb_net(const AtomNetId net_id) const {
auto iter = atom_net_to_clb_net_.find(net_id);
if (iter == atom_net_to_clb_net_.end()) {
vtr::optional<const std::vector<ClusterNetId>&> AtomLookup::clb_nets(const AtomNetId atom_net) const {
auto iter = atom_net_to_clb_nets_.find(atom_net);
if (iter == atom_net_to_clb_nets_.end()) {
//Not found
return ClusterNetId::INVALID();
return vtr::nullopt;
}
return iter->second;
}

void AtomLookup::set_atom_clb_net(const AtomNetId net_id, const ClusterNetId clb_net_index) {
VTR_ASSERT(net_id);
//If either are invalid remove any mapping
if (!net_id && clb_net_index != ClusterNetId::INVALID()) {
//Remove
atom_net_to_clb_net_.erase(clb_net_index);
} else if (net_id && clb_net_index == ClusterNetId::INVALID()) {
//Remove
atom_net_to_clb_net_.erase(net_id);
} else if (net_id && clb_net_index != ClusterNetId::INVALID()) {
//Store
atom_net_to_clb_net_.update(net_id, clb_net_index);
void AtomLookup::add_atom_clb_net(const AtomNetId atom_net, const ClusterNetId clb_net) {
VTR_ASSERT(atom_net && clb_net);

/* Use the default behavior of [] operator */
atom_net_to_clb_nets_[atom_net].push_back(clb_net);
clb_net_to_atom_net_[clb_net] = atom_net;
}

void AtomLookup::remove_clb_net(const ClusterNetId clb_net){
if(!clb_net_to_atom_net_.count(clb_net))
return;

auto atom_net = clb_net_to_atom_net_[clb_net];
auto& all_clb_nets = atom_net_to_clb_nets_[atom_net];
/* This is o(n), but an AtomNetId rarely has >5 ClusterNetIds */
all_clb_nets.erase(std::remove(all_clb_nets.begin(), all_clb_nets.end(), clb_net), all_clb_nets.end());
}

/* Remove mapping for given atom net */
void AtomLookup::remove_atom_net(const AtomNetId atom_net) {
if(!atom_net_to_clb_nets_.count(atom_net))
return;

auto cluster_nets = atom_net_to_clb_nets_[atom_net];
for(auto c: cluster_nets){
clb_net_to_atom_net_.erase(c);
}
atom_net_to_clb_nets_.erase(atom_net);
}

/*
Expand Down
21 changes: 14 additions & 7 deletions vpr/src/base/atom_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "vpr_types.h"
#include "tatum/TimingGraphFwd.hpp"

#include "vtr_optional.h"

/**
* @brief The AtomLookup class describes the mapping between components in the AtomNetlist
* and other netlists/entities (i.e. atom block <-> t_pb, atom block <-> clb)
Expand Down Expand Up @@ -76,17 +78,21 @@ class AtomLookup {
*/

///@brief Returns the atom net id associated with the clb_net_index
AtomNetId atom_net(const ClusterNetId clb_net_index) const;
AtomNetId atom_net(const ClusterNetId cluster_net_id) const;

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

/**
* @brief Sets the bidirectional mapping between an atom net and a clb net
*
* If either net_id or clb_net_index are not valid any existing mapping is removed
*/
void set_atom_clb_net(const AtomNetId net_id, const ClusterNetId clb_net_index);
void add_atom_clb_net(const AtomNetId atom_net, const ClusterNetId clb_net);

/** Remove given clb net from the mapping */
void remove_clb_net(const ClusterNetId clb_net);

/** Remove given atom net from the mapping */
void remove_atom_net(const AtomNetId atom_net);

/*
* Timing Nodes
Expand All @@ -112,7 +118,8 @@ class AtomLookup {

vtr::vector_map<AtomBlockId, ClusterBlockId> atom_to_clb_;

vtr::bimap<AtomNetId, ClusterNetId, vtr::linear_map, vtr::linear_map> atom_net_to_clb_net_;
vtr::linear_map<AtomNetId, std::vector<ClusterNetId>> atom_net_to_clb_nets_;
vtr::linear_map<ClusterNetId, AtomNetId> clb_net_to_atom_net_;

vtr::linear_map<AtomPinId, tatum::NodeId> atom_pin_tnode_external_;
vtr::linear_map<AtomPinId, tatum::NodeId> atom_pin_tnode_internal_;
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/base/read_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ ClusteredNetlist read_netlist(const char* net_file,

/* load mapping between external nets and all nets */
for (auto net_id : atom_ctx.nlist.nets()) {
atom_ctx.lookup.set_atom_clb_net(net_id, ClusterNetId::INVALID());
atom_ctx.lookup.remove_atom_net(net_id);
}

//Save the mapping between clb and atom nets
for (auto clb_net_id : clb_nlist.nets()) {
AtomNetId net_id = atom_ctx.nlist.find_net(clb_nlist.net_name(clb_net_id));
VTR_ASSERT(net_id);
atom_ctx.lookup.set_atom_clb_net(net_id, clb_net_id);
atom_ctx.lookup.add_atom_clb_net(net_id, clb_net_id);
}

// Mark ignored and global atom nets
Expand Down
29 changes: 14 additions & 15 deletions vpr/src/base/vpr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#include "arch_util.h"

#include "post_routing_pb_pin_fixup.h"

#include "sync_netlists_to_routing_flat.h"

#include "load_flat_place.h"

Expand Down Expand Up @@ -1468,27 +1468,26 @@ bool vpr_analysis_flow(const Netlist<>& net_list,
* - Turn on verbose output when users require verbose output
* for packer (default verbosity is set to 2 for compact logs)
*/
if (!is_flat) {
if (route_status.success()) {
if (route_status.success()) {
if (is_flat) {
sync_netlists_to_routing_flat();
} else {
sync_netlists_to_routing(net_list,
g_vpr_ctx.device(),
g_vpr_ctx.mutable_atom(),
g_vpr_ctx.atom().lookup,
g_vpr_ctx.mutable_clustering(),
g_vpr_ctx.placement(),
g_vpr_ctx.routing(),
vpr_setup.PackerOpts.pack_verbosity > 2,
is_flat);

std::string post_routing_packing_output_file_name = vpr_setup.PackerOpts.output_file + ".post_routing";
write_packing_results_to_xml(vpr_setup.PackerOpts.global_clocks,
Arch.architecture_id,
post_routing_packing_output_file_name.c_str());
} else {
VTR_LOG_WARN("Synchronization between packing and routing results is not applied due to illegal circuit implementation\n");
vpr_setup.PackerOpts.pack_verbosity > 2);
}
VTR_LOG("\n");

std::string post_routing_packing_output_file_name = vpr_setup.PackerOpts.output_file + ".post_routing";
write_packing_results_to_xml(vpr_setup.PackerOpts.global_clocks,
Arch.architecture_id,
post_routing_packing_output_file_name.c_str());
} else {
VTR_LOG_WARN("Synchronization between packing and routing results is not applied due to illegal circuit implementation\n");
}
VTR_LOG("\n");

vpr_analysis(net_list,
vpr_setup,
Expand Down
3 changes: 3 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ struct RoutingContext : public Context {
* @brief User specified routing constraints
*/
UserRouteConstraints constraints;

/** Is flat routing enabled? */
bool is_flat;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions vpr/src/draw/search_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ void search_and_highlight(GtkWidget* /*widget*/, ezgl::application* app) {
warning_dialog_box("Invalid Net Name");
return; //name not exist
}
ClusterNetId clb_net_id = atom_ctx.lookup.clb_net(atom_net_id);
highlight_nets(clb_net_id);
for(auto clb_net_id: atom_ctx.lookup.clb_nets(atom_net_id).value()){
highlight_nets(clb_net_id);
}
}

else
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/pack/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ bool try_pack(t_packer_opts* packer_opts,
g_vpr_ctx.mutable_atom().lookup.set_atom_pb(blk, nullptr);
}
for (auto net : g_vpr_ctx.atom().nlist.nets()) {
g_vpr_ctx.mutable_atom().lookup.set_atom_clb_net(net, ClusterNetId::INVALID());
g_vpr_ctx.mutable_atom().lookup.remove_atom_net(net);
}
g_vpr_ctx.mutable_floorplanning().cluster_constraints.clear();
//attraction_groups.reset_attraction_groups();
Expand Down
Loading
Loading