Skip to content

Commit e29dcd9

Browse files
committed
Adding a way to dump sets of resub problems.
1 parent e7d3608 commit e29dcd9

File tree

2 files changed

+111
-6
lines changed

2 files changed

+111
-6
lines changed

src/base/abci/abc.c

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8619,7 +8619,9 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
86198619
int fUseZeros;
86208620
int fVerbose;
86218621
int fVeryVerbose;
8622-
extern int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutsMax, int nNodesMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose );
8622+
int Log2Probs;
8623+
int Log2Divs;
8624+
extern int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutsMax, int nNodesMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int Log2Probs, int Log2Divs );
86238625

86248626
// set defaults
86258627
nCutsMax = 8;
@@ -8630,8 +8632,10 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
86308632
fUseZeros = 0;
86318633
fVerbose = 0;
86328634
fVeryVerbose = 0;
8635+
Log2Probs = 0;
8636+
Log2Divs = 0;
86338637
Extra_UtilGetoptReset();
8634-
while ( ( c = Extra_UtilGetopt( argc, argv, "KNMFlzvwh" ) ) != EOF )
8638+
while ( ( c = Extra_UtilGetopt( argc, argv, "KNMFlzvwhPDV" ) ) != EOF )
86358639
{
86368640
switch ( c )
86378641
{
@@ -8679,6 +8683,41 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
86798683
if ( nLevelsOdc < 0 )
86808684
goto usage;
86818685
break;
8686+
8687+
case 'P':
8688+
if ( globalUtilOptind >= argc )
8689+
{
8690+
Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
8691+
goto usage;
8692+
}
8693+
Log2Probs = atoi(argv[globalUtilOptind]);
8694+
globalUtilOptind++;
8695+
if ( Log2Probs < 0 )
8696+
goto usage;
8697+
break;
8698+
case 'D':
8699+
if ( globalUtilOptind >= argc )
8700+
{
8701+
Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
8702+
goto usage;
8703+
}
8704+
Log2Divs = atoi(argv[globalUtilOptind]);
8705+
globalUtilOptind++;
8706+
if ( Log2Divs < 0 )
8707+
goto usage;
8708+
break;
8709+
case 'V':
8710+
if ( globalUtilOptind >= argc )
8711+
{
8712+
Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
8713+
goto usage;
8714+
}
8715+
nCutsMax = atoi(argv[globalUtilOptind]);
8716+
globalUtilOptind++;
8717+
if ( nCutsMax < 0 )
8718+
goto usage;
8719+
break;
8720+
86828721
case 'l':
86838722
fUpdateLevel ^= 1;
86848723
break;
@@ -8729,15 +8768,15 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
87298768
}
87308769

87318770
// modify the current network
8732-
if ( !Abc_NtkResubstitute( pNtk, nCutsMax, nNodesMax, nMinSaved, nLevelsOdc, fUpdateLevel, fVerbose, fVeryVerbose ) )
8771+
if ( !Abc_NtkResubstitute( pNtk, nCutsMax, nNodesMax, nMinSaved, nLevelsOdc, fUpdateLevel, fVerbose, fVeryVerbose, Log2Probs, Log2Divs ) )
87338772
{
87348773
Abc_Print( -1, "Refactoring has failed.\n" );
87358774
return 1;
87368775
}
87378776
return 0;
87388777

87398778
usage:
8740-
Abc_Print( -2, "usage: resub [-KNMF <num>] [-lzvwh]\n" );
8779+
Abc_Print( -2, "usage: resub [-KNMF <num>] [-lzvwh] [-PDV <num>]\n" );
87418780
Abc_Print( -2, "\t performs technology-independent restructuring of the AIG\n" );
87428781
Abc_Print( -2, "\t-K <num> : the max cut size (%d <= num <= %d) [default = %d]\n", RS_CUT_MIN, RS_CUT_MAX, nCutsMax );
87438782
Abc_Print( -2, "\t-N <num> : the max number of nodes to add (0 <= num <= 3) [default = %d]\n", nNodesMax );
@@ -8747,7 +8786,16 @@ int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
87478786
Abc_Print( -2, "\t-z : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
87488787
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
87498788
Abc_Print( -2, "\t-w : toggle verbose printout of ODC computation [default = %s]\n", fVeryVerbose? "yes": "no" );
8750-
Abc_Print( -2, "\t-h : print the command usage\n");
8789+
Abc_Print( -2, "\t-h : print the command usage\n\n");
8790+
Abc_Print( -2, "\t When command line options '-P num', '-D num', and '-V num' are used,\n");
8791+
Abc_Print( -2, "\t this command does not perform resubstitution; instead, it dumps a binary file\n");
8792+
Abc_Print( -2, "\t containing 2^P resub problems, each containing 2^D-2 divs with support size V,\n");
8793+
Abc_Print( -2, "\t while the last two divisors are the offset and the onset of the function\n");
8794+
Abc_Print( -2, "\t (by default, the functions are completely specified; to get functions with don't-cares,\n");
8795+
Abc_Print( -2, "\t the user has to use command-line option '-F num' to enable the limited ODC computation)\n");
8796+
Abc_Print( -2, "\t-P <num> : the log2 of the number of problems to be dumped [default = %d]\n", Log2Probs );
8797+
Abc_Print( -2, "\t-D <num> : the log2 of the number of divisors to be collected (4 <= num <= 7) [default = %d]\n", Log2Divs );
8798+
Abc_Print( -2, "\t-V <num> : the support size of the function (%d <= num <= %d) [default = %d]\n", RS_CUT_MIN, RS_CUT_MAX, nCutsMax );
87518799
return 1;
87528800
}
87538801

src/base/abci/abcResub.c

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ struct Abc_ManRes_t_
3737
// paramers
3838
int nLeavesMax; // the max number of leaves in the cone
3939
int nDivsMax; // the max number of divisors in the cone
40+
// resub problem dumping
41+
int Log2Probs;
42+
int Log2Divs;
43+
int nProbs;
44+
FILE * pFile;
4045
// representation of the cone
4146
Abc_Obj_t * pRoot; // the root of the cone
4247
int nLeaves; // the number of leaves
@@ -51,6 +56,7 @@ struct Abc_ManRes_t_
5156
unsigned * pInfo; // pointer to simulation info
5257
// observability don't-cares
5358
unsigned * pCareSet;
59+
unsigned * pTempSim;
5460
// internal divisor storage
5561
Vec_Ptr_t * vDivs1UP; // the single-node unate divisors
5662
Vec_Ptr_t * vDivs1UN; // the single-node unate divisors
@@ -134,7 +140,7 @@ static int Abc_CutVolumeCheck( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves
134140
SeeAlso []
135141
136142
***********************************************************************/
137-
int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose )
143+
int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinSaved, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int Log2Probs, int Log2Divs )
138144
{
139145
extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
140146
ProgressBar * pProgress;
@@ -154,6 +160,19 @@ int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinS
154160
// start the managers
155161
pManCut = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
156162
pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
163+
if ( Log2Probs && Log2Divs )
164+
{
165+
pManRes->Log2Probs = Log2Probs;
166+
pManRes->Log2Divs = Log2Divs;
167+
pManRes->nProbs = 0;
168+
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d.bin", Log2Probs, nCutMax, Log2Divs );
169+
pManRes->pFile = fopen( pFileName, "wb" );
170+
if ( pManRes->pFile == NULL ) {
171+
printf( "Cannot open output file \"%s\".\n", pFileName );
172+
return 1;
173+
}
174+
printf( "Collecting resub problems into binary file \"%s\" expected to take %.3f MB...\n", pFileName, 1.0*(1 << Log2Probs)*(1 << Log2Divs)*(1 << (nCutMax-3)) / (1 << 20) );
175+
}
157176
if ( nLevelsOdc > 0 )
158177
pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
159178

@@ -245,6 +264,16 @@ pManRes->timeTotal = Abc_Clock() - clkStart;
245264
if ( fVerbose )
246265
Abc_ManResubPrint( pManRes );
247266

267+
if ( Log2Probs && Log2Divs )
268+
{
269+
fclose( pManRes->pFile );
270+
pManRes->pFile = NULL;
271+
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d.bin", Log2Probs, nCutMax, Log2Divs );
272+
printf( "Finished writing file \"%s\" containing %d (out of requested %d) resub problems,\n", pFileName, pManRes->nProbs, 1<<Log2Probs );
273+
printf( "each having %d divisors with support size %d (including the on-set and the off-set). ", 1<<Log2Divs, nCutMax );
274+
Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
275+
}
276+
248277
// delete the managers
249278
Abc_ManResubStop( pManRes );
250279
Abc_NtkManCutStop( pManCut );
@@ -321,6 +350,7 @@ Abc_ManRes_t * Abc_ManResubStart( int nLeavesMax, int nDivsMax )
321350
if ( i & (1 << k) )
322351
pData[i>>5] |= (1 << (i&31));
323352
}
353+
p->pTempSim = ABC_CALLOC( unsigned, p->nWords );
324354
// create the remaining divisors
325355
p->vDivs1UP = Vec_PtrAlloc( p->nDivsMax );
326356
p->vDivs1UN = Vec_PtrAlloc( p->nDivsMax );
@@ -356,6 +386,7 @@ void Abc_ManResubStop( Abc_ManRes_t * p )
356386
Vec_PtrFree( p->vDivs2UN0 );
357387
Vec_PtrFree( p->vDivs2UN1 );
358388
Vec_PtrFree( p->vTemp );
389+
ABC_FREE( p->pTempSim );
359390
ABC_FREE( p->pInfo );
360391
ABC_FREE( p );
361392
}
@@ -1943,6 +1974,32 @@ clk = Abc_Clock();
19431974
Abc_ManResubSimulate( p->vDivs, p->nLeaves, p->vSims, p->nLeavesMax, p->nWords );
19441975
p->timeSim += Abc_Clock() - clk;
19451976

1977+
if ( p->pFile && Vec_PtrSize(vLeaves) != p->nLeavesMax && p->nProbs < (1 << p->Log2Probs) )
1978+
{
1979+
Abc_Obj_t * pObj; int i, w, Count = 0;
1980+
unsigned * pFunc = (unsigned *)pRoot->pData;
1981+
int Limit = Abc_MinInt( Vec_PtrSize(p->vDivs), (1 << p->Log2Divs) - 2 );
1982+
Vec_PtrForEachEntryStop( Abc_Obj_t *, p->vDivs, pObj, i, Limit )
1983+
Count += fwrite( (unsigned *)pObj->pData, 1, sizeof(unsigned) * p->nWords, p->pFile );
1984+
// write constant zeros
1985+
memset( p->pTempSim, 0, sizeof(unsigned) * p->nWords );
1986+
for ( ; i < (1 << p->Log2Divs) - 2; i++ )
1987+
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
1988+
// write offset
1989+
for ( w = 0; w < p->nWords; w++ )
1990+
p->pTempSim[w] = p->pCareSet[w] & ~pFunc[w];
1991+
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
1992+
// write onset
1993+
for ( w = 0; w < p->nWords; w++ )
1994+
p->pTempSim[w] = p->pCareSet[w] & pFunc[w];
1995+
Count += fwrite( p->pTempSim, 1, sizeof(unsigned) * p->nWords, p->pFile );
1996+
assert( Count == (1 << p->Log2Divs) * (1 << (p->nLeavesMax-3)) );
1997+
p->nProbs++;
1998+
//printf( "Finished dumping node %d. Written %d bytes of data (expected %d bytes).\n", pRoot->Id, Count, (1 << p->Log2Divs) * (1 << (p->nLeavesMax-3)) );
1999+
//printf( "%d ", Vec_PtrSize(p->vDivs) );
2000+
return NULL;
2001+
}
2002+
19462003
clk = Abc_Clock();
19472004
// consider constants
19482005
if ( (pGraph = Abc_ManResubQuit( p )) )

0 commit comments

Comments
 (0)