Skip to content

Commit 4d5ad82

Browse files
authored
Merge pull request #8238 from The-OpenROAD-Project-staging/mpl-align-macros
mpl: accept macro alignment only if it improves the result
2 parents a64d3a6 + c2f3876 commit 4d5ad82

File tree

9 files changed

+2465
-2427
lines changed

9 files changed

+2465
-2427
lines changed

src/mpl/src/SACoreSoftMacro.cpp

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ void SACoreSoftMacro::run()
9494

9595
fastSA();
9696

97-
if (centralization_on_) {
97+
if (enhancements_on_) {
9898
attemptCentralization(calNormCost());
99+
if (centralization_was_reverted_) {
100+
attemptMacroClusterAlignment();
101+
}
99102
}
100103

101104
if (graphics_) {
@@ -554,11 +557,16 @@ void SACoreSoftMacro::calFixedMacrosPenalty()
554557
}
555558

556559
// Align macro clusters to reduce notch
557-
void SACoreSoftMacro::alignMacroClusters()
560+
void SACoreSoftMacro::attemptMacroClusterAlignment()
558561
{
559-
if (width_ > outline_.getWidth() || height_ > outline_.getHeight()) {
562+
if (!isValid()) {
560563
return;
561564
}
565+
566+
float pre_cost = calNormCost();
567+
// Cache current solution to allow reversal
568+
auto clusters_locations = getClustersLocations();
569+
562570
// update threshold value
563571
adjust_h_th_ = notch_h_th_;
564572
adjust_v_th_ = notch_v_th_;
@@ -597,6 +605,19 @@ void SACoreSoftMacro::alignMacroClusters()
597605
}
598606
}
599607
}
608+
609+
calPenalty();
610+
611+
// Revert macro alignemnt
612+
if (calNormCost() > pre_cost) {
613+
setClustersLocations(clusters_locations);
614+
615+
if (graphics_) {
616+
graphics_->saStep(macros_);
617+
}
618+
619+
calPenalty();
620+
}
600621
}
601622

602623
float SACoreSoftMacro::calSingleNotchPenalty(float width, float height)
@@ -984,6 +1005,33 @@ void SACoreSoftMacro::addBlockages(const std::vector<Rect>& blockages)
9841005
blockages_.insert(blockages_.end(), blockages.begin(), blockages.end());
9851006
}
9861007

1008+
std::vector<std::pair<float, float>> SACoreSoftMacro::getClustersLocations()
1009+
const
1010+
{
1011+
std::vector<std::pair<float, float>> clusters_locations(pos_seq_.size());
1012+
for (int id : pos_seq_) {
1013+
clusters_locations[id] = {macros_[id].getX(), macros_[id].getY()};
1014+
}
1015+
1016+
return clusters_locations;
1017+
}
1018+
1019+
void SACoreSoftMacro::setClustersLocations(
1020+
const std::vector<std::pair<float, float>>& clusters_locations)
1021+
{
1022+
if (clusters_locations.size() != pos_seq_.size()) {
1023+
logger_->error(MPL,
1024+
52,
1025+
"setClustersLocation called with a different numbers of "
1026+
"clusters of that in the sequence pair");
1027+
}
1028+
1029+
for (int& id : pos_seq_) {
1030+
macros_[id].setX(clusters_locations[id].first);
1031+
macros_[id].setY(clusters_locations[id].second);
1032+
}
1033+
}
1034+
9871035
void SACoreSoftMacro::attemptCentralization(const float pre_cost)
9881036
{
9891037
if (outline_penalty_ > 0) {
@@ -993,24 +1041,18 @@ void SACoreSoftMacro::attemptCentralization(const float pre_cost)
9931041
// In order to revert the centralization, we cache the current location
9941042
// of the clusters to avoid floating-point evilness when creating the
9951043
// x,y grid to fill the dead space by expanding mixed clusters.
996-
std::map<int, std::pair<float, float>> clusters_locations;
997-
998-
for (int& id : pos_seq_) {
999-
clusters_locations[id] = {macros_[id].getX(), macros_[id].getY()};
1000-
}
1044+
auto clusters_locations = getClustersLocations();
10011045

10021046
std::pair<float, float> offset((outline_.getWidth() - width_) / 2,
10031047
(outline_.getHeight() - height_) / 2);
10041048
moveFloorplan(offset);
1049+
calPenalty();
10051050

10061051
// revert centralization
10071052
if (calNormCost() > pre_cost) {
10081053
centralization_was_reverted_ = true;
10091054

1010-
for (int& id : pos_seq_) {
1011-
macros_[id].setX(clusters_locations[id].first);
1012-
macros_[id].setY(clusters_locations[id].second);
1013-
}
1055+
setClustersLocations(clusters_locations);
10141056

10151057
if (graphics_) {
10161058
graphics_->saStep(macros_);
@@ -1030,8 +1072,6 @@ void SACoreSoftMacro::moveFloorplan(const std::pair<float, float>& offset)
10301072
if (graphics_) {
10311073
graphics_->saStep(macros_);
10321074
}
1033-
1034-
calPenalty();
10351075
}
10361076

10371077
Tiling SACoreSoftMacro::computeOverlapShape(const Rect& rect_a,

src/mpl/src/SACoreSoftMacro.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>
6363
void initialize() override;
6464
// adjust the size of MixedCluster to fill the empty space
6565
void fillDeadSpace() override;
66-
void alignMacroClusters();
66+
void attemptMacroClusterAlignment();
6767
void addBlockages(const std::vector<Rect>& blockages);
6868

6969
bool centralizationWasReverted() { return centralization_was_reverted_; }
70-
void setCentralizationAttemptOn(bool centralization_on)
71-
{
72-
centralization_on_ = centralization_on;
73-
};
70+
71+
void enableEnhancements() { enhancements_on_ = true; };
7472

7573
private:
7674
float calNormCost() const override;
@@ -90,6 +88,9 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>
9088
void calMacroBlockagePenalty();
9189
void calFixedMacrosPenalty();
9290

91+
std::vector<std::pair<float, float>> getClustersLocations() const;
92+
void setClustersLocations(
93+
const std::vector<std::pair<float, float>>& clusters_locations);
9394
// Only for Cluster Placement:
9495
void attemptCentralization(float pre_cost);
9596
void moveFloorplan(const std::pair<float, float>& offset);
@@ -135,7 +136,7 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>
135136
// action prob
136137
float resize_prob_ = 0.0;
137138

138-
bool centralization_on_ = false;
139+
bool enhancements_on_ = false;
139140
bool centralization_was_reverted_ = false;
140141
};
141142

src/mpl/src/hier_rtlmp.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
16511651
logger_,
16521652
block_);
16531653
sa->setNumberOfSequencePairMacros(number_of_sequence_pair_macros);
1654-
sa->setCentralizationAttemptOn(true);
1654+
sa->enableEnhancements();
16551655
sa->setFences(fences);
16561656
sa->setGuides(guides);
16571657
sa->setNets(nets);
@@ -1707,9 +1707,6 @@ void HierRTLMP::placeChildren(Cluster* parent, bool ignore_std_cell_area)
17071707
logger_->error(MPL, 40, "Failed on cluster {}", parent->getName());
17081708
}
17091709
} else {
1710-
if (best_sa->centralizationWasReverted()) {
1711-
best_sa->alignMacroClusters();
1712-
}
17131710
best_sa->fillDeadSpace();
17141711

17151712
std::vector<SoftMacro> shaped_macros = best_sa->getMacros();

0 commit comments

Comments
 (0)