Skip to content

Commit 287fefd

Browse files
committed
Merge branch 'master' into mpl-notch-penalty
2 parents 42676d1 + ea001a1 commit 287fefd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2208
-927
lines changed

src/mpl/src/SimulatedAnnealingCore.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -707,38 +707,40 @@ void SimulatedAnnealingCore<T>::fastSA()
707707
{
708708
float cost = calNormCost();
709709
float pre_cost = cost;
710-
float delta_cost = 0.0;
711710
int step = 1;
712711
float temperature = init_temperature_;
713712
const float min_t = 1e-10;
714713
const float t_factor
715714
= std::exp(std::log(min_t / init_temperature_) / max_num_step_);
716715

717-
if (isValid()) {
718-
updateBestValidResult(cost);
719-
}
716+
updateBestResult(cost);
720717

721718
while (step <= max_num_step_) {
722719
for (int i = 0; i < num_perturb_per_step_; i++) {
723720
saveState();
724721
perturb();
725722
cost = calNormCost();
726723

727-
const bool keep_result
728-
= cost < pre_cost
729-
|| best_valid_result_.sequence_pair.pos_sequence.empty();
730-
if (isValid() && keep_result) {
731-
updateBestValidResult(cost);
724+
const bool is_valid = isValid();
725+
const bool improved = cost < pre_cost || best_result_.empty();
726+
if ((!is_best_result_valid_ || is_valid) && improved) {
727+
updateBestResult(cost);
728+
is_best_result_valid_ = is_valid;
732729
}
733730

734-
delta_cost = cost - pre_cost;
735-
const float num = distribution_(generator_);
736-
const float prob
737-
= (delta_cost > 0.0) ? std::exp((-1) * delta_cost / temperature) : 1;
738-
if (num < prob) {
731+
const float delta_cost = cost - pre_cost;
732+
if (delta_cost <= 0) {
733+
// always accept improvements
739734
pre_cost = cost;
740735
} else {
741-
restoreState();
736+
// probabilistically accept degradations for hill climbing
737+
const float num = distribution_(generator_);
738+
const float prob = std::exp(-delta_cost / temperature);
739+
if (num < prob) {
740+
pre_cost = cost;
741+
} else {
742+
restoreState();
743+
}
742744
}
743745
}
744746

@@ -754,40 +756,42 @@ void SimulatedAnnealingCore<T>::fastSA()
754756
graphics_->doNotSkip();
755757
}
756758
calPenalty();
759+
cost = calNormCost();
757760

758-
if (!best_valid_result_.sequence_pair.pos_sequence.empty()
759-
&& (!isValid() || best_valid_result_.cost < calNormCost())) {
760-
useBestValidResult();
761+
const bool is_valid = isValid();
762+
const bool improved = cost < best_result_.cost || best_result_.empty();
763+
if ((is_best_result_valid_ && !is_valid) || !improved) {
764+
useBestResult();
761765
}
762766
}
763767

764768
template <class T>
765-
void SimulatedAnnealingCore<T>::updateBestValidResult(const float cost)
769+
void SimulatedAnnealingCore<T>::updateBestResult(const float cost)
766770
{
767-
best_valid_result_.sequence_pair.pos_sequence = pos_seq_;
768-
best_valid_result_.sequence_pair.neg_sequence = neg_seq_;
771+
best_result_.sequence_pair.pos_sequence = pos_seq_;
772+
best_result_.sequence_pair.neg_sequence = neg_seq_;
769773

770774
if constexpr (std::is_same_v<T, SoftMacro>) {
771775
for (const int macro_id : pos_seq_) {
772776
SoftMacro& macro = macros_[macro_id];
773-
best_valid_result_.macro_id_to_width[macro_id] = macro.getWidth();
777+
best_result_.macro_id_to_width[macro_id] = macro.getWidth();
774778
}
775779
}
776780

777-
best_valid_result_.cost = cost;
781+
best_result_.cost = cost;
778782
}
779783

780784
template <class T>
781-
void SimulatedAnnealingCore<T>::useBestValidResult()
785+
void SimulatedAnnealingCore<T>::useBestResult()
782786
{
783-
pos_seq_ = best_valid_result_.sequence_pair.pos_sequence;
784-
neg_seq_ = best_valid_result_.sequence_pair.neg_sequence;
787+
pos_seq_ = best_result_.sequence_pair.pos_sequence;
788+
neg_seq_ = best_result_.sequence_pair.neg_sequence;
785789

786790
if constexpr (std::is_same_v<T, SoftMacro>) {
787791
for (const int macro_id : pos_seq_) {
788792
SoftMacro& macro = macros_[macro_id];
789793
const float valid_result_width
790-
= best_valid_result_.macro_id_to_width.at(macro_id);
794+
= best_result_.macro_id_to_width.at(macro_id);
791795

792796
if (macro.isMacroCluster()) {
793797
const float valid_result_height = macro.getArea() / valid_result_width;

src/mpl/src/SimulatedAnnealingCore.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class SimulatedAnnealingCore
9292
protected:
9393
struct Result
9494
{
95+
bool empty() const { return sequence_pair.pos_sequence.empty(); }
96+
9597
float cost{std::numeric_limits<float>::max()};
9698
SequencePair sequence_pair;
9799
// [Only for SoftMacro] The same sequence pair can represent different
@@ -105,8 +107,8 @@ class SimulatedAnnealingCore
105107
const BoundaryRegionList& regions);
106108
void initSequencePair();
107109
void setDieArea(const Rect& die_area);
108-
void updateBestValidResult(float cost);
109-
void useBestValidResult();
110+
void updateBestResult(float cost);
111+
void useBestResult();
110112

111113
virtual float calNormCost() const = 0;
112114
virtual void calPenalty() = 0;
@@ -207,7 +209,8 @@ class SimulatedAnnealingCore
207209
MplObserver* graphics_ = nullptr;
208210
odb::dbBlock* block_;
209211

210-
Result best_valid_result_;
212+
Result best_result_;
213+
bool is_best_result_valid_ = false;
211214

212215
std::vector<float> cost_list_; // store the cost in the list
213216
std::vector<float> T_list_; // store the temperature

src/mpl/test/boundary_push1.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 4 ;
186-
- MACRO_1 HM_100x100_1x1 + FIXED ( 600 610 ) FS ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 600 241970 ) FS ;
188-
- MACRO_3 HM_100x100_1x1 + FIXED ( 239440 241970 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 610 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 239440 610 ) S ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 600 241970 ) S ;
188+
- MACRO_3 HM_100x100_1x1 + FIXED ( 600 610 ) S ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 241970 ) S ;
190190
END COMPONENTS
191191
PINS 4 ;
192192
- io_1 + NET io_1 + DIRECTION INPUT + USE SIGNAL ;

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 ( 239440 20770 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 600 20770 ) FS ;
188-
- MACRO_3 HM_100x100_1x1 + FIXED ( 239440 221810 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 600 221810 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 600 20770 ) FS ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 239440 221810 ) FS ;
188+
- MACRO_3 HM_100x100_1x1 + FIXED ( 600 221810 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 20770 ) FS ;
190190
- _001_ DFF_X1 + PLACED ( 216791 219800 ) N ;
191191
- _002_ DFF_X1 + PLACED ( 216791 219800 ) N ;
192192
- _003_ DFF_X1 + PLACED ( 216791 219800 ) 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 ( 220620 241970 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 19420 241970 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 19420 610 ) FS ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 220620 241970 ) FS ;
188188
- MACRO_3 HM_100x100_1x1 + FIXED ( 220620 610 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 19420 610 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 19420 241970 ) FS ;
190190
- _001_ DFF_X1 + PLACED ( 216791 219800 ) N ;
191191
- _002_ DFF_X1 + PLACED ( 216791 219800 ) N ;
192192
- _003_ DFF_X1 + PLACED ( 216791 219800 ) N ;

src/mpl/test/centralization1.defok

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ;
241241
TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ;
242242
TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ;
243243
COMPONENTS 1 ;
244-
- MACRO_1 HM_100x100_1x1 + FIXED ( 202100 202490 ) FS ;
244+
- MACRO_1 HM_100x100_1x1 + FIXED ( 202100 202490 ) S ;
245245
END COMPONENTS
246246
PINS 1 ;
247247
- io_1 + NET io_1 + DIRECTION INPUT + USE SIGNAL ;

src/mpl/test/clocked_macro.defok

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ;
339339
TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ;
340340
TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ;
341341
COMPONENTS 1 ;
342-
- U1 CLOCKED_MACRO + FIXED ( 17880 16610 ) FS ;
342+
- U1 CLOCKED_MACRO + FIXED ( 17880 16610 ) S ;
343343
END COMPONENTS
344344
NETS 3 ;
345345
- clk ( U1 CK ) + USE SIGNAL ;

0 commit comments

Comments
 (0)