Skip to content

Commit 62b63f8

Browse files
authored
Merge pull request The-OpenROAD-Project#9310 from The-OpenROAD-Project-staging/mbff-row-col
gpl: just use the bit count and avoid row/col computation
2 parents c7fa950 + 9b0fdf2 commit 62b63f8

File tree

2 files changed

+23
-48
lines changed

2 files changed

+23
-48
lines changed

src/gpl/src/mbff.cpp

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,6 @@ float MBFF::GetDistAR(const Point& a, const Point& b, const float AR)
178178
return (abs(a.x - b.x) / AR + abs(a.y - b.y));
179179
}
180180

181-
int MBFF::GetRows(const int slot_cnt, const Mask& array_mask)
182-
{
183-
const int idx = GetBitIdx(slot_cnt);
184-
185-
const std::vector<float>& ys = slot_to_tray_y_[array_mask][idx];
186-
const std::set<float> vals(ys.begin(), ys.end());
187-
188-
return vals.size();
189-
}
190-
191181
int MBFF::GetBitCnt(const int bit_idx)
192182
{
193183
return (1 << bit_idx);
@@ -1322,15 +1312,14 @@ double MBFF::RunILP(const std::vector<Flop>& flops,
13221312
}
13231313

13241314
void MBFF::GetSlots(const Point& tray,
1325-
const int rows,
1326-
const int cols,
1315+
const int bit_cnt,
13271316
std::vector<Point>& slots,
13281317
const Mask& array_mask)
13291318
{
13301319
slots.clear();
1331-
const int idx = GetBitIdx(rows * cols);
1320+
const int idx = GetBitIdx(bit_cnt);
13321321
const Point center = GetTrayCenter(array_mask, idx);
1333-
for (int i = 0; i < rows * cols; i++) {
1322+
for (int i = 0; i < bit_cnt; i++) {
13341323
slots.push_back({tray.x + slot_to_tray_x_[array_mask][idx][i] - center.x,
13351324
tray.y + slot_to_tray_y_[array_mask][idx][i] - center.y});
13361325
}
@@ -1541,17 +1530,15 @@ void MBFF::RunCapacitatedKMeans(const std::vector<Flop>& flops,
15411530
{
15421531
cluster.clear();
15431532
const int num_flops = flops.size();
1544-
const int rows = GetRows(sz, array_mask);
1545-
const int cols = sz / rows;
15461533
const int num_trays = (num_flops + (sz - 1)) / sz;
15471534

15481535
for (int i = 0; i < iter; i++) {
15491536
MinCostFlow(flops, trays, sz, cluster);
15501537
const float delta = RunLP(flops, trays, cluster);
15511538

15521539
for (int j = 0; j < num_trays; j++) {
1553-
GetSlots(trays[j].pt, rows, cols, trays[j].slots, array_mask);
1554-
for (int k = 0; k < rows * cols; k++) {
1540+
GetSlots(trays[j].pt, sz, trays[j].slots, array_mask);
1541+
for (int k = 0; k < sz; k++) {
15551542
trays[j].cand[k] = -1;
15561543
}
15571544
}
@@ -1600,18 +1587,16 @@ void MBFF::RunMultistart(
16001587
for (int i = 1; i < num_sizes_; i++) {
16011588
if (best_master_[array_mask][i] != nullptr) {
16021589
for (int j = 0; j < 5; j++) {
1603-
const int rows = GetRows(GetBitCnt(i), array_mask);
1604-
const int cols = GetBitCnt(i) / rows;
1590+
const int bit_cnt = GetBitCnt(i);
16051591
const int num_trays = (num_flops + (GetBitCnt(i) - 1)) / GetBitCnt(i);
16061592

16071593
for (int k = 0; k < num_trays; k++) {
16081594
GetSlots(start_trays[i][j][k].pt,
1609-
rows,
1610-
cols,
1595+
bit_cnt,
16111596
start_trays[i][j][k].slots,
16121597
array_mask);
1613-
start_trays[i][j][k].cand.reserve(rows * cols);
1614-
for (int idx = 0; idx < rows * cols; idx++) {
1598+
start_trays[i][j][k].cand.reserve(bit_cnt);
1599+
for (int idx = 0; idx < bit_cnt; idx++) {
16151600
start_trays[i][j][k].cand.emplace_back(-1);
16161601
}
16171602
}
@@ -1620,14 +1605,13 @@ void MBFF::RunMultistart(
16201605
}
16211606

16221607
for (const auto& [bit_idx, tray_idx] : ind) {
1623-
const int rows = GetRows(GetBitCnt(bit_idx), array_mask);
1624-
const int cols = GetBitCnt(bit_idx) / rows;
1608+
const int bit_cnt = GetBitCnt(bit_idx);
16251609

16261610
std::vector<std::pair<int, int>> tmp_cluster;
16271611

16281612
RunCapacitatedKMeans(flops,
16291613
start_trays[bit_idx][tray_idx],
1630-
rows * cols,
1614+
bit_cnt,
16311615
8,
16321616
tmp_cluster,
16331617
array_mask);
@@ -2042,17 +2026,17 @@ float MBFF::RunClustering(const std::vector<Flop>& flops,
20422026
for (int t = 0; t < num_pointsets; t++) {
20432027
all_start_trays[t].resize(num_sizes_);
20442028
for (int i = 1; i < num_sizes_; i++) {
2045-
if (best_master_[array_mask][i] != nullptr) {
2046-
const int rows = GetRows(GetBitCnt(i), array_mask);
2047-
const int cols = GetBitCnt(i) / rows;
2048-
const float AR = (cols * single_bit_width_ * norm_area_[i])
2049-
/ (rows * single_bit_height_);
2029+
odb::dbMaster* master = best_master_[array_mask][i];
2030+
if (master != nullptr) {
2031+
const float aspect_ratio
2032+
= master->getWidth() / static_cast<float>(master->getHeight());
20502033
const int num_trays
20512034
= (pointsets[t].size() + (GetBitCnt(i) - 1)) / GetBitCnt(i);
20522035
all_start_trays[t][i].resize(5);
20532036
for (int j = 0; j < 5; j++) {
20542037
// running in parallel ==> not reproducible
2055-
GetStartTrays(pointsets[t], num_trays, AR, all_start_trays[t][i][j]);
2038+
GetStartTrays(
2039+
pointsets[t], num_trays, aspect_ratio, all_start_trays[t][i][j]);
20562040
}
20572041
}
20582042
}
@@ -2071,28 +2055,21 @@ float MBFF::RunClustering(const std::vector<Flop>& flops,
20712055
const int num_flops = pointsets[t].size();
20722056
for (int i = 1; i < num_sizes_; i++) {
20732057
if (best_master_[array_mask][i] != nullptr) {
2074-
const int rows = GetRows(GetBitCnt(i), array_mask),
2075-
cols = GetBitCnt(i) / rows;
2058+
const int bit_cnt = GetBitCnt(i);
20762059
const int num_trays = (num_flops + (GetBitCnt(i) - 1)) / GetBitCnt(i);
20772060

20782061
for (int j = 0; j < num_trays; j++) {
2079-
GetSlots(cur_trays[i][j].pt,
2080-
rows,
2081-
cols,
2082-
cur_trays[i][j].slots,
2083-
array_mask);
2062+
GetSlots(
2063+
cur_trays[i][j].pt, bit_cnt, cur_trays[i][j].slots, array_mask);
20842064
}
20852065

20862066
std::vector<std::pair<int, int>> cluster;
20872067
RunCapacitatedKMeans(
20882068
pointsets[t], cur_trays[i], GetBitCnt(i), 35, cluster, array_mask);
20892069
MinCostFlow(pointsets[t], cur_trays[i], GetBitCnt(i), cluster);
20902070
for (int j = 0; j < num_trays; j++) {
2091-
GetSlots(cur_trays[i][j].pt,
2092-
rows,
2093-
cols,
2094-
cur_trays[i][j].slots,
2095-
array_mask);
2071+
GetSlots(
2072+
cur_trays[i][j].pt, bit_cnt, cur_trays[i][j].slots, array_mask);
20962073
}
20972074
}
20982075
}

src/gpl/src/mbff.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class MBFF
9696
const sta::LibertyCell* getLibertyCell(const sta::Cell* cell);
9797
float GetDist(const Point& a, const Point& b);
9898
float GetDistAR(const Point& a, const Point& b, float AR);
99-
int GetRows(int slot_cnt, const Mask& array_mask);
10099
int GetBitCnt(int bit_idx);
101100
int GetBitIdx(int bit_cnt);
102101

@@ -147,8 +146,7 @@ class MBFF
147146
Point GetTrayCenter(const Mask& array_mask, int idx);
148147
// get slots w.r.t. tray center
149148
void GetSlots(const Point& tray,
150-
int rows,
151-
int cols,
149+
int bit_cnt,
152150
std::vector<Point>& slots,
153151
const Mask& array_mask);
154152

0 commit comments

Comments
 (0)