Improving the placer output

Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
David Shah 2018-06-17 11:45:41 +02:00
parent c604426341
commit 3afce5ff5a
6 changed files with 42 additions and 15 deletions

View File

@ -18,7 +18,9 @@
*/ */
#include "design_utils.h" #include "design_utils.h"
#include <map>
#include "log.h"
#include "util.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
void replace_port(CellInfo *old_cell, IdString old_name, CellInfo *rep_cell, void replace_port(CellInfo *old_cell, IdString old_name, CellInfo *rep_cell,
@ -49,4 +51,23 @@ void replace_port(CellInfo *old_cell, IdString old_name, CellInfo *rep_cell,
} }
} }
// Print utilisation of a design
void print_utilisation(const Design *design)
{
// Sort by Bel type
std::map<BelType, int> used_types;
for (auto cell : design->cells) {
used_types[belTypeFromId(cell.second->type)]++;
}
std::map<BelType, int> available_types;
for (auto bel : design->chip.getBels()) {
available_types[design->chip.getBelType(bel)]++;
}
log("\nDesign utilisation:\n");
for (auto type : available_types) {
log("\t%20s: %5d/%5d\n", belTypeToId(type.first).c_str(),
get_or_default(used_types, type.first, 0), type.second);
}
}
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -83,6 +83,9 @@ CellInfo *net_driven_by(const NetInfo *net, F1 cell_pred, IdString port)
} }
} }
void print_utilisation(const Design *design);
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END
#endif #endif

View File

@ -183,7 +183,8 @@ static bool try_swap_position(Design *design, CellInfo *cell, BelId newBel,
chip.bindBel(oldBel, other_cell->name); chip.bindBel(oldBel, other_cell->name);
} }
if (!isBelLocationValid(design, newBel) || ((other != IdString() && !isBelLocationValid(design, oldBel)))) { if (!isBelLocationValid(design, newBel) ||
((other != IdString() && !isBelLocationValid(design, oldBel)))) {
chip.unbindBel(newBel); chip.unbindBel(newBel);
if (other != IdString()) if (other != IdString())
chip.unbindBel(oldBel); chip.unbindBel(oldBel);
@ -309,7 +310,7 @@ void place_design_sa(Design *design)
autoplaced.push_back(cell.second); autoplaced.push_back(cell.second);
placed_cells++; placed_cells++;
} }
log_info("placed %d/%d\n", int(placed_cells), int(total_cells)); // log_info("placed %d/%d\n", int(placed_cells), int(total_cells));
} }
// Build up a fast position/type to Bel lookup table // Build up a fast position/type to Bel lookup table
int max_x = 0, max_y = 0; int max_x = 0, max_y = 0;
@ -345,9 +346,9 @@ void place_design_sa(Design *design)
state.n_move = state.n_accept = 0; state.n_move = state.n_accept = 0;
state.improved = false; state.improved = false;
// if (iter % 50 == 0) if (iter % 5 == 0)
log(" at iteration #%d: temp = %f, wire length = %f\n", iter, log(" at iteration #%d: temp = %f, wire length = %f\n", iter,
state.temp, state.curr_wirelength); state.temp, state.curr_wirelength);
for (int m = 0; m < 15; ++m) { for (int m = 0; m < 15; ++m) {
// Loop through all automatically placed cells // Loop through all automatically placed cells
@ -403,7 +404,8 @@ void place_design_sa(Design *design)
IdString cell = design->chip.getBelCell(bel, false); IdString cell = design->chip.getBelCell(bel, false);
if (cell != IdString()) if (cell != IdString())
cell_text = std::string("cell '") + cell.str() + "'"; cell_text = std::string("cell '") + cell.str() + "'";
log_error("post-placement validity check failed for Bel '%s' (%s)", design->chip.getBelName(bel).c_str(), cell_text.c_str()); log_error("post-placement validity check failed for Bel '%s' (%s)",
design->chip.getBelName(bel).c_str(), cell_text.c_str());
} }
} }
} }

View File

@ -27,7 +27,7 @@ NEXTPNR_NAMESPACE_BEGIN
// Get a value from a map-style container, returning default if value is not // Get a value from a map-style container, returning default if value is not
// found // found
template<typename Container, typename KeyType, typename ValueType> template <typename Container, typename KeyType, typename ValueType>
ValueType get_or_default(const Container &ct, const KeyType &key, ValueType get_or_default(const Container &ct, const KeyType &key,
ValueType def = ValueType()) ValueType def = ValueType())
{ {
@ -40,9 +40,8 @@ ValueType get_or_default(const Container &ct, const KeyType &key,
// Get a value from a map-style container, converting to int, and returning // Get a value from a map-style container, converting to int, and returning
// default if value is not found // default if value is not found
template<typename Container, typename KeyType> template <typename Container, typename KeyType>
int int_or_default(const Container &ct, const KeyType &key, int int_or_default(const Container &ct, const KeyType &key, int def = 0)
int def = 0)
{ {
auto found = ct.find(key); auto found = ct.find(key);
if (found == ct.end()) if (found == ct.end())
@ -52,9 +51,8 @@ int int_or_default(const Container &ct, const KeyType &key,
}; };
// As above, but convert to bool // As above, but convert to bool
template<typename Container, typename KeyType> template <typename Container, typename KeyType>
bool bool_or_default(const Container &ct, const KeyType &key, bool bool_or_default(const Container &ct, const KeyType &key, bool def = false)
bool def = false)
{ {
return bool(int_or_default(ct, key, int(def))); return bool(int_or_default(ct, key, int(def)));
}; };

View File

@ -80,7 +80,8 @@ static bool logicCellsCompatible(const std::vector<const CellInfo *> &cells)
return locals.size() <= 32; return locals.size() <= 32;
} }
bool isBelLocationValid(Design *design, BelId bel) { bool isBelLocationValid(Design *design, BelId bel)
{
const Chip &chip = design->chip; const Chip &chip = design->chip;
if (chip.getBelType(bel) == TYPE_ICESTORM_LC) { if (chip.getBelType(bel) == TYPE_ICESTORM_LC) {
std::vector<const CellInfo *> cells; std::vector<const CellInfo *> cells;

View File

@ -35,6 +35,7 @@
#include "pybindings.h" #include "pybindings.h"
#include "route.h" #include "route.h"
#include "version.h" #include "version.h"
#include "design_utils.h"
void svg_dump_el(const GraphicElement &el) void svg_dump_el(const GraphicElement &el)
{ {
@ -221,6 +222,7 @@ int main(int argc, char *argv[])
} }
pack_design(&design); pack_design(&design);
print_utilisation(&design);
if (!vm.count("pack-only")) { if (!vm.count("pack-only")) {
place_design_sa(&design); place_design_sa(&design);
route_design(&design, verbose); route_design(&design, verbose);