Adding randomness and changes metrics to placer

Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
David Shah 2018-06-15 09:27:02 +02:00
parent 828c96f80b
commit 104c2dad9b

View File

@ -31,6 +31,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <vector> #include <vector>
#include <random>
#include <algorithm>
#include "arch_place.h" #include "arch_place.h"
#include "log.h" #include "log.h"
@ -124,9 +126,9 @@ void place_design(Design *design)
} }
} }
static void place_cell(Design *design, CellInfo *cell) static void place_cell(Design *design, CellInfo *cell, std::mt19937 &rnd)
{ {
std::uniform_real_distribution<float> random_wirelength(0.0, 30.0);
float best_distance = std::numeric_limits<float>::infinity(); float best_distance = std::numeric_limits<float>::infinity();
BelId best_bel = BelId(); BelId best_bel = BelId();
Chip &chip = design->chip; Chip &chip = design->chip;
@ -140,16 +142,21 @@ static void place_cell(Design *design, CellInfo *cell)
isValidBelForCell(design, cell, bel)) { isValidBelForCell(design, cell, bel)) {
float distance = 0; float distance = 0;
float belx, bely; float belx, bely;
bool has_conns = false;
chip.estimatePosition(bel, belx, bely); chip.estimatePosition(bel, belx, bely);
for (auto port : cell->ports) { for (auto port : cell->ports) {
const PortInfo &pi = port.second; const PortInfo &pi = port.second;
if (pi.net != nullptr) { if (pi.net != nullptr) {
CellInfo *drv = pi.net->driver.cell; CellInfo *drv = pi.net->driver.cell;
float pin_wirelength = std::numeric_limits<float>::infinity();
if (drv != nullptr && drv->bel != BelId()) { if (drv != nullptr && drv->bel != BelId()) {
float otherx, othery; float otherx, othery;
chip.estimatePosition(drv->bel, otherx, othery); chip.estimatePosition(drv->bel, otherx, othery);
distance += std::abs(belx - otherx) + float local_wl = std::abs(belx - otherx) +
std::abs(bely - othery); std::abs(bely - othery);
if (local_wl < pin_wirelength)
pin_wirelength = local_wl;
has_conns = true;
} }
if (pi.net->users.size() < 5) { if (pi.net->users.size() < 5) {
for (auto user : pi.net->users) { for (auto user : pi.net->users) {
@ -157,13 +164,20 @@ static void place_cell(Design *design, CellInfo *cell)
if (uc != nullptr && uc->bel != BelId()) { if (uc != nullptr && uc->bel != BelId()) {
float otherx, othery; float otherx, othery;
chip.estimatePosition(uc->bel, otherx, othery); chip.estimatePosition(uc->bel, otherx, othery);
distance += std::abs(belx - otherx) + float local_wl = std::abs(belx - otherx) +
std::abs(bely - othery); std::abs(bely - othery);
if (local_wl < pin_wirelength)
pin_wirelength = local_wl;
has_conns = true;
} }
} }
} }
if (!std::isinf(pin_wirelength))
distance += pin_wirelength;
} }
} }
if (!has_conns)
distance = random_wirelength(rnd);
if (distance <= best_distance) { if (distance <= best_distance) {
best_distance = distance; best_distance = distance;
best_bel = bel; best_bel = bel;
@ -213,21 +227,23 @@ void place_design_heuristic(Design *design)
} }
} }
log_info("place_constraints placed %d\n", placed_cells); log_info("place_constraints placed %d\n", placed_cells);
std::unordered_set<IdString> autoplaced; std::mt19937 rnd;
std::vector<IdString> autoplaced;
for (auto cell : design->cells) { for (auto cell : design->cells) {
CellInfo *ci = cell.second; CellInfo *ci = cell.second;
if (ci->bel == BelId()) { if (ci->bel == BelId()) {
place_cell(design, ci); place_cell(design, ci, rnd);
autoplaced.insert(cell.first); autoplaced.push_back(cell.first);
placed_cells++; placed_cells++;
} }
log_info("placed %d/%d\n", placed_cells, total_cells); log_info("placed %d/%d\n", placed_cells, total_cells);
} }
for (int i = 0 ; i < 3; i ++) { for (int i = 0 ; i < 2; i ++) {
int replaced_cells = 0; int replaced_cells = 0;
std::shuffle(autoplaced.begin(), autoplaced.end(), rnd);
for (auto cell : autoplaced) { for (auto cell : autoplaced) {
CellInfo *ci = design->cells[cell]; CellInfo *ci = design->cells[cell];
place_cell(design, ci); place_cell(design, ci, rnd);
replaced_cells++; replaced_cells++;
log_info("replaced %d/%d\n", replaced_cells, autoplaced.size()); log_info("replaced %d/%d\n", replaced_cells, autoplaced.size());
} }