Skip to content

Commit b1b1023

Browse files
committed
update rrr
1 parent 27f2429 commit b1b1023

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
@@ -45457,7 +45457,7 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4545745457
{
4545845458
Gia_Man_t *pNew;
4545945459
int c;
45460-
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;
45460+
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;
4546145461
Extra_UtilGetoptReset();
4546245462
while ( ( c = Extra_UtilGetopt( argc, argv, "XYZNJKLBDRWTCGVPOAQSabdegh" ) ) != EOF )
4546345463
{
@@ -45576,6 +45576,51 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4557645576
return 1;
4557745577
}
4557845578

45579+
if ( nSchedulerVerbose )
45580+
{
45581+
Abc_Print( 2, "Using the following parameters :\n" );
45582+
Abc_Print( 2, "\t-X %3d : method ", nOptimizerFlow );
45583+
switch( nOptimizerFlow )
45584+
{
45585+
case 0:
45586+
Abc_Print( 2, "(0 = single-add resub)" );
45587+
break;
45588+
case 1:
45589+
Abc_Print( 2, "(1 = multi-add resub)" );
45590+
break;
45591+
case 2:
45592+
Abc_Print( 2, "(2 = repeat single-add and multi-add resubs)" );
45593+
break;
45594+
case 3:
45595+
Abc_Print( 2, "(3 = random one meaningful resub)" );
45596+
break;
45597+
}
45598+
Abc_Print( 2, "\n" );
45599+
Abc_Print( 2, "\t-Y %3d : flow ", nSchedulerFlow );
45600+
switch ( nSchedulerFlow )
45601+
{
45602+
case 0:
45603+
Abc_Print( 2, "(0 = apply method once)" );
45604+
break;
45605+
case 1:
45606+
Abc_Print( 2, "(1 = iterate like transtoch)" );
45607+
break;
45608+
case 2:
45609+
Abc_Print( 2, "(2 = iterate like deepsyn)" );
45610+
break;
45611+
}
45612+
Abc_Print( 2, "\n" );
45613+
Abc_Print( 2, "\t-N %3d : number of jobs to create by restarting or partitioning\n", nJobs );
45614+
Abc_Print( 2, "\t-J %3d : number of threads\n", nThreads );
45615+
Abc_Print( 2, "\t-K %3d : maximum partition size (0 = no partitioning)\n", nPartitionSize );
45616+
Abc_Print( 2, "\t-L %3d : minimum partition size\n", nPartitionSizeMin );
45617+
Abc_Print( 2, "\t-B %3d : maximum number of partitions to optimize in parallel\n", nParallelPartitions );
45618+
Abc_Print( 2, "\t-R %3d : random number generator seed\n", iSeed );
45619+
Abc_Print( 2, "\t-T %3d : timeout in seconds (0 = no timeout)\n", nTimeout );
45620+
Abc_Print( 2, "\t-C %3d : conflict limit (0 = no limit)\n", nConflictLimit );
45621+
Abc_Print( 2, "Use command line switch \"-h\" to see more options\n\n" );
45622+
}
45623+
4557945624
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 );
4558045625

4558145626
Abc_FrameUpdateGia( pAbc, pNew );
@@ -45599,10 +45644,10 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4559945644
Abc_Print( -2, "\t 1: level base\n" );
4560045645
Abc_Print( -2, "\t-N num : number of jobs to create by restarting or partitioning [default = %d]\n", nJobs );
4560145646
Abc_Print( -2, "\t-J num : number of threads [default = %d]\n", nThreads );
45602-
Abc_Print( -2, "\t-K num : partition size (0 = no partitioning) [default = %d]\n", nPartitionSize );
45603-
Abc_Print( -2, "\t-K num : minimum partition size [default = %d]\n", nPartitionSizeMin );
45604-
Abc_Print( -2, "\t-B num : max number of partitions in parallel [default = %d]\n", nParallelPartitions );
45605-
Abc_Print( -2, "\t-D num : distance between nodes (0 = no limit) [default = %d]\n", nDistance );
45647+
Abc_Print( -2, "\t-K num : maximum partition size (0 = no partitioning) [default = %d]\n", nPartitionSize );
45648+
Abc_Print( -2, "\t-L num : minimum partition size [default = %d]\n", nPartitionSizeMin );
45649+
Abc_Print( -2, "\t-B num : maximum number of partitions in parallel [default = %d]\n", nParallelPartitions );
45650+
Abc_Print( -2, "\t-D num : maximum distance between node and new fanin (0 = no limit) [default = %d]\n", nDistance );
4560645651
Abc_Print( -2, "\t-R num : random number generator seed [default = %d]\n", iSeed );
4560745652
Abc_Print( -2, "\t-W num : number of simulation words [default = %d]\n", nWords );
4560845653
Abc_Print( -2, "\t-T num : timeout in seconds (0 = no timeout) [default = %d]\n", nTimeout );
@@ -45617,7 +45662,7 @@ int Abc_CommandAbc9Rrr( Abc_Frame_t * pAbc, int argc, char ** argv )
4561745662
Abc_Print( -2, "\t-a : use BDD-based analyzer (CSPF) [default = %s]\n", fUseBddCspf? "yes": "no" );
4561845663
Abc_Print( -2, "\t-b : use BDD-based analyzer (MSPF) [default = %s]\n", fUseBddMspf? "yes": "no" );
4561945664
Abc_Print( -2, "\t-d : ensure deterministic execution [default = %s]\n", fDeterministic? "yes": "no" );
45620-
Abc_Print( -2, "\t-e : apply c2rs; dc2 after importing changes of partitions [default = %s]\n", fOptOnInsert? "yes": "no" );
45665+
Abc_Print( -2, "\t-e : apply \"c2rs; dc2\" after importing changes of partitions [default = %s]\n", fOptOnInsert? "yes": "no" );
4562145666
Abc_Print( -2, "\t-g : discard changes that increased the cost [default = %s]\n", fGreedy? "yes": "no" );
4562245667
Abc_Print( -2, "\t-h : print the command usage\n");
4562345668
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)