Enable saving choices in &deepsyn.

This commit is contained in:
Alan Mishchenko
2025-09-30 15:48:45 -07:00
parent b28e042afd
commit 613fa4f5eb
4 changed files with 77 additions and 39 deletions

View File

@@ -43,7 +43,7 @@ ABC_NAMESPACE_IMPL_START
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDeepSynOne( int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose )
Gia_Man_t * Gia_ManDeepSynOne( int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose, Vec_Ptr_t * vGias )
{
abctime nTimeToStop = TimeOut ? Abc_Clock() + TimeOut * CLOCKS_PER_SEC : 0;
abctime clkStart = Abc_Clock();
@@ -100,6 +100,8 @@ Gia_Man_t * Gia_ManDeepSynOne( int nNoImpr, int TimeOut, int nAnds, int Seed, in
pNew = Gia_ManDup( pTemp );
fChange = 1;
iIterLast = i;
if ( vGias )
Vec_PtrPush( vGias, Gia_ManDup(pTemp) );
}
else if ( Gia_ManAndNum(pNew) + Gia_ManAndNum(pNew)/10 < Gia_ManAndNum(pTemp) )
{
@@ -139,16 +141,19 @@ Gia_Man_t * Gia_ManDeepSynOne( int nNoImpr, int TimeOut, int nAnds, int Seed, in
nAndsMin, nAnds, i, (float)1.0*(Abc_Clock() - clkStart)/CLOCKS_PER_SEC );
return pNew;
}
Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose )
Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fChoices, int fVerbose )
{
Vec_Ptr_t * vGias = fChoices ? Vec_PtrAlloc(100) : NULL;
Gia_Man_t * pInit = Gia_ManDup(pGia);
Gia_Man_t * pBest = Gia_ManDup(pGia);
Gia_Man_t * pThis;
int i;
if ( vGias )
Vec_PtrPush( vGias, Gia_ManDup(pGia) );
for ( i = 0; i < nIters; i++ )
{
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), Gia_ManDup(pInit) );
pThis = Gia_ManDeepSynOne( nNoImpr, TimeOut, nAnds, Seed+i, fUseTwo, fVerbose );
pThis = Gia_ManDeepSynOne( nNoImpr, TimeOut, nAnds, Seed+i, fUseTwo, fVerbose, vGias );
if ( Gia_ManAndNum(pBest) > Gia_ManAndNum(pThis) )
{
Gia_ManStop( pBest );
@@ -159,6 +164,16 @@ Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeO
}
Gia_ManStop( pInit );
if ( vGias ) {
extern Gia_Man_t * Gia_ManCreateChoicesArray( Vec_Ptr_t * vGias, int fVerbose );
Gia_ManStopP( &pBest );
pBest = Gia_ManCreateChoicesArray( vGias, fVerbose );
// cleanup
Gia_Man_t * pTemp;
Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
Gia_ManStop( pTemp );
Vec_PtrFree( vGias );
}
return pBest;
}

View File

@@ -1020,6 +1020,50 @@ Vec_Wec_t * Gia_ManStochOutputs( Gia_Man_t * p, Vec_Wec_t * vAnds )
return vRes;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManCreateChoicesArray( Vec_Ptr_t * vGias, int fVerbose )
{
abctime clkStart = Abc_Clock(); int i;
// swap around the first and the last
Gia_Man_t * pTemp = (Gia_Man_t *)Vec_PtrPop( vGias );
Vec_PtrPush( vGias, Vec_PtrEntry(vGias,0) );
Vec_PtrWriteEntry( vGias, 0, pTemp );
if ( fVerbose ) {
printf( "Choicing will be performed with %d AIGs:\n", Vec_PtrSize(vGias) );
Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
Gia_ManPrintStats( pTemp, NULL );
}
Dch_Pars_t Pars, * pPars = &Pars;
Dch_ManSetDefaultParams( pPars );
// derive the miter
Gia_Man_t * pMiter = Gia_ManChoiceMiter( vGias );
Aig_Man_t * pAux, * pMan = Gia_ManToAigSkip( pMiter, Vec_PtrSize(vGias) );
Gia_ManStop( pMiter );
pMan = Dch_ComputeChoices( pAux = pMan, pPars );
Aig_ManStop( pAux );
// reconstruct the network
extern Vec_Ptr_t * Gia_ManOrderPios( Aig_Man_t * p, Gia_Man_t * pOrder );
Vec_Ptr_t * vPios = Gia_ManOrderPios( pMan, (Gia_Man_t *)Vec_PtrEntry(vGias,0) );
pMan = Aig_ManDupDfsGuided( pAux = pMan, vPios );
Aig_ManStop( pAux );
Vec_PtrFree( vPios );
// convert to GIA
Gia_Man_t * pChoices = Gia_ManFromAigChoices( pMan );
if ( fVerbose )
Abc_PrintTime( 0, "Choice computation time", Abc_Clock() - clkStart );
return pChoices;
}
/**Function*************************************************************
Synopsis []
@@ -1124,39 +1168,14 @@ void Gia_ManStochSyn( int nSuppMax, int nMaxSize, int nIters, int TimeOut, int S
if ( fVerbose )
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
if ( vGias ) {
abctime clkStart = Abc_Clock();
// swap around the first and the last
Gia_Man_t * pTemp = (Gia_Man_t *)Vec_PtrPop( vGias );
Vec_PtrPush( vGias, Vec_PtrEntry(vGias,0) );
Vec_PtrWriteEntry( vGias, 0, pTemp );
if ( fVerbose ) {
printf( "Choicing will be performed with %d AIGs:\n", Vec_PtrSize(vGias) );
Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
Gia_ManPrintStats( pTemp, NULL );
}
Dch_Pars_t Pars, * pPars = &Pars;
Dch_ManSetDefaultParams( pPars );
// derive the miter
Gia_Man_t * pMiter = Gia_ManChoiceMiter( vGias );
Aig_Man_t * pAux, * pMan = Gia_ManToAigSkip( pMiter, Vec_PtrSize(vGias) );
Gia_ManStop( pMiter );
pMan = Dch_ComputeChoices( pAux = pMan, pPars );
Aig_ManStop( pAux );
// reconstruct the network
extern Vec_Ptr_t * Gia_ManOrderPios( Aig_Man_t * p, Gia_Man_t * pOrder );
Vec_Ptr_t * vPios = Gia_ManOrderPios( pMan, (Gia_Man_t *)Vec_PtrEntry(vGias,0) );
pMan = Aig_ManDupDfsGuided( pAux = pMan, vPios );
Aig_ManStop( pAux );
Vec_PtrFree( vPios );
// convert to GIA
Gia_Man_t * pChoices = Gia_ManFromAigChoices( pMan );
Gia_Man_t * pChoices = Gia_ManCreateChoicesArray( vGias, fVerbose );
Abc_FrameUpdateGia( Abc_FrameGetGlobalFrame(), pChoices );
// cleanup
Gia_Man_t * pTemp;
Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
Gia_ManStop( pTemp );
Vec_PtrFree( vGias );
if ( fVerbose )
Abc_PrintTime( 0, "Choice computation time", Abc_Clock() - clkStart );
Vec_PtrFree( vGias );
}
}

View File

@@ -53436,10 +53436,10 @@ usage:
***********************************************************************/
int Abc_CommandAbc9DeepSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose );
Gia_Man_t * pTemp; int c, nIters = 1, nNoImpr = ABC_INFINITY, TimeOut = 0, nAnds = 0, Seed = 0, fUseTwo = 0, fVerbose = 0;
extern Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fChoices, int fVerbose );
Gia_Man_t * pTemp; int c, nIters = 1, nNoImpr = ABC_INFINITY, TimeOut = 0, nAnds = 0, Seed = 0, fUseTwo = 0, fChoices = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "IJTAStvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "IJTAStcvh" ) ) != EOF )
{
switch ( c )
{
@@ -53501,6 +53501,9 @@ int Abc_CommandAbc9DeepSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
case 't':
fUseTwo ^= 1;
break;
case 'c':
fChoices ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
@@ -53515,12 +53518,12 @@ int Abc_CommandAbc9DeepSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Abc_CommandAbc9DeepSyn(): There is no AIG.\n" );
return 0;
}
pTemp = Gia_ManDeepSyn( pAbc->pGia, nIters, nNoImpr, TimeOut, nAnds, Seed, fUseTwo, fVerbose );
pTemp = Gia_ManDeepSyn( pAbc->pGia, nIters, nNoImpr, TimeOut, nAnds, Seed, fUseTwo, fChoices, fVerbose );
Abc_FrameUpdateGia( pAbc, pTemp );
return 0;
usage:
Abc_Print( -2, "usage: &deepsyn [-IJTAS <num>] [-tvh]\n" );
Abc_Print( -2, "usage: &deepsyn [-IJTAS <num>] [-tcvh]\n" );
Abc_Print( -2, "\t performs synthesis\n" );
Abc_Print( -2, "\t-I <num> : the number of iterations [default = %d]\n", nIters );
Abc_Print( -2, "\t-J <num> : the number of steps without improvements [default = %d]\n", nNoImpr );
@@ -53528,6 +53531,7 @@ usage:
Abc_Print( -2, "\t-A <num> : the number of nodes to stop (0 = no limit) [default = %d]\n", nAnds );
Abc_Print( -2, "\t-S <num> : user-specified random seed (0 <= num <= 100) [default = %d]\n", Seed );
Abc_Print( -2, "\t-t : toggle using two-input LUTs [default = %s]\n", fUseTwo? "yes": "no" );
Abc_Print( -2, "\t-c : toggle computing structural choices [default = %s]\n", fChoices? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;

View File

@@ -28,7 +28,7 @@
#include "eSLIM.h"
ABC_NAMESPACE_HEADER_START
Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fVerbose );
Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int nIters, int nNoImpr, int TimeOut, int nAnds, int Seed, int fUseTwo, int fChoices, int fVerbose );
ABC_NAMESPACE_HEADER_END
ABC_NAMESPACE_IMPL_START
@@ -100,7 +100,7 @@ Gia_Man_t* selectApproach(Gia_Man_t* pGia, eSLIM::eSLIMConfig params, eSLIM::eSL
}
Gia_Man_t* runInprocessing(Gia_Man_t * pGia, const eSLIM_ParamStruct* params, unsigned int it) {
Gia_Man_t * tmp = Gia_ManDeepSyn( pGia, 1, ABC_INFINITY, params->timeout_inprocessing, 0, params->seed + it, 0, 0);
Gia_Man_t * tmp = Gia_ManDeepSyn( pGia, 1, ABC_INFINITY, params->timeout_inprocessing, 0, params->seed + it, 0, 0, 0);
if ( Gia_ManAndNum(pGia) > Gia_ManAndNum(tmp) ) {
Gia_ManStop( pGia );
pGia = tmp;