aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-05-20 14:54:23 +0100
committergatecat <gatecat@ds0.me>2021-05-20 14:54:23 +0100
commit1595c0726079e62313e0df82bdb31120b72bdc39 (patch)
tree0b8e243e8b72785bde9c4d1b3758aa5658ffa465 /common
parent5a41d2070c8a7c065d4e3fbfb70b3a3fbd19b319 (diff)
downloadnextpnr-1595c0726079e62313e0df82bdb31120b72bdc39.tar.gz
nextpnr-1595c0726079e62313e0df82bdb31120b72bdc39.tar.bz2
nextpnr-1595c0726079e62313e0df82bdb31120b72bdc39.zip
router2: Add heatmap by routing resource type
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to 'common')
-rw-r--r--common/command.cc5
-rw-r--r--common/router2.cc43
-rw-r--r--common/router2.h4
3 files changed, 49 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