aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-05-21 09:59:19 +0100
committerGitHub <noreply@github.com>2021-05-21 09:59:19 +0100
commit81818fd38c5405005305d1b8354eb75beb8dc18d (patch)
tree776fbc43bd241c48505a033d3a5ab7bf367596c8
parent54b8364ceaa3be52cf5161e268cdefa96588e749 (diff)
parent1595c0726079e62313e0df82bdb31120b72bdc39 (diff)
downloadnextpnr-81818fd38c5405005305d1b8354eb75beb8dc18d.tar.gz
nextpnr-81818fd38c5405005305d1b8354eb75beb8dc18d.tar.bz2
nextpnr-81818fd38c5405005305d1b8354eb75beb8dc18d.zip
Merge pull request #712 from YosysHQ/gatecat/rr-heatmap
router2: Add heatmap by routing resource type
-rw-r--r--common/command.cc5
-rw-r--r--common/router2.cc43
-rw-r--r--common/router2.h4
-rw-r--r--nexus/arch.cc11
-rw-r--r--nexus/arch.h2
-rw-r--r--nexus/constids.inc2
6 files changed, 64 insertions, 3 deletions
diff --git a/common/command.cc b/common/command.cc
index 5f19e01b..f48d6adf 100644
--- a/common/command.cc
+++ b/common/command.cc
@@ -170,6 +170,9 @@ po::options_description CommandHandler::getGeneralOptions()
"placer heap criticality exponent (int, default: 2)");
general.add_options()("placer-heap-timingweight", po::value<int>(), "placer heap timing weight (int, default: 10)");
+ general.add_options()("router2-heatmap", po::value<std::string>(),
+ "prefix for router2 resource congestion heatmaps");
+
general.add_options()("placed-svg", po::value<std::string>(), "write render of placement to SVG file");
general.add_options()("routed-svg", po::value<std::string>(), "write render of routing to SVG file");
@@ -278,6 +281,8 @@ void CommandHandler::setupContext(Context *ctx)
if (vm.count("placer-heap-timingweight"))
ctx->settings[ctx->id("placerHeap/timingWeight")] = std::to_string(vm["placer-heap-timingweight"].as<int>());
+ if (vm.count("router2-heatmap"))
+ ctx->settings[ctx->id("router2/heatmap")] = vm["router2-heatmap"].as<std::string>();
// Setting default values
if (ctx->settings.find(ctx->id("target_freq")) == ctx->settings.end())
diff --git a/common/router2.cc b/common/router2.cc
index 19fb5574..2156ce28 100644
--- a/common/router2.cc
+++ b/common/router2.cc
@@ -1043,7 +1043,7 @@ struct Router2
return success;
}
- void write_heatmap(std::ostream &out, bool congestion = false)
+ void write_xy_heatmap(std::ostream &out, bool congestion = false)
{
std::vector<std::vector<int>> hm_xy;
int max_x = 0, max_y = 0;
@@ -1080,6 +1080,33 @@ struct Router2
out << std::endl;
}
}
+
+ void write_wiretype_heatmap(std::ostream &out)
+ {
+ std::unordered_map<IdString, std::vector<int>> cong_by_type;
+ size_t max_cong = 0;
+ // Build histogram
+ for (auto &wd : flat_wires) {
+ size_t val = wd.bound_nets.size();
+ IdString type = ctx->getWireType(wd.w);
+ max_cong = std::max(max_cong, val);
+ if (cong_by_type[type].size() <= max_cong)
+ cong_by_type[type].resize(max_cong + 1);
+ cong_by_type[type].at(val) += 1;
+ }
+ // Write csv
+ out << "type,";
+ for (size_t i = 0; i <= max_cong; i++)
+ out << "bound=" << i << ",";
+ out << std::endl;
+ for (auto &ty : sorted_ref(cong_by_type)) {
+ out << ctx->nameOf(ty.first) << ",";
+ for (int count : ty.second)
+ out << count << ",";
+ out << std::endl;
+ }
+ }
+
int mid_x = 0, mid_y = 0;
void partition_nets()
@@ -1332,9 +1359,17 @@ struct Router2
#if 0
if (iter == 1 && ctx->debug) {
std::ofstream cong_map("cong_map_0.csv");
- write_heatmap(cong_map, true);
+ write_xy_heatmap(cong_map, true);
}
#endif
+ if (!cfg.heatmap.empty()) {
+ std::string filename(cfg.heatmap + "_" + std::to_string(iter) + ".csv");
+ std::ofstream cong_map(filename);
+ if (!cong_map)
+ log_error("Failed to open wiretype heatmap %s for writing.\n", filename.c_str());
+ write_wiretype_heatmap(cong_map);
+ log_info(" wrote wiretype heatmap to %s.\n", filename.c_str());
+ }
dump_statistics();
if (overused_wires == 0) {
@@ -1394,6 +1429,10 @@ Router2Cfg::Router2Cfg(Context *ctx)
curr_cong_mult = ctx->setting<float>("router2/currCongWeightMult", 2.0f);
estimate_weight = ctx->setting<float>("router2/estimateWeight", 1.75f);
perf_profile = ctx->setting<bool>("router2/perfProfile", false);
+ if (ctx->settings.count(ctx->id("router2/heatmap")))
+ heatmap = ctx->settings.at(ctx->id("router2/heatmap")).as_string();
+ else
+ heatmap = "";
}
NEXTPNR_NAMESPACE_END
diff --git a/common/router2.h b/common/router2.h
index fb11f92d..b12e62c6 100644
--- a/common/router2.h
+++ b/common/router2.h
@@ -49,8 +49,10 @@ struct Router2Cfg
// Print additional performance profiling information
bool perf_profile = false;
+
+ std::string heatmap;
};
void router2(Context *ctx, const Router2Cfg &cfg);
-NEXTPNR_NAMESPACE_END \ No newline at end of file
+NEXTPNR_NAMESPACE_END
diff --git a/nexus/arch.cc b/nexus/arch.cc
index f804cdd9..d5bb9deb 100644
--- a/nexus/arch.cc
+++ b/nexus/arch.cc
@@ -325,6 +325,17 @@ std::vector<std::pair<IdString, std::string>> Arch::getWireAttrs(WireId wire) co
return ret;
}
+IdString Arch::getWireType(WireId wire) const
+{
+ IdString basename(wire_data(wire).name);
+ const std::string &basename_str = basename.str(this);
+ // Interconnect - derive a type
+ if ((basename_str[0] == 'H' || basename_str[0] == 'V') && basename_str[1] == '0')
+ return id(basename_str.substr(0, 4));
+ else
+ return id_GENERAL;
+}
+
// -----------------------------------------------------------------------
PipId Arch::getPipByName(IdStringList name) const
diff --git a/nexus/arch.h b/nexus/arch.h
index 55e9becd..b3558413 100644
--- a/nexus/arch.h
+++ b/nexus/arch.h
@@ -1034,6 +1034,7 @@ struct Arch : BaseArch<ArchRanges>
// -------------------------------------------------
WireId getWireByName(IdStringList name) const override;
+
IdStringList getWireName(WireId wire) const override
{
NPNR_ASSERT(wire != WireId());
@@ -1043,6 +1044,7 @@ struct Arch : BaseArch<ArchRanges>
}
std::vector<std::pair<IdString, std::string>> getWireAttrs(WireId wire) const override;
+ IdString getWireType(WireId wire) const override;
DelayQuad getWireDelay(WireId wire) const override { return DelayQuad(0); }
diff --git a/nexus/constids.inc b/nexus/constids.inc
index 03b144a2..d75b6ea5 100644
--- a/nexus/constids.inc
+++ b/nexus/constids.inc
@@ -503,3 +503,5 @@ X(U2END2)
X(U3END3)
X(UED0THEN)
X(URXCKINE)
+
+X(GENERAL)