Another heuristic experiment

Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
David Shah 2018-06-13 19:10:12 +02:00
parent b1e08fa064
commit 3ef45d2a27

View File

@ -123,45 +123,32 @@ void place_design(Design *design)
} }
} }
static void place_cell(Design *design, CellInfo *cell, BelId closeTo, static void place_cell(Design *design, CellInfo *cell)
size_t &placed_cells,
std::queue<CellInfo *> &visit_cells)
{ {
assert(cell->bel == BelId()); assert(cell->bel == BelId());
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;
BelType targetType = belTypeFromId(cell->type); BelType targetType = belTypeFromId(cell->type);
PosInfo origin;
if (closeTo != BelId()) {
origin = chip.getBelPosition(closeTo);
for (auto bel : chip.getBelsAtSameTile(closeTo)) {
if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
isValidBelForCell(design, cell, bel)) {
// prefer same tile
best_bel = bel;
goto placed;
}
}
}
for (auto bel : chip.getBels()) { for (auto bel : chip.getBels()) {
if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) && if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
isValidBelForCell(design, cell, bel)) { isValidBelForCell(design, cell, bel)) {
if (closeTo == BelId()) { float distance = 0;
best_distance = 0; PosInfo belPosition = chip.getBelPosition(bel);
best_bel = bel; for (auto port : cell->ports) {
goto placed; const PortInfo &pi = port.second;
} else { if(pi.net != nullptr && pi.type == PORT_IN) {
float distance = CellInfo *drv = pi.net->driver.cell;
chip.estimateDelay(origin, chip.getBelPosition(bel)); if (drv != nullptr && drv->bel != BelId())
if (distance < best_distance) { distance += chip.estimateDelay(chip.getBelPosition(drv->bel), belPosition);
best_distance = distance;
best_bel = bel;
} }
} }
if (distance < best_distance) {
best_distance = distance;
best_bel = bel;
}
} }
} }
placed:
if (best_bel == BelId()) { if (best_bel == BelId()) {
log_error("failed to place cell '%s' of type '%s'\n", log_error("failed to place cell '%s' of type '%s'\n",
cell->name.c_str(), cell->type.c_str()); cell->name.c_str(), cell->type.c_str());
@ -171,42 +158,6 @@ placed:
// Back annotate location // Back annotate location
cell->attrs["BEL"] = chip.getBelName(cell->bel).str(); cell->attrs["BEL"] = chip.getBelName(cell->bel).str();
placed_cells++;
visit_cells.push(cell);
}
static void place_cell_neighbours(Design *design, CellInfo *cell,
size_t &placed_cells,
std::queue<CellInfo *> &visit_cells)
{
if (cell->bel == BelId())
return;
int placed_count = 0;
const int count_thresh = 15;
for (auto port : cell->ports) {
NetInfo *net = port.second.net;
if (net != nullptr) {
for (auto user : net->users) {
if (net->users.size() > 3)
continue;
if (user.cell != nullptr && user.cell->bel == BelId()) {
place_cell(design, user.cell, cell->bel, placed_cells,
visit_cells);
placed_count++;
if (placed_count > count_thresh)
return;
}
}
if (net->driver.cell != nullptr && net->driver.cell->bel == BelId()) {
place_cell(design, net->driver.cell, cell->bel, placed_cells,
visit_cells);
placed_count++;
}
if (placed_count > count_thresh)
return;
}
}
} }
void place_design_heuristic(Design *design) void place_design_heuristic(Design *design)
@ -241,21 +192,11 @@ void place_design_heuristic(Design *design)
} }
} }
log_info("place_constraints placed %d\n", placed_cells); log_info("place_constraints placed %d\n", placed_cells);
while (placed_cells < total_cells) { for (auto cell : design->cells) {
if (!visit_cells.empty()) { CellInfo *ci = cell.second;
CellInfo *next = visit_cells.front(); if (ci->bel == BelId())
visit_cells.pop(); place_cell(design, ci);
place_cell_neighbours(design, next, placed_cells, visit_cells); placed_cells++;
} else {
// Nothing to visit (netlist is split), pick the next unplaced cell
for (auto cell : design->cells) {
CellInfo *ci = cell.second;
if (ci->bel == BelId()) {
place_cell(design, ci, BelId(), placed_cells, visit_cells);
break;
}
}
}
log_info("placed %d/%d\n", placed_cells, total_cells); log_info("placed %d/%d\n", placed_cells, total_cells);
} }
} }