Skip to content

Commit 5319993

Browse files
authored
Merge pull request #7136 from AcKoucher/mpl-fix-indexing
mpl, par: move to boost random number generator due to bug in STL
2 parents 25acd37 + 34c70c9 commit 5319993

13 files changed

+1734
-1736
lines changed

src/mpl/src/SACoreSoftMacro.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "SACoreSoftMacro.h"
55

66
#include <algorithm>
7+
#include <boost/random/uniform_int_distribution.hpp>
78
#include <cmath>
89
#include <map>
910
#include <set>
@@ -713,15 +714,17 @@ void SACoreSoftMacro::calNotchPenalty()
713714

714715
void SACoreSoftMacro::resizeOneCluster()
715716
{
716-
// TODO: See for explanation
717-
// https://github.com/The-OpenROAD-Project/OpenROAD/pull/6649
718-
float random_variable_0_1;
719-
do {
720-
random_variable_0_1 = distribution_(generator_);
721-
} while (random_variable_0_1 >= 1.0);
722-
723-
const int idx
724-
= static_cast<int>(std::floor(random_variable_0_1 * pos_seq_.size()));
717+
if (pos_seq_.empty()) {
718+
logger_->error(
719+
utl::MPL,
720+
51,
721+
"Position sequence array is empty, please report this internal error");
722+
}
723+
724+
boost::random::uniform_int_distribution<> index_distribution(
725+
0, pos_seq_.size() - 1);
726+
const int idx = index_distribution(generator_);
727+
725728
macro_id_ = idx;
726729
SoftMacro& src_macro = macros_[idx];
727730
if (src_macro.isMacroCluster()) {

src/mpl/src/SimulatedAnnealingCore.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "SimulatedAnnealingCore.h"
55

66
#include <algorithm>
7+
#include <boost/random/uniform_int_distribution.hpp>
78
#include <cmath>
89
#include <fstream>
910
#include <iostream>
@@ -601,27 +602,14 @@ void SimulatedAnnealingCore<T>::exchangeMacros()
601602
template <class T>
602603
void SimulatedAnnealingCore<T>::generateRandomIndices(int& index1, int& index2)
603604
{
604-
// TODO: See for explanation.
605-
// https://github.com/The-OpenROAD-Project/OpenROAD/pull/6649
606-
// This code is ugly on purpose to incentivize merging the proper
607-
// fix.
608-
float random_variable_0_1_index1;
609-
float random_variable_0_1_index2;
610-
do {
611-
random_variable_0_1_index1 = distribution_(generator_);
612-
random_variable_0_1_index2 = distribution_(generator_);
613-
} while (random_variable_0_1_index1 >= 1.0
614-
|| random_variable_0_1_index2 >= 1.0);
615-
616-
index1 = (int) (std::floor(random_variable_0_1_index1 * pos_seq_.size()));
617-
index2 = (int) (std::floor(random_variable_0_1_index2 * pos_seq_.size()));
605+
boost::random::uniform_int_distribution<> index_distribution(
606+
0, pos_seq_.size() - 1);
618607

619-
while (index1 == index2) {
620-
do {
621-
random_variable_0_1_index2 = distribution_(generator_);
622-
} while (random_variable_0_1_index2 >= 1.0);
608+
index1 = index_distribution(generator_);
609+
index2 = index_distribution(generator_);
623610

624-
index2 = (int) (std::floor(random_variable_0_1_index2 * pos_seq_.size()));
611+
while (index1 == index2) {
612+
index2 = index_distribution(generator_);
625613
}
626614
}
627615

src/mpl/src/object.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "object.h"
55

66
#include <algorithm>
7+
#include <boost/random/uniform_int_distribution.hpp>
78
#include <cmath>
89
#include <map>
910
#include <memory>
@@ -1239,15 +1240,11 @@ void SoftMacro::resizeRandomly(
12391240
if (width_list_.empty()) {
12401241
return;
12411242
}
1242-
// TODO: See for explanation
1243-
// https://github.com/The-OpenROAD-Project/OpenROAD/pull/6649
1244-
float random_variable_0_1;
1245-
do {
1246-
random_variable_0_1 = distribution(generator);
1247-
} while (random_variable_0_1 >= 1.0);
12481243

1249-
const int idx
1250-
= static_cast<int>(std::floor(random_variable_0_1 * width_list_.size()));
1244+
boost::random::uniform_int_distribution<> index_distribution(
1245+
0, width_list_.size() - 1);
1246+
const int idx = index_distribution(generator);
1247+
12511248
const float min_width = width_list_[idx].first;
12521249
const float max_width = width_list_[idx].second;
12531250
width_ = min_width + distribution(generator) * (max_width - min_width);

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 222090 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 600 222090 ) FS ;
188-
- MACRO_3 HM_100x100_1x1 + FIXED ( 239440 21050 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 600 21050 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 600 21050 ) S ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 239440 222090 ) FS ;
188+
- MACRO_3 HM_100x100_1x1 + FIXED ( 600 222090 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 239440 21050 ) 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: 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 ( 19420 242250 ) S ;
187-
- MACRO_2 HM_100x100_1x1 + FIXED ( 19420 890 ) FS ;
188-
- MACRO_3 HM_100x100_1x1 + FIXED ( 220620 242250 ) FS ;
189-
- MACRO_4 HM_100x100_1x1 + FIXED ( 220620 890 ) FS ;
186+
- MACRO_1 HM_100x100_1x1 + FIXED ( 19420 890 ) S ;
187+
- MACRO_2 HM_100x100_1x1 + FIXED ( 19420 242250 ) FS ;
188+
- MACRO_3 HM_100x100_1x1 + FIXED ( 220620 890 ) FS ;
189+
- MACRO_4 HM_100x100_1x1 + FIXED ( 220620 242250 ) 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)