Skip to content

Commit 7f649c1

Browse files
authored
Merge pull request #7932 from The-OpenROAD-Project-staging/mpl-bug-inconsistent-restore
mpl: inconsistent restore during annealing
2 parents 3bbfc26 + 8bc6814 commit 7f649c1

10 files changed

+874
-850
lines changed

src/mpl/src/SACoreHardMacro.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ void SACoreHardMacro::perturb()
117117
return;
118118
}
119119

120-
// Keep back up
121-
pre_pos_seq_ = pos_seq_;
122-
pre_neg_seq_ = neg_seq_;
123-
pre_width_ = width_;
124-
pre_height_ = height_;
125-
pre_outline_penalty_ = outline_penalty_;
126-
pre_wirelength_ = wirelength_;
127-
pre_guidance_penalty_ = guidance_penalty_;
128-
pre_fence_penalty_ = fence_penalty_;
129-
130120
// generate random number (0 - 1) to determine actions
131121
const float op = distribution_(generator_);
132122
const float action_prob_1 = pos_swap_prob_;
@@ -148,7 +138,6 @@ void SACoreHardMacro::perturb()
148138
exchangeMacros(); // exchange two macros in the sequence pair
149139
} else {
150140
action_id_ = 5;
151-
pre_macros_ = macros_;
152141
flipAllMacros();
153142
}
154143

@@ -158,7 +147,26 @@ void SACoreHardMacro::perturb()
158147
calPenalty();
159148
}
160149

161-
void SACoreHardMacro::restore()
150+
void SACoreHardMacro::saveState()
151+
{
152+
if (macros_.empty()) {
153+
return;
154+
}
155+
156+
pre_macros_ = macros_;
157+
pre_pos_seq_ = pos_seq_;
158+
pre_neg_seq_ = neg_seq_;
159+
160+
pre_width_ = width_;
161+
pre_height_ = height_;
162+
163+
pre_outline_penalty_ = outline_penalty_;
164+
pre_wirelength_ = wirelength_;
165+
pre_guidance_penalty_ = guidance_penalty_;
166+
pre_fence_penalty_ = fence_penalty_;
167+
}
168+
169+
void SACoreHardMacro::restoreState()
162170
{
163171
if (macros_.empty()) {
164172
return;
@@ -167,20 +175,20 @@ void SACoreHardMacro::restore()
167175
// To reduce the runtime, here we do not call PackFloorplan
168176
// again. So when we need to generate the final floorplan out,
169177
// we need to call PackFloorplan again at the end of SA process
170-
if (action_id_ == 5) {
171-
macros_ = pre_macros_;
172-
// macros_[macro_id_] = pre_macros_[macro_id_];
173-
} else if (action_id_ == 1) {
178+
if (action_id_ == 1) {
174179
pos_seq_ = pre_pos_seq_;
175180
} else if (action_id_ == 2) {
176181
neg_seq_ = pre_neg_seq_;
177-
} else {
182+
} else if (action_id_ == 3 || action_id_ == 4) {
178183
pos_seq_ = pre_pos_seq_;
179184
neg_seq_ = pre_neg_seq_;
180185
}
181186

187+
macros_ = pre_macros_;
188+
182189
width_ = pre_width_;
183190
height_ = pre_height_;
191+
184192
outline_penalty_ = pre_outline_penalty_;
185193
wirelength_ = pre_wirelength_;
186194
guidance_penalty_ = pre_guidance_penalty_;

src/mpl/src/SACoreHardMacro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class SACoreHardMacro : public SimulatedAnnealingCore<HardMacro>
5555
void calPenalty() override;
5656

5757
void perturb() override;
58-
void restore() override;
58+
void saveState() override;
59+
void restoreState() override;
5960
// actions used
6061
void flipAllMacros();
6162

src/mpl/src/SACoreSoftMacro.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,6 @@ void SACoreSoftMacro::perturb()
181181
return;
182182
}
183183

184-
// Keep back up
185-
pre_pos_seq_ = pos_seq_;
186-
pre_neg_seq_ = neg_seq_;
187-
pre_width_ = width_;
188-
pre_height_ = height_;
189-
pre_outline_penalty_ = outline_penalty_;
190-
pre_wirelength_ = wirelength_;
191-
pre_guidance_penalty_ = guidance_penalty_;
192-
pre_fence_penalty_ = fence_penalty_;
193-
pre_boundary_penalty_ = boundary_penalty_;
194-
pre_macro_blockage_penalty_ = macro_blockage_penalty_;
195-
pre_notch_penalty_ = notch_penalty_;
196-
197184
// generate random number (0 - 1) to determine actions
198185
const float op = distribution_(generator_);
199186
const float action_prob_1 = pos_swap_prob_;
@@ -215,7 +202,6 @@ void SACoreSoftMacro::perturb()
215202
exchangeMacros(); // exchange two macros in the sequence pair
216203
} else {
217204
action_id_ = 5;
218-
pre_macros_ = macros_;
219205
resizeOneCluster();
220206
}
221207

@@ -225,7 +211,29 @@ void SACoreSoftMacro::perturb()
225211
calPenalty();
226212
}
227213

228-
void SACoreSoftMacro::restore()
214+
void SACoreSoftMacro::saveState()
215+
{
216+
if (macros_.empty()) {
217+
return;
218+
}
219+
220+
pre_macros_ = macros_;
221+
pre_pos_seq_ = pos_seq_;
222+
pre_neg_seq_ = neg_seq_;
223+
224+
pre_width_ = width_;
225+
pre_height_ = height_;
226+
227+
pre_outline_penalty_ = outline_penalty_;
228+
pre_wirelength_ = wirelength_;
229+
pre_guidance_penalty_ = guidance_penalty_;
230+
pre_fence_penalty_ = fence_penalty_;
231+
pre_boundary_penalty_ = boundary_penalty_;
232+
pre_macro_blockage_penalty_ = macro_blockage_penalty_;
233+
pre_notch_penalty_ = notch_penalty_;
234+
}
235+
236+
void SACoreSoftMacro::restoreState()
229237
{
230238
if (macros_.empty()) {
231239
return;
@@ -234,19 +242,21 @@ void SACoreSoftMacro::restore()
234242
// To reduce the runtime, here we do not call PackFloorplan
235243
// again. So when we need to generate the final floorplan out,
236244
// we need to call PackFloorplan again at the end of SA process
237-
if (action_id_ == 5) {
238-
macros_[macro_id_] = pre_macros_[macro_id_];
239-
} else if (action_id_ == 1) {
245+
246+
if (action_id_ == 1) {
240247
pos_seq_ = pre_pos_seq_;
241248
} else if (action_id_ == 2) {
242249
neg_seq_ = pre_neg_seq_;
243-
} else {
250+
} else if (action_id_ == 3 || action_id_ == 4) {
244251
pos_seq_ = pre_pos_seq_;
245252
neg_seq_ = pre_neg_seq_;
246253
}
247254

255+
macros_ = pre_macros_;
256+
248257
width_ = pre_width_;
249258
height_ = pre_height_;
259+
250260
outline_penalty_ = pre_outline_penalty_;
251261
wirelength_ = pre_wirelength_;
252262
guidance_penalty_ = pre_guidance_penalty_;
@@ -539,7 +549,9 @@ void SACoreSoftMacro::calNotchPenalty()
539549
return;
540550
}
541551

542-
pre_macros_ = macros_;
552+
// Macros need to be saved (and restored) since alignMacroClusters and
553+
// fillDeadSpace move them
554+
std::vector<SoftMacro> pre_macros = macros_;
543555
// align macro clusters to reduce notches
544556
alignMacroClusters();
545557
// Fill dead space
@@ -709,7 +721,7 @@ void SACoreSoftMacro::calNotchPenalty()
709721
+= (y_grid[y_end_new] - y_grid[y_end]) * macros_[macro_id].getWidth();
710722
}
711723
}
712-
macros_ = pre_macros_;
724+
macros_ = pre_macros;
713725
// normalization
714726
notch_penalty_
715727
= notch_penalty_ / (outline_.getWidth() * outline_.getHeight());

src/mpl/src/SACoreSoftMacro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class SACoreSoftMacro : public SimulatedAnnealingCore<SoftMacro>
7878
void calPenalty() override;
7979

8080
void perturb() override;
81-
void restore() override;
81+
void saveState() override;
82+
void restoreState() override;
8283
// actions used
8384
void resizeOneCluster();
8485

src/mpl/src/SimulatedAnnealingCore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ void SimulatedAnnealingCore<T>::fastSA()
728728

729729
while (step <= max_num_step_) {
730730
for (int i = 0; i < num_perturb_per_step_; i++) {
731+
saveState();
731732
perturb();
732733
cost = calNormCost();
733734

@@ -745,7 +746,7 @@ void SimulatedAnnealingCore<T>::fastSA()
745746
if (num < prob) {
746747
pre_cost = cost;
747748
} else {
748-
restore();
749+
restoreState();
749750
}
750751
}
751752

src/mpl/src/SimulatedAnnealingCore.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class SimulatedAnnealingCore
122122
// operations
123123
void packFloorplan();
124124
virtual void perturb() = 0;
125-
virtual void restore() = 0;
125+
virtual void saveState() = 0;
126+
virtual void restoreState() = 0;
126127
// actions used
127128
void singleSeqSwap(bool pos);
128129
void doubleSeqSwap();

src/mpl/test/boundary_push2.defok

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ;
183183
TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ;
184184
TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ;
185185
COMPONENTS 54 ;
186-
- MACRO_1 HM_100x100_1x1 + FIXED ( 600 20770 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 239440 20770 ) FS ;
188-
- MACRO_3 HM_100x100_1x1 + FIXED ( 600 221810 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 221810 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 239440 221810 ) S ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 600 221810 ) FS ;
188+
- MACRO_3 HM_100x100_1x1 + FIXED ( 600 20770 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 20770 ) FS ;
190190
- _001_ DFF_X1 + PLACED ( 15591 18600 ) N ;
191191
- _002_ DFF_X1 + PLACED ( 15591 18600 ) N ;
192192
- _003_ DFF_X1 + PLACED ( 15591 18600 ) N ;

src/mpl/test/boundary_push3.defok

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ;
183183
TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ;
184184
TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ;
185185
COMPONENTS 54 ;
186-
- MACRO_1 HM_100x100_1x1 + FIXED ( 19420 610 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 220620 610 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 220620 610 ) S ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 19420 241970 ) FS ;
188188
- MACRO_3 HM_100x100_1x1 + FIXED ( 220620 241970 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 19420 241970 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 19420 610 ) FS ;
190190
- _001_ DFF_X1 + PLACED ( 15590 18601 ) N ;
191191
- _002_ DFF_X1 + PLACED ( 15590 18601 ) N ;
192192
- _003_ DFF_X1 + PLACED ( 15590 18601 ) N ;

0 commit comments

Comments
 (0)