diff options
author | Clifford Wolf <clifford@clifford.at> | 2018-06-22 15:38:17 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2018-06-22 15:38:17 +0200 |
commit | 001c6ceb5661976eb3f0146c1b819a7f2ad8ea7d (patch) | |
tree | 06846f1268806265eaaa4d1ec97410e8c0045621 /common | |
parent | 9b98a7175be440a6a59ddcc022615e04b8538bda (diff) | |
parent | 56c09fc5e5f7fb5c299f7a0b52e839556146615d (diff) | |
download | nextpnr-001c6ceb5661976eb3f0146c1b819a7f2ad8ea7d.tar.gz nextpnr-001c6ceb5661976eb3f0146c1b819a7f2ad8ea7d.tar.bz2 nextpnr-001c6ceb5661976eb3f0146c1b819a7f2ad8ea7d.zip |
Merge branch 'master' of gitlab.com:SymbioticEDA/nextpnr
Diffstat (limited to 'common')
-rw-r--r-- | common/place_sa.cc | 29 | ||||
-rw-r--r-- | common/util.h | 9 |
2 files changed, 27 insertions, 11 deletions
diff --git a/common/place_sa.cc b/common/place_sa.cc index 69ba968f..058f0a84 100644 --- a/common/place_sa.cc +++ b/common/place_sa.cc @@ -146,8 +146,9 @@ class SAPlacer // Calculate wirelength after initial placement curr_wirelength = 0; + curr_tns = 0; for (auto net : ctx->nets) { - wirelen_t wl = get_wirelength(net.second); + wirelen_t wl = get_wirelength(net.second, curr_tns); wirelengths[net.first] = wl; curr_wirelength += wl; } @@ -162,8 +163,9 @@ class SAPlacer improved = false; if (iter % 5 == 0 || iter == 1) - log_info(" at iteration #%d: temp = %f, wire length = %f\n", - iter, temp, double(curr_wirelength)); + log_info(" at iteration #%d: temp = %f, wire length = " + "%.0f, est tns = %.02fns\n", + iter, temp, double(curr_wirelength), curr_tns); for (int m = 0; m < 15; ++m) { // Loop through all automatically placed cells @@ -220,8 +222,9 @@ class SAPlacer // Recalculate total wirelength entirely to avoid rounding errors // accumulating over time curr_wirelength = 0; + curr_tns = 0; for (auto net : ctx->nets) { - wirelen_t wl = get_wirelength(net.second); + wirelen_t wl = get_wirelength(net.second, curr_tns); wirelengths[net.first] = wl; curr_wirelength += wl; } @@ -308,7 +311,7 @@ class SAPlacer } // Get the total estimated wirelength for a net - wirelen_t get_wirelength(NetInfo *net) + wirelen_t get_wirelength(NetInfo *net, float &tns) { wirelen_t wirelength = 0; int driver_x, driver_y; @@ -337,6 +340,8 @@ class SAPlacer delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); + if (slack < 0) + tns += slack; worst_slack = std::min(slack, worst_slack); int load_x, load_y; bool load_gb; @@ -348,8 +353,9 @@ class SAPlacer xmax = std::max(xmax, load_x); ymax = std::max(ymax, load_y); } - wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * - (1.0 + std::exp(-worst_slack / 5)))); + wirelength = + wirelen_t((((ymax - ymin) + (xmax - xmin)) * + std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); return wirelength; } @@ -403,16 +409,16 @@ class SAPlacer // Recalculate wirelengths for all nets touched by the peturbation for (auto net : update) { new_wirelength -= wirelengths.at(net->name); - wirelen_t net_new_wl = get_wirelength(net); + float temp_tns = 0; + wirelen_t net_new_wl = get_wirelength(net, temp_tns); new_wirelength += net_new_wl; new_lengths.push_back(std::make_pair(net->name, net_new_wl)); } delta = new_wirelength - curr_wirelength; n_move++; // SA acceptance criterea - if (delta < 0 || (temp > 1e-6 && - (ctx->rng() / float(0x3fffffff)) <= - std::exp(-(delta / 2) / temp))) { + if (delta < 0 || (temp > 1e-6 && (ctx->rng() / float(0x3fffffff)) <= + std::exp(-delta / temp))) { n_accept++; if (delta < 2) improved = true; @@ -466,6 +472,7 @@ class SAPlacer Context *ctx; std::unordered_map<IdString, wirelen_t> wirelengths; wirelen_t curr_wirelength = std::numeric_limits<wirelen_t>::max(); + float curr_tns = 0; float temp = 1000; bool improved = false; int n_move, n_accept; diff --git a/common/util.h b/common/util.h index 34b2ed02..4c60292b 100644 --- a/common/util.h +++ b/common/util.h @@ -20,6 +20,7 @@ #ifndef UTIL_H #define UTIL_H +#include <map> #include <string> #include "nextpnr.h" @@ -56,6 +57,14 @@ bool bool_or_default(const Container &ct, const KeyType &key, bool def = false) { return bool(int_or_default(ct, key, int(def))); }; + +// Wrap an unordered_map, and allow it to be iterated over sorted by key +template <typename K, typename V> +std::map<K, V> sorted(const std::unordered_map<K, V> &orig) +{ + return std::map<K, V>(orig.begin(), orig.end()); +}; + NEXTPNR_NAMESPACE_END #endif |