Skip to content

Commit 15151c5

Browse files
committed
Updating &stochsyn with switch '-d' to support level-preserving AIG optimizations.
1 parent 00910e3 commit 15151c5

File tree

2 files changed

+71
-25
lines changed

2 files changed

+71
-25
lines changed

src/aig/gia/giaStoch.c

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ void Gia_ManStochSynthesis( Vec_Ptr_t * vAigs, char * pScript )
296296
SeeAlso []
297297
298298
***********************************************************************/
299-
int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vWins, Vec_Int_t * vGains )
299+
int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vWins, Vec_Int_t * vGains, int fDelayOpt )
300300
{
301301
int RetValue = Vec_PtrSize(vvIns);
302302
Vec_Ptr_t * vvInsNew = Vec_PtrAlloc( 10 );
@@ -312,8 +312,8 @@ int Gia_ManFilterPartitions( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNod
312312
Vec_PtrPush( vvInsNew, Vec_IntDup((Vec_Int_t *)Vec_PtrEntry(vvIns, iEntry)) );
313313
Vec_PtrPush( vvOutsNew, Vec_IntDup((Vec_Int_t *)Vec_PtrEntry(vvOuts, iEntry)) );
314314
Vec_PtrPush( vvWinsNew, Gia_ManDupDfs((Gia_Man_t *)Vec_PtrEntry(vWins, iEntry)) );
315-
extern void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan );
316-
Gia_ManMarkTfiTfo( (Vec_Int_t *)Vec_PtrEntryLast(vvInsNew), p );
315+
extern void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan, int fDelayOpt );
316+
Gia_ManMarkTfiTfo( (Vec_Int_t *)Vec_PtrEntryLast(vvInsNew), p, fDelayOpt );
317317
Vec_IntForEachEntry( vGains, Gain, i ) {
318318
if ( Gain < 0 )
319319
continue;
@@ -556,12 +556,14 @@ void Gia_ManSelectRemove( Vec_Wec_t * vSupps, Vec_Int_t * vOne )
556556
Vec_WecRemoveEmpty( vSupps );
557557
}
558558
// marks TFI/TFO of this one
559-
void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan )
559+
void Gia_ManMarkTfiTfo( Vec_Int_t * vOne, Gia_Man_t * pMan, int fDelayOpt )
560560
{
561561
int i; Gia_Obj_t * pObj;
562562
Gia_ManForEachObjVec( vOne, pMan, pObj, i ) {
563-
//Gia_ObjSetTravIdPrevious(pMan, pObj);
564-
//Gia_ObjDfsMark_rec( pMan, pObj );
563+
if ( fDelayOpt ) {
564+
Gia_ObjSetTravIdPrevious(pMan, pObj);
565+
Gia_ObjDfsMark_rec( pMan, pObj );
566+
}
565567
Gia_ObjSetTravIdPrevious(pMan, pObj);
566568
Gia_ObjDfsMark2_rec( pMan, pObj );
567569
}
@@ -632,7 +634,7 @@ Vec_Ptr_t * Gia_ManDeriveWinInsAll( Vec_Wec_t * vSupps, int nSuppMax, Gia_Man_t
632634
}
633635
return vRes;
634636
}
635-
Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos )
637+
Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos, Vec_Int_t * vLevels[2], int nLevels )
636638
{
637639
Gia_Man_t * pNew;
638640
Gia_Obj_t * pObj;
@@ -647,10 +649,28 @@ Gia_Man_t * Gia_ManDupFromArrays( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * v
647649
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
648650
Gia_ManForEachObjVec( vCos, p, pObj, i )
649651
pObj->Value = Gia_ManAppendCo( pNew, pObj->Value );
652+
if ( vLevels[0] ) {
653+
pNew->vCiArrs = Vec_IntAlloc( Gia_ManCiNum(pNew) );
654+
Gia_ManForEachObjVec( vCis, p, pObj, i )
655+
Vec_IntPush( pNew->vCiArrs, Gia_ObjLevel(p, pObj) );
656+
pNew->vCoReqs = Vec_IntAlloc( Gia_ManCoNum(pNew) );
657+
Gia_ManForEachObjVec( vCos, p, pObj, i )
658+
Vec_IntPush( pNew->vCoReqs, nLevels - Gia_ObjLevel(p, pObj) );
659+
}
650660
return pNew;
651661
}
652-
Vec_Ptr_t * Gia_ManDupWindows( Gia_Man_t * pMan, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts )
662+
Vec_Ptr_t * Gia_ManDupWindows( Gia_Man_t * pMan, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvNodes, Vec_Ptr_t * vvOuts, int fDelayOpt )
653663
{
664+
// compute direct and reverse level
665+
Vec_Int_t * vLevels[2] = {NULL};
666+
if ( fDelayOpt ) {
667+
int Levels[2];
668+
Levels[0] = Gia_ManLevelNum( pMan );
669+
ABC_SWAP( Vec_Int_t *, vLevels[0], pMan->vLevels );
670+
Levels[1] = Gia_ManLevelRNum( pMan );
671+
ABC_SWAP( Vec_Int_t *, vLevels[1], pMan->vLevels );
672+
assert( Levels[0] == Levels[1] );
673+
}
654674
Vec_Int_t * vNodes; int i;
655675
Vec_Ptr_t * vWins = Vec_PtrAlloc( Vec_PtrSize(vvIns) );
656676
assert( Vec_PtrSize(vvIns) == Vec_PtrSize(vvNodes) );
@@ -660,9 +680,11 @@ Vec_Ptr_t * Gia_ManDupWindows( Gia_Man_t * pMan, Vec_Ptr_t * vvIns, Vec_Ptr_t *
660680
Vec_PtrForEachEntry( Vec_Int_t *, vvNodes, vNodes, i ) {
661681
Vec_Int_t * vIns = (Vec_Int_t *)Vec_PtrEntry(vvIns, i);
662682
Vec_Int_t * vOuts = (Vec_Int_t *)Vec_PtrEntry(vvOuts, i);
663-
Gia_Man_t * pNew = Gia_ManDupFromArrays( pMan, vIns, vNodes, vOuts );
683+
Gia_Man_t * pNew = Gia_ManDupFromArrays( pMan, vIns, vNodes, vOuts, vLevels, pMan->nLevels );
664684
Vec_PtrPush( vWins, pNew );
665685
}
686+
Vec_IntFreeP( &vLevels[0] );
687+
Vec_IntFreeP( &vLevels[1] );
666688
return vWins;
667689
}
668690
int Gia_ManLevelR( Gia_Man_t * pMan )
@@ -675,7 +697,7 @@ int Gia_ManLevelR( Gia_Man_t * pMan )
675697
Gia_ObjSetLevel( pMan, pNode, 0 );
676698
return LevelMax;
677699
}
678-
Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax, Vec_Ptr_t ** pvIns, Vec_Ptr_t ** pvOuts, Vec_Ptr_t ** pvNodes, int fOverlap )
700+
Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax, Vec_Ptr_t ** pvIns, Vec_Ptr_t ** pvOuts, Vec_Ptr_t ** pvNodes, int fOverlap, int fDelayOpt )
679701
{
680702
// if ( Gia_ManCiNum(pMan) <= nSuppMax ) {
681703
// Vec_Ptr_t * vWins = Vec_PtrAlloc( 1 );
@@ -695,7 +717,7 @@ Vec_Ptr_t * Gia_ManExtractPartitions( Gia_Man_t * pMan, int Iter, int nSuppMax,
695717
Vec_Ptr_t * vIns = Gia_ManDeriveWinInsAll( vSupps, nSuppMax, pMan, fOverlap );
696718
Vec_Ptr_t * vNodes = Gia_ManDeriveWinNodesAll( pMan, vIns, vStore );
697719
Vec_Ptr_t * vOuts = Gia_ManDeriveWinOutsAll( pMan, vNodes );
698-
Vec_Ptr_t * vWins = Gia_ManDupWindows( pMan, vIns, vNodes, vOuts );
720+
Vec_Ptr_t * vWins = Gia_ManDupWindows( pMan, vIns, vNodes, vOuts, fDelayOpt );
699721
Vec_WecFree( vSupps );
700722
Vec_WecFree( vStore );
701723
*pvIns = vIns;
@@ -742,7 +764,7 @@ void Gia_ManCollectNodes( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Ve
742764
Vec_IntForEachEntry( vCos, iObj, i )
743765
Gia_ManCollectNodes_rec( p, iObj, vAnds );
744766
}
745-
Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos )
767+
Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vAnds, Vec_Int_t * vCos, Vec_Int_t * vLevels[2], int nLevels )
746768
{
747769
Vec_Int_t * vMapping; int i;
748770
Gia_Man_t * pNew; Gia_Obj_t * pObj;
@@ -757,8 +779,16 @@ Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vA
757779
Gia_ManForEachObjVec( vCos, p, pObj, i )
758780
Gia_ManAppendCo( pNew, pObj->Value );
759781
assert( Gia_ManCiNum(pNew) > 0 && Gia_ManCoNum(pNew) > 0 );
760-
if ( !Gia_ManHasMapping(p) )
782+
if ( !Gia_ManHasMapping(p) ) {
783+
if ( vLevels[0] == NULL ) return pNew;
784+
pNew->vCiArrs = Vec_IntAlloc( Gia_ManCiNum(pNew) );
785+
Gia_ManForEachObjVec( vCis, p, pObj, i )
786+
Vec_IntPush( pNew->vCiArrs, Gia_ObjLevel(p, pObj) );
787+
pNew->vCoReqs = Vec_IntAlloc( Gia_ManCoNum(pNew) );
788+
Gia_ManForEachObjVec( vCos, p, pObj, i )
789+
Vec_IntPush( pNew->vCoReqs, nLevels - Gia_ObjLevel(p, pObj) );
761790
return pNew;
791+
}
762792
vMapping = Vec_IntAlloc( 4*Gia_ManObjNum(pNew) );
763793
Vec_IntFill( vMapping, Gia_ManObjNum(pNew), 0 );
764794
Gia_ManForEachObjVec( vAnds, p, pObj, i )
@@ -776,17 +806,29 @@ Gia_Man_t * Gia_ManDupDivideOne( Gia_Man_t * p, Vec_Int_t * vCis, Vec_Int_t * vA
776806
pNew->vMapping = vMapping;
777807
return pNew;
778808
}
779-
Vec_Ptr_t * Gia_ManDupDivide( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, char * pScript, int nProcs, int TimeOut )
809+
Vec_Ptr_t * Gia_ManDupDivide( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, char * pScript, int nProcs, int TimeOut, int fDelayOpt )
780810
{
811+
// compute direct and reverse level
812+
Vec_Int_t * vLevels[2] = {NULL};
813+
if ( fDelayOpt ) {
814+
int Levels[2];
815+
Levels[0] = Gia_ManLevelNum( p );
816+
ABC_SWAP( Vec_Int_t *, vLevels[0], p->vLevels );
817+
Levels[1] = Gia_ManLevelRNum( p );
818+
ABC_SWAP( Vec_Int_t *, vLevels[1], p->vLevels );
819+
assert( Levels[0] == Levels[1] );
820+
}
781821
Vec_Ptr_t * vAigs = Vec_PtrAlloc( Vec_WecSize(vCis) ); int i;
782822
for ( i = 0; i < Vec_WecSize(vCis); i++ )
783823
{
784824
Gia_ManCollectNodes( p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i) );
785-
Vec_PtrPush( vAigs, Gia_ManDupDivideOne(p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i)) );
825+
Vec_PtrPush( vAigs, Gia_ManDupDivideOne(p, Vec_WecEntry(vCis, i), Vec_WecEntry(vAnds, i), Vec_WecEntry(vCos, i), vLevels, p->nLevels) );
786826
}
787827
//Gia_ManStochSynthesis( vAigs, pScript );
788828
Vec_Int_t * vGains = Gia_StochProcess( vAigs, pScript, nProcs, TimeOut, 0 );
789829
Vec_IntFree( vGains );
830+
Vec_IntFreeP( &vLevels[0] );
831+
Vec_IntFreeP( &vLevels[1] );
790832
return vAigs;
791833
}
792834
Gia_Man_t * Gia_ManDupStitch( Gia_Man_t * p, Vec_Wec_t * vCis, Vec_Wec_t * vAnds, Vec_Wec_t * vCos, Vec_Ptr_t * vAigs, int fHash )
@@ -982,7 +1024,7 @@ Vec_Wec_t * Gia_ManStochOutputs( Gia_Man_t * p, Vec_Wec_t * vAnds )
9821024
SeeAlso []
9831025
9841026
***********************************************************************/
985-
void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs )
1027+
void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs, int fDelayOpt )
9861028
{
9871029
abctime nTimeToStop = TimeOut ? Abc_Clock() + TimeOut * CLOCKS_PER_SEC : 0;
9881030
abctime clkStart = Abc_Clock();
@@ -1008,7 +1050,7 @@ void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int S
10081050
Vec_Wec_t * vAnds = Gia_ManStochNodes( pGia, nMaxSize, Abc_Random(0) & 0x7FFFFFFF );
10091051
Vec_Wec_t * vIns = Gia_ManStochInputs( pGia, vAnds );
10101052
Vec_Wec_t * vOuts = Gia_ManStochOutputs( pGia, vAnds );
1011-
Vec_Ptr_t * vAigs = Gia_ManDupDivide( pGia, vIns, vAnds, vOuts, pScript, nProcs, TimeOut );
1053+
Vec_Ptr_t * vAigs = Gia_ManDupDivide( pGia, vIns, vAnds, vOuts, pScript, nProcs, TimeOut, fDelayOpt );
10121054
Gia_Man_t * pNew = Gia_ManDupStitchMap( pGia, vIns, vAnds, vOuts, vAigs );
10131055
int fMapped = Gia_ManHasMapping(pGia) && Gia_ManHasMapping(pNew);
10141056
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), pNew );
@@ -1039,9 +1081,9 @@ void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int S
10391081
extern Gia_Man_t * Gia_ManDupInsertWindows( Gia_Man_t * p, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vAigs );
10401082
abctime clk = Abc_Clock();
10411083
Gia_Man_t * pGia = Gia_ManDup( Abc_FrameReadGia(Abc_FrameGetGlobalFrame()) ); Gia_ManStaticFanoutStart(pGia);
1042-
Vec_Ptr_t * vAigs = Gia_ManExtractPartitions( pGia, i, nSuppMax, &vIns, &vOuts, &vNodes, fOverlap );
1084+
Vec_Ptr_t * vAigs = Gia_ManExtractPartitions( pGia, i, nSuppMax, &vIns, &vOuts, &vNodes, fOverlap, fDelayOpt );
10431085
Vec_Int_t * vGains = Gia_StochProcess( vAigs, pScript, nProcs, TimeOut, 0 );
1044-
int nPartsInit = fOverlap ? Gia_ManFilterPartitions( pGia, vIns, vNodes, vOuts, vAigs, vGains ) : Vec_PtrSize(vIns);
1086+
int nPartsInit = fOverlap ? Gia_ManFilterPartitions( pGia, vIns, vNodes, vOuts, vAigs, vGains, fDelayOpt ) : Vec_PtrSize(vIns);
10451087
Gia_Man_t * pNew = Gia_ManDupInsertWindows( pGia, vIns, vOuts, vAigs ); Gia_ManStaticFanoutStop(pGia);
10461088
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), pNew );
10471089
if ( fVerbose )

src/base/abci/abc.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53618,10 +53618,10 @@ int Abc_CommandAbc9SatSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
5361853618
***********************************************************************/
5361953619
int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
5362053620
{
53621-
extern void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs );
53622-
int c, nSuppMax = 0, nMaxSize = 1000, nIters = 10, TimeOut = 0, Seed = 0, nProcs = 1, fVerbose = 0; char * pScript;
53621+
extern void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int Seed, int fVerbose, char * pScript, int nProcs, int fDelayOpt );
53622+
int c, nSuppMax = 0, nMaxSize = 1000, nIters = 10, TimeOut = 0, Seed = 0, nProcs = 1, fDelayOpt = 0, fVerbose = 0; char * pScript;
5362353623
Extra_UtilGetoptReset();
53624-
while ( ( c = Extra_UtilGetopt( argc, argv, "NMITSPvh" ) ) != EOF )
53624+
while ( ( c = Extra_UtilGetopt( argc, argv, "NMITSPdvh" ) ) != EOF )
5362553625
{
5362653626
switch ( c )
5362753627
{
@@ -53691,6 +53691,9 @@ int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
5369153691
if ( nProcs < 0 )
5369253692
goto usage;
5369353693
break;
53694+
case 'd':
53695+
fDelayOpt ^= 1;
53696+
break;
5369453697
case 'v':
5369553698
fVerbose ^= 1;
5369653699
break;
@@ -53711,19 +53714,20 @@ int Abc_CommandAbc9StochSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
5371153714
goto usage;
5371253715
}
5371353716
pScript = Abc_UtilStrsav( argv[globalUtilOptind] );
53714-
Gia_ManStochSyn( nSuppMax, nMaxSize, nIters, TimeOut, Seed, fVerbose, pScript, nProcs );
53717+
Gia_ManStochSyn( nSuppMax, nMaxSize, nIters, TimeOut, Seed, fVerbose, pScript, nProcs, fDelayOpt );
5371553718
ABC_FREE( pScript );
5371653719
return 0;
5371753720

5371853721
usage:
53719-
Abc_Print( -2, "usage: &stochsyn [-NMITSP <num>] [-tvh] <script>\n" );
53720-
Abc_Print( -2, "\t performs stochastic synthesis\n" );
53722+
Abc_Print( -2, "usage: &stochsyn [-NMITSP <num>] [-dvh] <script>\n" );
53723+
Abc_Print( -2, "\t performs stochastic synthesis using the given script\n" );
5372153724
Abc_Print( -2, "\t-N <num> : the max partition support size [default = %d]\n", nSuppMax );
5372253725
Abc_Print( -2, "\t-M <num> : the max partition size (in AIG nodes or LUTs) [default = %d]\n", nMaxSize );
5372353726
Abc_Print( -2, "\t-I <num> : the number of iterations [default = %d]\n", nIters );
5372453727
Abc_Print( -2, "\t-T <num> : the timeout in seconds (0 = no timeout) [default = %d]\n", TimeOut );
5372553728
Abc_Print( -2, "\t-S <num> : user-specified random seed (0 <= num <= 100) [default = %d]\n", Seed );
5372653729
Abc_Print( -2, "\t-P <num> : the number of concurrent processes (1 <= num <= 100) [default = %d]\n", nProcs );
53730+
Abc_Print( -2, "\t-d : toggle using delay-aware synthesis (if the script supports it) [default = %s]\n", fDelayOpt? "yes": "no" );
5372753731
Abc_Print( -2, "\t-v : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
5372853732
Abc_Print( -2, "\t-h : print the command usage\n");
5372953733
Abc_Print( -2, "\t<script> : synthesis script to use for each partition\n");

0 commit comments

Comments
 (0)