mirror of https://github.com/YosysHQ/abc.git
Performance improvements.
This commit is contained in:
parent
1b6b553922
commit
c0be439b45
|
|
@ -9059,7 +9059,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||||
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, char * pGuide );
|
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, char * pGuide );
|
||||||
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose );
|
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose );
|
||||||
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
|
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
|
||||||
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, nIters = 1, fGen = 0, fVerbose = 0, fVeryVerbose = 0;
|
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, nIters = 10, fGen = 0, fVerbose = 0, fVeryVerbose = 0;
|
||||||
Extra_UtilGetoptReset();
|
Extra_UtilGetoptReset();
|
||||||
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSINFgvwh" ) ) != EOF )
|
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSINFgvwh" ) ) != EOF )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -621,46 +621,51 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int n
|
||||||
{
|
{
|
||||||
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
|
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
|
||||||
extern word * Abc_LutCascade2( word * p, int nVars, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
|
extern word * Abc_LutCascade2( word * p, int nVars, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
|
||||||
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
|
|
||||||
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
|
|
||||||
int nWords = Abc_TtWordNum(Abc_NtkCiNum(pNtk));
|
int nWords = Abc_TtWordNum(Abc_NtkCiNum(pNtk));
|
||||||
word * pCopy = ABC_ALLOC( word, nWords );
|
word * pCopy = ABC_ALLOC( word, nWords );
|
||||||
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
|
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
|
||||||
|
Abc_Ntk_t * pNew = NULL;
|
||||||
|
Abc_Random(1);
|
||||||
|
for ( int Iter = 0; Iter < nIters; Iter++ ) {
|
||||||
|
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
|
||||||
|
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
|
||||||
|
|
||||||
int nVars = -1;
|
int nVars = -1;
|
||||||
Vec_Int_t * vVarIDs = Vec_IntStartNatural( Abc_NtkCiNum(pNtk) );
|
Vec_Int_t * vVarIDs = Vec_IntStartNatural( Abc_NtkCiNum(pNtk) );
|
||||||
Abc_TtMinimumBase( pTruth1, Vec_IntArray(vVarIDs), Abc_NtkCiNum(pNtk), &nVars );
|
Abc_TtMinimumBase( pTruth1, Vec_IntArray(vVarIDs), Abc_NtkCiNum(pNtk), &nVars );
|
||||||
Vec_IntShrink( vVarIDs, nVars );
|
Vec_IntShrink( vVarIDs, nVars );
|
||||||
if ( fVerbose ) {
|
if ( fVerbose ) {
|
||||||
if ( Abc_NtkCiNum(pNtk) != nVars )
|
if ( Abc_NtkCiNum(pNtk) != nVars )
|
||||||
printf( "The support of the function is reduced from %d to %d variables.\n", Abc_NtkCiNum(pNtk), nVars );
|
printf( "The support of the function is reduced from %d to %d variables.\n", Abc_NtkCiNum(pNtk), nVars );
|
||||||
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs", nVars, nRails, nLutSize );
|
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs", nVars, nRails, nLutSize );
|
||||||
if ( pGuide )
|
if ( pGuide )
|
||||||
printf( " using structural info: %s", pGuide );
|
printf( " using structural info: %s", pGuide );
|
||||||
printf( ".\n" );
|
printf( ".\n" );
|
||||||
}
|
|
||||||
|
|
||||||
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, fVerbose );
|
|
||||||
Abc_Ntk_t * pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
|
|
||||||
Vec_IntFree( vVarIDs );
|
|
||||||
|
|
||||||
if ( pLuts ) {
|
|
||||||
if ( fVerbose )
|
|
||||||
Abc_LutCascadePrint( pLuts );
|
|
||||||
word * pTruth2 = Abc_LutCascadeTruth( pLuts, Abc_NtkCiNum(pNtk) );
|
|
||||||
if ( !Abc_TtEqual(pCopy, pTruth2, nWords) ) {
|
|
||||||
printf( "Verification FAILED.\n" );
|
|
||||||
printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, Abc_NtkCiNum(pNtk) ); printf( "\n" );
|
|
||||||
printf("Function after: "); Abc_TtPrintHexRev( stdout, pTruth2, Abc_NtkCiNum(pNtk) ); printf( "\n" );
|
|
||||||
}
|
}
|
||||||
else if ( fVerbose )
|
|
||||||
printf( "Verification passed.\n" );
|
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, fVerbose );
|
||||||
ABC_FREE( pLuts );
|
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
|
||||||
ABC_FREE( pTruth2 );
|
Vec_IntFree( vVarIDs );
|
||||||
|
|
||||||
|
if ( pLuts ) {
|
||||||
|
if ( fVerbose )
|
||||||
|
Abc_LutCascadePrint( pLuts );
|
||||||
|
word * pTruth2 = Abc_LutCascadeTruth( pLuts, Abc_NtkCiNum(pNtk) );
|
||||||
|
if ( !Abc_TtEqual(pCopy, pTruth2, nWords) ) {
|
||||||
|
printf( "Verification FAILED.\n" );
|
||||||
|
printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, Abc_NtkCiNum(pNtk) ); printf( "\n" );
|
||||||
|
printf("Function after: "); Abc_TtPrintHexRev( stdout, pTruth2, Abc_NtkCiNum(pNtk) ); printf( "\n" );
|
||||||
|
}
|
||||||
|
else if ( fVerbose )
|
||||||
|
printf( "Verification passed.\n" );
|
||||||
|
ABC_FREE( pLuts );
|
||||||
|
ABC_FREE( pTruth2 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//ABC_FREE( pTruth1 );
|
||||||
}
|
}
|
||||||
Gia_ManStop( pGia );
|
|
||||||
ABC_FREE( pCopy );
|
ABC_FREE( pCopy );
|
||||||
//ABC_FREE( pTruth1 );
|
Gia_ManStop( pGia );
|
||||||
return pNew;
|
return pNew;
|
||||||
}
|
}
|
||||||
Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose )
|
Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose )
|
||||||
|
|
@ -1154,7 +1159,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
|
||||||
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose )
|
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose )
|
||||||
{
|
{
|
||||||
abctime clkStart = Abc_Clock();
|
abctime clkStart = Abc_Clock();
|
||||||
int i, Sum = 0, nWords = Abc_TtWordNum(nVarsOrig);
|
int i, Sum = 0, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig);
|
||||||
Vec_Wrd_t * vTruths = NULL;
|
Vec_Wrd_t * vTruths = NULL;
|
||||||
if ( strstr(pFileName, ".txt") )
|
if ( strstr(pFileName, ".txt") )
|
||||||
vTruths = Abc_NtkLutCasReadTruths( pFileName, nVarsOrig );
|
vTruths = Abc_NtkLutCasReadTruths( pFileName, nVarsOrig );
|
||||||
|
|
@ -1172,7 +1177,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
||||||
|
|
||||||
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
|
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
|
||||||
word * pCopy = ABC_ALLOC( word, nWords );
|
word * pCopy = ABC_ALLOC( word, nWords );
|
||||||
int LutStats[100] = {0};
|
int Iter = 0, LutStats[100] = {0};
|
||||||
|
Abc_Random(1);
|
||||||
for ( i = 0; i < nFuncs; i++ )
|
for ( i = 0; i < nFuncs; i++ )
|
||||||
{
|
{
|
||||||
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
|
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
|
||||||
|
|
@ -1199,11 +1205,18 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
||||||
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, fVeryVerbose );
|
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, fVeryVerbose );
|
||||||
Vec_IntFree( vVarIDs );
|
Vec_IntFree( vVarIDs );
|
||||||
if ( pLuts == NULL ) {
|
if ( pLuts == NULL ) {
|
||||||
|
if ( ++Iter < nIters ) {
|
||||||
|
i--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Iter = 0;
|
||||||
if ( fVerbose || fVeryVerbose )
|
if ( fVerbose || fVeryVerbose )
|
||||||
printf( "Not decomposable.\n" );
|
printf( "Not decomposable.\n" );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Iter = 0;
|
||||||
Sum++;
|
Sum++;
|
||||||
|
nTotalLuts += Abc_LutCascadeCount(pLuts);
|
||||||
LutStats[Abc_LutCascadeCount(pLuts)]++;
|
LutStats[Abc_LutCascadeCount(pLuts)]++;
|
||||||
word * pTruth2 = Abc_LutCascadeTruth( pLuts, nVarsOrig );
|
word * pTruth2 = Abc_LutCascadeTruth( pLuts, nVarsOrig );
|
||||||
if ( fVeryVerbose )
|
if ( fVeryVerbose )
|
||||||
|
|
@ -1227,7 +1240,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
||||||
if ( LutStats[i] )
|
if ( LutStats[i] )
|
||||||
printf( " %d LUT6 : Function count = %8d (%6.2f %%)\n", i, LutStats[i], 100.0*LutStats[i]/nFuncs );
|
printf( " %d LUT6 : Function count = %8d (%6.2f %%)\n", i, LutStats[i], 100.0*LutStats[i]/nFuncs );
|
||||||
printf( "Non-decomp : Function count = %8d (%6.2f %%)\n", nFuncs-Sum, 100.0*(nFuncs-Sum)/Abc_MaxInt(1, nFuncs) );
|
printf( "Non-decomp : Function count = %8d (%6.2f %%)\n", nFuncs-Sum, 100.0*(nFuncs-Sum)/Abc_MaxInt(1, nFuncs) );
|
||||||
printf( "Finished %d functions (speed = %.2f functions / second). ", nFuncs, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );
|
printf( "Finished %d functions (%.2f LUTs / function; %.2f functions / sec). ",
|
||||||
|
nFuncs, 1.0*nTotalLuts/Sum, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );
|
||||||
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
|
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ void Abc_BSEvalOneTest( word * pT, int nVars, int nBVars, int fVerbose )
|
||||||
int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int fShared )
|
int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int fShared )
|
||||||
{
|
{
|
||||||
int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32];
|
int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32];
|
||||||
int nPermVars = nVars-nCVars;
|
int nPermVars = nVars-nCVars, Count = 0;
|
||||||
assert( p->nVars == nPermVars && p->nBVars == nVars-nFVars );
|
assert( p->nVars == nPermVars && p->nBVars == nVars-nFVars );
|
||||||
for ( i = 0; i < nVars; i++ )
|
for ( i = 0; i < nVars; i++ )
|
||||||
Pla2Var[i] = Var2Pla[i] = i;
|
Pla2Var[i] = Var2Pla[i] = i;
|
||||||
|
|
@ -605,6 +605,11 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int n
|
||||||
CostBest = CostThis;
|
CostBest = CostThis;
|
||||||
if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 );
|
if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 );
|
||||||
if ( pPermBest ) memcpy( pPermBest, Pla2Var, sizeof(int)*nVars );
|
if ( pPermBest ) memcpy( pPermBest, Pla2Var, sizeof(int)*nVars );
|
||||||
|
Count = 1;
|
||||||
|
}
|
||||||
|
else if ( CostBest == CostThis && (Abc_Random(0) % ++Count) == 0 ) {
|
||||||
|
if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 );
|
||||||
|
if ( pPermBest ) memcpy( pPermBest, Pla2Var, sizeof(int)*nVars );
|
||||||
}
|
}
|
||||||
if ( fVerbose )
|
if ( fVerbose )
|
||||||
{
|
{
|
||||||
|
|
@ -922,7 +927,7 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR
|
||||||
word * pTruth = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
word * pTruth = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
||||||
word * pBest = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
word * pBest = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
||||||
Abc_TtCopy( pTruth, pFunc, Abc_TtWordNum(nVars), 0 );
|
Abc_TtCopy( pTruth, pFunc, Abc_TtWordNum(nVars), 0 );
|
||||||
int i, nVarsCur = nVars, nOutVars = 0;
|
int i, r, nVarsCur = nVars, nOutVars = 0;
|
||||||
while ( nVarsCur > nLutSize )
|
while ( nVarsCur > nLutSize )
|
||||||
{
|
{
|
||||||
int pPerm[32] = {0};
|
int pPerm[32] = {0};
|
||||||
|
|
@ -943,8 +948,12 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR
|
||||||
}
|
}
|
||||||
int MyuMin = Abc_BSEvalBest( p, pTruth, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, fVerbose, pPerm, 0 );
|
int MyuMin = Abc_BSEvalBest( p, pTruth, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, fVerbose, pPerm, 0 );
|
||||||
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
|
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
|
||||||
if ( nRailsMin > nRails )
|
for ( r = 1; r <= nRails && nRailsMin > r; r++ ) {
|
||||||
nRailsMin = Abc_SharedEvalBest( p, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, MyuMin, nRails, fVerbose, &Shared, p->pPat );
|
int nRailsMinNew = Abc_SharedEvalBest( p, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, MyuMin, nRails, fVerbose, &Shared, p->pPat );
|
||||||
|
if ( nRailsMinNew < 100 )
|
||||||
|
nRailsMin = nRailsMinNew;
|
||||||
|
}
|
||||||
|
MyuMin = 1 << nRailsMin;
|
||||||
if ( nRailsMin > nRails ) {
|
if ( nRailsMin > nRails ) {
|
||||||
Vec_WrdFreeP( &vRes );
|
Vec_WrdFreeP( &vRes );
|
||||||
break;
|
break;
|
||||||
|
|
@ -1007,7 +1016,7 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int
|
||||||
p->nBVars = nLutSize;
|
p->nBVars = nLutSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int v, nWords = Abc_TtWordNum(nVars);
|
int v, r, nWords = Abc_TtWordNum(nVars);
|
||||||
word * pCopy = ABC_ALLOC( word, nWords );
|
word * pCopy = ABC_ALLOC( word, nWords );
|
||||||
Abc_TtCopy( pCopy, pTruth, nWords, 0 );
|
Abc_TtCopy( pCopy, pTruth, nWords, 0 );
|
||||||
//word pPat[MAX_PAT_WORD_SIZE];
|
//word pPat[MAX_PAT_WORD_SIZE];
|
||||||
|
|
@ -1026,10 +1035,12 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int
|
||||||
}
|
}
|
||||||
|
|
||||||
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
|
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
|
||||||
if ( nRailsMin > nRails ) {
|
for ( r = 1; r <= nRails && nRailsMin > r; r++ ) {
|
||||||
nRailsMin = Abc_SharedEvalBest( p, pBest, nVars, nRVars, nVars-nLutSize, MyuMin, nRails, 0, &Shared, p->pPat );
|
int nRailsMinNew = Abc_SharedEvalBest( p, pBest, nVars, nRVars, nVars-nLutSize, MyuMin, r, 0, &Shared, p->pPat );
|
||||||
MyuMin = 1 << nRailsMin;
|
if ( nRailsMinNew < 100 )
|
||||||
|
nRailsMin = nRailsMinNew;
|
||||||
}
|
}
|
||||||
|
MyuMin = 1 << nRailsMin;
|
||||||
|
|
||||||
ABC_FREE( pCopy );
|
ABC_FREE( pCopy );
|
||||||
ABC_FREE( pBest );
|
ABC_FREE( pBest );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue