Another heuristic experiment
Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
parent
b1e08fa064
commit
3ef45d2a27
@ -123,45 +123,32 @@ void place_design(Design *design)
|
||||
}
|
||||
}
|
||||
|
||||
static void place_cell(Design *design, CellInfo *cell, BelId closeTo,
|
||||
size_t &placed_cells,
|
||||
std::queue<CellInfo *> &visit_cells)
|
||||
static void place_cell(Design *design, CellInfo *cell)
|
||||
{
|
||||
assert(cell->bel == BelId());
|
||||
float best_distance = std::numeric_limits<float>::infinity();
|
||||
BelId best_bel = BelId();
|
||||
Chip &chip = design->chip;
|
||||
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()) {
|
||||
if (chip.getBelType(bel) == targetType && chip.checkBelAvail(bel) &&
|
||||
isValidBelForCell(design, cell, bel)) {
|
||||
if (closeTo == BelId()) {
|
||||
best_distance = 0;
|
||||
best_bel = bel;
|
||||
goto placed;
|
||||
} else {
|
||||
float distance =
|
||||
chip.estimateDelay(origin, chip.getBelPosition(bel));
|
||||
if (distance < best_distance) {
|
||||
best_distance = distance;
|
||||
best_bel = bel;
|
||||
float distance = 0;
|
||||
PosInfo belPosition = chip.getBelPosition(bel);
|
||||
for (auto port : cell->ports) {
|
||||
const PortInfo &pi = port.second;
|
||||
if(pi.net != nullptr && pi.type == PORT_IN) {
|
||||
CellInfo *drv = pi.net->driver.cell;
|
||||
if (drv != nullptr && drv->bel != BelId())
|
||||
distance += chip.estimateDelay(chip.getBelPosition(drv->bel), belPosition);
|
||||
}
|
||||
}
|
||||
if (distance < best_distance) {
|
||||
best_distance = distance;
|
||||
best_bel = bel;
|
||||
}
|
||||
}
|
||||
}
|
||||
placed:
|
||||
if (best_bel == BelId()) {
|
||||
log_error("failed to place cell '%s' of type '%s'\n",
|
||||
cell->name.c_str(), cell->type.c_str());
|
||||
@ -171,42 +158,6 @@ placed:
|
||||
|
||||
// Back annotate location
|
||||
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)
|
||||
@ -241,21 +192,11 @@ void place_design_heuristic(Design *design)
|
||||
}
|
||||
}
|
||||
log_info("place_constraints placed %d\n", placed_cells);
|
||||
while (placed_cells < total_cells) {
|
||||
if (!visit_cells.empty()) {
|
||||
CellInfo *next = visit_cells.front();
|
||||
visit_cells.pop();
|
||||
place_cell_neighbours(design, next, placed_cells, visit_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto cell : design->cells) {
|
||||
CellInfo *ci = cell.second;
|
||||
if (ci->bel == BelId())
|
||||
place_cell(design, ci);
|
||||
placed_cells++;
|
||||
log_info("placed %d/%d\n", placed_cells, total_cells);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user