HeAP: Improve handling of heterogeneous slice arches

Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
David Shah 2020-02-02 15:40:23 +00:00
parent 1ff060c5ad
commit d1f5cdcb93
2 changed files with 205 additions and 94 deletions

View File

@ -190,6 +190,13 @@ class HeAPPlacer
break; break;
} }
if (cfg.placeAllAtOnce) {
// Never want to deal with LUTs, FFs, MUXFxs seperately,
// for now disable all single-cell-type runs and only have heteregenous
// runs
heap_runs.clear();
}
heap_runs.push_back(all_celltypes); heap_runs.push_back(all_celltypes);
// The main HeAP placer loop // The main HeAP placer loop
log_info("Running main analytical placer.\n"); log_info("Running main analytical placer.\n");
@ -218,8 +225,14 @@ class HeAPPlacer
solved_hpwl = total_hpwl(); solved_hpwl = total_hpwl();
update_all_chains(); update_all_chains();
for (const auto &group : cfg.cellGroups)
CutSpreader(this, group).run();
for (auto type : sorted(run)) for (auto type : sorted(run))
CutSpreader(this, type).run(); if (std::all_of(cfg.cellGroups.begin(), cfg.cellGroups.end(),
[type](const std::unordered_set<IdString> &grp) { return !grp.count(type); }))
CutSpreader(this, {type}).run();
update_all_chains(); update_all_chains();
spread_hpwl = total_hpwl(); spread_hpwl = total_hpwl();
@ -577,6 +590,8 @@ class HeAPPlacer
{ {
const auto &base = cell_locs[cell->name]; const auto &base = cell_locs[cell->name];
for (auto child : cell->constr_children) { for (auto child : cell->constr_children) {
// FIXME: Improve handling of heterogeneous chains
if (child->type == root->type)
chain_size[root->name]++; chain_size[root->name]++;
if (child->constr_x != child->UNCONSTR) if (child->constr_x != child->UNCONSTR)
cell_locs[child->name].x = std::min(max_x, base.x + child->constr_x); cell_locs[child->name].x = std::min(max_x, base.x + child->constr_x);
@ -1033,22 +1048,33 @@ class HeAPPlacer
{ {
int id; int id;
int x0, y0, x1, y1; int x0, y0, x1, y1;
int cells, bels; std::vector<int> cells, bels;
bool overused() const bool overused() const
{ {
if (bels < 4) for (size_t t = 0; t < cells.size(); t++) {
return cells > bels; if (bels.at(t) < 4) {
else if (cells.at(t) > bels.at(t))
return cells > beta * bels; return true;
} else {
if (cells.at(t) > beta * bels.at(t))
return true;
}
}
return false;
} }
}; };
class CutSpreader class CutSpreader
{ {
public: public:
CutSpreader(HeAPPlacer *p, IdString beltype) CutSpreader(HeAPPlacer *p, const std::unordered_set<IdString> &beltype) : p(p), ctx(p->ctx), beltype(beltype)
: p(p), ctx(p->ctx), beltype(beltype), fb(p->fast_bels.at(std::get<0>(p->bel_types.at(beltype))))
{ {
int idx = 0;
for (IdString type : sorted(beltype)) {
type_index[type] = idx;
fb.emplace_back(&(p->fast_bels.at(std::get<0>(p->bel_types.at(type)))));
++idx;
}
} }
static int seq; static int seq;
void run() void run()
@ -1076,8 +1102,11 @@ class HeAPPlacer
if (merged_regions.count(r.id)) if (merged_regions.count(r.id))
continue; continue;
#if 0 #if 0
log_info("%s (%d, %d) |_> (%d, %d) %d/%d\n", beltype.c_str(ctx), r.x0, r.y0, r.x1, r.y1, r.cells, for (auto t : sorted(beltype)) {
r.bels); log_info("%s (%d, %d) |_> (%d, %d) %d/%d\n", t.c_str(ctx), r.x0, r.y0, r.x1, r.y1,
r.cells.at(type_index.at(t)), r.bels.at(type_index.at(t)));
}
#endif #endif
workqueue.emplace(r.id, false); workqueue.emplace(r.id, false);
// cut_region(r, false); // cut_region(r, false);
@ -1086,7 +1115,7 @@ class HeAPPlacer
auto front = workqueue.front(); auto front = workqueue.front();
workqueue.pop(); workqueue.pop();
auto &r = regions.at(front.first); auto &r = regions.at(front.first);
if (r.cells == 0) if (std::all_of(r.cells.begin(), r.cells.end(), [](int x) { return x == 0; }))
continue; continue;
auto res = cut_region(r, front.second); auto res = cut_region(r, front.second);
if (res) { if (res) {
@ -1128,37 +1157,41 @@ class HeAPPlacer
private: private:
HeAPPlacer *p; HeAPPlacer *p;
Context *ctx; Context *ctx;
IdString beltype; std::unordered_set<IdString> beltype;
std::vector<std::vector<int>> occupancy; std::unordered_map<IdString, int> type_index;
std::vector<std::vector<std::vector<int>>> occupancy;
std::vector<std::vector<int>> groups; std::vector<std::vector<int>> groups;
std::vector<std::vector<ChainExtent>> chaines; std::vector<std::vector<ChainExtent>> chaines;
std::map<IdString, ChainExtent> cell_extents; std::map<IdString, ChainExtent> cell_extents;
std::vector<std::vector<std::vector<BelId>>> &fb; std::vector<std::vector<std::vector<std::vector<BelId>>> *> fb;
std::vector<SpreaderRegion> regions; std::vector<SpreaderRegion> regions;
std::unordered_set<int> merged_regions; std::unordered_set<int> merged_regions;
// Cells at a location, sorted by real (not integer) x and y // Cells at a location, sorted by real (not integer) x and y
std::vector<std::vector<std::vector<CellInfo *>>> cells_at_location; std::vector<std::vector<std::vector<CellInfo *>>> cells_at_location;
int occ_at(int x, int y) { return occupancy.at(x).at(y); } int occ_at(int x, int y, int type) { return occupancy.at(x).at(y).at(type); }
int bels_at(int x, int y) int bels_at(int x, int y, int type)
{ {
if (x >= int(fb.size()) || y >= int(fb.at(x).size())) if (x >= int(fb.at(type)->size()) || y >= int(fb.at(type)->at(x).size()))
return 0; return 0;
return int(fb.at(x).at(y).size()); return int(fb.at(type)->at(x).at(y).size());
} }
void init() void init()
{ {
occupancy.resize(p->max_x + 1, std::vector<int>(p->max_y + 1, 0)); occupancy.resize(p->max_x + 1,
std::vector<std::vector<int>>(p->max_y + 1, std::vector<int>(beltype.size(), 0)));
groups.resize(p->max_x + 1, std::vector<int>(p->max_y + 1, -1)); groups.resize(p->max_x + 1, std::vector<int>(p->max_y + 1, -1));
chaines.resize(p->max_x + 1, std::vector<ChainExtent>(p->max_y + 1)); chaines.resize(p->max_x + 1, std::vector<ChainExtent>(p->max_y + 1));
cells_at_location.resize(p->max_x + 1, std::vector<std::vector<CellInfo *>>(p->max_y + 1)); cells_at_location.resize(p->max_x + 1, std::vector<std::vector<CellInfo *>>(p->max_y + 1));
for (int x = 0; x <= p->max_x; x++) for (int x = 0; x <= p->max_x; x++)
for (int y = 0; y <= p->max_y; y++) { for (int y = 0; y <= p->max_y; y++) {
occupancy.at(x).at(y) = 0; for (int t = 0; t < int(beltype.size()); t++) {
occupancy.at(x).at(y).at(t) = 0;
}
groups.at(x).at(y) = -1; groups.at(x).at(y) = -1;
chaines.at(x).at(y) = {x, y, x, y}; chaines.at(x).at(y) = {x, y, x, y};
} }
@ -1175,11 +1208,11 @@ class HeAPPlacer
}; };
for (auto &cell : p->cell_locs) { for (auto &cell : p->cell_locs) {
if (ctx->cells.at(cell.first)->type != beltype) if (!beltype.count(ctx->cells.at(cell.first)->type))
continue; continue;
if (ctx->cells.at(cell.first)->belStrength > STRENGTH_STRONG) if (ctx->cells.at(cell.first)->belStrength > STRENGTH_STRONG)
continue; continue;
occupancy.at(cell.second.x).at(cell.second.y)++; occupancy.at(cell.second.x).at(cell.second.y).at(type_index.at(ctx->cells.at(cell.first)->type))++;
// Compute ultimate extent of each chain root // Compute ultimate extent of each chain root
if (p->chain_root.count(cell.first)) { if (p->chain_root.count(cell.first)) {
set_chain_ext(p->chain_root.at(cell.first)->name, cell.second.x, cell.second.y); set_chain_ext(p->chain_root.at(cell.first)->name, cell.second.x, cell.second.y);
@ -1188,7 +1221,7 @@ class HeAPPlacer
} }
} }
for (auto &cell : p->cell_locs) { for (auto &cell : p->cell_locs) {
if (ctx->cells.at(cell.first)->type != beltype) if (!beltype.count(ctx->cells.at(cell.first)->type))
continue; continue;
// Transfer chain extents to the actual chaines structure // Transfer chain extents to the actual chaines structure
ChainExtent *ce = nullptr; ChainExtent *ce = nullptr;
@ -1205,7 +1238,7 @@ class HeAPPlacer
} }
} }
for (auto cell : p->solve_cells) { for (auto cell : p->solve_cells) {
if (cell->type != beltype) if (!beltype.count(cell->type))
continue; continue;
cells_at_location.at(p->cell_locs.at(cell->name).x).at(p->cell_locs.at(cell->name).y).push_back(cell); cells_at_location.at(p->cell_locs.at(cell->name).x).at(p->cell_locs.at(cell->name).y).push_back(cell);
} }
@ -1218,8 +1251,10 @@ class HeAPPlacer
// log_info("%d %d\n", groups.at(x).at(y), mergee.id); // log_info("%d %d\n", groups.at(x).at(y), mergee.id);
NPNR_ASSERT(groups.at(x).at(y) == mergee.id); NPNR_ASSERT(groups.at(x).at(y) == mergee.id);
groups.at(x).at(y) = merged.id; groups.at(x).at(y) = merged.id;
merged.cells += occ_at(x, y); for (size_t t = 0; t < beltype.size(); t++) {
merged.bels += bels_at(x, y); merged.cells.at(t) += occ_at(x, y, t);
merged.bels.at(t) += bels_at(x, y, t);
}
} }
merged_regions.insert(mergee.id); merged_regions.insert(mergee.id);
grow_region(merged, mergee.x0, mergee.y0, mergee.x1, mergee.y1); grow_region(merged, mergee.x0, mergee.y0, mergee.x1, mergee.y1);
@ -1239,8 +1274,10 @@ class HeAPPlacer
auto process_location = [&](int x, int y) { auto process_location = [&](int x, int y) {
// Merge with any overlapping regions // Merge with any overlapping regions
if (groups.at(x).at(y) == -1) { if (groups.at(x).at(y) == -1) {
r.bels += bels_at(x, y); for (int t = 0; t < int(beltype.size()); t++) {
r.cells += occ_at(x, y); r.bels.at(t) += bels_at(x, y, t);
r.cells.at(t) += occ_at(x, y, t);
}
} }
if (groups.at(x).at(y) != -1 && groups.at(x).at(y) != r.id) if (groups.at(x).at(y) != -1 && groups.at(x).at(y) != r.id)
merge_regions(r, regions.at(groups.at(x).at(y))); merge_regions(r, regions.at(groups.at(x).at(y)));
@ -1268,7 +1305,16 @@ class HeAPPlacer
for (int x = 0; x <= p->max_x; x++) for (int x = 0; x <= p->max_x; x++)
for (int y = 0; y <= p->max_y; y++) { for (int y = 0; y <= p->max_y; y++) {
// Either already in a group, or not overutilised. Ignore // Either already in a group, or not overutilised. Ignore
if (groups.at(x).at(y) != -1 || (occ_at(x, y) <= bels_at(x, y))) if (groups.at(x).at(y) != -1)
continue;
bool overutilised = false;
for (size_t t = 0; t < beltype.size(); t++) {
if (occ_at(x, y, t) > bels_at(x, y, t)) {
overutilised = true;
break;
}
}
if (!overutilised)
continue; continue;
// log_info("%d %d %d\n", x, y, occ_at(x, y)); // log_info("%d %d %d\n", x, y, occ_at(x, y));
int id = int(regions.size()); int id = int(regions.size());
@ -1277,8 +1323,10 @@ class HeAPPlacer
reg.id = id; reg.id = id;
reg.x0 = reg.x1 = x; reg.x0 = reg.x1 = x;
reg.y0 = reg.y1 = y; reg.y0 = reg.y1 = y;
reg.bels = bels_at(x, y); for (size_t t = 0; t < beltype.size(); t++) {
reg.cells = occ_at(x, y); reg.bels.push_back(bels_at(x, y, t));
reg.cells.push_back(occ_at(x, y, t));
}
// Make sure we cover carries, etc // Make sure we cover carries, etc
grow_region(reg, reg.x0, reg.y0, reg.x1, reg.y1, true); grow_region(reg, reg.x0, reg.y0, reg.x1, reg.y1, true);
@ -1292,13 +1340,15 @@ class HeAPPlacer
if (reg.x1 < p->max_x) { if (reg.x1 < p->max_x) {
bool over_occ_x = false; bool over_occ_x = false;
for (int y1 = reg.y0; y1 <= reg.y1; y1++) { for (int y1 = reg.y0; y1 <= reg.y1; y1++) {
if (occ_at(reg.x1 + 1, y1) > bels_at(reg.x1 + 1, y1)) { for (size_t t = 0; t < beltype.size(); t++) {
if (occ_at(reg.x1 + 1, y1, t) > bels_at(reg.x1 + 1, y1, t)) {
// log_info("(%d, %d) occ %d bels %d\n", reg.x1+ 1, y1, occ_at(reg.x1 + 1, y1), // log_info("(%d, %d) occ %d bels %d\n", reg.x1+ 1, y1, occ_at(reg.x1 + 1, y1),
// bels_at(reg.x1 + 1, y1)); // bels_at(reg.x1 + 1, y1));
over_occ_x = true; over_occ_x = true;
break; break;
} }
} }
}
if (over_occ_x) { if (over_occ_x) {
expanded = true; expanded = true;
grow_region(reg, reg.x0, reg.y0, reg.x1 + 1, reg.y1); grow_region(reg, reg.x0, reg.y0, reg.x1 + 1, reg.y1);
@ -1308,13 +1358,15 @@ class HeAPPlacer
if (reg.y1 < p->max_y) { if (reg.y1 < p->max_y) {
bool over_occ_y = false; bool over_occ_y = false;
for (int x1 = reg.x0; x1 <= reg.x1; x1++) { for (int x1 = reg.x0; x1 <= reg.x1; x1++) {
if (occ_at(x1, reg.y1 + 1) > bels_at(x1, reg.y1 + 1)) { for (size_t t = 0; t < beltype.size(); t++) {
if (occ_at(x1, reg.y1 + 1, t) > bels_at(x1, reg.y1 + 1, t)) {
// log_info("(%d, %d) occ %d bels %d\n", x1, reg.y1 + 1, occ_at(x1, reg.y1 + 1), // log_info("(%d, %d) occ %d bels %d\n", x1, reg.y1 + 1, occ_at(x1, reg.y1 + 1),
// bels_at(x1, reg.y1 + 1)); // bels_at(x1, reg.y1 + 1));
over_occ_y = true; over_occ_y = true;
break; break;
} }
} }
}
if (over_occ_y) { if (over_occ_y) {
expanded = true; expanded = true;
grow_region(reg, reg.x0, reg.y0, reg.x1, reg.y1 + 1); grow_region(reg, reg.x0, reg.y0, reg.x1, reg.y1 + 1);
@ -1340,6 +1392,8 @@ class HeAPPlacer
auto &reg = regions.at(rid); auto &reg = regions.at(rid);
while (reg.overused()) { while (reg.overused()) {
bool changed = false; bool changed = false;
// 2 x units for every 1 y unit to account for INT gaps between CLBs
for (int j = 0; j < 2; j++) {
if (reg.x0 > 0) { if (reg.x0 > 0) {
grow_region(reg, reg.x0 - 1, reg.y0, reg.x1, reg.y1); grow_region(reg, reg.x0 - 1, reg.y0, reg.x1, reg.y1);
changed = true; changed = true;
@ -1352,6 +1406,7 @@ class HeAPPlacer
if (!reg.overused()) if (!reg.overused())
break; break;
} }
}
if (reg.y0 > 0) { if (reg.y0 > 0) {
grow_region(reg, reg.x0, reg.y0 - 1, reg.x1, reg.y1); grow_region(reg, reg.x0, reg.y0 - 1, reg.x1, reg.y1);
changed = true; changed = true;
@ -1365,10 +1420,11 @@ class HeAPPlacer
break; break;
} }
if (!changed) { if (!changed) {
for (auto bt : sorted(beltype)) {
if (reg.cells > reg.bels) if (reg.cells > reg.bels)
log_error("Failed to expand region (%d, %d) |_> (%d, %d) of %d %ss\n", reg.x0, reg.y0, log_error("Failed to expand region (%d, %d) |_> (%d, %d) of %d %ss\n", reg.x0, reg.y0,
reg.x1, reg.y1, reg.cells, beltype.c_str(ctx)); reg.x1, reg.y1, reg.cells.at(type_index.at(bt)), bt.c_str(ctx));
else }
break; break;
} }
} }
@ -1388,7 +1444,8 @@ class HeAPPlacer
for (int x = r.x0; x <= r.x1; x++) { for (int x = r.x0; x <= r.x1; x++) {
for (int y = r.y0; y <= r.y1; y++) { for (int y = r.y0; y <= r.y1; y++) {
std::copy(cal.at(x).at(y).begin(), cal.at(x).at(y).end(), std::back_inserter(cut_cells)); std::copy(cal.at(x).at(y).begin(), cal.at(x).at(y).end(), std::back_inserter(cut_cells));
total_bels += bels_at(x, y); for (size_t t = 0; t < beltype.size(); t++)
total_bels += bels_at(x, y, t);
} }
} }
for (auto &cell : cut_cells) { for (auto &cell : cut_cells) {
@ -1410,9 +1467,11 @@ class HeAPPlacer
break; break;
pivot++; pivot++;
} }
if (pivot == int(cut_cells.size())) if (pivot >= int(cut_cells.size())) {
pivot = int(cut_cells.size()) - 1; pivot = int(cut_cells.size()) - 1;
// log_info("orig pivot %d lc %d rc %d\n", pivot, pivot_cells, r.cells - pivot_cells); }
// log_info("orig pivot %d/%d lc %d rc %d\n", pivot, int(cut_cells.size()), pivot_cells, total_cells -
// pivot_cells);
// Find the clearance required either side of the pivot // Find the clearance required either side of the pivot
int clearance_l = 0, clearance_r = 0; int clearance_l = 0, clearance_r = 0;
@ -1438,7 +1497,8 @@ class HeAPPlacer
while (trimmed_l < (dir ? r.y1 : r.x1)) { while (trimmed_l < (dir ? r.y1 : r.x1)) {
bool have_bels = false; bool have_bels = false;
for (int i = dir ? r.x0 : r.y0; i <= (dir ? r.x1 : r.y1); i++) for (int i = dir ? r.x0 : r.y0; i <= (dir ? r.x1 : r.y1); i++)
if (bels_at(dir ? i : trimmed_l, dir ? trimmed_l : i) > 0) { for (size_t t = 0; t < beltype.size(); t++)
if (bels_at(dir ? i : trimmed_l, dir ? trimmed_l : i, t) > 0) {
have_bels = true; have_bels = true;
break; break;
} }
@ -1449,7 +1509,8 @@ class HeAPPlacer
while (trimmed_r > (dir ? r.y0 : r.x0)) { while (trimmed_r > (dir ? r.y0 : r.x0)) {
bool have_bels = false; bool have_bels = false;
for (int i = dir ? r.x0 : r.y0; i <= (dir ? r.x1 : r.y1); i++) for (int i = dir ? r.x0 : r.y0; i <= (dir ? r.x1 : r.y1); i++)
if (bels_at(dir ? i : trimmed_r, dir ? trimmed_r : i) > 0) { for (size_t t = 0; t < beltype.size(); t++)
if (bels_at(dir ? i : trimmed_r, dir ? trimmed_r : i, t) > 0) {
have_bels = true; have_bels = true;
break; break;
} }
@ -1462,50 +1523,94 @@ class HeAPPlacer
return {}; return {};
// Now find the initial target cut that minimises utilisation imbalance, whilst // Now find the initial target cut that minimises utilisation imbalance, whilst
// meeting the clearance requirements for any large macros // meeting the clearance requirements for any large macros
int left_cells = pivot_cells, right_cells = total_cells - pivot_cells; std::vector<int> left_cells_v(beltype.size(), 0), right_cells_v(beltype.size(), 0);
int left_bels = 0, right_bels = total_bels; std::vector<int> left_bels_v(beltype.size(), 0), right_bels_v(r.bels);
for (int i = 0; i <= pivot; i++)
left_cells_v.at(type_index.at(cut_cells.at(i)->type)) +=
p->chain_size.count(cut_cells.at(i)->name) ? p->chain_size.at(cut_cells.at(i)->name) : 1;
for (int i = pivot + 1; i < int(cut_cells.size()); i++)
right_cells_v.at(type_index.at(cut_cells.at(i)->type)) +=
p->chain_size.count(cut_cells.at(i)->name) ? p->chain_size.at(cut_cells.at(i)->name) : 1;
int best_tgt_cut = -1; int best_tgt_cut = -1;
double best_deltaU = std::numeric_limits<double>::max(); double best_deltaU = std::numeric_limits<double>::max();
std::pair<int, int> target_cut_bels; // std::pair<int, int> target_cut_bels;
std::vector<int> slither_bels(beltype.size(), 0);
for (int i = trimmed_l; i <= trimmed_r; i++) { for (int i = trimmed_l; i <= trimmed_r; i++) {
int slither_bels = 0; for (size_t t = 0; t < beltype.size(); t++)
slither_bels.at(t) = 0;
for (int j = dir ? r.x0 : r.y0; j <= (dir ? r.x1 : r.y1); j++) { for (int j = dir ? r.x0 : r.y0; j <= (dir ? r.x1 : r.y1); j++) {
slither_bels += dir ? bels_at(j, i) : bels_at(i, j); for (size_t t = 0; t < beltype.size(); t++)
slither_bels.at(t) += dir ? bels_at(j, i, t) : bels_at(i, j, t);
} }
left_bels += slither_bels; for (size_t t = 0; t < beltype.size(); t++) {
right_bels -= slither_bels; left_bels_v.at(t) += slither_bels.at(t);
right_bels_v.at(t) -= slither_bels.at(t);
}
if (((i - trimmed_l) + 1) >= clearance_l && ((trimmed_r - i) + 1) >= clearance_r) { if (((i - trimmed_l) + 1) >= clearance_l && ((trimmed_r - i) + 1) >= clearance_r) {
// Solution is potentially valid // Solution is potentially valid
double aU = double aU = 0;
std::abs(double(left_cells) / double(left_bels) - double(right_cells) / double(right_bels)); for (size_t t = 0; t < beltype.size(); t++)
aU += (left_cells_v.at(t) + right_cells_v.at(t)) *
std::abs(double(left_cells_v.at(t)) / double(std::max(left_bels_v.at(t), 1)) -
double(right_cells_v.at(t)) / double(std::max(right_bels_v.at(t), 1)));
if (aU < best_deltaU) { if (aU < best_deltaU) {
best_deltaU = aU; best_deltaU = aU;
best_tgt_cut = i; best_tgt_cut = i;
target_cut_bels = std::make_pair(left_bels, right_bels);
} }
} }
} }
if (best_tgt_cut == -1) if (best_tgt_cut == -1)
return {}; return {};
left_bels = target_cut_bels.first; // left_bels = target_cut_bels.first;
right_bels = target_cut_bels.second; // right_bels = target_cut_bels.second;
// log_info("pivot %d target cut %d lc %d lb %d rc %d rb %d\n", pivot, best_tgt_cut, left_cells, left_bels, for (size_t t = 0; t < beltype.size(); t++) {
// right_cells, right_bels); left_bels_v.at(t) = 0;
right_bels_v.at(t) = 0;
}
for (int x = r.x0; x <= (dir ? r.x1 : best_tgt_cut); x++)
for (int y = r.y0; y <= (dir ? best_tgt_cut : r.y1); y++) {
for (size_t t = 0; t < beltype.size(); t++) {
left_bels_v.at(t) += bels_at(x, y, t);
}
}
for (int x = dir ? r.x0 : (best_tgt_cut + 1); x <= r.x1; x++)
for (int y = dir ? (best_tgt_cut + 1) : r.y0; y <= r.y1; y++) {
for (size_t t = 0; t < beltype.size(); t++) {
right_bels_v.at(t) += bels_at(x, y, t);
}
}
if (std::accumulate(left_bels_v.begin(), left_bels_v.end(), 0) == 0 ||
std::accumulate(right_bels_v.begin(), right_bels_v.end(), 0) == 0)
return {};
// log_info("pivot %d target cut %d lc %d lb %d rc %d rb %d\n", pivot, best_tgt_cut,
// std::accumulate(left_cells_v.begin(), left_cells_v.end(), 0), std::accumulate(left_bels_v.begin(),
// left_bels_v.end(), 0),
// std::accumulate(right_cells_v.begin(), right_cells_v.end(), 0),
// std::accumulate(right_bels_v.begin(), right_bels_v.end(), 0));
// Peturb the source cut to eliminate overutilisation // Peturb the source cut to eliminate overutilisation
while (pivot > 0 && (double(left_cells) / double(left_bels) > double(right_cells) / double(right_bels))) { auto is_part_overutil = [&](bool r) {
double delta = 0;
for (size_t t = 0; t < left_cells_v.size(); t++) {
delta += double(left_cells_v.at(t)) / double(std::max(left_bels_v.at(t), 1)) -
double(right_cells_v.at(t)) / double(std::max(right_bels_v.at(t), 1));
}
return r ? delta < 0 : delta > 0;
};
while (pivot > 0 && is_part_overutil(false)) {
auto &move_cell = cut_cells.at(pivot); auto &move_cell = cut_cells.at(pivot);
int size = p->chain_size.count(move_cell->name) ? p->chain_size.at(move_cell->name) : 1; int size = p->chain_size.count(move_cell->name) ? p->chain_size.at(move_cell->name) : 1;
left_cells -= size; left_cells_v.at(type_index.at(cut_cells.at(pivot)->type)) -= size;
right_cells += size; right_cells_v.at(type_index.at(cut_cells.at(pivot)->type)) += size;
pivot--; pivot--;
} }
while (pivot < int(cut_cells.size()) - 1 && while (pivot < int(cut_cells.size()) - 1 && is_part_overutil(true)) {
(double(left_cells) / double(left_bels) < double(right_cells) / double(right_bels))) {
auto &move_cell = cut_cells.at(pivot + 1); auto &move_cell = cut_cells.at(pivot + 1);
int size = p->chain_size.count(move_cell->name) ? p->chain_size.at(move_cell->name) : 1; int size = p->chain_size.count(move_cell->name) ? p->chain_size.at(move_cell->name) : 1;
left_cells += size; left_cells_v.at(type_index.at(cut_cells.at(pivot)->type)) += size;
right_cells -= size; right_cells_v.at(type_index.at(cut_cells.at(pivot)->type)) -= size;
pivot++; pivot++;
} }
// log_info("peturbed pivot %d lc %d lb %d rc %d rb %d\n", pivot, left_cells, left_bels, right_cells, // log_info("peturbed pivot %d lc %d lb %d rc %d rb %d\n", pivot, left_cells, left_bels, right_cells,
@ -1577,15 +1682,15 @@ class HeAPPlacer
rl.y0 = r.y0; rl.y0 = r.y0;
rl.x1 = dir ? r.x1 : best_tgt_cut; rl.x1 = dir ? r.x1 : best_tgt_cut;
rl.y1 = dir ? best_tgt_cut : r.y1; rl.y1 = dir ? best_tgt_cut : r.y1;
rl.cells = left_cells; rl.cells = left_cells_v;
rl.bels = left_bels; rl.bels = left_bels_v;
rr.id = int(regions.size()) + 1; rr.id = int(regions.size()) + 1;
rr.x0 = dir ? r.x0 : (best_tgt_cut + 1); rr.x0 = dir ? r.x0 : (best_tgt_cut + 1);
rr.y0 = dir ? (best_tgt_cut + 1) : r.y0; rr.y0 = dir ? (best_tgt_cut + 1) : r.y0;
rr.x1 = r.x1; rr.x1 = r.x1;
rr.y1 = r.y1; rr.y1 = r.y1;
rr.cells = right_cells; rr.cells = right_cells_v;
rr.bels = right_bels; rr.bels = right_bels_v;
regions.push_back(rl); regions.push_back(rl);
regions.push_back(rr); regions.push_back(rr);
for (int x = rl.x0; x <= rl.x1; x++) for (int x = rl.x0; x <= rl.x1; x++)
@ -1611,6 +1716,7 @@ PlacerHeapCfg::PlacerHeapCfg(Context *ctx)
timingWeight = ctx->setting<int>("placerHeap/timingWeight", 10); timingWeight = ctx->setting<int>("placerHeap/timingWeight", 10);
timing_driven = ctx->setting<bool>("timing_driven"); timing_driven = ctx->setting<bool>("timing_driven");
solverTolerance = 1e-5; solverTolerance = 1e-5;
placeAllAtOnce = false;
} }
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END

View File

@ -40,8 +40,13 @@ struct PlacerHeapCfg
float timingWeight; float timingWeight;
bool timing_driven; bool timing_driven;
float solverTolerance; float solverTolerance;
bool placeAllAtOnce;
// These cell types will be randomly locked to prevent singular matrices
std::unordered_set<IdString> ioBufTypes; std::unordered_set<IdString> ioBufTypes;
// These cell types are part of the same unit (e.g. slices split into
// components) so will always be spread together
std::vector<std::unordered_set<IdString>> cellGroups;
}; };
extern bool placer_heap(Context *ctx, PlacerHeapCfg cfg); extern bool placer_heap(Context *ctx, PlacerHeapCfg cfg);