Skip to content

Commit 5305d93

Browse files
authored
Merge pull request #405 from MyskYko/rrr
update rrr
2 parents eaf974d + b1b1023 commit 5305d93

17 files changed

+1528
-659
lines changed

src/aig/gia/giaRrr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Gia_Man_t *Gia_ManRrr(Gia_Man_t *pGia, int iSeed, int nWords, int nTimeout, int
3535
Par.fOptOnInsert = fOptOnInsert;
3636
Par.fGreedy = fGreedy;
3737
rrr::Perform(&ntk, &Par);
38-
Gia_Man_t *pNew = rrr::CreateGia(&ntk);
38+
Gia_Man_t *pNew = rrr::CreateGia(&ntk, false);
3939
return pNew;
4040
}
4141

src/base/abci/abc.c

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46327,7 +46327,7 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4632746327
{
4632846328
Gia_Man_t *pNew;
4632946329
int c;
46330-
int iSeed = 0, nWords = 10, nTimeout = 0, nSchedulerVerbose = 1, nPartitionerVerbose = 0, nOptimizerVerbose = 0, nAnalyzerVerbose = 0, nSimulatorVerbose = 0, nSatSolverVerbose = 0, fUseBddCspf = 0, fUseBddMspf = 0, nConflictLimit = 0, nSortType = -1, nOptimizerFlow = 0, nSchedulerFlow = 0, nPartitionType = 0, nDistance = 0, nJobs = 1, nThreads = 1, nPartitionSize = 0, nPartitionSizeMin = 0, fDeterministic = 1, nParallelPartitions = 1, fOptOnInsert = 0, fGreedy = 1;
46330+
int iSeed = 0, nWords = 10, nTimeout = 0, nSchedulerVerbose = 0, nPartitionerVerbose = 0, nOptimizerVerbose = 0, nAnalyzerVerbose = 0, nSimulatorVerbose = 0, nSatSolverVerbose = 0, fUseBddCspf = 0, fUseBddMspf = 0, nConflictLimit = 0, nSortType = -1, nOptimizerFlow = 0, nSchedulerFlow = 0, nPartitionType = 0, nDistance = 0, nJobs = 1, nThreads = 1, nPartitionSize = 0, nPartitionSizeMin = 0, fDeterministic = 1, nParallelPartitions = 1, fOptOnInsert = 0, fGreedy = 1;
4633146331
Extra_UtilGetoptReset();
4633246332
while ( ( c = Extra_UtilGetopt( argc, argv, "XYZNJKLBDRWTCGVPOAQSabdegh" ) ) != EOF )
4633346333
{
@@ -46446,6 +46446,51 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4644646446
return 1;
4644746447
}
4644846448

46449+
if ( nSchedulerVerbose )
46450+
{
46451+
Abc_Print( 2, "Using the following parameters :\n" );
46452+
Abc_Print( 2, "\t-X %3d : method ", nOptimizerFlow );
46453+
switch( nOptimizerFlow )
46454+
{
46455+
case 0:
46456+
Abc_Print( 2, "(0 = single-add resub)" );
46457+
break;
46458+
case 1:
46459+
Abc_Print( 2, "(1 = multi-add resub)" );
46460+
break;
46461+
case 2:
46462+
Abc_Print( 2, "(2 = repeat single-add and multi-add resubs)" );
46463+
break;
46464+
case 3:
46465+
Abc_Print( 2, "(3 = random one meaningful resub)" );
46466+
break;
46467+
}
46468+
Abc_Print( 2, "\n" );
46469+
Abc_Print( 2, "\t-Y %3d : flow ", nSchedulerFlow );
46470+
switch ( nSchedulerFlow )
46471+
{
46472+
case 0:
46473+
Abc_Print( 2, "(0 = apply method once)" );
46474+
break;
46475+
case 1:
46476+
Abc_Print( 2, "(1 = iterate like transtoch)" );
46477+
break;
46478+
case 2:
46479+
Abc_Print( 2, "(2 = iterate like deepsyn)" );
46480+
break;
46481+
}
46482+
Abc_Print( 2, "\n" );
46483+
Abc_Print( 2, "\t-N %3d : number of jobs to create by restarting or partitioning\n", nJobs );
46484+
Abc_Print( 2, "\t-J %3d : number of threads\n", nThreads );
46485+
Abc_Print( 2, "\t-K %3d : maximum partition size (0 = no partitioning)\n", nPartitionSize );
46486+
Abc_Print( 2, "\t-L %3d : minimum partition size\n", nPartitionSizeMin );
46487+
Abc_Print( 2, "\t-B %3d : maximum number of partitions to optimize in parallel\n", nParallelPartitions );
46488+
Abc_Print( 2, "\t-R %3d : random number generator seed\n", iSeed );
46489+
Abc_Print( 2, "\t-T %3d : timeout in seconds (0 = no timeout)\n", nTimeout );
46490+
Abc_Print( 2, "\t-C %3d : conflict limit (0 = no limit)\n", nConflictLimit );
46491+
Abc_Print( 2, "Use command line switch \"-h\" to see more options\n\n" );
46492+
}
46493+
4644946494
pNew = Gia_ManRrr( pAbc->pGia, iSeed, nWords, nTimeout, nSchedulerVerbose, nPartitionerVerbose, nOptimizerVerbose, nAnalyzerVerbose, nSimulatorVerbose, nSatSolverVerbose, fUseBddCspf, fUseBddMspf, nConflictLimit, nSortType, nOptimizerFlow, nSchedulerFlow, nPartitionType, nDistance, nJobs, nThreads, nPartitionSize, nPartitionSizeMin, fDeterministic, nParallelPartitions, fOptOnInsert, fGreedy );
4645046495

4645146496
Abc_FrameUpdateGia( pAbc, pNew );
@@ -46469,10 +46514,10 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4646946514
Abc_Print( -2, "\t 1: level base\n" );
4647046515
Abc_Print( -2, "\t-N num : number of jobs to create by restarting or partitioning [default = %d]\n", nJobs );
4647146516
Abc_Print( -2, "\t-J num : number of threads [default = %d]\n", nThreads );
46472-
Abc_Print( -2, "\t-K num : partition size (0 = no partitioning) [default = %d]\n", nPartitionSize );
46473-
Abc_Print( -2, "\t-K num : minimum partition size [default = %d]\n", nPartitionSizeMin );
46474-
Abc_Print( -2, "\t-B num : max number of partitions in parallel [default = %d]\n", nParallelPartitions );
46475-
Abc_Print( -2, "\t-D num : distance between nodes (0 = no limit) [default = %d]\n", nDistance );
46517+
Abc_Print( -2, "\t-K num : maximum partition size (0 = no partitioning) [default = %d]\n", nPartitionSize );
46518+
Abc_Print( -2, "\t-L num : minimum partition size [default = %d]\n", nPartitionSizeMin );
46519+
Abc_Print( -2, "\t-B num : maximum number of partitions in parallel [default = %d]\n", nParallelPartitions );
46520+
Abc_Print( -2, "\t-D num : maximum distance between node and new fanin (0 = no limit) [default = %d]\n", nDistance );
4647646521
Abc_Print( -2, "\t-R num : random number generator seed [default = %d]\n", iSeed );
4647746522
Abc_Print( -2, "\t-W num : number of simulation words [default = %d]\n", nWords );
4647846523
Abc_Print( -2, "\t-T num : timeout in seconds (0 = no timeout) [default = %d]\n", nTimeout );
@@ -46487,7 +46532,7 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4648746532
Abc_Print( -2, "\t-a : use BDD-based analyzer (CSPF) [default = %s]\n", fUseBddCspf? "yes": "no" );
4648846533
Abc_Print( -2, "\t-b : use BDD-based analyzer (MSPF) [default = %s]\n", fUseBddMspf? "yes": "no" );
4648946534
Abc_Print( -2, "\t-d : ensure deterministic execution [default = %s]\n", fDeterministic? "yes": "no" );
46490-
Abc_Print( -2, "\t-e : apply c2rs; dc2 after importing changes of partitions [default = %s]\n", fOptOnInsert? "yes": "no" );
46535+
Abc_Print( -2, "\t-e : apply \"c2rs; dc2\" after importing changes of partitions [default = %s]\n", fOptOnInsert? "yes": "no" );
4649146536
Abc_Print( -2, "\t-g : discard changes that increased the cost [default = %s]\n", fGreedy? "yes": "no" );
4649246537
Abc_Print( -2, "\t-h : print the command usage\n");
4649346538
return 1;

src/opt/rrr/rrrAbc.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ namespace rrr {
2929
}
3030

3131
template <typename Ntk>
32-
Gia_Man_t *CreateGia(Ntk *pNtk) {
32+
Gia_Man_t *CreateGia(Ntk *pNtk, bool fHash = true) {
3333
Gia_Man_t *pGia = Gia_ManStart(pNtk->GetNumNodes());
34-
Gia_ManHashStart(pGia);
34+
if(fHash) {
35+
Gia_ManHashStart(pGia);
36+
}
3537
std::vector<int> v(pNtk->GetNumNodes());
3638
v[0] = Gia_ManConst0Lit();
3739
pNtk->ForEachPi([&](int id) {
@@ -43,8 +45,10 @@ namespace rrr {
4345
pNtk->ForEachFanin(id, [&](int fi, bool c) {
4446
if(x == -1) {
4547
x = Abc_LitNotCond(v[fi], c);
46-
} else {
48+
} else if(fHash) {
4749
x = Gia_ManHashAnd(pGia, x, Abc_LitNotCond(v[fi], c));
50+
} else {
51+
x = Gia_ManAppendAnd(pGia, x, Abc_LitNotCond(v[fi], c));
4852
}
4953
});
5054
if(x == -1) {
@@ -55,7 +59,9 @@ namespace rrr {
5559
pNtk->ForEachPoDriver([&](int fi, bool c) {
5660
Gia_ManAppendCo(pGia, Abc_LitNotCond(v[fi], c));
5761
});
58-
Gia_ManHashStop(pGia);
62+
if(fHash) {
63+
Gia_ManHashStop(pGia);
64+
}
5965
return pGia;
6066
}
6167

@@ -72,7 +78,7 @@ namespace rrr {
7278
assert(r == 0);
7379
Abc_FrameSetBatchMode(0);
7480
}
75-
pNtk->Read(Abc_FrameReadGia(pAbc), GiaReader<Ntk>);
81+
pNtk->Read(Abc_FrameReadGia(pAbc), GiaReader<Ntk>, false);
7682
}
7783

7884
}

src/opt/rrr/rrrAnalyzer.h

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ namespace rrr {
2323
public:
2424
// constructors
2525
Analyzer(Parameter const *pPar);
26-
void UpdateNetwork(Ntk *pNtk_, bool fSame);
26+
void AssignNetwork(Ntk *pNtk_, bool fReuse);
2727

2828
// checks
2929
bool CheckRedundancy(int id, int idx);
3030
bool CheckFeasibility(int id, int fi, bool c);
31+
32+
// summary
33+
void ResetSummary();
34+
summary<int> GetStatsSummary() const;
35+
summary<double> GetTimesSummary() const;
3136
};
3237

3338
/* {{{ Constructors */
@@ -39,12 +44,12 @@ namespace rrr {
3944
sim(pPar),
4045
sol(pPar) {
4146
}
42-
47+
4348
template <typename Ntk, typename Sim, typename Sol>
44-
void Analyzer<Ntk, Sim, Sol>::UpdateNetwork(Ntk *pNtk_, bool fSame) {
49+
void Analyzer<Ntk, Sim, Sol>::AssignNetwork(Ntk *pNtk_, bool fReuse) {
4550
pNtk = pNtk_;
46-
sim.UpdateNetwork(pNtk, fSame);
47-
sol.UpdateNetwork(pNtk, fSame);
51+
sim.AssignNetwork(pNtk, fReuse);
52+
sol.AssignNetwork(pNtk, fReuse);
4853
}
4954

5055
/* }}} */
@@ -70,6 +75,10 @@ namespace rrr {
7075
}
7176
sim.AddCex(sol.GetCex());
7277
}
78+
} else {
79+
// if(nVerbose) {
80+
// std::cout << "node " << id << " fanin " << (pNtk->GetCompl(id, idx)? "!": "") << pNtk->GetFanin(id, idx) << " index " << idx << " is not redundant" << std::endl;
81+
// }
7382
}
7483
return false;
7584
}
@@ -93,11 +102,41 @@ namespace rrr {
93102
}
94103
sim.AddCex(sol.GetCex());
95104
}
105+
} else {
106+
// if(nVerbose) {
107+
// std::cout << "node " << id << " fanin " << (c? "!": "") << fi << " is not feasible" << std::endl;
108+
// }
96109
}
97110
return false;
98111
}
99112

100113
/* }}} */
114+
115+
/* {{{ Summary */
116+
117+
template <typename Ntk, typename Sim, typename Sol>
118+
void Analyzer<Ntk, Sim, Sol>::ResetSummary() {
119+
sim.ResetSummary();
120+
sol.ResetSummary();
121+
}
122+
123+
template <typename Ntk, typename Sim, typename Sol>
124+
summary<int> Analyzer<Ntk, Sim, Sol>::GetStatsSummary() const {
125+
summary<int> v = sim.GetStatsSummary();
126+
summary<int> v2 = sol.GetStatsSummary();
127+
v.insert(v.end(), v2.begin(), v2.end());
128+
return v;
129+
}
130+
131+
template <typename Ntk, typename Sim, typename Sol>
132+
summary<double> Analyzer<Ntk, Sim, Sol>::GetTimesSummary() const {
133+
summary<double> v = sim.GetTimesSummary();
134+
summary<double> v2 = sol.GetTimesSummary();
135+
v.insert(v.end(), v2.begin(), v2.end());
136+
return v;
137+
}
138+
139+
/* }}} */
101140

102141
}
103142

src/opt/rrr/rrrAndNetwork.h

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ namespace rrr {
6464
AndNetwork &operator=(AndNetwork const &x);
6565

6666
// initialization APIs (should not be called after optimization has started)
67-
void Clear();
67+
void Clear(bool fClearCallbacks = true);
6868
void Reserve(int nReserve);
6969
int AddPi();
7070
int AddAnd(int id0, int id1, bool c0, bool c1);
7171
int AddPo(int id, bool c);
7272
template <typename Ntk, typename Reader>
73-
void Read(Ntk *pFrom, Reader &reader);
73+
void Read(Ntk *pFrom, Reader &reader, bool fNew = true);
7474

7575
// network properties
7676
bool UseComplementedEdges() const;
7777
int GetNumNodes() const; // number of allocated nodes (max id + 1)
7878
int GetNumPis() const;
7979
int GetNumInts() const;
8080
int GetNumPos() const;
81+
int GetNumLevels() const;
8182
int GetConst0() const;
8283
int GetPi(int idx) const;
8384
int GetPo(int idx) const;
@@ -272,7 +273,7 @@ namespace rrr {
272273

273274
/* {{{ Initialization APIs */
274275

275-
void AndNetwork::Clear() {
276+
void AndNetwork::Clear(bool fClearCallbacks) {
276277
nNodes = 0;
277278
vPis.clear();
278279
lInts.clear();
@@ -284,7 +285,9 @@ namespace rrr {
284285
iTrav = 0;
285286
vTrav.clear();
286287
fPropagating = false;
287-
vCallbacks.clear();
288+
if(fClearCallbacks) {
289+
vCallbacks.clear();
290+
}
288291
vBackups.clear();
289292
// add constant node
290293
vvFaninEdges.emplace_back();
@@ -330,9 +333,13 @@ namespace rrr {
330333
}
331334

332335
template <typename Ntk, typename Reader>
333-
void AndNetwork::Read(Ntk *pFrom, Reader &reader) {
334-
Clear();
336+
void AndNetwork::Read(Ntk *pFrom, Reader &reader, bool fNew) {
337+
Clear(false);
335338
reader(pFrom, this);
339+
Action action;
340+
action.type = READ;
341+
action.fNew = fNew;
342+
TakenAction(action);
336343
}
337344

338345
/* }}} */
@@ -359,6 +366,23 @@ namespace rrr {
359366
return int_size(vPos);
360367
}
361368

369+
int AndNetwork::GetNumLevels() const {
370+
int nMaxLevel = 0;
371+
std::vector<int> vLevels(nNodes);
372+
ForEachInt([&](int id) {
373+
ForEachFanin(id, [&](int fi) {
374+
if(vLevels[id] < vLevels[fi]) {
375+
vLevels[id] = vLevels[fi];
376+
}
377+
});
378+
vLevels[id] += 1;
379+
if(nMaxLevel < vLevels[id]) {
380+
nMaxLevel = vLevels[id];
381+
}
382+
});
383+
return nMaxLevel;
384+
}
385+
362386
inline int AndNetwork::GetConst0() const {
363387
return 0;
364388
}

0 commit comments

Comments
 (0)