From 2ad355ebeb00d9698efe2bb910a500e401f5d50b Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 11 Jul 2018 08:05:42 +0200 Subject: Renamed dummy->generic for tests, also fix warning --- common/pybindings.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common') diff --git a/common/pybindings.cc b/common/pybindings.cc index 64055755..1a0eba8f 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -151,7 +151,9 @@ BOOST_PYTHON_MODULE(MODULE_NAME) arch_wrap_python(); } +#ifdef MAIN_EXECUTABLE static wchar_t *program; +#endif void init_python(const char *executable, bool first) { -- cgit v1.2.3 From c4af52dd5b3830905e2b9e8f7135f886882841ba Mon Sep 17 00:00:00 2001 From: David Shah Date: Thu, 5 Jul 2018 20:59:11 +0200 Subject: ecp5: Working on arch implementation Signed-off-by: David Shah --- common/pybindings.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/pybindings.cc b/common/pybindings.cc index 1a0eba8f..061dfc47 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -110,13 +110,13 @@ BOOST_PYTHON_MODULE(MODULE_NAME) readwrite_wrapper, pass_through>::def_wrap(ci_cls, "belStrength"); readonly_wrapper>::def_wrap(ci_cls, - "pins"); + "pins"); auto pi_cls = class_>("PortInfo", no_init); readwrite_wrapper, conv_from_str>::def_wrap(pi_cls, "name"); readonly_wrapper>::def_wrap(pi_cls, - "net"); + "net"); readwrite_wrapper, pass_through>::def_wrap(pi_cls, "type"); @@ -131,11 +131,11 @@ BOOST_PYTHON_MODULE(MODULE_NAME) readonly_wrapper>::def_wrap( ni_cls, "users"); readonly_wrapper>::def_wrap(ni_cls, - "wires"); + "wires"); auto pr_cls = class_>("PortRef", no_init); readonly_wrapper>::def_wrap(pr_cls, - "cell"); + "cell"); readwrite_wrapper, conv_from_str>::def_wrap(pr_cls, "port"); readwrite_wrapper, -- cgit v1.2.3 From b397dd80712005e4c71b492e27d6af35e6bdc1e9 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 9 Jul 2018 12:55:56 +0200 Subject: ecp5: Adding bitstream gen for slice config Signed-off-by: David Shah --- common/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common') diff --git a/common/util.h b/common/util.h index 60eb35af..b492b98c 100644 --- a/common/util.h +++ b/common/util.h @@ -39,6 +39,18 @@ ValueType get_or_default(const Container &ct, const KeyType &key, ValueType def return found->second; }; +// Get a value from a map-style container, returning default if value is not +// found (forces string) +template +std::string str_or_default(const Container &ct, const KeyType &key, std::string def = "") +{ + auto found = ct.find(key); + if (found == ct.end()) + return def; + else + return found->second; +}; + // Get a value from a map-style container, converting to int, and returning // default if value is not found template int int_or_default(const Container &ct, const KeyType &key, int def = 0) -- cgit v1.2.3 From 29d65bd368fa32f7ea13515902df752d30ec4f39 Mon Sep 17 00:00:00 2001 From: David Shah Date: Tue, 10 Jul 2018 11:24:30 +0200 Subject: ecp5: Working on bitstream gen Signed-off-by: David Shah --- common/util.h | 1 + 1 file changed, 1 insertion(+) (limited to 'common') diff --git a/common/util.h b/common/util.h index b492b98c..8f361dc8 100644 --- a/common/util.h +++ b/common/util.h @@ -96,6 +96,7 @@ inline const NetInfo *get_net_or_empty(const CellInfo *cell, const IdString port else return nullptr; }; + NEXTPNR_NAMESPACE_END #endif -- cgit v1.2.3 From 7081cca01654030f9a3b731cebf36e68590e3ed1 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 11 Jul 2018 14:03:23 +0200 Subject: Add GUI Decals API Signed-off-by: Clifford Wolf --- common/nextpnr.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 37e193b9..0b41ff81 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -155,6 +155,12 @@ NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_BEGIN +struct DecalXY +{ + DecalId decal; + float x = 0, y = 0; +}; + struct BelPin { BelId bel; @@ -273,6 +279,60 @@ struct Context : Arch // -------------------------------------------------------------- + std::vector getFrameGraphics() const __attribute__ ((deprecated)) { + std::vector ret; + DecalXY decalxy = getFrameDecal(); + ret = getDecalGraphics(decalxy.decal); + for (auto &it : ret) { + it.x1 += decalxy.x; + it.x2 += decalxy.x; + it.y1 += decalxy.y; + it.y2 += decalxy.y; + } + return ret; + } + + std::vector getBelGraphics(BelId bel) const __attribute__ ((deprecated)) { + std::vector ret; + DecalXY decalxy = getBelDecal(bel); + ret = getDecalGraphics(decalxy.decal); + for (auto &it : ret) { + it.x1 += decalxy.x; + it.x2 += decalxy.x; + it.y1 += decalxy.y; + it.y2 += decalxy.y; + } + return ret; + } + + std::vector getWireGraphics(WireId wire) const __attribute__ ((deprecated)) { + std::vector ret; + DecalXY decalxy = getWireDecal(wire); + ret = getDecalGraphics(decalxy.decal); + for (auto &it : ret) { + it.x1 += decalxy.x; + it.x2 += decalxy.x; + it.y1 += decalxy.y; + it.y2 += decalxy.y; + } + return ret; + } + + std::vector getPipGraphics(PipId pip) const __attribute__ ((deprecated)) { + std::vector ret; + DecalXY decalxy = getPipDecal(pip); + ret = getDecalGraphics(decalxy.decal); + for (auto &it : ret) { + it.x1 += decalxy.x; + it.x2 += decalxy.x; + it.y1 += decalxy.y; + it.y2 += decalxy.y; + } + return ret; + } + + // -------------------------------------------------------------- + uint64_t rngstate = 0x3141592653589793; uint64_t rng64() -- cgit v1.2.3 From 09735694b28f9d1807dad5cb52232b4a40b48a77 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 11 Jul 2018 14:39:42 +0200 Subject: Fixed MSVC build --- common/nextpnr.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 0b41ff81..bf3a5c28 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -279,7 +279,7 @@ struct Context : Arch // -------------------------------------------------------------- - std::vector getFrameGraphics() const __attribute__ ((deprecated)) { + NPNR_DEPRECATED std::vector getFrameGraphics() const { std::vector ret; DecalXY decalxy = getFrameDecal(); ret = getDecalGraphics(decalxy.decal); @@ -292,7 +292,7 @@ struct Context : Arch return ret; } - std::vector getBelGraphics(BelId bel) const __attribute__ ((deprecated)) { + NPNR_DEPRECATED std::vector getBelGraphics(BelId bel) const { std::vector ret; DecalXY decalxy = getBelDecal(bel); ret = getDecalGraphics(decalxy.decal); @@ -305,7 +305,7 @@ struct Context : Arch return ret; } - std::vector getWireGraphics(WireId wire) const __attribute__ ((deprecated)) { + NPNR_DEPRECATED std::vector getWireGraphics(WireId wire) const { std::vector ret; DecalXY decalxy = getWireDecal(wire); ret = getDecalGraphics(decalxy.decal); @@ -318,7 +318,7 @@ struct Context : Arch return ret; } - std::vector getPipGraphics(PipId pip) const __attribute__ ((deprecated)) { + NPNR_DEPRECATED std::vector getPipGraphics(PipId pip) const { std::vector ret; DecalXY decalxy = getPipDecal(pip); ret = getDecalGraphics(decalxy.decal); -- cgit v1.2.3 From 2a01b5e4d326f697636c592b7589080f88d5fa2c Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 11 Jul 2018 17:02:13 +0200 Subject: New refreshUi API Signed-off-by: Clifford Wolf --- common/nextpnr.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index bf3a5c28..856d8993 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -259,6 +259,39 @@ struct BaseCtx delete idstring_str_to_idx; delete idstring_idx_to_str; } + + // -------------------------------------------------------------- + + bool allUiReload = false; + bool frameUiReload = false; + std::unordered_set belUiReload; + std::unordered_set wireUiReload; + std::unordered_set pipUiReload; + + void refreshUi() + { + allUiReload = true; + } + + void refreshUiFrame() + { + frameUiReload = true; + } + + void refreshUiBel(BelId bel) + { + belUiReload.insert(bel); + } + + void refreshUiWire(WireId wire) + { + wireUiReload.insert(wire); + } + + void refreshUiPip(PipId pip) + { + pipUiReload.insert(pip); + } }; NEXTPNR_NAMESPACE_END -- cgit v1.2.3 From 7df67c91b38433e8a1002f8e9f53926aafaa4d1b Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 11 Jul 2018 18:04:09 +0200 Subject: Add ctx->route() API Signed-off-by: Clifford Wolf --- common/nextpnr.h | 9 + common/route.cc | 655 ------------------------------------------------------ common/route.h | 32 --- common/router1.cc | 655 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/router1.h | 31 +++ 5 files changed, 695 insertions(+), 687 deletions(-) delete mode 100644 common/route.cc delete mode 100644 common/route.h create mode 100644 common/router1.cc create mode 100644 common/router1.h (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 856d8993..09bd1554 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -260,6 +260,10 @@ struct BaseCtx delete idstring_idx_to_str; } + Context *getCtx() { return reinterpret_cast(this); } + + const Context *getCtx() const { return reinterpret_cast(this); } + // -------------------------------------------------------------- bool allUiReload = false; @@ -366,6 +370,11 @@ struct Context : Arch // -------------------------------------------------------------- + // provided by router1.cc + bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay); + + // -------------------------------------------------------------- + uint64_t rngstate = 0x3141592653589793; uint64_t rng64() diff --git a/common/route.cc b/common/route.cc deleted file mode 100644 index 82525fcc..00000000 --- a/common/route.cc +++ /dev/null @@ -1,655 +0,0 @@ -/* - * nextpnr -- Next Generation Place and Route - * - * Copyright (C) 2018 Clifford Wolf - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#include -#include - -#include "log.h" -#include "route.h" - -namespace { - -USING_NEXTPNR_NAMESPACE - -struct hash_id_wire -{ - std::size_t operator()(const std::pair &arg) const noexcept - { - std::size_t seed = std::hash()(arg.first); - seed ^= std::hash()(arg.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -struct hash_id_pip -{ - std::size_t operator()(const std::pair &arg) const noexcept - { - std::size_t seed = std::hash()(arg.first); - seed ^= std::hash()(arg.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - return seed; - } -}; - -struct QueuedWire -{ - WireId wire; - PipId pip; - - delay_t delay = 0, togo = 0; - int randtag = 0; - - struct Greater - { - bool operator()(const QueuedWire &lhs, const QueuedWire &rhs) const noexcept - { - delay_t l = lhs.delay + lhs.togo, r = rhs.delay + rhs.togo; - return l == r ? lhs.randtag > rhs.randtag : l > r; - } - }; -}; - -struct RipupScoreboard -{ - std::unordered_map wireScores; - std::unordered_map pipScores; - std::unordered_map, int, hash_id_wire> netWireScores; - std::unordered_map, int, hash_id_pip> netPipScores; -}; - -void ripup_net(Context *ctx, IdString net_name) -{ - auto net_info = ctx->nets.at(net_name).get(); - std::vector pips; - std::vector wires; - - pips.reserve(net_info->wires.size()); - wires.reserve(net_info->wires.size()); - - for (auto &it : net_info->wires) { - if (it.second.pip != PipId()) - pips.push_back(it.second.pip); - else - wires.push_back(it.first); - } - - for (auto pip : pips) - ctx->unbindPip(pip); - - for (auto wire : wires) - ctx->unbindWire(wire); - - NPNR_ASSERT(net_info->wires.empty()); -} - -struct Router -{ - Context *ctx; - RipupScoreboard scores; - IdString net_name; - - bool ripup; - delay_t ripup_penalty; - - std::unordered_set rippedNets; - std::unordered_map visited; - int visitCnt = 0, revisitCnt = 0, overtimeRevisitCnt = 0; - bool routedOkay = false; - delay_t maxDelay = 0.0; - WireId failedDest; - - void route(const std::unordered_map &src_wires, WireId dst_wire) - { - std::priority_queue, QueuedWire::Greater> queue; - - visited.clear(); - - for (auto &it : src_wires) { - QueuedWire qw; - qw.wire = it.first; - qw.pip = PipId(); - qw.delay = it.second; - qw.togo = ctx->estimateDelay(qw.wire, dst_wire); - qw.randtag = ctx->rng(); - - queue.push(qw); - visited[qw.wire] = qw; - } - - int thisVisitCnt = 0; - int thisVisitCntLimit = 0; - - while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { - QueuedWire qw = queue.top(); - queue.pop(); - - if (thisVisitCntLimit == 0 && visited.count(dst_wire)) - thisVisitCntLimit = (thisVisitCnt * 3) / 2; - - for (auto pip : ctx->getPipsDownhill(qw.wire)) { - delay_t next_delay = qw.delay + ctx->getPipDelay(pip).avgDelay(); - WireId next_wire = ctx->getPipDstWire(pip); - bool foundRipupNet = false; - thisVisitCnt++; - - if (!ctx->checkWireAvail(next_wire)) { - if (!ripup) - continue; - IdString ripupWireNet = ctx->getConflictingWireNet(next_wire); - if (ripupWireNet == net_name || ripupWireNet == IdString()) - continue; - - auto it1 = scores.wireScores.find(next_wire); - if (it1 != scores.wireScores.end()) - next_delay += (it1->second * ripup_penalty) / 8; - - auto it2 = scores.netWireScores.find(std::make_pair(ripupWireNet, next_wire)); - if (it2 != scores.netWireScores.end()) - next_delay += it2->second * ripup_penalty; - - foundRipupNet = true; - } - - if (!ctx->checkPipAvail(pip)) { - if (!ripup) - continue; - IdString ripupPipNet = ctx->getConflictingPipNet(pip); - if (ripupPipNet == net_name || ripupPipNet == IdString()) - continue; - - auto it1 = scores.pipScores.find(pip); - if (it1 != scores.pipScores.end()) - next_delay += (it1->second * ripup_penalty) / 8; - - auto it2 = scores.netPipScores.find(std::make_pair(ripupPipNet, pip)); - if (it2 != scores.netPipScores.end()) - next_delay += it2->second * ripup_penalty; - - foundRipupNet = true; - } - - if (foundRipupNet) - next_delay += ripup_penalty; - - NPNR_ASSERT(next_delay >= 0); - - if (visited.count(next_wire)) { - if (visited.at(next_wire).delay <= next_delay + ctx->getDelayEpsilon()) - continue; -#if 0 // FIXME - if (ctx->debug) - log("Found better route to %s. Old vs new delay " - "estimate: %.3f %.3f\n", - ctx->getWireName(next_wire).c_str(), - ctx->getDelayNS(visited.at(next_wire).delay), - ctx->getDelayNS(next_delay)); -#endif - if (thisVisitCntLimit == 0) - revisitCnt++; - else - overtimeRevisitCnt++; - } - - QueuedWire next_qw; - next_qw.wire = next_wire; - next_qw.pip = pip; - next_qw.delay = next_delay; - next_qw.togo = ctx->estimateDelay(next_wire, dst_wire); - qw.randtag = ctx->rng(); - - visited[next_qw.wire] = next_qw; - queue.push(next_qw); - } - } - - visitCnt += thisVisitCnt; - } - - Router(Context *ctx, RipupScoreboard &scores, WireId src_wire, WireId dst_wire, bool ripup = false, - delay_t ripup_penalty = 0) - : ctx(ctx), scores(scores), ripup(ripup), ripup_penalty(ripup_penalty) - { - std::unordered_map src_wires; - src_wires[src_wire] = 0; - route(src_wires, dst_wire); - routedOkay = visited.count(dst_wire); - - if (ctx->debug) { - log("Route (from destination to source):\n"); - - WireId cursor = dst_wire; - - while (1) { - log(" %8.3f %s\n", ctx->getDelayNS(visited[cursor].delay), ctx->getWireName(cursor).c_str(ctx)); - - if (cursor == src_wire) - break; - - cursor = ctx->getPipSrcWire(visited[cursor].pip); - } - } - } - - Router(Context *ctx, RipupScoreboard &scores, IdString net_name, bool ripup = false, delay_t ripup_penalty = 0) - : ctx(ctx), scores(scores), net_name(net_name), ripup(ripup), ripup_penalty(ripup_penalty) - { - auto net_info = ctx->nets.at(net_name).get(); - - if (ctx->debug) - log("Routing net %s.\n", net_name.c_str(ctx)); - - if (ctx->debug) - log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx), net_info->driver.port.c_str(ctx)); - - auto src_bel = net_info->driver.cell->bel; - - if (src_bel == BelId()) - log_error("Source cell %s (%s) is not mapped to a bel.\n", net_info->driver.cell->name.c_str(ctx), - net_info->driver.cell->type.c_str(ctx)); - - if (ctx->debug) - log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str(ctx)); - - IdString driver_port = net_info->driver.port; - - auto driver_port_it = net_info->driver.cell->pins.find(driver_port); - if (driver_port_it != net_info->driver.cell->pins.end()) - driver_port = driver_port_it->second; - - auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); - - if (src_wire == WireId()) - log_error("No wire found for port %s (pin %s) on source cell %s " - "(bel %s).\n", - net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), net_info->driver.cell->name.c_str(ctx), - ctx->getBelName(src_bel).c_str(ctx)); - - if (ctx->debug) - log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str(ctx)); - - std::unordered_map src_wires; - src_wires[src_wire] = 0; - - ripup_net(ctx, net_name); - ctx->bindWire(src_wire, net_name, STRENGTH_WEAK); - - std::vector users_array = net_info->users; - ctx->shuffle(users_array); - - for (auto &user_it : users_array) { - if (ctx->debug) - log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx), user_it.port.c_str(ctx)); - - auto dst_bel = user_it.cell->bel; - - if (dst_bel == BelId()) - log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_it.cell->name.c_str(ctx), - user_it.cell->type.c_str(ctx)); - - if (ctx->debug) - log(" Destination bel: %s\n", ctx->getBelName(dst_bel).c_str(ctx)); - - IdString user_port = user_it.port; - - auto user_port_it = user_it.cell->pins.find(user_port); - - if (user_port_it != user_it.cell->pins.end()) - user_port = user_port_it->second; - - auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); - - if (dst_wire == WireId()) - log_error("No wire found for port %s (pin %s) on destination " - "cell %s (bel %s).\n", - user_it.port.c_str(ctx), user_port.c_str(ctx), user_it.cell->name.c_str(ctx), - ctx->getBelName(dst_bel).c_str(ctx)); - - if (ctx->debug) { - log(" Destination wire: %s\n", ctx->getWireName(dst_wire).c_str(ctx)); - log(" Path delay estimate: %.2f\n", float(ctx->estimateDelay(src_wire, dst_wire))); - } - - route(src_wires, dst_wire); - - if (visited.count(dst_wire) == 0) { - if (ctx->debug) - log("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), - ctx->getWireName(dst_wire).c_str(ctx)); - else if (ripup) - log_info("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), - ctx->getWireName(dst_wire).c_str(ctx)); - ripup_net(ctx, net_name); - failedDest = dst_wire; - return; - } - - if (ctx->debug) - log(" Final path delay: %.3f\n", ctx->getDelayNS(visited[dst_wire].delay)); - maxDelay = fmaxf(maxDelay, visited[dst_wire].delay); - - if (ctx->debug) - log(" Route (from destination to source):\n"); - - WireId cursor = dst_wire; - - while (1) { - if (ctx->debug) - log(" %8.3f %s\n", ctx->getDelayNS(visited[cursor].delay), ctx->getWireName(cursor).c_str(ctx)); - - if (src_wires.count(cursor)) - break; - - IdString conflicting_wire_net = ctx->getConflictingWireNet(cursor); - - if (conflicting_wire_net != IdString()) { - NPNR_ASSERT(ripup); - NPNR_ASSERT(conflicting_wire_net != net_name); - - ctx->unbindWire(cursor); - if (!ctx->checkWireAvail(cursor)) - ripup_net(ctx, conflicting_wire_net); - - rippedNets.insert(conflicting_wire_net); - scores.wireScores[cursor]++; - scores.netWireScores[std::make_pair(net_name, cursor)]++; - scores.netWireScores[std::make_pair(conflicting_wire_net, cursor)]++; - } - - PipId pip = visited[cursor].pip; - IdString conflicting_pip_net = ctx->getConflictingPipNet(pip); - - if (conflicting_pip_net != IdString()) { - NPNR_ASSERT(ripup); - NPNR_ASSERT(conflicting_pip_net != net_name); - - ctx->unbindPip(pip); - if (!ctx->checkPipAvail(pip)) - ripup_net(ctx, conflicting_pip_net); - - rippedNets.insert(conflicting_pip_net); - scores.pipScores[visited[cursor].pip]++; - scores.netPipScores[std::make_pair(net_name, visited[cursor].pip)]++; - scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; - } - - ctx->bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); - src_wires[cursor] = visited[cursor].delay; - cursor = ctx->getPipSrcWire(visited[cursor].pip); - } - } - - routedOkay = true; - } -}; - -} // namespace - -NEXTPNR_NAMESPACE_BEGIN - -bool route_design(Context *ctx) -{ - try { - int totalVisitCnt = 0, totalRevisitCnt = 0, totalOvertimeRevisitCnt = 0; - delay_t ripup_penalty = ctx->getRipupDelayPenalty(); - RipupScoreboard scores; - - log_break(); - log_info("Routing..\n"); - - std::unordered_set netsQueue; - - for (auto &net_it : ctx->nets) { - auto net_name = net_it.first; - auto net_info = net_it.second.get(); - - if (net_info->driver.cell == nullptr) - continue; - - if (!net_info->wires.empty()) - continue; - - netsQueue.insert(net_name); - } - - if (netsQueue.empty()) { - log_info("found no unrouted nets. no routing necessary.\n"); - return true; - } - - log_info("found %d unrouted nets. starting routing procedure.\n", int(netsQueue.size())); - - delay_t estimatedTotalDelay = 0.0; - int estimatedTotalDelayCnt = 0; - - for (auto net_name : netsQueue) { - auto net_info = ctx->nets.at(net_name).get(); - - auto src_bel = net_info->driver.cell->bel; - - if (src_bel == BelId()) - continue; - - IdString driver_port = net_info->driver.port; - - auto driver_port_it = net_info->driver.cell->pins.find(driver_port); - if (driver_port_it != net_info->driver.cell->pins.end()) - driver_port = driver_port_it->second; - - auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); - - if (src_wire == WireId()) - continue; - - for (auto &user_it : net_info->users) { - auto dst_bel = user_it.cell->bel; - - if (dst_bel == BelId()) - continue; - - IdString user_port = user_it.port; - - auto user_port_it = user_it.cell->pins.find(user_port); - - if (user_port_it != user_it.cell->pins.end()) - user_port = user_port_it->second; - - auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); - - if (dst_wire == WireId()) - continue; - - estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); - estimatedTotalDelayCnt++; - } - } - - log_info("estimated total wire delay: %.2f (avg %.2f)\n", float(estimatedTotalDelay), - float(estimatedTotalDelay) / estimatedTotalDelayCnt); - - int iterCnt = 0; - - while (!netsQueue.empty()) { - if (iterCnt == 200) { - log_warning("giving up after %d iterations.\n", iterCnt); - log_info("Checksum: 0x%08x\n", ctx->checksum()); -#ifndef NDEBUG - ctx->check(); -#endif - return false; - } - - iterCnt++; - if (ctx->verbose) - log_info("-- %d --\n", iterCnt); - - int visitCnt = 0, revisitCnt = 0, overtimeRevisitCnt = 0, netCnt = 0; - - std::unordered_set ripupQueue; - - if (ctx->verbose || iterCnt == 1) - log_info("routing queue contains %d nets.\n", int(netsQueue.size())); - - bool printNets = ctx->verbose && (netsQueue.size() < 10); - - std::vector netsArray(netsQueue.begin(), netsQueue.end()); - ctx->sorted_shuffle(netsArray); - netsQueue.clear(); - - for (auto net_name : netsArray) { - if (printNets) - log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), - int(ctx->nets.at(net_name)->users.size())); - - Router router(ctx, scores, net_name, false); - - netCnt++; - visitCnt += router.visitCnt; - revisitCnt += router.revisitCnt; - overtimeRevisitCnt += router.overtimeRevisitCnt; - - if (!router.routedOkay) { - if (printNets) - log_info(" failed to route to %s.\n", ctx->getWireName(router.failedDest).c_str(ctx)); - ripupQueue.insert(net_name); - } - - if ((ctx->verbose || iterCnt == 1) && !printNets && (netCnt % 100 == 0)) - log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt, netCnt - int(ripupQueue.size()), - int(ripupQueue.size())); - } - - int normalRouteCnt = netCnt - int(ripupQueue.size()); - - if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) - log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt, normalRouteCnt, - int(ripupQueue.size())); - - if (ctx->verbose) - log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime " - "revisits).\n", - visitCnt, (100.0 * revisitCnt) / visitCnt, (100.0 * overtimeRevisitCnt) / visitCnt); - - if (!ripupQueue.empty()) { - if (ctx->verbose || iterCnt == 1) - log_info("failed to route %d nets. re-routing in ripup " - "mode.\n", - int(ripupQueue.size())); - - printNets = ctx->verbose && (ripupQueue.size() < 10); - - visitCnt = 0; - revisitCnt = 0; - overtimeRevisitCnt = 0; - netCnt = 0; - int ripCnt = 0; - - std::vector ripupArray(ripupQueue.begin(), ripupQueue.end()); - ctx->sorted_shuffle(ripupArray); - - for (auto net_name : ripupArray) { - if (printNets) - log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), - int(ctx->nets.at(net_name)->users.size())); - - Router router(ctx, scores, net_name, true, ripup_penalty); - - netCnt++; - visitCnt += router.visitCnt; - revisitCnt += router.revisitCnt; - overtimeRevisitCnt += router.overtimeRevisitCnt; - - if (!router.routedOkay) - log_error("Net %s is impossible to route.\n", net_name.c_str(ctx)); - - for (auto it : router.rippedNets) - netsQueue.insert(it); - - if (printNets) { - if (router.rippedNets.size() < 10) { - log_info(" ripped up %d other nets:\n", int(router.rippedNets.size())); - for (auto n : router.rippedNets) - log_info(" %s (%d users)\n", n.c_str(ctx), int(ctx->nets.at(n)->users.size())); - } else { - log_info(" ripped up %d other nets.\n", int(router.rippedNets.size())); - } - } - - ripCnt += router.rippedNets.size(); - - if ((ctx->verbose || iterCnt == 1) && !printNets && (netCnt % 100 == 0)) - log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt); - } - - if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) - log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt); - - if (ctx->verbose) - log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% " - "overtime revisits).\n", - visitCnt, (100.0 * revisitCnt) / visitCnt, (100.0 * overtimeRevisitCnt) / visitCnt); - - if (ctx->verbose && !netsQueue.empty()) - log_info(" ripped up %d previously routed nets. continue " - "routing.\n", - int(netsQueue.size())); - } - - if (!ctx->verbose) - log_info("iteration %d: routed %d nets without ripup, routed %d " - "nets with ripup.\n", - iterCnt, normalRouteCnt, int(ripupQueue.size())); - - totalVisitCnt += visitCnt; - totalRevisitCnt += revisitCnt; - totalOvertimeRevisitCnt += overtimeRevisitCnt; - - if (iterCnt == 8 || iterCnt == 16 || iterCnt == 32 || iterCnt == 64 || iterCnt == 128) - ripup_penalty += ctx->getRipupDelayPenalty(); - } - - log_info("routing complete after %d iterations.\n", iterCnt); - - log_info("visited %d PIPs (%.2f%% revisits, %.2f%% " - "overtime revisits).\n", - totalVisitCnt, (100.0 * totalRevisitCnt) / totalVisitCnt, - (100.0 * totalOvertimeRevisitCnt) / totalVisitCnt); - - log_info("Checksum: 0x%08x\n", ctx->checksum()); -#ifndef NDEBUG - ctx->check(); -#endif - return true; - } catch (log_execution_error_exception) { -#ifndef NDEBUG - ctx->check(); -#endif - return false; - } -} - -bool get_actual_route_delay(Context *ctx, WireId src_wire, WireId dst_wire, delay_t &delay) -{ - RipupScoreboard scores; - Router router(ctx, scores, src_wire, dst_wire); - if (router.routedOkay) - delay = router.visited.at(dst_wire).delay; - return router.routedOkay; -} - -NEXTPNR_NAMESPACE_END diff --git a/common/route.h b/common/route.h deleted file mode 100644 index 1da9edc2..00000000 --- a/common/route.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * nextpnr -- Next Generation Place and Route - * - * Copyright (C) 2018 Clifford Wolf - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifndef ROUTE_H -#define ROUTE_H - -#include "nextpnr.h" - -NEXTPNR_NAMESPACE_BEGIN - -extern bool route_design(Context *ctx); -extern bool get_actual_route_delay(Context *ctx, WireId src_wire, WireId dst_wire, delay_t &delay); - -NEXTPNR_NAMESPACE_END - -#endif // ROUTE_H diff --git a/common/router1.cc b/common/router1.cc new file mode 100644 index 00000000..94c7070e --- /dev/null +++ b/common/router1.cc @@ -0,0 +1,655 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Clifford Wolf + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include + +#include "log.h" +#include "router1.h" + +namespace { + +USING_NEXTPNR_NAMESPACE + +struct hash_id_wire +{ + std::size_t operator()(const std::pair &arg) const noexcept + { + std::size_t seed = std::hash()(arg.first); + seed ^= std::hash()(arg.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + return seed; + } +}; + +struct hash_id_pip +{ + std::size_t operator()(const std::pair &arg) const noexcept + { + std::size_t seed = std::hash()(arg.first); + seed ^= std::hash()(arg.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + return seed; + } +}; + +struct QueuedWire +{ + WireId wire; + PipId pip; + + delay_t delay = 0, togo = 0; + int randtag = 0; + + struct Greater + { + bool operator()(const QueuedWire &lhs, const QueuedWire &rhs) const noexcept + { + delay_t l = lhs.delay + lhs.togo, r = rhs.delay + rhs.togo; + return l == r ? lhs.randtag > rhs.randtag : l > r; + } + }; +}; + +struct RipupScoreboard +{ + std::unordered_map wireScores; + std::unordered_map pipScores; + std::unordered_map, int, hash_id_wire> netWireScores; + std::unordered_map, int, hash_id_pip> netPipScores; +}; + +void ripup_net(Context *ctx, IdString net_name) +{ + auto net_info = ctx->nets.at(net_name).get(); + std::vector pips; + std::vector wires; + + pips.reserve(net_info->wires.size()); + wires.reserve(net_info->wires.size()); + + for (auto &it : net_info->wires) { + if (it.second.pip != PipId()) + pips.push_back(it.second.pip); + else + wires.push_back(it.first); + } + + for (auto pip : pips) + ctx->unbindPip(pip); + + for (auto wire : wires) + ctx->unbindWire(wire); + + NPNR_ASSERT(net_info->wires.empty()); +} + +struct Router +{ + Context *ctx; + RipupScoreboard scores; + IdString net_name; + + bool ripup; + delay_t ripup_penalty; + + std::unordered_set rippedNets; + std::unordered_map visited; + int visitCnt = 0, revisitCnt = 0, overtimeRevisitCnt = 0; + bool routedOkay = false; + delay_t maxDelay = 0.0; + WireId failedDest; + + void route(const std::unordered_map &src_wires, WireId dst_wire) + { + std::priority_queue, QueuedWire::Greater> queue; + + visited.clear(); + + for (auto &it : src_wires) { + QueuedWire qw; + qw.wire = it.first; + qw.pip = PipId(); + qw.delay = it.second; + qw.togo = ctx->estimateDelay(qw.wire, dst_wire); + qw.randtag = ctx->rng(); + + queue.push(qw); + visited[qw.wire] = qw; + } + + int thisVisitCnt = 0; + int thisVisitCntLimit = 0; + + while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { + QueuedWire qw = queue.top(); + queue.pop(); + + if (thisVisitCntLimit == 0 && visited.count(dst_wire)) + thisVisitCntLimit = (thisVisitCnt * 3) / 2; + + for (auto pip : ctx->getPipsDownhill(qw.wire)) { + delay_t next_delay = qw.delay + ctx->getPipDelay(pip).avgDelay(); + WireId next_wire = ctx->getPipDstWire(pip); + bool foundRipupNet = false; + thisVisitCnt++; + + if (!ctx->checkWireAvail(next_wire)) { + if (!ripup) + continue; + IdString ripupWireNet = ctx->getConflictingWireNet(next_wire); + if (ripupWireNet == net_name || ripupWireNet == IdString()) + continue; + + auto it1 = scores.wireScores.find(next_wire); + if (it1 != scores.wireScores.end()) + next_delay += (it1->second * ripup_penalty) / 8; + + auto it2 = scores.netWireScores.find(std::make_pair(ripupWireNet, next_wire)); + if (it2 != scores.netWireScores.end()) + next_delay += it2->second * ripup_penalty; + + foundRipupNet = true; + } + + if (!ctx->checkPipAvail(pip)) { + if (!ripup) + continue; + IdString ripupPipNet = ctx->getConflictingPipNet(pip); + if (ripupPipNet == net_name || ripupPipNet == IdString()) + continue; + + auto it1 = scores.pipScores.find(pip); + if (it1 != scores.pipScores.end()) + next_delay += (it1->second * ripup_penalty) / 8; + + auto it2 = scores.netPipScores.find(std::make_pair(ripupPipNet, pip)); + if (it2 != scores.netPipScores.end()) + next_delay += it2->second * ripup_penalty; + + foundRipupNet = true; + } + + if (foundRipupNet) + next_delay += ripup_penalty; + + NPNR_ASSERT(next_delay >= 0); + + if (visited.count(next_wire)) { + if (visited.at(next_wire).delay <= next_delay + ctx->getDelayEpsilon()) + continue; +#if 0 // FIXME + if (ctx->debug) + log("Found better route to %s. Old vs new delay " + "estimate: %.3f %.3f\n", + ctx->getWireName(next_wire).c_str(), + ctx->getDelayNS(visited.at(next_wire).delay), + ctx->getDelayNS(next_delay)); +#endif + if (thisVisitCntLimit == 0) + revisitCnt++; + else + overtimeRevisitCnt++; + } + + QueuedWire next_qw; + next_qw.wire = next_wire; + next_qw.pip = pip; + next_qw.delay = next_delay; + next_qw.togo = ctx->estimateDelay(next_wire, dst_wire); + qw.randtag = ctx->rng(); + + visited[next_qw.wire] = next_qw; + queue.push(next_qw); + } + } + + visitCnt += thisVisitCnt; + } + + Router(Context *ctx, RipupScoreboard &scores, WireId src_wire, WireId dst_wire, bool ripup = false, + delay_t ripup_penalty = 0) + : ctx(ctx), scores(scores), ripup(ripup), ripup_penalty(ripup_penalty) + { + std::unordered_map src_wires; + src_wires[src_wire] = 0; + route(src_wires, dst_wire); + routedOkay = visited.count(dst_wire); + + if (ctx->debug) { + log("Route (from destination to source):\n"); + + WireId cursor = dst_wire; + + while (1) { + log(" %8.3f %s\n", ctx->getDelayNS(visited[cursor].delay), ctx->getWireName(cursor).c_str(ctx)); + + if (cursor == src_wire) + break; + + cursor = ctx->getPipSrcWire(visited[cursor].pip); + } + } + } + + Router(Context *ctx, RipupScoreboard &scores, IdString net_name, bool ripup = false, delay_t ripup_penalty = 0) + : ctx(ctx), scores(scores), net_name(net_name), ripup(ripup), ripup_penalty(ripup_penalty) + { + auto net_info = ctx->nets.at(net_name).get(); + + if (ctx->debug) + log("Routing net %s.\n", net_name.c_str(ctx)); + + if (ctx->debug) + log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx), net_info->driver.port.c_str(ctx)); + + auto src_bel = net_info->driver.cell->bel; + + if (src_bel == BelId()) + log_error("Source cell %s (%s) is not mapped to a bel.\n", net_info->driver.cell->name.c_str(ctx), + net_info->driver.cell->type.c_str(ctx)); + + if (ctx->debug) + log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str(ctx)); + + IdString driver_port = net_info->driver.port; + + auto driver_port_it = net_info->driver.cell->pins.find(driver_port); + if (driver_port_it != net_info->driver.cell->pins.end()) + driver_port = driver_port_it->second; + + auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + + if (src_wire == WireId()) + log_error("No wire found for port %s (pin %s) on source cell %s " + "(bel %s).\n", + net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), net_info->driver.cell->name.c_str(ctx), + ctx->getBelName(src_bel).c_str(ctx)); + + if (ctx->debug) + log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str(ctx)); + + std::unordered_map src_wires; + src_wires[src_wire] = 0; + + ripup_net(ctx, net_name); + ctx->bindWire(src_wire, net_name, STRENGTH_WEAK); + + std::vector users_array = net_info->users; + ctx->shuffle(users_array); + + for (auto &user_it : users_array) { + if (ctx->debug) + log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx), user_it.port.c_str(ctx)); + + auto dst_bel = user_it.cell->bel; + + if (dst_bel == BelId()) + log_error("Destination cell %s (%s) is not mapped to a bel.\n", user_it.cell->name.c_str(ctx), + user_it.cell->type.c_str(ctx)); + + if (ctx->debug) + log(" Destination bel: %s\n", ctx->getBelName(dst_bel).c_str(ctx)); + + IdString user_port = user_it.port; + + auto user_port_it = user_it.cell->pins.find(user_port); + + if (user_port_it != user_it.cell->pins.end()) + user_port = user_port_it->second; + + auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + + if (dst_wire == WireId()) + log_error("No wire found for port %s (pin %s) on destination " + "cell %s (bel %s).\n", + user_it.port.c_str(ctx), user_port.c_str(ctx), user_it.cell->name.c_str(ctx), + ctx->getBelName(dst_bel).c_str(ctx)); + + if (ctx->debug) { + log(" Destination wire: %s\n", ctx->getWireName(dst_wire).c_str(ctx)); + log(" Path delay estimate: %.2f\n", float(ctx->estimateDelay(src_wire, dst_wire))); + } + + route(src_wires, dst_wire); + + if (visited.count(dst_wire) == 0) { + if (ctx->debug) + log("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), + ctx->getWireName(dst_wire).c_str(ctx)); + else if (ripup) + log_info("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), + ctx->getWireName(dst_wire).c_str(ctx)); + ripup_net(ctx, net_name); + failedDest = dst_wire; + return; + } + + if (ctx->debug) + log(" Final path delay: %.3f\n", ctx->getDelayNS(visited[dst_wire].delay)); + maxDelay = fmaxf(maxDelay, visited[dst_wire].delay); + + if (ctx->debug) + log(" Route (from destination to source):\n"); + + WireId cursor = dst_wire; + + while (1) { + if (ctx->debug) + log(" %8.3f %s\n", ctx->getDelayNS(visited[cursor].delay), ctx->getWireName(cursor).c_str(ctx)); + + if (src_wires.count(cursor)) + break; + + IdString conflicting_wire_net = ctx->getConflictingWireNet(cursor); + + if (conflicting_wire_net != IdString()) { + NPNR_ASSERT(ripup); + NPNR_ASSERT(conflicting_wire_net != net_name); + + ctx->unbindWire(cursor); + if (!ctx->checkWireAvail(cursor)) + ripup_net(ctx, conflicting_wire_net); + + rippedNets.insert(conflicting_wire_net); + scores.wireScores[cursor]++; + scores.netWireScores[std::make_pair(net_name, cursor)]++; + scores.netWireScores[std::make_pair(conflicting_wire_net, cursor)]++; + } + + PipId pip = visited[cursor].pip; + IdString conflicting_pip_net = ctx->getConflictingPipNet(pip); + + if (conflicting_pip_net != IdString()) { + NPNR_ASSERT(ripup); + NPNR_ASSERT(conflicting_pip_net != net_name); + + ctx->unbindPip(pip); + if (!ctx->checkPipAvail(pip)) + ripup_net(ctx, conflicting_pip_net); + + rippedNets.insert(conflicting_pip_net); + scores.pipScores[visited[cursor].pip]++; + scores.netPipScores[std::make_pair(net_name, visited[cursor].pip)]++; + scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; + } + + ctx->bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); + src_wires[cursor] = visited[cursor].delay; + cursor = ctx->getPipSrcWire(visited[cursor].pip); + } + } + + routedOkay = true; + } +}; + +} // namespace + +NEXTPNR_NAMESPACE_BEGIN + +bool router1(Context *ctx) +{ + try { + int totalVisitCnt = 0, totalRevisitCnt = 0, totalOvertimeRevisitCnt = 0; + delay_t ripup_penalty = ctx->getRipupDelayPenalty(); + RipupScoreboard scores; + + log_break(); + log_info("Routing..\n"); + + std::unordered_set netsQueue; + + for (auto &net_it : ctx->nets) { + auto net_name = net_it.first; + auto net_info = net_it.second.get(); + + if (net_info->driver.cell == nullptr) + continue; + + if (!net_info->wires.empty()) + continue; + + netsQueue.insert(net_name); + } + + if (netsQueue.empty()) { + log_info("found no unrouted nets. no routing necessary.\n"); + return true; + } + + log_info("found %d unrouted nets. starting routing procedure.\n", int(netsQueue.size())); + + delay_t estimatedTotalDelay = 0.0; + int estimatedTotalDelayCnt = 0; + + for (auto net_name : netsQueue) { + auto net_info = ctx->nets.at(net_name).get(); + + auto src_bel = net_info->driver.cell->bel; + + if (src_bel == BelId()) + continue; + + IdString driver_port = net_info->driver.port; + + auto driver_port_it = net_info->driver.cell->pins.find(driver_port); + if (driver_port_it != net_info->driver.cell->pins.end()) + driver_port = driver_port_it->second; + + auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + + if (src_wire == WireId()) + continue; + + for (auto &user_it : net_info->users) { + auto dst_bel = user_it.cell->bel; + + if (dst_bel == BelId()) + continue; + + IdString user_port = user_it.port; + + auto user_port_it = user_it.cell->pins.find(user_port); + + if (user_port_it != user_it.cell->pins.end()) + user_port = user_port_it->second; + + auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + + if (dst_wire == WireId()) + continue; + + estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); + estimatedTotalDelayCnt++; + } + } + + log_info("estimated total wire delay: %.2f (avg %.2f)\n", float(estimatedTotalDelay), + float(estimatedTotalDelay) / estimatedTotalDelayCnt); + + int iterCnt = 0; + + while (!netsQueue.empty()) { + if (iterCnt == 200) { + log_warning("giving up after %d iterations.\n", iterCnt); + log_info("Checksum: 0x%08x\n", ctx->checksum()); +#ifndef NDEBUG + ctx->check(); +#endif + return false; + } + + iterCnt++; + if (ctx->verbose) + log_info("-- %d --\n", iterCnt); + + int visitCnt = 0, revisitCnt = 0, overtimeRevisitCnt = 0, netCnt = 0; + + std::unordered_set ripupQueue; + + if (ctx->verbose || iterCnt == 1) + log_info("routing queue contains %d nets.\n", int(netsQueue.size())); + + bool printNets = ctx->verbose && (netsQueue.size() < 10); + + std::vector netsArray(netsQueue.begin(), netsQueue.end()); + ctx->sorted_shuffle(netsArray); + netsQueue.clear(); + + for (auto net_name : netsArray) { + if (printNets) + log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), + int(ctx->nets.at(net_name)->users.size())); + + Router router(ctx, scores, net_name, false); + + netCnt++; + visitCnt += router.visitCnt; + revisitCnt += router.revisitCnt; + overtimeRevisitCnt += router.overtimeRevisitCnt; + + if (!router.routedOkay) { + if (printNets) + log_info(" failed to route to %s.\n", ctx->getWireName(router.failedDest).c_str(ctx)); + ripupQueue.insert(net_name); + } + + if ((ctx->verbose || iterCnt == 1) && !printNets && (netCnt % 100 == 0)) + log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt, netCnt - int(ripupQueue.size()), + int(ripupQueue.size())); + } + + int normalRouteCnt = netCnt - int(ripupQueue.size()); + + if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) + log_info(" processed %d nets. (%d routed, %d failed)\n", netCnt, normalRouteCnt, + int(ripupQueue.size())); + + if (ctx->verbose) + log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% overtime " + "revisits).\n", + visitCnt, (100.0 * revisitCnt) / visitCnt, (100.0 * overtimeRevisitCnt) / visitCnt); + + if (!ripupQueue.empty()) { + if (ctx->verbose || iterCnt == 1) + log_info("failed to route %d nets. re-routing in ripup " + "mode.\n", + int(ripupQueue.size())); + + printNets = ctx->verbose && (ripupQueue.size() < 10); + + visitCnt = 0; + revisitCnt = 0; + overtimeRevisitCnt = 0; + netCnt = 0; + int ripCnt = 0; + + std::vector ripupArray(ripupQueue.begin(), ripupQueue.end()); + ctx->sorted_shuffle(ripupArray); + + for (auto net_name : ripupArray) { + if (printNets) + log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), + int(ctx->nets.at(net_name)->users.size())); + + Router router(ctx, scores, net_name, true, ripup_penalty); + + netCnt++; + visitCnt += router.visitCnt; + revisitCnt += router.revisitCnt; + overtimeRevisitCnt += router.overtimeRevisitCnt; + + if (!router.routedOkay) + log_error("Net %s is impossible to route.\n", net_name.c_str(ctx)); + + for (auto it : router.rippedNets) + netsQueue.insert(it); + + if (printNets) { + if (router.rippedNets.size() < 10) { + log_info(" ripped up %d other nets:\n", int(router.rippedNets.size())); + for (auto n : router.rippedNets) + log_info(" %s (%d users)\n", n.c_str(ctx), int(ctx->nets.at(n)->users.size())); + } else { + log_info(" ripped up %d other nets.\n", int(router.rippedNets.size())); + } + } + + ripCnt += router.rippedNets.size(); + + if ((ctx->verbose || iterCnt == 1) && !printNets && (netCnt % 100 == 0)) + log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt); + } + + if ((ctx->verbose || iterCnt == 1) && (netCnt % 100 != 0)) + log_info(" routed %d nets, ripped %d nets.\n", netCnt, ripCnt); + + if (ctx->verbose) + log_info(" visited %d PIPs (%.2f%% revisits, %.2f%% " + "overtime revisits).\n", + visitCnt, (100.0 * revisitCnt) / visitCnt, (100.0 * overtimeRevisitCnt) / visitCnt); + + if (ctx->verbose && !netsQueue.empty()) + log_info(" ripped up %d previously routed nets. continue " + "routing.\n", + int(netsQueue.size())); + } + + if (!ctx->verbose) + log_info("iteration %d: routed %d nets without ripup, routed %d " + "nets with ripup.\n", + iterCnt, normalRouteCnt, int(ripupQueue.size())); + + totalVisitCnt += visitCnt; + totalRevisitCnt += revisitCnt; + totalOvertimeRevisitCnt += overtimeRevisitCnt; + + if (iterCnt == 8 || iterCnt == 16 || iterCnt == 32 || iterCnt == 64 || iterCnt == 128) + ripup_penalty += ctx->getRipupDelayPenalty(); + } + + log_info("routing complete after %d iterations.\n", iterCnt); + + log_info("visited %d PIPs (%.2f%% revisits, %.2f%% " + "overtime revisits).\n", + totalVisitCnt, (100.0 * totalRevisitCnt) / totalVisitCnt, + (100.0 * totalOvertimeRevisitCnt) / totalVisitCnt); + + log_info("Checksum: 0x%08x\n", ctx->checksum()); +#ifndef NDEBUG + ctx->check(); +#endif + return true; + } catch (log_execution_error_exception) { +#ifndef NDEBUG + ctx->check(); +#endif + return false; + } +} + +bool Context::getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay) +{ + RipupScoreboard scores; + Router router(this, scores, src_wire, dst_wire); + if (router.routedOkay) + delay = router.visited.at(dst_wire).delay; + return router.routedOkay; +} + +NEXTPNR_NAMESPACE_END diff --git a/common/router1.h b/common/router1.h new file mode 100644 index 00000000..38552c58 --- /dev/null +++ b/common/router1.h @@ -0,0 +1,31 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Clifford Wolf + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef ROUTER1_H +#define ROUTER1_H + +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN + +extern bool router1(Context *ctx); + +NEXTPNR_NAMESPACE_END + +#endif // ROUTER1_H -- cgit v1.2.3 From 7daa8524c8ab8c9ff5400d5074b80573b0d39a14 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 11 Jul 2018 18:15:08 +0200 Subject: Add ctx->place() API Signed-off-by: Clifford Wolf --- common/place_sa.cc | 450 ----------------------------------------------------- common/place_sa.h | 30 ---- common/placer1.cc | 450 +++++++++++++++++++++++++++++++++++++++++++++++++++++ common/placer1.h | 30 ++++ 4 files changed, 480 insertions(+), 480 deletions(-) delete mode 100644 common/place_sa.cc delete mode 100644 common/place_sa.h create mode 100644 common/placer1.cc create mode 100644 common/placer1.h (limited to 'common') diff --git a/common/place_sa.cc b/common/place_sa.cc deleted file mode 100644 index ab161c57..00000000 --- a/common/place_sa.cc +++ /dev/null @@ -1,450 +0,0 @@ -/* - * nextpnr -- Next Generation Place and Route - * - * Copyright (C) 2018 Clifford Wolf - * Copyright (C) 2018 David Shah - * - * Simulated annealing implementation based on arachne-pnr - * Copyright (C) 2015-2018 Cotton Seed - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#include "place_sa.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "place_common.h" -#include "place_legaliser.h" -#include "timing.h" -#include "util.h" -NEXTPNR_NAMESPACE_BEGIN - -class SAPlacer -{ - public: - SAPlacer(Context *ctx) : ctx(ctx) - { - int num_bel_types = 0; - for (auto bel : ctx->getBels()) { - int x, y; - bool gb; - ctx->estimatePosition(bel, x, y, gb); - BelType type = ctx->getBelType(bel); - int type_idx; - if (bel_types.find(type) == bel_types.end()) { - type_idx = num_bel_types++; - bel_types[type] = type_idx; - } else { - type_idx = bel_types.at(type); - } - if (int(fast_bels.size()) < type_idx + 1) - fast_bels.resize(type_idx + 1); - if (int(fast_bels.at(type_idx).size()) < (x + 1)) - fast_bels.at(type_idx).resize(x + 1); - if (int(fast_bels.at(type_idx).at(x).size()) < (y + 1)) - fast_bels.at(type_idx).at(x).resize(y + 1); - max_x = std::max(max_x, x); - max_y = std::max(max_y, y); - fast_bels.at(type_idx).at(x).at(y).push_back(bel); - } - diameter = std::max(max_x, max_y) + 1; - } - - bool place() - { - log_break(); - - size_t placed_cells = 0; - // Initial constraints placer - for (auto &cell_entry : ctx->cells) { - CellInfo *cell = cell_entry.second.get(); - auto loc = cell->attrs.find(ctx->id("BEL")); - if (loc != cell->attrs.end()) { - std::string loc_name = loc->second; - BelId bel = ctx->getBelByName(ctx->id(loc_name)); - if (bel == BelId()) { - log_error("No Bel named \'%s\' located for " - "this chip (processing BEL attribute on \'%s\')\n", - loc_name.c_str(), cell->name.c_str(ctx)); - } - - BelType bel_type = ctx->getBelType(bel); - if (bel_type != ctx->belTypeFromId(cell->type)) { - log_error("Bel \'%s\' of type \'%s\' does not match cell " - "\'%s\' of type \'%s\'", - loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), - cell->type.c_str(ctx)); - } - - ctx->bindBel(bel, cell->name, STRENGTH_USER); - locked_bels.insert(bel); - placed_cells++; - } - } - int constr_placed_cells = placed_cells; - log_info("Placed %d cells based on constraints.\n", int(placed_cells)); - - // Sort to-place cells for deterministic initial placement - std::vector autoplaced; - for (auto &cell : ctx->cells) { - CellInfo *ci = cell.second.get(); - if (ci->bel == BelId()) { - autoplaced.push_back(cell.second.get()); - } - } - std::sort(autoplaced.begin(), autoplaced.end(), [](CellInfo *a, CellInfo *b) { return a->name < b->name; }); - ctx->shuffle(autoplaced); - - // Place cells randomly initially - log_info("Creating initial placement for remaining %d cells.\n", int(autoplaced.size())); - - for (auto cell : autoplaced) { - place_initial(cell); - placed_cells++; - if ((placed_cells - constr_placed_cells) % 500 == 0) - log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), - int(autoplaced.size())); - } - if ((placed_cells - constr_placed_cells) % 500 != 0) - log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), - int(autoplaced.size())); - - log_info("Running simulated annealing placer.\n"); - - // Calculate wirelength after initial placement - curr_wirelength = 0; - curr_tns = 0; - for (auto &net : ctx->nets) { - wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; - } - - int n_no_progress = 0; - double avg_wirelength = curr_wirelength; - temp = 10000; - - // Main simulated annealing loop - for (int iter = 1;; iter++) { - n_move = n_accept = 0; - improved = false; - - if (iter % 5 == 0 || iter == 1) - 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 - for (auto cell : autoplaced) { - // Find another random Bel for this cell - BelId try_bel = random_bel_for_cell(cell); - // If valid, try and swap to a new position and see if - // the new position is valid/worthwhile - if (try_bel != BelId() && try_bel != cell->bel) - try_swap_position(cell, try_bel); - } - } - // Heuristic to improve placement on the 8k - if (improved) - n_no_progress = 0; - else - n_no_progress++; - - if (temp <= 1e-3 && n_no_progress >= 5) { - if (iter % 5 != 0) - log_info(" at iteration #%d: temp = %f, wire length = %f\n", iter, temp, double(curr_wirelength)); - break; - } - - double Raccept = double(n_accept) / double(n_move); - - int M = std::max(max_x, max_y) + 1; - - double upper = 0.6, lower = 0.4; - - if (curr_wirelength < 0.95 * avg_wirelength) { - avg_wirelength = 0.8 * avg_wirelength + 0.2 * curr_wirelength; - } else { - if (Raccept >= 0.8) { - temp *= 0.7; - } else if (Raccept > upper) { - if (diameter < M) - diameter++; - else - temp *= 0.9; - } else if (Raccept > lower) { - temp *= 0.95; - } else { - // Raccept < 0.3 - if (diameter > 1) - diameter--; - else - temp *= 0.8; - } - } - // Once cooled below legalise threshold, run legalisation and start requiring - // legal moves only - if (temp < legalise_temp && !require_legal) { - legalise_design(ctx); - require_legal = true; - autoplaced.clear(); - for (auto cell : sorted(ctx->cells)) { - if (cell.second->belStrength < STRENGTH_STRONG) - autoplaced.push_back(cell.second); - } - temp = post_legalise_temp; - diameter *= post_legalise_dia_scale; - ctx->shuffle(autoplaced); - assign_budget(ctx); - } - - // 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_net_wirelength(ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; - } - } - // Final post-pacement validitiy check - for (auto bel : ctx->getBels()) { - IdString cell = ctx->getBoundBelCell(bel); - if (!ctx->isBelLocationValid(bel)) { - std::string cell_text = "no cell"; - if (cell != IdString()) - cell_text = std::string("cell '") + cell.str(ctx) + "'"; - if (ctx->force) { - log_warning("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); - } else { - log_error("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); - } - } - } - return true; - } - - private: - // Initial random placement - void place_initial(CellInfo *cell) - { - bool all_placed = false; - int iters = 25; - while (!all_placed) { - BelId best_bel = BelId(); - uint64_t best_score = std::numeric_limits::max(), - best_ripup_score = std::numeric_limits::max(); - CellInfo *ripup_target = nullptr; - BelId ripup_bel = BelId(); - if (cell->bel != BelId()) { - ctx->unbindBel(cell->bel); - } - BelType targetType = ctx->belTypeFromId(cell->type); - for (auto bel : ctx->getBels()) { - if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { - if (ctx->checkBelAvail(bel)) { - uint64_t score = ctx->rng64(); - if (score <= best_score) { - best_score = score; - best_bel = bel; - } - } else { - uint64_t score = ctx->rng64(); - if (score <= best_ripup_score) { - best_ripup_score = score; - ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); - ripup_bel = bel; - } - } - } - } - if (best_bel == BelId()) { - if (iters == 0 || ripup_bel == BelId()) - log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); - --iters; - ctx->unbindBel(ripup_target->bel); - best_bel = ripup_bel; - } else { - all_placed = true; - } - ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); - - // Back annotate location - cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); - cell = ripup_target; - } - } - - // Attempt a SA position swap, return true on success or false on failure - bool try_swap_position(CellInfo *cell, BelId newBel) - { - static std::unordered_set update; - static std::vector> new_lengths; - new_lengths.clear(); - update.clear(); - BelId oldBel = cell->bel; - IdString other = ctx->getBoundBelCell(newBel); - CellInfo *other_cell = nullptr; - if (other != IdString()) { - other_cell = ctx->cells[other].get(); - if (other_cell->belStrength > STRENGTH_WEAK) - return false; - } - wirelen_t new_wirelength = 0, delta; - ctx->unbindBel(oldBel); - if (other != IdString()) { - ctx->unbindBel(newBel); - } - - for (const auto &port : cell->ports) - if (port.second.net != nullptr) - update.insert(port.second.net); - - if (other != IdString()) { - for (const auto &port : other_cell->ports) - if (port.second.net != nullptr) - update.insert(port.second.net); - } - - ctx->bindBel(newBel, cell->name, STRENGTH_WEAK); - - if (other != IdString()) { - ctx->bindBel(oldBel, other_cell->name, STRENGTH_WEAK); - } - if (require_legal) { - if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { - ctx->unbindBel(newBel); - if (other != IdString()) - ctx->unbindBel(oldBel); - goto swap_fail; - } - } - - new_wirelength = curr_wirelength; - - // Recalculate wirelengths for all nets touched by the peturbation - for (auto net : update) { - new_wirelength -= wirelengths.at(net->name); - float temp_tns = 0; - wirelen_t net_new_wl = get_net_wirelength(ctx, 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 / temp))) { - n_accept++; - if (delta < 2) - improved = true; - } else { - if (other != IdString()) - ctx->unbindBel(oldBel); - ctx->unbindBel(newBel); - goto swap_fail; - } - curr_wirelength = new_wirelength; - for (auto new_wl : new_lengths) - wirelengths.at(new_wl.first) = new_wl.second; - - return true; - swap_fail: - ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); - if (other != IdString()) { - ctx->bindBel(newBel, other, STRENGTH_WEAK); - } - return false; - } - - // Find a random Bel of the correct type for a cell, within the specified - // diameter - BelId random_bel_for_cell(CellInfo *cell) - { - BelType targetType = ctx->belTypeFromId(cell->type); - int x, y; - bool gb; - ctx->estimatePosition(cell->bel, x, y, gb); - while (true) { - int nx = ctx->rng(2 * diameter + 1) + std::max(x - diameter, 0); - int ny = ctx->rng(2 * diameter + 1) + std::max(y - diameter, 0); - int beltype_idx = bel_types.at(targetType); - if (nx >= int(fast_bels.at(beltype_idx).size())) - continue; - if (ny >= int(fast_bels.at(beltype_idx).at(nx).size())) - continue; - const auto &fb = fast_bels.at(beltype_idx).at(nx).at(ny); - if (fb.size() == 0) - continue; - BelId bel = fb.at(ctx->rng(int(fb.size()))); - if (locked_bels.find(bel) != locked_bels.end()) - continue; - return bel; - } - } - - Context *ctx; - std::unordered_map wirelengths; - wirelen_t curr_wirelength = std::numeric_limits::max(); - float curr_tns = 0; - float temp = 1000; - bool improved = false; - int n_move, n_accept; - int diameter = 35, max_x = 1, max_y = 1; - std::unordered_map bel_types; - std::vector>>> fast_bels; - std::unordered_set locked_bels; - bool require_legal = false; - const float legalise_temp = 1; - const float post_legalise_temp = 20; - const float post_legalise_dia_scale = 2; -}; - -bool place_design_sa(Context *ctx) -{ - try { - SAPlacer placer(ctx); - placer.place(); - log_info("Checksum: 0x%08x\n", ctx->checksum()); -#ifndef NDEBUG - ctx->check(); -#endif - return true; - } catch (log_execution_error_exception) { -#ifndef NDEBUG - ctx->check(); -#endif - return false; - } -} - -NEXTPNR_NAMESPACE_END diff --git a/common/place_sa.h b/common/place_sa.h deleted file mode 100644 index 1fd8c712..00000000 --- a/common/place_sa.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * nextpnr -- Next Generation Place and Route - * - * Copyright (C) 2018 Clifford Wolf - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -#ifndef PLACE_H -#define PLACE_H - -#include "nextpnr.h" - -NEXTPNR_NAMESPACE_BEGIN - -extern bool place_design_sa(Context *ctx); - -NEXTPNR_NAMESPACE_END - -#endif // PLACE_H diff --git a/common/placer1.cc b/common/placer1.cc new file mode 100644 index 00000000..53295a91 --- /dev/null +++ b/common/placer1.cc @@ -0,0 +1,450 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Clifford Wolf + * Copyright (C) 2018 David Shah + * + * Simulated annealing implementation based on arachne-pnr + * Copyright (C) 2015-2018 Cotton Seed + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include "placer1.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "place_common.h" +#include "place_legaliser.h" +#include "timing.h" +#include "util.h" +NEXTPNR_NAMESPACE_BEGIN + +class SAPlacer +{ + public: + SAPlacer(Context *ctx) : ctx(ctx) + { + int num_bel_types = 0; + for (auto bel : ctx->getBels()) { + int x, y; + bool gb; + ctx->estimatePosition(bel, x, y, gb); + BelType type = ctx->getBelType(bel); + int type_idx; + if (bel_types.find(type) == bel_types.end()) { + type_idx = num_bel_types++; + bel_types[type] = type_idx; + } else { + type_idx = bel_types.at(type); + } + if (int(fast_bels.size()) < type_idx + 1) + fast_bels.resize(type_idx + 1); + if (int(fast_bels.at(type_idx).size()) < (x + 1)) + fast_bels.at(type_idx).resize(x + 1); + if (int(fast_bels.at(type_idx).at(x).size()) < (y + 1)) + fast_bels.at(type_idx).at(x).resize(y + 1); + max_x = std::max(max_x, x); + max_y = std::max(max_y, y); + fast_bels.at(type_idx).at(x).at(y).push_back(bel); + } + diameter = std::max(max_x, max_y) + 1; + } + + bool place() + { + log_break(); + + size_t placed_cells = 0; + // Initial constraints placer + for (auto &cell_entry : ctx->cells) { + CellInfo *cell = cell_entry.second.get(); + auto loc = cell->attrs.find(ctx->id("BEL")); + if (loc != cell->attrs.end()) { + std::string loc_name = loc->second; + BelId bel = ctx->getBelByName(ctx->id(loc_name)); + if (bel == BelId()) { + log_error("No Bel named \'%s\' located for " + "this chip (processing BEL attribute on \'%s\')\n", + loc_name.c_str(), cell->name.c_str(ctx)); + } + + BelType bel_type = ctx->getBelType(bel); + if (bel_type != ctx->belTypeFromId(cell->type)) { + log_error("Bel \'%s\' of type \'%s\' does not match cell " + "\'%s\' of type \'%s\'", + loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), + cell->type.c_str(ctx)); + } + + ctx->bindBel(bel, cell->name, STRENGTH_USER); + locked_bels.insert(bel); + placed_cells++; + } + } + int constr_placed_cells = placed_cells; + log_info("Placed %d cells based on constraints.\n", int(placed_cells)); + + // Sort to-place cells for deterministic initial placement + std::vector autoplaced; + for (auto &cell : ctx->cells) { + CellInfo *ci = cell.second.get(); + if (ci->bel == BelId()) { + autoplaced.push_back(cell.second.get()); + } + } + std::sort(autoplaced.begin(), autoplaced.end(), [](CellInfo *a, CellInfo *b) { return a->name < b->name; }); + ctx->shuffle(autoplaced); + + // Place cells randomly initially + log_info("Creating initial placement for remaining %d cells.\n", int(autoplaced.size())); + + for (auto cell : autoplaced) { + place_initial(cell); + placed_cells++; + if ((placed_cells - constr_placed_cells) % 500 == 0) + log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), + int(autoplaced.size())); + } + if ((placed_cells - constr_placed_cells) % 500 != 0) + log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), + int(autoplaced.size())); + + log_info("Running simulated annealing placer.\n"); + + // Calculate wirelength after initial placement + curr_wirelength = 0; + curr_tns = 0; + for (auto &net : ctx->nets) { + wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; + } + + int n_no_progress = 0; + double avg_wirelength = curr_wirelength; + temp = 10000; + + // Main simulated annealing loop + for (int iter = 1;; iter++) { + n_move = n_accept = 0; + improved = false; + + if (iter % 5 == 0 || iter == 1) + 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 + for (auto cell : autoplaced) { + // Find another random Bel for this cell + BelId try_bel = random_bel_for_cell(cell); + // If valid, try and swap to a new position and see if + // the new position is valid/worthwhile + if (try_bel != BelId() && try_bel != cell->bel) + try_swap_position(cell, try_bel); + } + } + // Heuristic to improve placement on the 8k + if (improved) + n_no_progress = 0; + else + n_no_progress++; + + if (temp <= 1e-3 && n_no_progress >= 5) { + if (iter % 5 != 0) + log_info(" at iteration #%d: temp = %f, wire length = %f\n", iter, temp, double(curr_wirelength)); + break; + } + + double Raccept = double(n_accept) / double(n_move); + + int M = std::max(max_x, max_y) + 1; + + double upper = 0.6, lower = 0.4; + + if (curr_wirelength < 0.95 * avg_wirelength) { + avg_wirelength = 0.8 * avg_wirelength + 0.2 * curr_wirelength; + } else { + if (Raccept >= 0.8) { + temp *= 0.7; + } else if (Raccept > upper) { + if (diameter < M) + diameter++; + else + temp *= 0.9; + } else if (Raccept > lower) { + temp *= 0.95; + } else { + // Raccept < 0.3 + if (diameter > 1) + diameter--; + else + temp *= 0.8; + } + } + // Once cooled below legalise threshold, run legalisation and start requiring + // legal moves only + if (temp < legalise_temp && !require_legal) { + legalise_design(ctx); + require_legal = true; + autoplaced.clear(); + for (auto cell : sorted(ctx->cells)) { + if (cell.second->belStrength < STRENGTH_STRONG) + autoplaced.push_back(cell.second); + } + temp = post_legalise_temp; + diameter *= post_legalise_dia_scale; + ctx->shuffle(autoplaced); + assign_budget(ctx); + } + + // 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_net_wirelength(ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; + } + } + // Final post-pacement validitiy check + for (auto bel : ctx->getBels()) { + IdString cell = ctx->getBoundBelCell(bel); + if (!ctx->isBelLocationValid(bel)) { + std::string cell_text = "no cell"; + if (cell != IdString()) + cell_text = std::string("cell '") + cell.str(ctx) + "'"; + if (ctx->force) { + log_warning("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + } else { + log_error("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + } + } + } + return true; + } + + private: + // Initial random placement + void place_initial(CellInfo *cell) + { + bool all_placed = false; + int iters = 25; + while (!all_placed) { + BelId best_bel = BelId(); + uint64_t best_score = std::numeric_limits::max(), + best_ripup_score = std::numeric_limits::max(); + CellInfo *ripup_target = nullptr; + BelId ripup_bel = BelId(); + if (cell->bel != BelId()) { + ctx->unbindBel(cell->bel); + } + BelType targetType = ctx->belTypeFromId(cell->type); + for (auto bel : ctx->getBels()) { + if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { + if (ctx->checkBelAvail(bel)) { + uint64_t score = ctx->rng64(); + if (score <= best_score) { + best_score = score; + best_bel = bel; + } + } else { + uint64_t score = ctx->rng64(); + if (score <= best_ripup_score) { + best_ripup_score = score; + ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); + ripup_bel = bel; + } + } + } + } + if (best_bel == BelId()) { + if (iters == 0 || ripup_bel == BelId()) + log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); + --iters; + ctx->unbindBel(ripup_target->bel); + best_bel = ripup_bel; + } else { + all_placed = true; + } + ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); + + // Back annotate location + cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); + cell = ripup_target; + } + } + + // Attempt a SA position swap, return true on success or false on failure + bool try_swap_position(CellInfo *cell, BelId newBel) + { + static std::unordered_set update; + static std::vector> new_lengths; + new_lengths.clear(); + update.clear(); + BelId oldBel = cell->bel; + IdString other = ctx->getBoundBelCell(newBel); + CellInfo *other_cell = nullptr; + if (other != IdString()) { + other_cell = ctx->cells[other].get(); + if (other_cell->belStrength > STRENGTH_WEAK) + return false; + } + wirelen_t new_wirelength = 0, delta; + ctx->unbindBel(oldBel); + if (other != IdString()) { + ctx->unbindBel(newBel); + } + + for (const auto &port : cell->ports) + if (port.second.net != nullptr) + update.insert(port.second.net); + + if (other != IdString()) { + for (const auto &port : other_cell->ports) + if (port.second.net != nullptr) + update.insert(port.second.net); + } + + ctx->bindBel(newBel, cell->name, STRENGTH_WEAK); + + if (other != IdString()) { + ctx->bindBel(oldBel, other_cell->name, STRENGTH_WEAK); + } + if (require_legal) { + if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { + ctx->unbindBel(newBel); + if (other != IdString()) + ctx->unbindBel(oldBel); + goto swap_fail; + } + } + + new_wirelength = curr_wirelength; + + // Recalculate wirelengths for all nets touched by the peturbation + for (auto net : update) { + new_wirelength -= wirelengths.at(net->name); + float temp_tns = 0; + wirelen_t net_new_wl = get_net_wirelength(ctx, 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 / temp))) { + n_accept++; + if (delta < 2) + improved = true; + } else { + if (other != IdString()) + ctx->unbindBel(oldBel); + ctx->unbindBel(newBel); + goto swap_fail; + } + curr_wirelength = new_wirelength; + for (auto new_wl : new_lengths) + wirelengths.at(new_wl.first) = new_wl.second; + + return true; + swap_fail: + ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); + if (other != IdString()) { + ctx->bindBel(newBel, other, STRENGTH_WEAK); + } + return false; + } + + // Find a random Bel of the correct type for a cell, within the specified + // diameter + BelId random_bel_for_cell(CellInfo *cell) + { + BelType targetType = ctx->belTypeFromId(cell->type); + int x, y; + bool gb; + ctx->estimatePosition(cell->bel, x, y, gb); + while (true) { + int nx = ctx->rng(2 * diameter + 1) + std::max(x - diameter, 0); + int ny = ctx->rng(2 * diameter + 1) + std::max(y - diameter, 0); + int beltype_idx = bel_types.at(targetType); + if (nx >= int(fast_bels.at(beltype_idx).size())) + continue; + if (ny >= int(fast_bels.at(beltype_idx).at(nx).size())) + continue; + const auto &fb = fast_bels.at(beltype_idx).at(nx).at(ny); + if (fb.size() == 0) + continue; + BelId bel = fb.at(ctx->rng(int(fb.size()))); + if (locked_bels.find(bel) != locked_bels.end()) + continue; + return bel; + } + } + + Context *ctx; + std::unordered_map wirelengths; + wirelen_t curr_wirelength = std::numeric_limits::max(); + float curr_tns = 0; + float temp = 1000; + bool improved = false; + int n_move, n_accept; + int diameter = 35, max_x = 1, max_y = 1; + std::unordered_map bel_types; + std::vector>>> fast_bels; + std::unordered_set locked_bels; + bool require_legal = false; + const float legalise_temp = 1; + const float post_legalise_temp = 20; + const float post_legalise_dia_scale = 2; +}; + +bool placer1(Context *ctx) +{ + try { + SAPlacer placer(ctx); + placer.place(); + log_info("Checksum: 0x%08x\n", ctx->checksum()); +#ifndef NDEBUG + ctx->check(); +#endif + return true; + } catch (log_execution_error_exception) { +#ifndef NDEBUG + ctx->check(); +#endif + return false; + } +} + +NEXTPNR_NAMESPACE_END diff --git a/common/placer1.h b/common/placer1.h new file mode 100644 index 00000000..477fae56 --- /dev/null +++ b/common/placer1.h @@ -0,0 +1,30 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Clifford Wolf + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ +#ifndef PLACE_H +#define PLACE_H + +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN + +extern bool placer1(Context *ctx); + +NEXTPNR_NAMESPACE_END + +#endif // PLACE_H -- cgit v1.2.3 From a436035424368b3d424822c7b72f99044c93dafd Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 12 Jul 2018 17:22:29 +0200 Subject: Add Groups API Signed-off-by: Clifford Wolf --- common/nextpnr.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 09bd1554..a162b85c 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -271,6 +271,7 @@ struct BaseCtx std::unordered_set belUiReload; std::unordered_set wireUiReload; std::unordered_set pipUiReload; + std::unordered_set groupUiReload; void refreshUi() { @@ -296,6 +297,11 @@ struct BaseCtx { pipUiReload.insert(pip); } + + void refreshUiGroup(GroupId group) + { + groupUiReload.insert(group); + } }; NEXTPNR_NAMESPACE_END @@ -368,6 +374,19 @@ struct Context : Arch return ret; } + NPNR_DEPRECATED std::vector getGroupGraphics(GroupId group) const { + std::vector ret; + DecalXY decalxy = getGroupDecal(group); + ret = getDecalGraphics(decalxy.decal); + for (auto &it : ret) { + it.x1 += decalxy.x; + it.x2 += decalxy.x; + it.y1 += decalxy.y; + it.y2 += decalxy.y; + } + return ret; + } + // -------------------------------------------------------------- // provided by router1.cc -- cgit v1.2.3 From 13e7cd868111300577c36a3fd45ba698ce926160 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 12 Jul 2018 21:04:47 +0200 Subject: Add GraphicElement style enum Signed-off-by: Clifford Wolf --- common/nextpnr.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index a162b85c..00a939a9 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -136,7 +136,7 @@ NEXTPNR_NAMESPACE_BEGIN struct GraphicElement { - enum + enum type_t { G_NONE, G_LINE, @@ -145,6 +145,14 @@ struct GraphicElement G_LABEL } type = G_NONE; + enum style_t + { + G_FRAME, + G_HIDDEN, + G_INACTIVE, + G_ACTIVE, + } style = G_FRAME; + float x1 = 0, y1 = 0, x2 = 0, y2 = 0, z = 0; std::string text; }; -- cgit v1.2.3 From b8a42ff53b1fbb6e03d169d14e58180a750f4cad Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 12 Jul 2018 22:04:13 +0200 Subject: Updates from clang-format Signed-off-by: Clifford Wolf --- common/nextpnr.h | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 00a939a9..5e8c2362 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -268,9 +268,9 @@ struct BaseCtx delete idstring_idx_to_str; } - Context *getCtx() { return reinterpret_cast(this); } + Context *getCtx() { return reinterpret_cast(this); } - const Context *getCtx() const { return reinterpret_cast(this); } + const Context *getCtx() const { return reinterpret_cast(this); } // -------------------------------------------------------------- @@ -281,35 +281,17 @@ struct BaseCtx std::unordered_set pipUiReload; std::unordered_set groupUiReload; - void refreshUi() - { - allUiReload = true; - } + void refreshUi() { allUiReload = true; } - void refreshUiFrame() - { - frameUiReload = true; - } + void refreshUiFrame() { frameUiReload = true; } - void refreshUiBel(BelId bel) - { - belUiReload.insert(bel); - } + void refreshUiBel(BelId bel) { belUiReload.insert(bel); } - void refreshUiWire(WireId wire) - { - wireUiReload.insert(wire); - } + void refreshUiWire(WireId wire) { wireUiReload.insert(wire); } - void refreshUiPip(PipId pip) - { - pipUiReload.insert(pip); - } + void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } - void refreshUiGroup(GroupId group) - { - groupUiReload.insert(group); - } + void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } }; NEXTPNR_NAMESPACE_END @@ -330,7 +312,8 @@ struct Context : Arch // -------------------------------------------------------------- - NPNR_DEPRECATED std::vector getFrameGraphics() const { + NPNR_DEPRECATED std::vector getFrameGraphics() const + { std::vector ret; DecalXY decalxy = getFrameDecal(); ret = getDecalGraphics(decalxy.decal); @@ -343,7 +326,8 @@ struct Context : Arch return ret; } - NPNR_DEPRECATED std::vector getBelGraphics(BelId bel) const { + NPNR_DEPRECATED std::vector getBelGraphics(BelId bel) const + { std::vector ret; DecalXY decalxy = getBelDecal(bel); ret = getDecalGraphics(decalxy.decal); @@ -356,7 +340,8 @@ struct Context : Arch return ret; } - NPNR_DEPRECATED std::vector getWireGraphics(WireId wire) const { + NPNR_DEPRECATED std::vector getWireGraphics(WireId wire) const + { std::vector ret; DecalXY decalxy = getWireDecal(wire); ret = getDecalGraphics(decalxy.decal); @@ -369,7 +354,8 @@ struct Context : Arch return ret; } - NPNR_DEPRECATED std::vector getPipGraphics(PipId pip) const { + NPNR_DEPRECATED std::vector getPipGraphics(PipId pip) const + { std::vector ret; DecalXY decalxy = getPipDecal(pip); ret = getDecalGraphics(decalxy.decal); @@ -382,7 +368,8 @@ struct Context : Arch return ret; } - NPNR_DEPRECATED std::vector getGroupGraphics(GroupId group) const { + NPNR_DEPRECATED std::vector getGroupGraphics(GroupId group) const + { std::vector ret; DecalXY decalxy = getGroupDecal(group); ret = getDecalGraphics(decalxy.decal); -- cgit v1.2.3 From 499951cb65ff31fe15aa360a6b44371b13815d66 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Thu, 12 Jul 2018 21:30:36 +0100 Subject: Remove legacy graphics API For now we do not optimize the OpenGL renderer against the new decal API, but this can be done in the future. --- common/nextpnr.h | 72 -------------------------------------------------------- 1 file changed, 72 deletions(-) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 5e8c2362..50465869 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -312,78 +312,6 @@ struct Context : Arch // -------------------------------------------------------------- - NPNR_DEPRECATED std::vector getFrameGraphics() const - { - std::vector ret; - DecalXY decalxy = getFrameDecal(); - ret = getDecalGraphics(decalxy.decal); - for (auto &it : ret) { - it.x1 += decalxy.x; - it.x2 += decalxy.x; - it.y1 += decalxy.y; - it.y2 += decalxy.y; - } - return ret; - } - - NPNR_DEPRECATED std::vector getBelGraphics(BelId bel) const - { - std::vector ret; - DecalXY decalxy = getBelDecal(bel); - ret = getDecalGraphics(decalxy.decal); - for (auto &it : ret) { - it.x1 += decalxy.x; - it.x2 += decalxy.x; - it.y1 += decalxy.y; - it.y2 += decalxy.y; - } - return ret; - } - - NPNR_DEPRECATED std::vector getWireGraphics(WireId wire) const - { - std::vector ret; - DecalXY decalxy = getWireDecal(wire); - ret = getDecalGraphics(decalxy.decal); - for (auto &it : ret) { - it.x1 += decalxy.x; - it.x2 += decalxy.x; - it.y1 += decalxy.y; - it.y2 += decalxy.y; - } - return ret; - } - - NPNR_DEPRECATED std::vector getPipGraphics(PipId pip) const - { - std::vector ret; - DecalXY decalxy = getPipDecal(pip); - ret = getDecalGraphics(decalxy.decal); - for (auto &it : ret) { - it.x1 += decalxy.x; - it.x2 += decalxy.x; - it.y1 += decalxy.y; - it.y2 += decalxy.y; - } - return ret; - } - - NPNR_DEPRECATED std::vector getGroupGraphics(GroupId group) const - { - std::vector ret; - DecalXY decalxy = getGroupDecal(group); - ret = getDecalGraphics(decalxy.decal); - for (auto &it : ret) { - it.x1 += decalxy.x; - it.x2 += decalxy.x; - it.y1 += decalxy.y; - it.y2 += decalxy.y; - } - return ret; - } - - // -------------------------------------------------------------- - // provided by router1.cc bool getActualRouteDelay(WireId src_wire, WireId dst_wire, delay_t &delay); -- cgit v1.2.3 From 9e4f97290a50fc5d9dc0cbe6ead945840b9811b1 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Fri, 13 Jul 2018 14:50:58 +0100 Subject: Make PnR use Unlocked methods --- common/place_common.cc | 14 +++++++------- common/placer1.cc | 38 +++++++++++++++++++------------------- common/router1.cc | 36 ++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 44 deletions(-) (limited to 'common') diff --git a/common/place_common.cc b/common/place_common.cc index 60735890..281e40a2 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -36,7 +36,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) if (driver_cell->bel == BelId()) return 0; ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); - WireId drv_wire = ctx->getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port)); + WireId drv_wire = ctx->getWireBelPinUnlocked(driver_cell->bel, ctx->portPinFromId(net->driver.port)); if (driver_gb) return 0; float worst_slack = 1000; @@ -48,7 +48,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) if (load_cell->bel == BelId()) continue; if (ctx->timing_driven) { - WireId user_wire = ctx->getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port)); + WireId user_wire = ctx->getWireBelPinUnlocked(load_cell->bel, ctx->portPinFromId(load.port)); delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); if (slack < 0) @@ -112,12 +112,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBel(cell->bel); + ctx->unbindBelUnlocked(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) { - if (ctx->checkBelAvail(bel)) { + if (ctx->checkBelAvailUnlocked(bel)) { wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); @@ -130,7 +130,7 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_ripup_wirelen) { - ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); + ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); if (ripup_target->belStrength < STRENGTH_STRONG) { best_ripup_wirelen = wirelen; ripup_bel = bel; @@ -148,12 +148,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); } --iters; - ctx->unbindBel(ripup_target->bel); + ctx->unbindBelUnlocked(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); cell = ripup_target; } diff --git a/common/placer1.cc b/common/placer1.cc index 53295a91..05f760a3 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -85,7 +85,7 @@ class SAPlacer auto loc = cell->attrs.find(ctx->id("BEL")); if (loc != cell->attrs.end()) { std::string loc_name = loc->second; - BelId bel = ctx->getBelByName(ctx->id(loc_name)); + BelId bel = ctx->getBelByNameUnlocked(ctx->id(loc_name)); if (bel == BelId()) { log_error("No Bel named \'%s\' located for " "this chip (processing BEL attribute on \'%s\')\n", @@ -100,7 +100,7 @@ class SAPlacer cell->type.c_str(ctx)); } - ctx->bindBel(bel, cell->name, STRENGTH_USER); + ctx->bindBelUnlocked(bel, cell->name, STRENGTH_USER); locked_bels.insert(bel); placed_cells++; } @@ -235,7 +235,7 @@ class SAPlacer } // Final post-pacement validitiy check for (auto bel : ctx->getBels()) { - IdString cell = ctx->getBoundBelCell(bel); + IdString cell = ctx->getBoundBelCellUnlocked(bel); if (!ctx->isBelLocationValid(bel)) { std::string cell_text = "no cell"; if (cell != IdString()) @@ -267,12 +267,12 @@ class SAPlacer CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBel(cell->bel); + ctx->unbindBelUnlocked(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { - if (ctx->checkBelAvail(bel)) { + if (ctx->checkBelAvailUnlocked(bel)) { uint64_t score = ctx->rng64(); if (score <= best_score) { best_score = score; @@ -282,7 +282,7 @@ class SAPlacer uint64_t score = ctx->rng64(); if (score <= best_ripup_score) { best_ripup_score = score; - ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); + ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); ripup_bel = bel; } } @@ -292,12 +292,12 @@ class SAPlacer if (iters == 0 || ripup_bel == BelId()) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); --iters; - ctx->unbindBel(ripup_target->bel); + ctx->unbindBelUnlocked(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); // Back annotate location cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); @@ -313,7 +313,7 @@ class SAPlacer new_lengths.clear(); update.clear(); BelId oldBel = cell->bel; - IdString other = ctx->getBoundBelCell(newBel); + IdString other = ctx->getBoundBelCellUnlocked(newBel); CellInfo *other_cell = nullptr; if (other != IdString()) { other_cell = ctx->cells[other].get(); @@ -321,9 +321,9 @@ class SAPlacer return false; } wirelen_t new_wirelength = 0, delta; - ctx->unbindBel(oldBel); + ctx->unbindBelUnlocked(oldBel); if (other != IdString()) { - ctx->unbindBel(newBel); + ctx->unbindBelUnlocked(newBel); } for (const auto &port : cell->ports) @@ -336,16 +336,16 @@ class SAPlacer update.insert(port.second.net); } - ctx->bindBel(newBel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(newBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBel(oldBel, other_cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(oldBel, other_cell->name, STRENGTH_WEAK); } if (require_legal) { if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { - ctx->unbindBel(newBel); + ctx->unbindBelUnlocked(newBel); if (other != IdString()) - ctx->unbindBel(oldBel); + ctx->unbindBelUnlocked(oldBel); goto swap_fail; } } @@ -369,8 +369,8 @@ class SAPlacer improved = true; } else { if (other != IdString()) - ctx->unbindBel(oldBel); - ctx->unbindBel(newBel); + ctx->unbindBelUnlocked(oldBel); + ctx->unbindBelUnlocked(newBel); goto swap_fail; } curr_wirelength = new_wirelength; @@ -379,9 +379,9 @@ class SAPlacer return true; swap_fail: - ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(oldBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBel(newBel, other, STRENGTH_WEAK); + ctx->bindBelUnlocked(newBel, other, STRENGTH_WEAK); } return false; } diff --git a/common/router1.cc b/common/router1.cc index 94c7070e..cbaf773d 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -90,10 +90,10 @@ void ripup_net(Context *ctx, IdString net_name) } for (auto pip : pips) - ctx->unbindPip(pip); + ctx->unbindPipUnlocked(pip); for (auto wire : wires) - ctx->unbindWire(wire); + ctx->unbindWireUnlocked(wire); NPNR_ASSERT(net_info->wires.empty()); } @@ -148,10 +148,10 @@ struct Router bool foundRipupNet = false; thisVisitCnt++; - if (!ctx->checkWireAvail(next_wire)) { + if (!ctx->checkWireAvailUnlocked(next_wire)) { if (!ripup) continue; - IdString ripupWireNet = ctx->getConflictingWireNet(next_wire); + IdString ripupWireNet = ctx->getConflictingWireNetUnlocked(next_wire); if (ripupWireNet == net_name || ripupWireNet == IdString()) continue; @@ -166,10 +166,10 @@ struct Router foundRipupNet = true; } - if (!ctx->checkPipAvail(pip)) { + if (!ctx->checkPipAvailUnlocked(pip)) { if (!ripup) continue; - IdString ripupPipNet = ctx->getConflictingPipNet(pip); + IdString ripupPipNet = ctx->getConflictingPipNetUnlocked(pip); if (ripupPipNet == net_name || ripupPipNet == IdString()) continue; @@ -272,7 +272,7 @@ struct Router if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) log_error("No wire found for port %s (pin %s) on source cell %s " @@ -287,7 +287,7 @@ struct Router src_wires[src_wire] = 0; ripup_net(ctx, net_name); - ctx->bindWire(src_wire, net_name, STRENGTH_WEAK); + ctx->bindWireUnlocked(src_wire, net_name, STRENGTH_WEAK); std::vector users_array = net_info->users; ctx->shuffle(users_array); @@ -312,7 +312,7 @@ struct Router if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) log_error("No wire found for port %s (pin %s) on destination " @@ -355,14 +355,14 @@ struct Router if (src_wires.count(cursor)) break; - IdString conflicting_wire_net = ctx->getConflictingWireNet(cursor); + IdString conflicting_wire_net = ctx->getConflictingWireNetUnlocked(cursor); if (conflicting_wire_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_wire_net != net_name); - ctx->unbindWire(cursor); - if (!ctx->checkWireAvail(cursor)) + ctx->unbindWireUnlocked(cursor); + if (!ctx->checkWireAvailUnlocked(cursor)) ripup_net(ctx, conflicting_wire_net); rippedNets.insert(conflicting_wire_net); @@ -372,14 +372,14 @@ struct Router } PipId pip = visited[cursor].pip; - IdString conflicting_pip_net = ctx->getConflictingPipNet(pip); + IdString conflicting_pip_net = ctx->getConflictingPipNetUnlocked(pip); if (conflicting_pip_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_pip_net != net_name); - ctx->unbindPip(pip); - if (!ctx->checkPipAvail(pip)) + ctx->unbindPipUnlocked(pip); + if (!ctx->checkPipAvailUnlocked(pip)) ripup_net(ctx, conflicting_pip_net); rippedNets.insert(conflicting_pip_net); @@ -388,7 +388,7 @@ struct Router scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; } - ctx->bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); + ctx->bindPipUnlocked(visited[cursor].pip, net_name, STRENGTH_WEAK); src_wires[cursor] = visited[cursor].delay; cursor = ctx->getPipSrcWire(visited[cursor].pip); } @@ -451,7 +451,7 @@ bool router1(Context *ctx) if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) continue; @@ -469,7 +469,7 @@ bool router1(Context *ctx) if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) continue; -- cgit v1.2.3 From 89809a8b810dd57f50f365d70a0ce547705f8dbb Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Fri, 13 Jul 2018 18:57:55 +0100 Subject: Introduce proxies for locked access to ctx --- common/place_common.cc | 95 +++----------------------- common/place_common.h | 83 +++++++++++++++++++++-- common/placer1.cc | 181 +++++++++++++++++++++++++++---------------------- common/router1.cc | 108 ++++++++++++++++------------- 4 files changed, 247 insertions(+), 220 deletions(-) (limited to 'common') diff --git a/common/place_common.cc b/common/place_common.cc index 281e40a2..48416370 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -2,6 +2,7 @@ * nextpnr -- Next Generation Place and Route * * Copyright (C) 2018 David Shah + * Copyright (C) 2018 Serge Bazanski * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,84 +25,8 @@ NEXTPNR_NAMESPACE_BEGIN -// Get the total estimated wirelength for a net -wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) -{ - wirelen_t wirelength = 0; - int driver_x, driver_y; - bool driver_gb; - CellInfo *driver_cell = net->driver.cell; - if (!driver_cell) - return 0; - if (driver_cell->bel == BelId()) - return 0; - ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); - WireId drv_wire = ctx->getWireBelPinUnlocked(driver_cell->bel, ctx->portPinFromId(net->driver.port)); - if (driver_gb) - return 0; - float worst_slack = 1000; - int xmin = driver_x, xmax = driver_x, ymin = driver_y, ymax = driver_y; - for (auto load : net->users) { - if (load.cell == nullptr) - continue; - CellInfo *load_cell = load.cell; - if (load_cell->bel == BelId()) - continue; - if (ctx->timing_driven) { - WireId user_wire = ctx->getWireBelPinUnlocked(load_cell->bel, ctx->portPinFromId(load.port)); - 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; - ctx->estimatePosition(load_cell->bel, load_x, load_y, load_gb); - if (load_gb) - continue; - xmin = std::min(xmin, load_x); - ymin = std::min(ymin, load_y); - xmax = std::max(xmax, load_x); - ymax = std::max(ymax, load_y); - } - if (ctx->timing_driven) { - wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); - } else { - wirelength = wirelen_t((ymax - ymin) + (xmax - xmin)); - } - - return wirelength; -} - -// Get the total wirelength for a cell -wirelen_t get_cell_wirelength(const Context *ctx, const CellInfo *cell) -{ - std::set nets; - for (auto p : cell->ports) { - if (p.second.net) - nets.insert(p.second.net->name); - } - wirelen_t wirelength = 0; - float tns = 0; - for (auto n : nets) { - wirelength += get_net_wirelength(ctx, ctx->nets.at(n).get(), tns); - } - return wirelength; -} - -wirelen_t get_cell_wirelength_at_bel(const Context *ctx, CellInfo *cell, BelId bel) -{ - BelId oldBel = cell->bel; - cell->bel = bel; - wirelen_t wirelen = get_cell_wirelength(ctx, cell); - cell->bel = oldBel; - return wirelen; -} - // Placing a single cell -bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) +bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality) { bool all_placed = false; int iters = 25; @@ -112,13 +37,13 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBelUnlocked(cell->bel); + proxy.unbindBel(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { - if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) { - if (ctx->checkBelAvailUnlocked(bel)) { - wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); + if (ctx->getBelType(bel) == targetType && (!require_legality || proxy.isValidBelForCell(cell, bel))) { + if (proxy.checkBelAvail(bel)) { + wirelen_t wirelen = get_cell_wirelength_at_bel(proxy, ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_wirelen) { @@ -126,11 +51,11 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) best_bel = bel; } } else { - wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); + wirelen_t wirelen = get_cell_wirelength_at_bel(proxy, ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_ripup_wirelen) { - ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); + ripup_target = proxy.getCell(proxy.getBoundBelCell(bel)); if (ripup_target->belStrength < STRENGTH_STRONG) { best_ripup_wirelen = wirelen; ripup_bel = bel; @@ -148,12 +73,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); } --iters; - ctx->unbindBelUnlocked(ripup_target->bel); + proxy.unbindBel(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); + proxy.bindBel(best_bel, cell->name, STRENGTH_WEAK); cell = ripup_target; } diff --git a/common/place_common.h b/common/place_common.h index 67956072..57e82510 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -22,21 +22,94 @@ #include "nextpnr.h" +#include + NEXTPNR_NAMESPACE_BEGIN typedef int64_t wirelen_t; -// Return the wirelength of a net -wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns); +// Get the total estimated wirelength for a net +template +wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) +{ + wirelen_t wirelength = 0; + int driver_x, driver_y; + bool driver_gb; + CellInfo *driver_cell = net->driver.cell; + if (!driver_cell) + return 0; + if (driver_cell->bel == BelId()) + return 0; + ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); + WireId drv_wire = proxy.getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port)); + if (driver_gb) + return 0; + float worst_slack = 1000; + int xmin = driver_x, xmax = driver_x, ymin = driver_y, ymax = driver_y; + for (auto load : net->users) { + if (load.cell == nullptr) + continue; + CellInfo *load_cell = load.cell; + if (load_cell->bel == BelId()) + continue; + if (ctx->timing_driven) { + WireId user_wire = proxy.getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port)); + 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; + ctx->estimatePosition(load_cell->bel, load_x, load_y, load_gb); + if (load_gb) + continue; + xmin = std::min(xmin, load_x); + ymin = std::min(ymin, load_y); + xmax = std::max(xmax, load_x); + ymax = std::max(ymax, load_y); + } + if (ctx->timing_driven) { + wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); + } else { + wirelength = wirelen_t((ymax - ymin) + (xmax - xmin)); + } + + return wirelength; +} // Return the wirelength of all nets connected to a cell -wirelen_t get_cell_wirelength(const Context *ctx, const CellInfo *cell); +template +wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) +{ + std::set nets; + for (auto p : cell->ports) { + if (p.second.net) + nets.insert(p.second.net->name); + } + wirelen_t wirelength = 0; + float tns = 0; + for (auto n : nets) { + wirelength += get_net_wirelength(proxy, ctx, ctx->nets.at(n).get(), tns); + } + return wirelength; +} // Return the wirelength of all nets connected to a cell, when the cell is at a given bel -wirelen_t get_cell_wirelength_at_bel(const Context *ctx, CellInfo *cell, BelId bel); +template +wirelen_t get_cell_wirelength_at_bel(const T &proxy, const Context *ctx, CellInfo *cell, BelId bel) +{ + BelId oldBel = cell->bel; + cell->bel = bel; + wirelen_t wirelen = get_cell_wirelength(proxy, ctx, cell); + cell->bel = oldBel; + return wirelen; +} // Place a single cell in the lowest wirelength Bel available, optionally requiring validity check -bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality); +bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality); NEXTPNR_NAMESPACE_END diff --git a/common/placer1.cc b/common/placer1.cc index 05f760a3..0e3a84f7 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -3,6 +3,7 @@ * * Copyright (C) 2018 Clifford Wolf * Copyright (C) 2018 David Shah + * Copyright (C) 2018 Serge Bazanski * * Simulated annealing implementation based on arachne-pnr * Copyright (C) 2015-2018 Cotton Seed @@ -79,30 +80,33 @@ class SAPlacer log_break(); size_t placed_cells = 0; - // Initial constraints placer - for (auto &cell_entry : ctx->cells) { - CellInfo *cell = cell_entry.second.get(); - auto loc = cell->attrs.find(ctx->id("BEL")); - if (loc != cell->attrs.end()) { - std::string loc_name = loc->second; - BelId bel = ctx->getBelByNameUnlocked(ctx->id(loc_name)); - if (bel == BelId()) { - log_error("No Bel named \'%s\' located for " - "this chip (processing BEL attribute on \'%s\')\n", - loc_name.c_str(), cell->name.c_str(ctx)); - } + { + auto &&proxy = ctx->rwproxy(); + // Initial constraints placer + for (auto &cell_entry : ctx->cells) { + CellInfo *cell = cell_entry.second.get(); + auto loc = cell->attrs.find(ctx->id("BEL")); + if (loc != cell->attrs.end()) { + std::string loc_name = loc->second; + BelId bel = proxy.getBelByName(ctx->id(loc_name)); + if (bel == BelId()) { + log_error("No Bel named \'%s\' located for " + "this chip (processing BEL attribute on \'%s\')\n", + loc_name.c_str(), cell->name.c_str(ctx)); + } - BelType bel_type = ctx->getBelType(bel); - if (bel_type != ctx->belTypeFromId(cell->type)) { - log_error("Bel \'%s\' of type \'%s\' does not match cell " - "\'%s\' of type \'%s\'", - loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), - cell->type.c_str(ctx)); - } + BelType bel_type = ctx->getBelType(bel); + if (bel_type != ctx->belTypeFromId(cell->type)) { + log_error("Bel \'%s\' of type \'%s\' does not match cell " + "\'%s\' of type \'%s\'", + loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), + cell->type.c_str(ctx)); + } - ctx->bindBelUnlocked(bel, cell->name, STRENGTH_USER); - locked_bels.insert(bel); - placed_cells++; + proxy.bindBel(bel, cell->name, STRENGTH_USER); + locked_bels.insert(bel); + placed_cells++; + } } } int constr_placed_cells = placed_cells; @@ -122,12 +126,15 @@ class SAPlacer // Place cells randomly initially log_info("Creating initial placement for remaining %d cells.\n", int(autoplaced.size())); - for (auto cell : autoplaced) { - place_initial(cell); - placed_cells++; - if ((placed_cells - constr_placed_cells) % 500 == 0) - log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), - int(autoplaced.size())); + { + auto &&proxy = ctx->rwproxy(); + for (auto cell : autoplaced) { + place_initial(proxy, cell); + placed_cells++; + if ((placed_cells - constr_placed_cells) % 500 == 0) + log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), + int(autoplaced.size())); + } } if ((placed_cells - constr_placed_cells) % 500 != 0) log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), @@ -138,10 +145,13 @@ class SAPlacer // Calculate wirelength after initial placement curr_wirelength = 0; curr_tns = 0; - for (auto &net : ctx->nets) { - wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; + { + auto &&proxy = ctx->rproxy(); + for (auto &net : ctx->nets) { + wirelen_t wl = get_net_wirelength(proxy, ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; + } } int n_no_progress = 0; @@ -158,15 +168,18 @@ class SAPlacer "%.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 - for (auto cell : autoplaced) { - // Find another random Bel for this cell - BelId try_bel = random_bel_for_cell(cell); - // If valid, try and swap to a new position and see if - // the new position is valid/worthwhile - if (try_bel != BelId() && try_bel != cell->bel) - try_swap_position(cell, try_bel); + { + auto &&proxy = ctx->rwproxy(); + for (int m = 0; m < 15; ++m) { + // Loop through all automatically placed cells + for (auto cell : autoplaced) { + // Find another random Bel for this cell + BelId try_bel = random_bel_for_cell(cell); + // If valid, try and swap to a new position and see if + // the new position is valid/worthwhile + if (try_bel != BelId() && try_bel != cell->bel) + try_swap_position(proxy, cell, try_bel); + } } } // Heuristic to improve placement on the 8k @@ -227,27 +240,33 @@ class SAPlacer // accumulating over time curr_wirelength = 0; curr_tns = 0; - for (auto &net : ctx->nets) { - wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; + { + auto &&proxy = ctx->rproxy(); + for (auto &net : ctx->nets) { + wirelen_t wl = get_net_wirelength(proxy, ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; + } } } - // Final post-pacement validitiy check - for (auto bel : ctx->getBels()) { - IdString cell = ctx->getBoundBelCellUnlocked(bel); - if (!ctx->isBelLocationValid(bel)) { - std::string cell_text = "no cell"; - if (cell != IdString()) - cell_text = std::string("cell '") + cell.str(ctx) + "'"; - if (ctx->force) { - log_warning("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); - } else { - log_error("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + { + // Final post-pacement validitiy check + auto &&proxy = ctx->rproxy(); + for (auto bel : ctx->getBels()) { + IdString cell = proxy.getBoundBelCell(bel); + if (!proxy.isBelLocationValid(bel)) { + std::string cell_text = "no cell"; + if (cell != IdString()) + cell_text = std::string("cell '") + cell.str(ctx) + "'"; + if (ctx->force) { + log_warning("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + } else { + log_error("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + } } } } @@ -256,7 +275,7 @@ class SAPlacer private: // Initial random placement - void place_initial(CellInfo *cell) + void place_initial(ArchRWProxy &proxy, CellInfo *cell) { bool all_placed = false; int iters = 25; @@ -267,12 +286,12 @@ class SAPlacer CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBelUnlocked(cell->bel); + proxy.unbindBel(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { - if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { - if (ctx->checkBelAvailUnlocked(bel)) { + if (ctx->getBelType(bel) == targetType && (proxy.isValidBelForCell(cell, bel) || !require_legal)) { + if (proxy.checkBelAvail(bel)) { uint64_t score = ctx->rng64(); if (score <= best_score) { best_score = score; @@ -282,7 +301,7 @@ class SAPlacer uint64_t score = ctx->rng64(); if (score <= best_ripup_score) { best_ripup_score = score; - ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); + ripup_target = ctx->cells.at(proxy.getBoundBelCell(bel)).get(); ripup_bel = bel; } } @@ -292,12 +311,12 @@ class SAPlacer if (iters == 0 || ripup_bel == BelId()) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); --iters; - ctx->unbindBelUnlocked(ripup_target->bel); + proxy.unbindBel(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); + proxy.bindBel(best_bel, cell->name, STRENGTH_WEAK); // Back annotate location cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); @@ -306,14 +325,14 @@ class SAPlacer } // Attempt a SA position swap, return true on success or false on failure - bool try_swap_position(CellInfo *cell, BelId newBel) + bool try_swap_position(ArchRWProxy &proxy, CellInfo *cell, BelId newBel) { static std::unordered_set update; static std::vector> new_lengths; new_lengths.clear(); update.clear(); BelId oldBel = cell->bel; - IdString other = ctx->getBoundBelCellUnlocked(newBel); + IdString other = proxy.getBoundBelCell(newBel); CellInfo *other_cell = nullptr; if (other != IdString()) { other_cell = ctx->cells[other].get(); @@ -321,9 +340,9 @@ class SAPlacer return false; } wirelen_t new_wirelength = 0, delta; - ctx->unbindBelUnlocked(oldBel); + proxy.unbindBel(oldBel); if (other != IdString()) { - ctx->unbindBelUnlocked(newBel); + proxy.unbindBel(newBel); } for (const auto &port : cell->ports) @@ -336,16 +355,16 @@ class SAPlacer update.insert(port.second.net); } - ctx->bindBelUnlocked(newBel, cell->name, STRENGTH_WEAK); + proxy.bindBel(newBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBelUnlocked(oldBel, other_cell->name, STRENGTH_WEAK); + proxy.bindBel(oldBel, other_cell->name, STRENGTH_WEAK); } if (require_legal) { - if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { - ctx->unbindBelUnlocked(newBel); + if (!proxy.isBelLocationValid(newBel) || ((other != IdString() && !proxy.isBelLocationValid(oldBel)))) { + proxy.unbindBel(newBel); if (other != IdString()) - ctx->unbindBelUnlocked(oldBel); + proxy.unbindBel(oldBel); goto swap_fail; } } @@ -356,7 +375,7 @@ class SAPlacer for (auto net : update) { new_wirelength -= wirelengths.at(net->name); float temp_tns = 0; - wirelen_t net_new_wl = get_net_wirelength(ctx, net, temp_tns); + wirelen_t net_new_wl = get_net_wirelength<>(proxy, ctx, net, temp_tns); new_wirelength += net_new_wl; new_lengths.push_back(std::make_pair(net->name, net_new_wl)); } @@ -369,8 +388,8 @@ class SAPlacer improved = true; } else { if (other != IdString()) - ctx->unbindBelUnlocked(oldBel); - ctx->unbindBelUnlocked(newBel); + proxy.unbindBel(oldBel); + proxy.unbindBel(newBel); goto swap_fail; } curr_wirelength = new_wirelength; @@ -379,9 +398,9 @@ class SAPlacer return true; swap_fail: - ctx->bindBelUnlocked(oldBel, cell->name, STRENGTH_WEAK); + proxy.bindBel(oldBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBelUnlocked(newBel, other, STRENGTH_WEAK); + proxy.bindBel(newBel, other, STRENGTH_WEAK); } return false; } diff --git a/common/router1.cc b/common/router1.cc index cbaf773d..0d26a36d 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -2,6 +2,7 @@ * nextpnr -- Next Generation Place and Route * * Copyright (C) 2018 Clifford Wolf + * Copyright (C) 2018 Serge Bazanski * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -73,7 +74,7 @@ struct RipupScoreboard std::unordered_map, int, hash_id_pip> netPipScores; }; -void ripup_net(Context *ctx, IdString net_name) +void ripup_net(ArchRWProxy &proxy, Context *ctx, IdString net_name) { auto net_info = ctx->nets.at(net_name).get(); std::vector pips; @@ -90,10 +91,10 @@ void ripup_net(Context *ctx, IdString net_name) } for (auto pip : pips) - ctx->unbindPipUnlocked(pip); + proxy.unbindPip(pip); for (auto wire : wires) - ctx->unbindWireUnlocked(wire); + proxy.unbindWire(wire); NPNR_ASSERT(net_info->wires.empty()); } @@ -114,7 +115,7 @@ struct Router delay_t maxDelay = 0.0; WireId failedDest; - void route(const std::unordered_map &src_wires, WireId dst_wire) + void route(ArchRWProxy &proxy, const std::unordered_map &src_wires, WireId dst_wire) { std::priority_queue, QueuedWire::Greater> queue; @@ -135,6 +136,7 @@ struct Router int thisVisitCnt = 0; int thisVisitCntLimit = 0; + while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { QueuedWire qw = queue.top(); queue.pop(); @@ -148,10 +150,10 @@ struct Router bool foundRipupNet = false; thisVisitCnt++; - if (!ctx->checkWireAvailUnlocked(next_wire)) { + if (!proxy.checkWireAvail(next_wire)) { if (!ripup) continue; - IdString ripupWireNet = ctx->getConflictingWireNetUnlocked(next_wire); + IdString ripupWireNet = proxy.getConflictingWireNet(next_wire); if (ripupWireNet == net_name || ripupWireNet == IdString()) continue; @@ -166,10 +168,10 @@ struct Router foundRipupNet = true; } - if (!ctx->checkPipAvailUnlocked(pip)) { + if (!proxy.checkPipAvail(pip)) { if (!ripup) continue; - IdString ripupPipNet = ctx->getConflictingPipNetUnlocked(pip); + IdString ripupPipNet = proxy.getConflictingPipNet(pip); if (ripupPipNet == net_name || ripupPipNet == IdString()) continue; @@ -227,7 +229,10 @@ struct Router { std::unordered_map src_wires; src_wires[src_wire] = 0; - route(src_wires, dst_wire); + { + auto &&proxy = ctx->rwproxy(); + route(proxy, src_wires, dst_wire); + } routedOkay = visited.count(dst_wire); if (ctx->debug) { @@ -272,7 +277,7 @@ struct Router if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->rproxy().getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) log_error("No wire found for port %s (pin %s) on source cell %s " @@ -286,8 +291,10 @@ struct Router std::unordered_map src_wires; src_wires[src_wire] = 0; - ripup_net(ctx, net_name); - ctx->bindWireUnlocked(src_wire, net_name, STRENGTH_WEAK); + auto &&proxy = ctx->rwproxy(); + + ripup_net(proxy, ctx, net_name); + proxy.bindWire(src_wire, net_name, STRENGTH_WEAK); std::vector users_array = net_info->users; ctx->shuffle(users_array); @@ -312,7 +319,7 @@ struct Router if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = proxy.getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) log_error("No wire found for port %s (pin %s) on destination " @@ -325,7 +332,7 @@ struct Router log(" Path delay estimate: %.2f\n", float(ctx->estimateDelay(src_wire, dst_wire))); } - route(src_wires, dst_wire); + route(proxy, src_wires, dst_wire); if (visited.count(dst_wire) == 0) { if (ctx->debug) @@ -334,7 +341,7 @@ struct Router else if (ripup) log_info("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), ctx->getWireName(dst_wire).c_str(ctx)); - ripup_net(ctx, net_name); + ripup_net(proxy, ctx, net_name); failedDest = dst_wire; return; } @@ -355,15 +362,15 @@ struct Router if (src_wires.count(cursor)) break; - IdString conflicting_wire_net = ctx->getConflictingWireNetUnlocked(cursor); + IdString conflicting_wire_net = proxy.getConflictingWireNet(cursor); if (conflicting_wire_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_wire_net != net_name); - ctx->unbindWireUnlocked(cursor); - if (!ctx->checkWireAvailUnlocked(cursor)) - ripup_net(ctx, conflicting_wire_net); + proxy.unbindWire(cursor); + if (!proxy.checkWireAvail(cursor)) + ripup_net(proxy, ctx, conflicting_wire_net); rippedNets.insert(conflicting_wire_net); scores.wireScores[cursor]++; @@ -372,15 +379,15 @@ struct Router } PipId pip = visited[cursor].pip; - IdString conflicting_pip_net = ctx->getConflictingPipNetUnlocked(pip); + IdString conflicting_pip_net = proxy.getConflictingPipNet(pip); if (conflicting_pip_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_pip_net != net_name); - ctx->unbindPipUnlocked(pip); - if (!ctx->checkPipAvailUnlocked(pip)) - ripup_net(ctx, conflicting_pip_net); + proxy.unbindPip(pip); + if (!proxy.checkPipAvail(pip)) + ripup_net(proxy, ctx, conflicting_pip_net); rippedNets.insert(conflicting_pip_net); scores.pipScores[visited[cursor].pip]++; @@ -388,7 +395,7 @@ struct Router scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; } - ctx->bindPipUnlocked(visited[cursor].pip, net_name, STRENGTH_WEAK); + proxy.bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); src_wires[cursor] = visited[cursor].delay; cursor = ctx->getPipSrcWire(visited[cursor].pip); } @@ -437,45 +444,48 @@ bool router1(Context *ctx) delay_t estimatedTotalDelay = 0.0; int estimatedTotalDelayCnt = 0; - for (auto net_name : netsQueue) { - auto net_info = ctx->nets.at(net_name).get(); + { + auto &&proxy = ctx->rproxy(); + for (auto net_name : netsQueue) { + auto net_info = ctx->nets.at(net_name).get(); - auto src_bel = net_info->driver.cell->bel; + auto src_bel = net_info->driver.cell->bel; - if (src_bel == BelId()) - continue; + if (src_bel == BelId()) + continue; - IdString driver_port = net_info->driver.port; + IdString driver_port = net_info->driver.port; - auto driver_port_it = net_info->driver.cell->pins.find(driver_port); - if (driver_port_it != net_info->driver.cell->pins.end()) - driver_port = driver_port_it->second; + auto driver_port_it = net_info->driver.cell->pins.find(driver_port); + if (driver_port_it != net_info->driver.cell->pins.end()) + driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = proxy.getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); - if (src_wire == WireId()) - continue; + if (src_wire == WireId()) + continue; - for (auto &user_it : net_info->users) { - auto dst_bel = user_it.cell->bel; + for (auto &user_it : net_info->users) { + auto dst_bel = user_it.cell->bel; - if (dst_bel == BelId()) - continue; + if (dst_bel == BelId()) + continue; - IdString user_port = user_it.port; + IdString user_port = user_it.port; - auto user_port_it = user_it.cell->pins.find(user_port); + auto user_port_it = user_it.cell->pins.find(user_port); - if (user_port_it != user_it.cell->pins.end()) - user_port = user_port_it->second; + if (user_port_it != user_it.cell->pins.end()) + user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = proxy.getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); - if (dst_wire == WireId()) - continue; + if (dst_wire == WireId()) + continue; - estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); - estimatedTotalDelayCnt++; + estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); + estimatedTotalDelayCnt++; + } } } -- cgit v1.2.3 From a8c84e90a39c54174dd24b5b76bd17aed8311481 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Fri, 13 Jul 2018 20:53:52 +0100 Subject: Make GUI nice and smooth. --- common/nextpnr.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index 50465869..efcab9fc 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -238,6 +238,16 @@ struct CellInfo std::unordered_map pins; }; +struct UIUpdatesRequired +{ + bool allUIReload; + bool frameUIReload; + std::unordered_set belUIReload; + std::unordered_set wireUIReload; + std::unordered_set pipUIReload; + std::unordered_set groupUIReload; +}; + struct BaseCtx { // -------------------------------------------------------------- @@ -260,6 +270,8 @@ struct BaseCtx idstring_idx_to_str = new std::vector; IdString::initialize_add(this, "", 0); IdString::initialize_arch(this); + + allUiReload = true; } ~BaseCtx() @@ -292,6 +304,25 @@ struct BaseCtx void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } + + UIUpdatesRequired getUIUpdatesRequired(void) + { + UIUpdatesRequired req; + req.allUIReload = allUiReload; + req.frameUIReload = frameUiReload; + req.belUIReload = belUiReload; + req.wireUIReload = wireUiReload; + req.pipUIReload = pipUiReload; + req.groupUIReload = groupUiReload; + + allUiReload = false; + frameUiReload = false; + belUiReload.clear(); + wireUiReload.clear(); + pipUiReload.clear(); + groupUiReload.clear(); + return req; + } }; NEXTPNR_NAMESPACE_END -- cgit v1.2.3 From 9b17fe385cf7e8d3025747b5f7c7822ac2d99920 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 11:10:31 +0100 Subject: Refactor proxies to nextpnr. --- common/nextpnr.cc | 11 ++++ common/nextpnr.h | 170 +++++++++++++++++++++++++++++++++++++++---------- common/place_common.cc | 2 +- common/place_common.h | 2 +- common/placer1.cc | 4 +- common/router1.cc | 4 +- 6 files changed, 155 insertions(+), 38 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 3861e5fe..54df5de1 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -21,6 +21,17 @@ NEXTPNR_NAMESPACE_BEGIN +MutateContext BaseCtx::rwproxy(void) +{ + return MutateContext(reinterpret_cast(this)); +} + +ReadContext BaseCtx::rproxy(void) const +{ + return ReadContext(reinterpret_cast(this)); +} + + assertion_failure::assertion_failure(std::string msg, std::string expr_str, std::string filename, int line) : runtime_error("Assertion failure: " + msg + " (" + filename + ":" + std::to_string(line) + ")"), msg(msg), expr_str(expr_str), filename(filename), line(line) diff --git a/common/nextpnr.h b/common/nextpnr.h index efcab9fc..c3fb913c 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef NEXTPNR_H #define NEXTPNR_H @@ -248,21 +249,37 @@ struct UIUpdatesRequired std::unordered_set groupUIReload; }; -struct BaseCtx +class ReadContext; +class MutateContext; +class BaseReadCtx; +class BaseMutateCtx; + +// Data that every architecture object should contain. +class BaseCtx { - // -------------------------------------------------------------- + friend class ReadContext; + friend class MutateContext; + friend class BaseReadCtx; + friend class BaseMutateCtx; +private: + mutable boost::shared_mutex mtx_; - mutable std::unordered_map *idstring_str_to_idx; - mutable std::vector *idstring_idx_to_str; + bool allUiReload = false; + bool frameUiReload = false; + std::unordered_set belUiReload; + std::unordered_set wireUiReload; + std::unordered_set pipUiReload; + std::unordered_set groupUiReload; +public: IdString id(const std::string &s) const { return IdString(this, s); } - IdString id(const char *s) const { return IdString(this, s); } - // -------------------------------------------------------------- - + // TODO(q3k): These need to be made private. std::unordered_map> nets; std::unordered_map> cells; + mutable std::unordered_map *idstring_str_to_idx; + mutable std::vector *idstring_idx_to_str; BaseCtx() { @@ -286,41 +303,83 @@ struct BaseCtx // -------------------------------------------------------------- - bool allUiReload = false; - bool frameUiReload = false; - std::unordered_set belUiReload; - std::unordered_set wireUiReload; - std::unordered_set pipUiReload; - std::unordered_set groupUiReload; + // Get a readwrite proxy to arch - this will keep a readwrite lock on the + // entire architecture until the proxy object goes out of scope. + MutateContext rwproxy(void); + // Get a read-only proxy to arch - this will keep a read lock on the + // entire architecture until the proxy object goes out of scope. Other read + // locks can be taken while this one still exists. Ie., the UI can draw + // elements while the PnR is going a RO operation. + ReadContext rproxy(void) const; + +}; - void refreshUi() { allUiReload = true; } +// State-accessing read-only methods that every architecture object should +// contain. +class BaseReadCtx +{ +protected: + const BaseCtx *base_; +public: + BaseReadCtx(const BaseCtx *base) : base_(base) {} +}; + +// State-accesssing read/write methods that every architecture object should +// contain. +class BaseMutateCtx +{ +protected: + BaseCtx *base_; + +public: + BaseMutateCtx(BaseCtx *base) : base_(base) {} + + void refreshUi(void) + { + base_->allUiReload = true; + } - void refreshUiFrame() { frameUiReload = true; } + void refreshUiFrame(void) + { + base_->frameUiReload = true; + } - void refreshUiBel(BelId bel) { belUiReload.insert(bel); } + void refreshUiBel(BelId bel) + { + base_->belUiReload.insert(bel); + } - void refreshUiWire(WireId wire) { wireUiReload.insert(wire); } + void refreshUiWire(WireId wire) + { + base_->wireUiReload.insert(wire); + } - void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } + void refreshUiPip(PipId pip) + { + base_->pipUiReload.insert(pip); + } - void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } + void refreshUiGroup(GroupId group) + { + base_->groupUiReload.insert(group); + } UIUpdatesRequired getUIUpdatesRequired(void) { UIUpdatesRequired req; - req.allUIReload = allUiReload; - req.frameUIReload = frameUiReload; - req.belUIReload = belUiReload; - req.wireUIReload = wireUiReload; - req.pipUIReload = pipUiReload; - req.groupUIReload = groupUiReload; - - allUiReload = false; - frameUiReload = false; - belUiReload.clear(); - wireUiReload.clear(); - pipUiReload.clear(); - groupUiReload.clear(); + req.allUIReload = base_->allUiReload; + req.frameUIReload = base_->frameUiReload; + req.belUIReload = base_->belUiReload; + req.wireUIReload = base_->wireUiReload; + req.pipUIReload = base_->pipUiReload; + req.groupUIReload = base_->groupUiReload; + + base_->allUiReload = false; + base_->frameUiReload = false; + base_->belUiReload.clear(); + base_->wireUiReload.clear(); + base_->pipUiReload.clear(); + base_->groupUiReload.clear(); return req; } }; @@ -331,6 +390,53 @@ NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_BEGIN +// Read proxy to access ReadMethods while holding lock on underlying BaseCtx. +class ReadContext : public ArchReadMethods +{ + friend class BaseCtx; +private: + boost::shared_mutex *lock_; + ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) + { + lock_->lock_shared(); + } +public: + ~ReadContext() + { + if (lock_ != nullptr) { + lock_->unlock_shared(); + } + } + ReadContext(ReadContext &&other): ArchReadMethods(other), lock_(other.lock_) + { + other.lock_ = nullptr; + } +}; + +// Read proxy to access MutateMethods while holding lock on underlying BaseCtx. +class MutateContext : public ArchReadMethods, public ArchMutateMethods +{ + friend class BaseCtx; +private: + boost::shared_mutex *lock_; + MutateContext(Arch *parent) : ArchReadMethods(parent), ArchMutateMethods(parent), lock_(&parent->mtx_) + { + lock_->lock(); + } +public: + ~MutateContext() + { + if (lock_ != nullptr) { + lock_->unlock(); + } + } + MutateContext(MutateContext &&other): ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) + { + other.lock_ = nullptr; + } +}; + + struct Context : Arch { bool verbose = false; diff --git a/common/place_common.cc b/common/place_common.cc index 48416370..9694b6fe 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -26,7 +26,7 @@ NEXTPNR_NAMESPACE_BEGIN // Placing a single cell -bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality) +bool place_single_cell(MutateContext &proxy, Context *ctx, CellInfo *cell, bool require_legality) { bool all_placed = false; int iters = 25; diff --git a/common/place_common.h b/common/place_common.h index 57e82510..96ac48a9 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -109,7 +109,7 @@ wirelen_t get_cell_wirelength_at_bel(const T &proxy, const Context *ctx, CellInf } // Place a single cell in the lowest wirelength Bel available, optionally requiring validity check -bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality); +bool place_single_cell(MutateContext &proxy, Context *ctx, CellInfo *cell, bool require_legality); NEXTPNR_NAMESPACE_END diff --git a/common/placer1.cc b/common/placer1.cc index 0e3a84f7..78515ece 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -275,7 +275,7 @@ class SAPlacer private: // Initial random placement - void place_initial(ArchRWProxy &proxy, CellInfo *cell) + void place_initial(MutateContext &proxy, CellInfo *cell) { bool all_placed = false; int iters = 25; @@ -325,7 +325,7 @@ class SAPlacer } // Attempt a SA position swap, return true on success or false on failure - bool try_swap_position(ArchRWProxy &proxy, CellInfo *cell, BelId newBel) + bool try_swap_position(MutateContext &proxy, CellInfo *cell, BelId newBel) { static std::unordered_set update; static std::vector> new_lengths; diff --git a/common/router1.cc b/common/router1.cc index 0d26a36d..f7a7e8a2 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -74,7 +74,7 @@ struct RipupScoreboard std::unordered_map, int, hash_id_pip> netPipScores; }; -void ripup_net(ArchRWProxy &proxy, Context *ctx, IdString net_name) +void ripup_net(MutateContext &proxy, Context *ctx, IdString net_name) { auto net_info = ctx->nets.at(net_name).get(); std::vector pips; @@ -115,7 +115,7 @@ struct Router delay_t maxDelay = 0.0; WireId failedDest; - void route(ArchRWProxy &proxy, const std::unordered_map &src_wires, WireId dst_wire) + void route(MutateContext &proxy, const std::unordered_map &src_wires, WireId dst_wire) { std::priority_queue, QueuedWire::Greater> queue; -- cgit v1.2.3 From 8ca7a6da2525463be5be4ee9f62cfae0acc06b01 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 11:10:59 +0100 Subject: clang-format --- common/nextpnr.cc | 11 ++------ common/nextpnr.h | 72 +++++++++++++++++++-------------------------------- common/place_common.h | 6 ++--- common/router1.cc | 1 - 4 files changed, 30 insertions(+), 60 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 54df5de1..33230db0 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -21,16 +21,9 @@ NEXTPNR_NAMESPACE_BEGIN -MutateContext BaseCtx::rwproxy(void) -{ - return MutateContext(reinterpret_cast(this)); -} - -ReadContext BaseCtx::rproxy(void) const -{ - return ReadContext(reinterpret_cast(this)); -} +MutateContext BaseCtx::rwproxy(void) { return MutateContext(reinterpret_cast(this)); } +ReadContext BaseCtx::rproxy(void) const { return ReadContext(reinterpret_cast(this)); } assertion_failure::assertion_failure(std::string msg, std::string expr_str, std::string filename, int line) : runtime_error("Assertion failure: " + msg + " (" + filename + ":" + std::to_string(line) + ")"), msg(msg), diff --git a/common/nextpnr.h b/common/nextpnr.h index c3fb913c..6228e653 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #ifndef NEXTPNR_H #define NEXTPNR_H @@ -261,7 +261,8 @@ class BaseCtx friend class MutateContext; friend class BaseReadCtx; friend class BaseMutateCtx; -private: + + private: mutable boost::shared_mutex mtx_; bool allUiReload = false; @@ -271,7 +272,7 @@ private: std::unordered_set pipUiReload; std::unordered_set groupUiReload; -public: + public: IdString id(const std::string &s) const { return IdString(this, s); } IdString id(const char *s) const { return IdString(this, s); } @@ -311,16 +312,16 @@ public: // locks can be taken while this one still exists. Ie., the UI can draw // elements while the PnR is going a RO operation. ReadContext rproxy(void) const; - }; // State-accessing read-only methods that every architecture object should // contain. class BaseReadCtx { -protected: + protected: const BaseCtx *base_; -public: + + public: BaseReadCtx(const BaseCtx *base) : base_(base) {} }; @@ -328,41 +329,23 @@ public: // contain. class BaseMutateCtx { -protected: + protected: BaseCtx *base_; -public: + public: BaseMutateCtx(BaseCtx *base) : base_(base) {} - void refreshUi(void) - { - base_->allUiReload = true; - } + void refreshUi(void) { base_->allUiReload = true; } - void refreshUiFrame(void) - { - base_->frameUiReload = true; - } + void refreshUiFrame(void) { base_->frameUiReload = true; } - void refreshUiBel(BelId bel) - { - base_->belUiReload.insert(bel); - } + void refreshUiBel(BelId bel) { base_->belUiReload.insert(bel); } - void refreshUiWire(WireId wire) - { - base_->wireUiReload.insert(wire); - } + void refreshUiWire(WireId wire) { base_->wireUiReload.insert(wire); } - void refreshUiPip(PipId pip) - { - base_->pipUiReload.insert(pip); - } + void refreshUiPip(PipId pip) { base_->pipUiReload.insert(pip); } - void refreshUiGroup(GroupId group) - { - base_->groupUiReload.insert(group); - } + void refreshUiGroup(GroupId group) { base_->groupUiReload.insert(group); } UIUpdatesRequired getUIUpdatesRequired(void) { @@ -394,49 +377,46 @@ NEXTPNR_NAMESPACE_BEGIN class ReadContext : public ArchReadMethods { friend class BaseCtx; -private: + + private: boost::shared_mutex *lock_; - ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) - { - lock_->lock_shared(); - } -public: + ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) { lock_->lock_shared(); } + + public: ~ReadContext() { if (lock_ != nullptr) { lock_->unlock_shared(); } } - ReadContext(ReadContext &&other): ArchReadMethods(other), lock_(other.lock_) - { - other.lock_ = nullptr; - } + ReadContext(ReadContext &&other) : ArchReadMethods(other), lock_(other.lock_) { other.lock_ = nullptr; } }; // Read proxy to access MutateMethods while holding lock on underlying BaseCtx. class MutateContext : public ArchReadMethods, public ArchMutateMethods { friend class BaseCtx; -private: + + private: boost::shared_mutex *lock_; MutateContext(Arch *parent) : ArchReadMethods(parent), ArchMutateMethods(parent), lock_(&parent->mtx_) { lock_->lock(); } -public: + + public: ~MutateContext() { if (lock_ != nullptr) { lock_->unlock(); } } - MutateContext(MutateContext &&other): ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) + MutateContext(MutateContext &&other) : ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) { other.lock_ = nullptr; } }; - struct Context : Arch { bool verbose = false; diff --git a/common/place_common.h b/common/place_common.h index 96ac48a9..dac2e607 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -29,8 +29,7 @@ NEXTPNR_NAMESPACE_BEGIN typedef int64_t wirelen_t; // Get the total estimated wirelength for a net -template -wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) +template wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) { wirelen_t wirelength = 0; int driver_x, driver_y; @@ -81,8 +80,7 @@ wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo * } // Return the wirelength of all nets connected to a cell -template -wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) +template wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) { std::set nets; for (auto p : cell->ports) { diff --git a/common/router1.cc b/common/router1.cc index f7a7e8a2..dc75a153 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -136,7 +136,6 @@ struct Router int thisVisitCnt = 0; int thisVisitCntLimit = 0; - while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { QueuedWire qw = queue.top(); queue.pop(); -- cgit v1.2.3 From 3352ff4abbcac563e08d78ed8aa77728d00284a8 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 11:46:32 +0100 Subject: Move read methods to ReadMethods, remove some legacy access to Arch --- common/nextpnr.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 33230db0..01c1397e 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -170,20 +170,21 @@ uint32_t Context::checksum() const void Context::check() const { + auto &&proxy = rproxy(); for (auto &n : nets) { auto ni = n.second.get(); NPNR_ASSERT(n.first == ni->name); for (auto &w : ni->wires) { - NPNR_ASSERT(n.first == getBoundWireNet(w.first)); + NPNR_ASSERT(n.first == proxy.getBoundWireNet(w.first)); if (w.second.pip != PipId()) { NPNR_ASSERT(w.first == getPipDstWire(w.second.pip)); - NPNR_ASSERT(n.first == getBoundPipNet(w.second.pip)); + NPNR_ASSERT(n.first == proxy.getBoundPipNet(w.second.pip)); } } } for (auto w : getWires()) { - IdString net = getBoundWireNet(w); + IdString net = proxy.getBoundWireNet(w); if (net != IdString()) { NPNR_ASSERT(nets.at(net)->wires.count(w)); } @@ -192,7 +193,7 @@ void Context::check() const for (auto &c : cells) { NPNR_ASSERT(c.first == c.second->name); if (c.second->bel != BelId()) - NPNR_ASSERT(getBoundBelCell(c.second->bel) == c.first); + NPNR_ASSERT(proxy.getBoundBelCell(c.second->bel) == c.first); for (auto &port : c.second->ports) { NetInfo *net = port.second.net; if (net != nullptr) { -- cgit v1.2.3 From ade67ecf21c274c73c99543e51eda99ac847686c Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:50:23 +0100 Subject: Revert "Move read methods to ReadMethods, remove some legacy access to Arch" This reverts commit 3352ff4abbcac563e08d78ed8aa77728d00284a8. --- common/nextpnr.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 01c1397e..33230db0 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -170,21 +170,20 @@ uint32_t Context::checksum() const void Context::check() const { - auto &&proxy = rproxy(); for (auto &n : nets) { auto ni = n.second.get(); NPNR_ASSERT(n.first == ni->name); for (auto &w : ni->wires) { - NPNR_ASSERT(n.first == proxy.getBoundWireNet(w.first)); + NPNR_ASSERT(n.first == getBoundWireNet(w.first)); if (w.second.pip != PipId()) { NPNR_ASSERT(w.first == getPipDstWire(w.second.pip)); - NPNR_ASSERT(n.first == proxy.getBoundPipNet(w.second.pip)); + NPNR_ASSERT(n.first == getBoundPipNet(w.second.pip)); } } } for (auto w : getWires()) { - IdString net = proxy.getBoundWireNet(w); + IdString net = getBoundWireNet(w); if (net != IdString()) { NPNR_ASSERT(nets.at(net)->wires.count(w)); } @@ -193,7 +192,7 @@ void Context::check() const for (auto &c : cells) { NPNR_ASSERT(c.first == c.second->name); if (c.second->bel != BelId()) - NPNR_ASSERT(proxy.getBoundBelCell(c.second->bel) == c.first); + NPNR_ASSERT(getBoundBelCell(c.second->bel) == c.first); for (auto &port : c.second->ports) { NetInfo *net = port.second.net; if (net != nullptr) { -- cgit v1.2.3 From d9c3c117a38c8bc42cfb96255b4762965bc1611b Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:50:34 +0100 Subject: Revert "clang-format" This reverts commit 8ca7a6da2525463be5be4ee9f62cfae0acc06b01. --- common/nextpnr.cc | 11 ++++++-- common/nextpnr.h | 72 ++++++++++++++++++++++++++++++++------------------- common/place_common.h | 6 +++-- common/router1.cc | 1 + 4 files changed, 60 insertions(+), 30 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 33230db0..54df5de1 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -21,9 +21,16 @@ NEXTPNR_NAMESPACE_BEGIN -MutateContext BaseCtx::rwproxy(void) { return MutateContext(reinterpret_cast(this)); } +MutateContext BaseCtx::rwproxy(void) +{ + return MutateContext(reinterpret_cast(this)); +} + +ReadContext BaseCtx::rproxy(void) const +{ + return ReadContext(reinterpret_cast(this)); +} -ReadContext BaseCtx::rproxy(void) const { return ReadContext(reinterpret_cast(this)); } assertion_failure::assertion_failure(std::string msg, std::string expr_str, std::string filename, int line) : runtime_error("Assertion failure: " + msg + " (" + filename + ":" + std::to_string(line) + ")"), msg(msg), diff --git a/common/nextpnr.h b/common/nextpnr.h index 6228e653..c3fb913c 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #ifndef NEXTPNR_H #define NEXTPNR_H @@ -261,8 +261,7 @@ class BaseCtx friend class MutateContext; friend class BaseReadCtx; friend class BaseMutateCtx; - - private: +private: mutable boost::shared_mutex mtx_; bool allUiReload = false; @@ -272,7 +271,7 @@ class BaseCtx std::unordered_set pipUiReload; std::unordered_set groupUiReload; - public: +public: IdString id(const std::string &s) const { return IdString(this, s); } IdString id(const char *s) const { return IdString(this, s); } @@ -312,16 +311,16 @@ class BaseCtx // locks can be taken while this one still exists. Ie., the UI can draw // elements while the PnR is going a RO operation. ReadContext rproxy(void) const; + }; // State-accessing read-only methods that every architecture object should // contain. class BaseReadCtx { - protected: +protected: const BaseCtx *base_; - - public: +public: BaseReadCtx(const BaseCtx *base) : base_(base) {} }; @@ -329,23 +328,41 @@ class BaseReadCtx // contain. class BaseMutateCtx { - protected: +protected: BaseCtx *base_; - public: +public: BaseMutateCtx(BaseCtx *base) : base_(base) {} - void refreshUi(void) { base_->allUiReload = true; } + void refreshUi(void) + { + base_->allUiReload = true; + } - void refreshUiFrame(void) { base_->frameUiReload = true; } + void refreshUiFrame(void) + { + base_->frameUiReload = true; + } - void refreshUiBel(BelId bel) { base_->belUiReload.insert(bel); } + void refreshUiBel(BelId bel) + { + base_->belUiReload.insert(bel); + } - void refreshUiWire(WireId wire) { base_->wireUiReload.insert(wire); } + void refreshUiWire(WireId wire) + { + base_->wireUiReload.insert(wire); + } - void refreshUiPip(PipId pip) { base_->pipUiReload.insert(pip); } + void refreshUiPip(PipId pip) + { + base_->pipUiReload.insert(pip); + } - void refreshUiGroup(GroupId group) { base_->groupUiReload.insert(group); } + void refreshUiGroup(GroupId group) + { + base_->groupUiReload.insert(group); + } UIUpdatesRequired getUIUpdatesRequired(void) { @@ -377,46 +394,49 @@ NEXTPNR_NAMESPACE_BEGIN class ReadContext : public ArchReadMethods { friend class BaseCtx; - - private: +private: boost::shared_mutex *lock_; - ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) { lock_->lock_shared(); } - - public: + ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) + { + lock_->lock_shared(); + } +public: ~ReadContext() { if (lock_ != nullptr) { lock_->unlock_shared(); } } - ReadContext(ReadContext &&other) : ArchReadMethods(other), lock_(other.lock_) { other.lock_ = nullptr; } + ReadContext(ReadContext &&other): ArchReadMethods(other), lock_(other.lock_) + { + other.lock_ = nullptr; + } }; // Read proxy to access MutateMethods while holding lock on underlying BaseCtx. class MutateContext : public ArchReadMethods, public ArchMutateMethods { friend class BaseCtx; - - private: +private: boost::shared_mutex *lock_; MutateContext(Arch *parent) : ArchReadMethods(parent), ArchMutateMethods(parent), lock_(&parent->mtx_) { lock_->lock(); } - - public: +public: ~MutateContext() { if (lock_ != nullptr) { lock_->unlock(); } } - MutateContext(MutateContext &&other) : ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) + MutateContext(MutateContext &&other): ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) { other.lock_ = nullptr; } }; + struct Context : Arch { bool verbose = false; diff --git a/common/place_common.h b/common/place_common.h index dac2e607..96ac48a9 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -29,7 +29,8 @@ NEXTPNR_NAMESPACE_BEGIN typedef int64_t wirelen_t; // Get the total estimated wirelength for a net -template wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) +template +wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) { wirelen_t wirelength = 0; int driver_x, driver_y; @@ -80,7 +81,8 @@ template wirelen_t get_net_wirelength(const T &proxy, const Context } // Return the wirelength of all nets connected to a cell -template wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) +template +wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) { std::set nets; for (auto p : cell->ports) { diff --git a/common/router1.cc b/common/router1.cc index dc75a153..f7a7e8a2 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -136,6 +136,7 @@ struct Router int thisVisitCnt = 0; int thisVisitCntLimit = 0; + while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { QueuedWire qw = queue.top(); queue.pop(); -- cgit v1.2.3 From b0c05c7f751cf68165849a8f28d389541456f956 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:50:37 +0100 Subject: Revert "Refactor proxies to nextpnr." This reverts commit 9b17fe385cf7e8d3025747b5f7c7822ac2d99920. --- common/nextpnr.cc | 11 ---- common/nextpnr.h | 170 ++++++++++--------------------------------------- common/place_common.cc | 2 +- common/place_common.h | 2 +- common/placer1.cc | 4 +- common/router1.cc | 4 +- 6 files changed, 38 insertions(+), 155 deletions(-) (limited to 'common') diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 54df5de1..3861e5fe 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -21,17 +21,6 @@ NEXTPNR_NAMESPACE_BEGIN -MutateContext BaseCtx::rwproxy(void) -{ - return MutateContext(reinterpret_cast(this)); -} - -ReadContext BaseCtx::rproxy(void) const -{ - return ReadContext(reinterpret_cast(this)); -} - - assertion_failure::assertion_failure(std::string msg, std::string expr_str, std::string filename, int line) : runtime_error("Assertion failure: " + msg + " (" + filename + ":" + std::to_string(line) + ")"), msg(msg), expr_str(expr_str), filename(filename), line(line) diff --git a/common/nextpnr.h b/common/nextpnr.h index c3fb913c..efcab9fc 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -26,7 +26,6 @@ #include #include #include -#include #ifndef NEXTPNR_H #define NEXTPNR_H @@ -249,37 +248,21 @@ struct UIUpdatesRequired std::unordered_set groupUIReload; }; -class ReadContext; -class MutateContext; -class BaseReadCtx; -class BaseMutateCtx; - -// Data that every architecture object should contain. -class BaseCtx +struct BaseCtx { - friend class ReadContext; - friend class MutateContext; - friend class BaseReadCtx; - friend class BaseMutateCtx; -private: - mutable boost::shared_mutex mtx_; + // -------------------------------------------------------------- - bool allUiReload = false; - bool frameUiReload = false; - std::unordered_set belUiReload; - std::unordered_set wireUiReload; - std::unordered_set pipUiReload; - std::unordered_set groupUiReload; + mutable std::unordered_map *idstring_str_to_idx; + mutable std::vector *idstring_idx_to_str; -public: IdString id(const std::string &s) const { return IdString(this, s); } + IdString id(const char *s) const { return IdString(this, s); } - // TODO(q3k): These need to be made private. + // -------------------------------------------------------------- + std::unordered_map> nets; std::unordered_map> cells; - mutable std::unordered_map *idstring_str_to_idx; - mutable std::vector *idstring_idx_to_str; BaseCtx() { @@ -303,83 +286,41 @@ public: // -------------------------------------------------------------- - // Get a readwrite proxy to arch - this will keep a readwrite lock on the - // entire architecture until the proxy object goes out of scope. - MutateContext rwproxy(void); - // Get a read-only proxy to arch - this will keep a read lock on the - // entire architecture until the proxy object goes out of scope. Other read - // locks can be taken while this one still exists. Ie., the UI can draw - // elements while the PnR is going a RO operation. - ReadContext rproxy(void) const; - -}; - -// State-accessing read-only methods that every architecture object should -// contain. -class BaseReadCtx -{ -protected: - const BaseCtx *base_; -public: - BaseReadCtx(const BaseCtx *base) : base_(base) {} -}; - -// State-accesssing read/write methods that every architecture object should -// contain. -class BaseMutateCtx -{ -protected: - BaseCtx *base_; - -public: - BaseMutateCtx(BaseCtx *base) : base_(base) {} + bool allUiReload = false; + bool frameUiReload = false; + std::unordered_set belUiReload; + std::unordered_set wireUiReload; + std::unordered_set pipUiReload; + std::unordered_set groupUiReload; - void refreshUi(void) - { - base_->allUiReload = true; - } + void refreshUi() { allUiReload = true; } - void refreshUiFrame(void) - { - base_->frameUiReload = true; - } + void refreshUiFrame() { frameUiReload = true; } - void refreshUiBel(BelId bel) - { - base_->belUiReload.insert(bel); - } + void refreshUiBel(BelId bel) { belUiReload.insert(bel); } - void refreshUiWire(WireId wire) - { - base_->wireUiReload.insert(wire); - } + void refreshUiWire(WireId wire) { wireUiReload.insert(wire); } - void refreshUiPip(PipId pip) - { - base_->pipUiReload.insert(pip); - } + void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } - void refreshUiGroup(GroupId group) - { - base_->groupUiReload.insert(group); - } + void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } UIUpdatesRequired getUIUpdatesRequired(void) { UIUpdatesRequired req; - req.allUIReload = base_->allUiReload; - req.frameUIReload = base_->frameUiReload; - req.belUIReload = base_->belUiReload; - req.wireUIReload = base_->wireUiReload; - req.pipUIReload = base_->pipUiReload; - req.groupUIReload = base_->groupUiReload; - - base_->allUiReload = false; - base_->frameUiReload = false; - base_->belUiReload.clear(); - base_->wireUiReload.clear(); - base_->pipUiReload.clear(); - base_->groupUiReload.clear(); + req.allUIReload = allUiReload; + req.frameUIReload = frameUiReload; + req.belUIReload = belUiReload; + req.wireUIReload = wireUiReload; + req.pipUIReload = pipUiReload; + req.groupUIReload = groupUiReload; + + allUiReload = false; + frameUiReload = false; + belUiReload.clear(); + wireUiReload.clear(); + pipUiReload.clear(); + groupUiReload.clear(); return req; } }; @@ -390,53 +331,6 @@ NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_BEGIN -// Read proxy to access ReadMethods while holding lock on underlying BaseCtx. -class ReadContext : public ArchReadMethods -{ - friend class BaseCtx; -private: - boost::shared_mutex *lock_; - ReadContext(const Arch *parent) : ArchReadMethods(parent), lock_(&parent->mtx_) - { - lock_->lock_shared(); - } -public: - ~ReadContext() - { - if (lock_ != nullptr) { - lock_->unlock_shared(); - } - } - ReadContext(ReadContext &&other): ArchReadMethods(other), lock_(other.lock_) - { - other.lock_ = nullptr; - } -}; - -// Read proxy to access MutateMethods while holding lock on underlying BaseCtx. -class MutateContext : public ArchReadMethods, public ArchMutateMethods -{ - friend class BaseCtx; -private: - boost::shared_mutex *lock_; - MutateContext(Arch *parent) : ArchReadMethods(parent), ArchMutateMethods(parent), lock_(&parent->mtx_) - { - lock_->lock(); - } -public: - ~MutateContext() - { - if (lock_ != nullptr) { - lock_->unlock(); - } - } - MutateContext(MutateContext &&other): ArchReadMethods(other), ArchMutateMethods(other), lock_(other.lock_) - { - other.lock_ = nullptr; - } -}; - - struct Context : Arch { bool verbose = false; diff --git a/common/place_common.cc b/common/place_common.cc index 9694b6fe..48416370 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -26,7 +26,7 @@ NEXTPNR_NAMESPACE_BEGIN // Placing a single cell -bool place_single_cell(MutateContext &proxy, Context *ctx, CellInfo *cell, bool require_legality) +bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality) { bool all_placed = false; int iters = 25; diff --git a/common/place_common.h b/common/place_common.h index 96ac48a9..57e82510 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -109,7 +109,7 @@ wirelen_t get_cell_wirelength_at_bel(const T &proxy, const Context *ctx, CellInf } // Place a single cell in the lowest wirelength Bel available, optionally requiring validity check -bool place_single_cell(MutateContext &proxy, Context *ctx, CellInfo *cell, bool require_legality); +bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality); NEXTPNR_NAMESPACE_END diff --git a/common/placer1.cc b/common/placer1.cc index 78515ece..0e3a84f7 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -275,7 +275,7 @@ class SAPlacer private: // Initial random placement - void place_initial(MutateContext &proxy, CellInfo *cell) + void place_initial(ArchRWProxy &proxy, CellInfo *cell) { bool all_placed = false; int iters = 25; @@ -325,7 +325,7 @@ class SAPlacer } // Attempt a SA position swap, return true on success or false on failure - bool try_swap_position(MutateContext &proxy, CellInfo *cell, BelId newBel) + bool try_swap_position(ArchRWProxy &proxy, CellInfo *cell, BelId newBel) { static std::unordered_set update; static std::vector> new_lengths; diff --git a/common/router1.cc b/common/router1.cc index f7a7e8a2..0d26a36d 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -74,7 +74,7 @@ struct RipupScoreboard std::unordered_map, int, hash_id_pip> netPipScores; }; -void ripup_net(MutateContext &proxy, Context *ctx, IdString net_name) +void ripup_net(ArchRWProxy &proxy, Context *ctx, IdString net_name) { auto net_info = ctx->nets.at(net_name).get(); std::vector pips; @@ -115,7 +115,7 @@ struct Router delay_t maxDelay = 0.0; WireId failedDest; - void route(MutateContext &proxy, const std::unordered_map &src_wires, WireId dst_wire) + void route(ArchRWProxy &proxy, const std::unordered_map &src_wires, WireId dst_wire) { std::priority_queue, QueuedWire::Greater> queue; -- cgit v1.2.3 From 36b4e3382dc552fcd1b078bdd246dc14379394a1 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:50:50 +0100 Subject: Revert "Make GUI nice and smooth." This reverts commit a8c84e90a39c54174dd24b5b76bd17aed8311481. --- common/nextpnr.h | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'common') diff --git a/common/nextpnr.h b/common/nextpnr.h index efcab9fc..50465869 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -238,16 +238,6 @@ struct CellInfo std::unordered_map pins; }; -struct UIUpdatesRequired -{ - bool allUIReload; - bool frameUIReload; - std::unordered_set belUIReload; - std::unordered_set wireUIReload; - std::unordered_set pipUIReload; - std::unordered_set groupUIReload; -}; - struct BaseCtx { // -------------------------------------------------------------- @@ -270,8 +260,6 @@ struct BaseCtx idstring_idx_to_str = new std::vector; IdString::initialize_add(this, "", 0); IdString::initialize_arch(this); - - allUiReload = true; } ~BaseCtx() @@ -304,25 +292,6 @@ struct BaseCtx void refreshUiPip(PipId pip) { pipUiReload.insert(pip); } void refreshUiGroup(GroupId group) { groupUiReload.insert(group); } - - UIUpdatesRequired getUIUpdatesRequired(void) - { - UIUpdatesRequired req; - req.allUIReload = allUiReload; - req.frameUIReload = frameUiReload; - req.belUIReload = belUiReload; - req.wireUIReload = wireUiReload; - req.pipUIReload = pipUiReload; - req.groupUIReload = groupUiReload; - - allUiReload = false; - frameUiReload = false; - belUiReload.clear(); - wireUiReload.clear(); - pipUiReload.clear(); - groupUiReload.clear(); - return req; - } }; NEXTPNR_NAMESPACE_END -- cgit v1.2.3 From 447ed83638ef35967adae801430f24e92acb6010 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:52:56 +0100 Subject: Revert "Introduce proxies for locked access to ctx" This reverts commit 89809a8b810dd57f50f365d70a0ce547705f8dbb. --- common/place_common.cc | 95 +++++++++++++++++++++++--- common/place_common.h | 83 ++--------------------- common/placer1.cc | 181 ++++++++++++++++++++++--------------------------- common/router1.cc | 108 +++++++++++++---------------- 4 files changed, 220 insertions(+), 247 deletions(-) (limited to 'common') diff --git a/common/place_common.cc b/common/place_common.cc index 48416370..281e40a2 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -2,7 +2,6 @@ * nextpnr -- Next Generation Place and Route * * Copyright (C) 2018 David Shah - * Copyright (C) 2018 Serge Bazanski * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,8 +24,84 @@ NEXTPNR_NAMESPACE_BEGIN +// Get the total estimated wirelength for a net +wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) +{ + wirelen_t wirelength = 0; + int driver_x, driver_y; + bool driver_gb; + CellInfo *driver_cell = net->driver.cell; + if (!driver_cell) + return 0; + if (driver_cell->bel == BelId()) + return 0; + ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); + WireId drv_wire = ctx->getWireBelPinUnlocked(driver_cell->bel, ctx->portPinFromId(net->driver.port)); + if (driver_gb) + return 0; + float worst_slack = 1000; + int xmin = driver_x, xmax = driver_x, ymin = driver_y, ymax = driver_y; + for (auto load : net->users) { + if (load.cell == nullptr) + continue; + CellInfo *load_cell = load.cell; + if (load_cell->bel == BelId()) + continue; + if (ctx->timing_driven) { + WireId user_wire = ctx->getWireBelPinUnlocked(load_cell->bel, ctx->portPinFromId(load.port)); + 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; + ctx->estimatePosition(load_cell->bel, load_x, load_y, load_gb); + if (load_gb) + continue; + xmin = std::min(xmin, load_x); + ymin = std::min(ymin, load_y); + xmax = std::max(xmax, load_x); + ymax = std::max(ymax, load_y); + } + if (ctx->timing_driven) { + wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); + } else { + wirelength = wirelen_t((ymax - ymin) + (xmax - xmin)); + } + + return wirelength; +} + +// Get the total wirelength for a cell +wirelen_t get_cell_wirelength(const Context *ctx, const CellInfo *cell) +{ + std::set nets; + for (auto p : cell->ports) { + if (p.second.net) + nets.insert(p.second.net->name); + } + wirelen_t wirelength = 0; + float tns = 0; + for (auto n : nets) { + wirelength += get_net_wirelength(ctx, ctx->nets.at(n).get(), tns); + } + return wirelength; +} + +wirelen_t get_cell_wirelength_at_bel(const Context *ctx, CellInfo *cell, BelId bel) +{ + BelId oldBel = cell->bel; + cell->bel = bel; + wirelen_t wirelen = get_cell_wirelength(ctx, cell); + cell->bel = oldBel; + return wirelen; +} + // Placing a single cell -bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality) +bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) { bool all_placed = false; int iters = 25; @@ -37,13 +112,13 @@ bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool re CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - proxy.unbindBel(cell->bel); + ctx->unbindBelUnlocked(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { - if (ctx->getBelType(bel) == targetType && (!require_legality || proxy.isValidBelForCell(cell, bel))) { - if (proxy.checkBelAvail(bel)) { - wirelen_t wirelen = get_cell_wirelength_at_bel(proxy, ctx, cell, bel); + if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) { + if (ctx->checkBelAvailUnlocked(bel)) { + wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_wirelen) { @@ -51,11 +126,11 @@ bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool re best_bel = bel; } } else { - wirelen_t wirelen = get_cell_wirelength_at_bel(proxy, ctx, cell, bel); + wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_ripup_wirelen) { - ripup_target = proxy.getCell(proxy.getBoundBelCell(bel)); + ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); if (ripup_target->belStrength < STRENGTH_STRONG) { best_ripup_wirelen = wirelen; ripup_bel = bel; @@ -73,12 +148,12 @@ bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool re log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); } --iters; - proxy.unbindBel(ripup_target->bel); + ctx->unbindBelUnlocked(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - proxy.bindBel(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); cell = ripup_target; } diff --git a/common/place_common.h b/common/place_common.h index 57e82510..67956072 100644 --- a/common/place_common.h +++ b/common/place_common.h @@ -22,94 +22,21 @@ #include "nextpnr.h" -#include - NEXTPNR_NAMESPACE_BEGIN typedef int64_t wirelen_t; -// Get the total estimated wirelength for a net -template -wirelen_t get_net_wirelength(const T &proxy, const Context *ctx, const NetInfo *net, float &tns) -{ - wirelen_t wirelength = 0; - int driver_x, driver_y; - bool driver_gb; - CellInfo *driver_cell = net->driver.cell; - if (!driver_cell) - return 0; - if (driver_cell->bel == BelId()) - return 0; - ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); - WireId drv_wire = proxy.getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port)); - if (driver_gb) - return 0; - float worst_slack = 1000; - int xmin = driver_x, xmax = driver_x, ymin = driver_y, ymax = driver_y; - for (auto load : net->users) { - if (load.cell == nullptr) - continue; - CellInfo *load_cell = load.cell; - if (load_cell->bel == BelId()) - continue; - if (ctx->timing_driven) { - WireId user_wire = proxy.getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port)); - 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; - ctx->estimatePosition(load_cell->bel, load_x, load_y, load_gb); - if (load_gb) - continue; - xmin = std::min(xmin, load_x); - ymin = std::min(ymin, load_y); - xmax = std::max(xmax, load_x); - ymax = std::max(ymax, load_y); - } - if (ctx->timing_driven) { - wirelength = wirelen_t((((ymax - ymin) + (xmax - xmin)) * std::min(5.0, (1.0 + std::exp(-worst_slack / 5))))); - } else { - wirelength = wirelen_t((ymax - ymin) + (xmax - xmin)); - } - - return wirelength; -} +// Return the wirelength of a net +wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns); // Return the wirelength of all nets connected to a cell -template -wirelen_t get_cell_wirelength(const T &proxy, const Context *ctx, const CellInfo *cell) -{ - std::set nets; - for (auto p : cell->ports) { - if (p.second.net) - nets.insert(p.second.net->name); - } - wirelen_t wirelength = 0; - float tns = 0; - for (auto n : nets) { - wirelength += get_net_wirelength(proxy, ctx, ctx->nets.at(n).get(), tns); - } - return wirelength; -} +wirelen_t get_cell_wirelength(const Context *ctx, const CellInfo *cell); // Return the wirelength of all nets connected to a cell, when the cell is at a given bel -template -wirelen_t get_cell_wirelength_at_bel(const T &proxy, const Context *ctx, CellInfo *cell, BelId bel) -{ - BelId oldBel = cell->bel; - cell->bel = bel; - wirelen_t wirelen = get_cell_wirelength(proxy, ctx, cell); - cell->bel = oldBel; - return wirelen; -} +wirelen_t get_cell_wirelength_at_bel(const Context *ctx, CellInfo *cell, BelId bel); // Place a single cell in the lowest wirelength Bel available, optionally requiring validity check -bool place_single_cell(ArchRWProxy &proxy, Context *ctx, CellInfo *cell, bool require_legality); +bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality); NEXTPNR_NAMESPACE_END diff --git a/common/placer1.cc b/common/placer1.cc index 0e3a84f7..05f760a3 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -3,7 +3,6 @@ * * Copyright (C) 2018 Clifford Wolf * Copyright (C) 2018 David Shah - * Copyright (C) 2018 Serge Bazanski * * Simulated annealing implementation based on arachne-pnr * Copyright (C) 2015-2018 Cotton Seed @@ -80,33 +79,30 @@ class SAPlacer log_break(); size_t placed_cells = 0; - { - auto &&proxy = ctx->rwproxy(); - // Initial constraints placer - for (auto &cell_entry : ctx->cells) { - CellInfo *cell = cell_entry.second.get(); - auto loc = cell->attrs.find(ctx->id("BEL")); - if (loc != cell->attrs.end()) { - std::string loc_name = loc->second; - BelId bel = proxy.getBelByName(ctx->id(loc_name)); - if (bel == BelId()) { - log_error("No Bel named \'%s\' located for " - "this chip (processing BEL attribute on \'%s\')\n", - loc_name.c_str(), cell->name.c_str(ctx)); - } - - BelType bel_type = ctx->getBelType(bel); - if (bel_type != ctx->belTypeFromId(cell->type)) { - log_error("Bel \'%s\' of type \'%s\' does not match cell " - "\'%s\' of type \'%s\'", - loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), - cell->type.c_str(ctx)); - } + // Initial constraints placer + for (auto &cell_entry : ctx->cells) { + CellInfo *cell = cell_entry.second.get(); + auto loc = cell->attrs.find(ctx->id("BEL")); + if (loc != cell->attrs.end()) { + std::string loc_name = loc->second; + BelId bel = ctx->getBelByNameUnlocked(ctx->id(loc_name)); + if (bel == BelId()) { + log_error("No Bel named \'%s\' located for " + "this chip (processing BEL attribute on \'%s\')\n", + loc_name.c_str(), cell->name.c_str(ctx)); + } - proxy.bindBel(bel, cell->name, STRENGTH_USER); - locked_bels.insert(bel); - placed_cells++; + BelType bel_type = ctx->getBelType(bel); + if (bel_type != ctx->belTypeFromId(cell->type)) { + log_error("Bel \'%s\' of type \'%s\' does not match cell " + "\'%s\' of type \'%s\'", + loc_name.c_str(), ctx->belTypeToId(bel_type).c_str(ctx), cell->name.c_str(ctx), + cell->type.c_str(ctx)); } + + ctx->bindBelUnlocked(bel, cell->name, STRENGTH_USER); + locked_bels.insert(bel); + placed_cells++; } } int constr_placed_cells = placed_cells; @@ -126,15 +122,12 @@ class SAPlacer // Place cells randomly initially log_info("Creating initial placement for remaining %d cells.\n", int(autoplaced.size())); - { - auto &&proxy = ctx->rwproxy(); - for (auto cell : autoplaced) { - place_initial(proxy, cell); - placed_cells++; - if ((placed_cells - constr_placed_cells) % 500 == 0) - log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), - int(autoplaced.size())); - } + for (auto cell : autoplaced) { + place_initial(cell); + placed_cells++; + if ((placed_cells - constr_placed_cells) % 500 == 0) + log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), + int(autoplaced.size())); } if ((placed_cells - constr_placed_cells) % 500 != 0) log_info(" initial placement placed %d/%d cells\n", int(placed_cells - constr_placed_cells), @@ -145,13 +138,10 @@ class SAPlacer // Calculate wirelength after initial placement curr_wirelength = 0; curr_tns = 0; - { - auto &&proxy = ctx->rproxy(); - for (auto &net : ctx->nets) { - wirelen_t wl = get_net_wirelength(proxy, ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; - } + for (auto &net : ctx->nets) { + wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; } int n_no_progress = 0; @@ -168,18 +158,15 @@ class SAPlacer "%.0f, est tns = %.02fns\n", iter, temp, double(curr_wirelength), curr_tns); - { - auto &&proxy = ctx->rwproxy(); - for (int m = 0; m < 15; ++m) { - // Loop through all automatically placed cells - for (auto cell : autoplaced) { - // Find another random Bel for this cell - BelId try_bel = random_bel_for_cell(cell); - // If valid, try and swap to a new position and see if - // the new position is valid/worthwhile - if (try_bel != BelId() && try_bel != cell->bel) - try_swap_position(proxy, cell, try_bel); - } + for (int m = 0; m < 15; ++m) { + // Loop through all automatically placed cells + for (auto cell : autoplaced) { + // Find another random Bel for this cell + BelId try_bel = random_bel_for_cell(cell); + // If valid, try and swap to a new position and see if + // the new position is valid/worthwhile + if (try_bel != BelId() && try_bel != cell->bel) + try_swap_position(cell, try_bel); } } // Heuristic to improve placement on the 8k @@ -240,33 +227,27 @@ class SAPlacer // accumulating over time curr_wirelength = 0; curr_tns = 0; - { - auto &&proxy = ctx->rproxy(); - for (auto &net : ctx->nets) { - wirelen_t wl = get_net_wirelength(proxy, ctx, net.second.get(), curr_tns); - wirelengths[net.first] = wl; - curr_wirelength += wl; - } + for (auto &net : ctx->nets) { + wirelen_t wl = get_net_wirelength(ctx, net.second.get(), curr_tns); + wirelengths[net.first] = wl; + curr_wirelength += wl; } } - { - // Final post-pacement validitiy check - auto &&proxy = ctx->rproxy(); - for (auto bel : ctx->getBels()) { - IdString cell = proxy.getBoundBelCell(bel); - if (!proxy.isBelLocationValid(bel)) { - std::string cell_text = "no cell"; - if (cell != IdString()) - cell_text = std::string("cell '") + cell.str(ctx) + "'"; - if (ctx->force) { - log_warning("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); - } else { - log_error("post-placement validity check failed for Bel '%s' " - "(%s)\n", - ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); - } + // Final post-pacement validitiy check + for (auto bel : ctx->getBels()) { + IdString cell = ctx->getBoundBelCellUnlocked(bel); + if (!ctx->isBelLocationValid(bel)) { + std::string cell_text = "no cell"; + if (cell != IdString()) + cell_text = std::string("cell '") + cell.str(ctx) + "'"; + if (ctx->force) { + log_warning("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); + } else { + log_error("post-placement validity check failed for Bel '%s' " + "(%s)\n", + ctx->getBelName(bel).c_str(ctx), cell_text.c_str()); } } } @@ -275,7 +256,7 @@ class SAPlacer private: // Initial random placement - void place_initial(ArchRWProxy &proxy, CellInfo *cell) + void place_initial(CellInfo *cell) { bool all_placed = false; int iters = 25; @@ -286,12 +267,12 @@ class SAPlacer CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - proxy.unbindBel(cell->bel); + ctx->unbindBelUnlocked(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { - if (ctx->getBelType(bel) == targetType && (proxy.isValidBelForCell(cell, bel) || !require_legal)) { - if (proxy.checkBelAvail(bel)) { + if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { + if (ctx->checkBelAvailUnlocked(bel)) { uint64_t score = ctx->rng64(); if (score <= best_score) { best_score = score; @@ -301,7 +282,7 @@ class SAPlacer uint64_t score = ctx->rng64(); if (score <= best_ripup_score) { best_ripup_score = score; - ripup_target = ctx->cells.at(proxy.getBoundBelCell(bel)).get(); + ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); ripup_bel = bel; } } @@ -311,12 +292,12 @@ class SAPlacer if (iters == 0 || ripup_bel == BelId()) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); --iters; - proxy.unbindBel(ripup_target->bel); + ctx->unbindBelUnlocked(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - proxy.bindBel(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); // Back annotate location cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); @@ -325,14 +306,14 @@ class SAPlacer } // Attempt a SA position swap, return true on success or false on failure - bool try_swap_position(ArchRWProxy &proxy, CellInfo *cell, BelId newBel) + bool try_swap_position(CellInfo *cell, BelId newBel) { static std::unordered_set update; static std::vector> new_lengths; new_lengths.clear(); update.clear(); BelId oldBel = cell->bel; - IdString other = proxy.getBoundBelCell(newBel); + IdString other = ctx->getBoundBelCellUnlocked(newBel); CellInfo *other_cell = nullptr; if (other != IdString()) { other_cell = ctx->cells[other].get(); @@ -340,9 +321,9 @@ class SAPlacer return false; } wirelen_t new_wirelength = 0, delta; - proxy.unbindBel(oldBel); + ctx->unbindBelUnlocked(oldBel); if (other != IdString()) { - proxy.unbindBel(newBel); + ctx->unbindBelUnlocked(newBel); } for (const auto &port : cell->ports) @@ -355,16 +336,16 @@ class SAPlacer update.insert(port.second.net); } - proxy.bindBel(newBel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(newBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - proxy.bindBel(oldBel, other_cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(oldBel, other_cell->name, STRENGTH_WEAK); } if (require_legal) { - if (!proxy.isBelLocationValid(newBel) || ((other != IdString() && !proxy.isBelLocationValid(oldBel)))) { - proxy.unbindBel(newBel); + if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { + ctx->unbindBelUnlocked(newBel); if (other != IdString()) - proxy.unbindBel(oldBel); + ctx->unbindBelUnlocked(oldBel); goto swap_fail; } } @@ -375,7 +356,7 @@ class SAPlacer for (auto net : update) { new_wirelength -= wirelengths.at(net->name); float temp_tns = 0; - wirelen_t net_new_wl = get_net_wirelength<>(proxy, ctx, net, temp_tns); + wirelen_t net_new_wl = get_net_wirelength(ctx, net, temp_tns); new_wirelength += net_new_wl; new_lengths.push_back(std::make_pair(net->name, net_new_wl)); } @@ -388,8 +369,8 @@ class SAPlacer improved = true; } else { if (other != IdString()) - proxy.unbindBel(oldBel); - proxy.unbindBel(newBel); + ctx->unbindBelUnlocked(oldBel); + ctx->unbindBelUnlocked(newBel); goto swap_fail; } curr_wirelength = new_wirelength; @@ -398,9 +379,9 @@ class SAPlacer return true; swap_fail: - proxy.bindBel(oldBel, cell->name, STRENGTH_WEAK); + ctx->bindBelUnlocked(oldBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - proxy.bindBel(newBel, other, STRENGTH_WEAK); + ctx->bindBelUnlocked(newBel, other, STRENGTH_WEAK); } return false; } diff --git a/common/router1.cc b/common/router1.cc index 0d26a36d..cbaf773d 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -2,7 +2,6 @@ * nextpnr -- Next Generation Place and Route * * Copyright (C) 2018 Clifford Wolf - * Copyright (C) 2018 Serge Bazanski * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -74,7 +73,7 @@ struct RipupScoreboard std::unordered_map, int, hash_id_pip> netPipScores; }; -void ripup_net(ArchRWProxy &proxy, Context *ctx, IdString net_name) +void ripup_net(Context *ctx, IdString net_name) { auto net_info = ctx->nets.at(net_name).get(); std::vector pips; @@ -91,10 +90,10 @@ void ripup_net(ArchRWProxy &proxy, Context *ctx, IdString net_name) } for (auto pip : pips) - proxy.unbindPip(pip); + ctx->unbindPipUnlocked(pip); for (auto wire : wires) - proxy.unbindWire(wire); + ctx->unbindWireUnlocked(wire); NPNR_ASSERT(net_info->wires.empty()); } @@ -115,7 +114,7 @@ struct Router delay_t maxDelay = 0.0; WireId failedDest; - void route(ArchRWProxy &proxy, const std::unordered_map &src_wires, WireId dst_wire) + void route(const std::unordered_map &src_wires, WireId dst_wire) { std::priority_queue, QueuedWire::Greater> queue; @@ -136,7 +135,6 @@ struct Router int thisVisitCnt = 0; int thisVisitCntLimit = 0; - while (!queue.empty() && (thisVisitCntLimit == 0 || thisVisitCnt < thisVisitCntLimit)) { QueuedWire qw = queue.top(); queue.pop(); @@ -150,10 +148,10 @@ struct Router bool foundRipupNet = false; thisVisitCnt++; - if (!proxy.checkWireAvail(next_wire)) { + if (!ctx->checkWireAvailUnlocked(next_wire)) { if (!ripup) continue; - IdString ripupWireNet = proxy.getConflictingWireNet(next_wire); + IdString ripupWireNet = ctx->getConflictingWireNetUnlocked(next_wire); if (ripupWireNet == net_name || ripupWireNet == IdString()) continue; @@ -168,10 +166,10 @@ struct Router foundRipupNet = true; } - if (!proxy.checkPipAvail(pip)) { + if (!ctx->checkPipAvailUnlocked(pip)) { if (!ripup) continue; - IdString ripupPipNet = proxy.getConflictingPipNet(pip); + IdString ripupPipNet = ctx->getConflictingPipNetUnlocked(pip); if (ripupPipNet == net_name || ripupPipNet == IdString()) continue; @@ -229,10 +227,7 @@ struct Router { std::unordered_map src_wires; src_wires[src_wire] = 0; - { - auto &&proxy = ctx->rwproxy(); - route(proxy, src_wires, dst_wire); - } + route(src_wires, dst_wire); routedOkay = visited.count(dst_wire); if (ctx->debug) { @@ -277,7 +272,7 @@ struct Router if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->rproxy().getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) log_error("No wire found for port %s (pin %s) on source cell %s " @@ -291,10 +286,8 @@ struct Router std::unordered_map src_wires; src_wires[src_wire] = 0; - auto &&proxy = ctx->rwproxy(); - - ripup_net(proxy, ctx, net_name); - proxy.bindWire(src_wire, net_name, STRENGTH_WEAK); + ripup_net(ctx, net_name); + ctx->bindWireUnlocked(src_wire, net_name, STRENGTH_WEAK); std::vector users_array = net_info->users; ctx->shuffle(users_array); @@ -319,7 +312,7 @@ struct Router if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = proxy.getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) log_error("No wire found for port %s (pin %s) on destination " @@ -332,7 +325,7 @@ struct Router log(" Path delay estimate: %.2f\n", float(ctx->estimateDelay(src_wire, dst_wire))); } - route(proxy, src_wires, dst_wire); + route(src_wires, dst_wire); if (visited.count(dst_wire) == 0) { if (ctx->debug) @@ -341,7 +334,7 @@ struct Router else if (ripup) log_info("Failed to route %s -> %s.\n", ctx->getWireName(src_wire).c_str(ctx), ctx->getWireName(dst_wire).c_str(ctx)); - ripup_net(proxy, ctx, net_name); + ripup_net(ctx, net_name); failedDest = dst_wire; return; } @@ -362,15 +355,15 @@ struct Router if (src_wires.count(cursor)) break; - IdString conflicting_wire_net = proxy.getConflictingWireNet(cursor); + IdString conflicting_wire_net = ctx->getConflictingWireNetUnlocked(cursor); if (conflicting_wire_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_wire_net != net_name); - proxy.unbindWire(cursor); - if (!proxy.checkWireAvail(cursor)) - ripup_net(proxy, ctx, conflicting_wire_net); + ctx->unbindWireUnlocked(cursor); + if (!ctx->checkWireAvailUnlocked(cursor)) + ripup_net(ctx, conflicting_wire_net); rippedNets.insert(conflicting_wire_net); scores.wireScores[cursor]++; @@ -379,15 +372,15 @@ struct Router } PipId pip = visited[cursor].pip; - IdString conflicting_pip_net = proxy.getConflictingPipNet(pip); + IdString conflicting_pip_net = ctx->getConflictingPipNetUnlocked(pip); if (conflicting_pip_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_pip_net != net_name); - proxy.unbindPip(pip); - if (!proxy.checkPipAvail(pip)) - ripup_net(proxy, ctx, conflicting_pip_net); + ctx->unbindPipUnlocked(pip); + if (!ctx->checkPipAvailUnlocked(pip)) + ripup_net(ctx, conflicting_pip_net); rippedNets.insert(conflicting_pip_net); scores.pipScores[visited[cursor].pip]++; @@ -395,7 +388,7 @@ struct Router scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; } - proxy.bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); + ctx->bindPipUnlocked(visited[cursor].pip, net_name, STRENGTH_WEAK); src_wires[cursor] = visited[cursor].delay; cursor = ctx->getPipSrcWire(visited[cursor].pip); } @@ -444,48 +437,45 @@ bool router1(Context *ctx) delay_t estimatedTotalDelay = 0.0; int estimatedTotalDelayCnt = 0; - { - auto &&proxy = ctx->rproxy(); - for (auto net_name : netsQueue) { - auto net_info = ctx->nets.at(net_name).get(); + for (auto net_name : netsQueue) { + auto net_info = ctx->nets.at(net_name).get(); - auto src_bel = net_info->driver.cell->bel; + auto src_bel = net_info->driver.cell->bel; - if (src_bel == BelId()) - continue; + if (src_bel == BelId()) + continue; - IdString driver_port = net_info->driver.port; + IdString driver_port = net_info->driver.port; - auto driver_port_it = net_info->driver.cell->pins.find(driver_port); - if (driver_port_it != net_info->driver.cell->pins.end()) - driver_port = driver_port_it->second; + auto driver_port_it = net_info->driver.cell->pins.find(driver_port); + if (driver_port_it != net_info->driver.cell->pins.end()) + driver_port = driver_port_it->second; - auto src_wire = proxy.getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); - if (src_wire == WireId()) - continue; + if (src_wire == WireId()) + continue; - for (auto &user_it : net_info->users) { - auto dst_bel = user_it.cell->bel; + for (auto &user_it : net_info->users) { + auto dst_bel = user_it.cell->bel; - if (dst_bel == BelId()) - continue; + if (dst_bel == BelId()) + continue; - IdString user_port = user_it.port; + IdString user_port = user_it.port; - auto user_port_it = user_it.cell->pins.find(user_port); + auto user_port_it = user_it.cell->pins.find(user_port); - if (user_port_it != user_it.cell->pins.end()) - user_port = user_port_it->second; + if (user_port_it != user_it.cell->pins.end()) + user_port = user_port_it->second; - auto dst_wire = proxy.getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); - if (dst_wire == WireId()) - continue; + if (dst_wire == WireId()) + continue; - estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); - estimatedTotalDelayCnt++; - } + estimatedTotalDelay += ctx->estimateDelay(src_wire, dst_wire); + estimatedTotalDelayCnt++; } } -- cgit v1.2.3 From 57f75385b0960d6e1e30112a395a89ee4df07056 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Sat, 14 Jul 2018 18:53:08 +0100 Subject: Revert "Make PnR use Unlocked methods" This reverts commit 9e4f97290a50fc5d9dc0cbe6ead945840b9811b1. --- common/place_common.cc | 14 +++++++------- common/placer1.cc | 38 +++++++++++++++++++------------------- common/router1.cc | 36 ++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 44 deletions(-) (limited to 'common') diff --git a/common/place_common.cc b/common/place_common.cc index 281e40a2..60735890 100644 --- a/common/place_common.cc +++ b/common/place_common.cc @@ -36,7 +36,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) if (driver_cell->bel == BelId()) return 0; ctx->estimatePosition(driver_cell->bel, driver_x, driver_y, driver_gb); - WireId drv_wire = ctx->getWireBelPinUnlocked(driver_cell->bel, ctx->portPinFromId(net->driver.port)); + WireId drv_wire = ctx->getWireBelPin(driver_cell->bel, ctx->portPinFromId(net->driver.port)); if (driver_gb) return 0; float worst_slack = 1000; @@ -48,7 +48,7 @@ wirelen_t get_net_wirelength(const Context *ctx, const NetInfo *net, float &tns) if (load_cell->bel == BelId()) continue; if (ctx->timing_driven) { - WireId user_wire = ctx->getWireBelPinUnlocked(load_cell->bel, ctx->portPinFromId(load.port)); + WireId user_wire = ctx->getWireBelPin(load_cell->bel, ctx->portPinFromId(load.port)); delay_t raw_wl = ctx->estimateDelay(drv_wire, user_wire); float slack = ctx->getDelayNS(load.budget) - ctx->getDelayNS(raw_wl); if (slack < 0) @@ -112,12 +112,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBelUnlocked(cell->bel); + ctx->unbindBel(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { if (ctx->getBelType(bel) == targetType && (!require_legality || ctx->isValidBelForCell(cell, bel))) { - if (ctx->checkBelAvailUnlocked(bel)) { + if (ctx->checkBelAvail(bel)) { wirelen_t wirelen = get_cell_wirelength_at_bel(ctx, cell, bel); if (iters >= 4) wirelen += ctx->rng(25); @@ -130,7 +130,7 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) if (iters >= 4) wirelen += ctx->rng(25); if (wirelen <= best_ripup_wirelen) { - ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); + ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); if (ripup_target->belStrength < STRENGTH_STRONG) { best_ripup_wirelen = wirelen; ripup_bel = bel; @@ -148,12 +148,12 @@ bool place_single_cell(Context *ctx, CellInfo *cell, bool require_legality) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); } --iters; - ctx->unbindBelUnlocked(ripup_target->bel); + ctx->unbindBel(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); cell = ripup_target; } diff --git a/common/placer1.cc b/common/placer1.cc index 05f760a3..53295a91 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -85,7 +85,7 @@ class SAPlacer auto loc = cell->attrs.find(ctx->id("BEL")); if (loc != cell->attrs.end()) { std::string loc_name = loc->second; - BelId bel = ctx->getBelByNameUnlocked(ctx->id(loc_name)); + BelId bel = ctx->getBelByName(ctx->id(loc_name)); if (bel == BelId()) { log_error("No Bel named \'%s\' located for " "this chip (processing BEL attribute on \'%s\')\n", @@ -100,7 +100,7 @@ class SAPlacer cell->type.c_str(ctx)); } - ctx->bindBelUnlocked(bel, cell->name, STRENGTH_USER); + ctx->bindBel(bel, cell->name, STRENGTH_USER); locked_bels.insert(bel); placed_cells++; } @@ -235,7 +235,7 @@ class SAPlacer } // Final post-pacement validitiy check for (auto bel : ctx->getBels()) { - IdString cell = ctx->getBoundBelCellUnlocked(bel); + IdString cell = ctx->getBoundBelCell(bel); if (!ctx->isBelLocationValid(bel)) { std::string cell_text = "no cell"; if (cell != IdString()) @@ -267,12 +267,12 @@ class SAPlacer CellInfo *ripup_target = nullptr; BelId ripup_bel = BelId(); if (cell->bel != BelId()) { - ctx->unbindBelUnlocked(cell->bel); + ctx->unbindBel(cell->bel); } BelType targetType = ctx->belTypeFromId(cell->type); for (auto bel : ctx->getBels()) { if (ctx->getBelType(bel) == targetType && (ctx->isValidBelForCell(cell, bel) || !require_legal)) { - if (ctx->checkBelAvailUnlocked(bel)) { + if (ctx->checkBelAvail(bel)) { uint64_t score = ctx->rng64(); if (score <= best_score) { best_score = score; @@ -282,7 +282,7 @@ class SAPlacer uint64_t score = ctx->rng64(); if (score <= best_ripup_score) { best_ripup_score = score; - ripup_target = ctx->cells.at(ctx->getBoundBelCellUnlocked(bel)).get(); + ripup_target = ctx->cells.at(ctx->getBoundBelCell(bel)).get(); ripup_bel = bel; } } @@ -292,12 +292,12 @@ class SAPlacer if (iters == 0 || ripup_bel == BelId()) log_error("failed to place cell '%s' of type '%s'\n", cell->name.c_str(ctx), cell->type.c_str(ctx)); --iters; - ctx->unbindBelUnlocked(ripup_target->bel); + ctx->unbindBel(ripup_target->bel); best_bel = ripup_bel; } else { all_placed = true; } - ctx->bindBelUnlocked(best_bel, cell->name, STRENGTH_WEAK); + ctx->bindBel(best_bel, cell->name, STRENGTH_WEAK); // Back annotate location cell->attrs[ctx->id("BEL")] = ctx->getBelName(cell->bel).str(ctx); @@ -313,7 +313,7 @@ class SAPlacer new_lengths.clear(); update.clear(); BelId oldBel = cell->bel; - IdString other = ctx->getBoundBelCellUnlocked(newBel); + IdString other = ctx->getBoundBelCell(newBel); CellInfo *other_cell = nullptr; if (other != IdString()) { other_cell = ctx->cells[other].get(); @@ -321,9 +321,9 @@ class SAPlacer return false; } wirelen_t new_wirelength = 0, delta; - ctx->unbindBelUnlocked(oldBel); + ctx->unbindBel(oldBel); if (other != IdString()) { - ctx->unbindBelUnlocked(newBel); + ctx->unbindBel(newBel); } for (const auto &port : cell->ports) @@ -336,16 +336,16 @@ class SAPlacer update.insert(port.second.net); } - ctx->bindBelUnlocked(newBel, cell->name, STRENGTH_WEAK); + ctx->bindBel(newBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBelUnlocked(oldBel, other_cell->name, STRENGTH_WEAK); + ctx->bindBel(oldBel, other_cell->name, STRENGTH_WEAK); } if (require_legal) { if (!ctx->isBelLocationValid(newBel) || ((other != IdString() && !ctx->isBelLocationValid(oldBel)))) { - ctx->unbindBelUnlocked(newBel); + ctx->unbindBel(newBel); if (other != IdString()) - ctx->unbindBelUnlocked(oldBel); + ctx->unbindBel(oldBel); goto swap_fail; } } @@ -369,8 +369,8 @@ class SAPlacer improved = true; } else { if (other != IdString()) - ctx->unbindBelUnlocked(oldBel); - ctx->unbindBelUnlocked(newBel); + ctx->unbindBel(oldBel); + ctx->unbindBel(newBel); goto swap_fail; } curr_wirelength = new_wirelength; @@ -379,9 +379,9 @@ class SAPlacer return true; swap_fail: - ctx->bindBelUnlocked(oldBel, cell->name, STRENGTH_WEAK); + ctx->bindBel(oldBel, cell->name, STRENGTH_WEAK); if (other != IdString()) { - ctx->bindBelUnlocked(newBel, other, STRENGTH_WEAK); + ctx->bindBel(newBel, other, STRENGTH_WEAK); } return false; } diff --git a/common/router1.cc b/common/router1.cc index cbaf773d..94c7070e 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -90,10 +90,10 @@ void ripup_net(Context *ctx, IdString net_name) } for (auto pip : pips) - ctx->unbindPipUnlocked(pip); + ctx->unbindPip(pip); for (auto wire : wires) - ctx->unbindWireUnlocked(wire); + ctx->unbindWire(wire); NPNR_ASSERT(net_info->wires.empty()); } @@ -148,10 +148,10 @@ struct Router bool foundRipupNet = false; thisVisitCnt++; - if (!ctx->checkWireAvailUnlocked(next_wire)) { + if (!ctx->checkWireAvail(next_wire)) { if (!ripup) continue; - IdString ripupWireNet = ctx->getConflictingWireNetUnlocked(next_wire); + IdString ripupWireNet = ctx->getConflictingWireNet(next_wire); if (ripupWireNet == net_name || ripupWireNet == IdString()) continue; @@ -166,10 +166,10 @@ struct Router foundRipupNet = true; } - if (!ctx->checkPipAvailUnlocked(pip)) { + if (!ctx->checkPipAvail(pip)) { if (!ripup) continue; - IdString ripupPipNet = ctx->getConflictingPipNetUnlocked(pip); + IdString ripupPipNet = ctx->getConflictingPipNet(pip); if (ripupPipNet == net_name || ripupPipNet == IdString()) continue; @@ -272,7 +272,7 @@ struct Router if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) log_error("No wire found for port %s (pin %s) on source cell %s " @@ -287,7 +287,7 @@ struct Router src_wires[src_wire] = 0; ripup_net(ctx, net_name); - ctx->bindWireUnlocked(src_wire, net_name, STRENGTH_WEAK); + ctx->bindWire(src_wire, net_name, STRENGTH_WEAK); std::vector users_array = net_info->users; ctx->shuffle(users_array); @@ -312,7 +312,7 @@ struct Router if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) log_error("No wire found for port %s (pin %s) on destination " @@ -355,14 +355,14 @@ struct Router if (src_wires.count(cursor)) break; - IdString conflicting_wire_net = ctx->getConflictingWireNetUnlocked(cursor); + IdString conflicting_wire_net = ctx->getConflictingWireNet(cursor); if (conflicting_wire_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_wire_net != net_name); - ctx->unbindWireUnlocked(cursor); - if (!ctx->checkWireAvailUnlocked(cursor)) + ctx->unbindWire(cursor); + if (!ctx->checkWireAvail(cursor)) ripup_net(ctx, conflicting_wire_net); rippedNets.insert(conflicting_wire_net); @@ -372,14 +372,14 @@ struct Router } PipId pip = visited[cursor].pip; - IdString conflicting_pip_net = ctx->getConflictingPipNetUnlocked(pip); + IdString conflicting_pip_net = ctx->getConflictingPipNet(pip); if (conflicting_pip_net != IdString()) { NPNR_ASSERT(ripup); NPNR_ASSERT(conflicting_pip_net != net_name); - ctx->unbindPipUnlocked(pip); - if (!ctx->checkPipAvailUnlocked(pip)) + ctx->unbindPip(pip); + if (!ctx->checkPipAvail(pip)) ripup_net(ctx, conflicting_pip_net); rippedNets.insert(conflicting_pip_net); @@ -388,7 +388,7 @@ struct Router scores.netPipScores[std::make_pair(conflicting_pip_net, visited[cursor].pip)]++; } - ctx->bindPipUnlocked(visited[cursor].pip, net_name, STRENGTH_WEAK); + ctx->bindPip(visited[cursor].pip, net_name, STRENGTH_WEAK); src_wires[cursor] = visited[cursor].delay; cursor = ctx->getPipSrcWire(visited[cursor].pip); } @@ -451,7 +451,7 @@ bool router1(Context *ctx) if (driver_port_it != net_info->driver.cell->pins.end()) driver_port = driver_port_it->second; - auto src_wire = ctx->getWireBelPinUnlocked(src_bel, ctx->portPinFromId(driver_port)); + auto src_wire = ctx->getWireBelPin(src_bel, ctx->portPinFromId(driver_port)); if (src_wire == WireId()) continue; @@ -469,7 +469,7 @@ bool router1(Context *ctx) if (user_port_it != user_it.cell->pins.end()) user_port = user_port_it->second; - auto dst_wire = ctx->getWireBelPinUnlocked(dst_bel, ctx->portPinFromId(user_port)); + auto dst_wire = ctx->getWireBelPin(dst_bel, ctx->portPinFromId(user_port)); if (dst_wire == WireId()) continue; -- cgit v1.2.3