Commit 83d3cc88 by Alan Mishchenko

Adding CEC command &splitprove.

parent ab1e4ed7
...@@ -156,6 +156,7 @@ struct Gia_Man_t_ ...@@ -156,6 +156,7 @@ struct Gia_Man_t_
Vec_Int_t * vUserFfIds; // numbers assigned to FFs by the user Vec_Int_t * vUserFfIds; // numbers assigned to FFs by the user
Vec_Int_t * vCiNumsOrig; // original CI names Vec_Int_t * vCiNumsOrig; // original CI names
Vec_Int_t * vCoNumsOrig; // original CO names Vec_Int_t * vCoNumsOrig; // original CO names
Vec_Int_t * vCofVars; // cofactoring variables
Vec_Vec_t * vClockDoms; // clock domains Vec_Vec_t * vClockDoms; // clock domains
Vec_Flt_t * vTiming; // arrival/required/slack Vec_Flt_t * vTiming; // arrival/required/slack
void * pManTime; // the timing manager void * pManTime; // the timing manager
...@@ -1013,7 +1014,7 @@ extern Gia_Man_t * Gia_ManDupFlopClass( Gia_Man_t * p, int iClass ); ...@@ -1013,7 +1014,7 @@ extern Gia_Man_t * Gia_ManDupFlopClass( Gia_Man_t * p, int iClass );
extern Gia_Man_t * Gia_ManDupMarked( Gia_Man_t * p ); extern Gia_Man_t * Gia_ManDupMarked( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupTimes( Gia_Man_t * p, int nTimes ); extern Gia_Man_t * Gia_ManDupTimes( Gia_Man_t * p, int nTimes );
extern Gia_Man_t * Gia_ManDupDfs( Gia_Man_t * p ); extern Gia_Man_t * Gia_ManDupDfs( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupDfsRehash( Gia_Man_t * p, int nSteps, int Value ); extern Gia_Man_t * Gia_ManDupCofactor( Gia_Man_t * p, int iVar, int Value );
extern Gia_Man_t * Gia_ManDupDfsSkip( Gia_Man_t * p ); extern Gia_Man_t * Gia_ManDupDfsSkip( Gia_Man_t * p );
extern Gia_Man_t * Gia_ManDupDfsCone( Gia_Man_t * p, Gia_Obj_t * pObj ); extern Gia_Man_t * Gia_ManDupDfsCone( Gia_Man_t * p, Gia_Obj_t * pObj );
extern Gia_Man_t * Gia_ManDupDfsLitArray( Gia_Man_t * p, Vec_Int_t * vLits ); extern Gia_Man_t * Gia_ManDupDfsLitArray( Gia_Man_t * p, Vec_Int_t * vLits );
......
...@@ -1201,30 +1201,33 @@ Gia_Man_t * Gia_ManDupDfs( Gia_Man_t * p ) ...@@ -1201,30 +1201,33 @@ Gia_Man_t * Gia_ManDupDfs( Gia_Man_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Gia_ManDupDfsRehash_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj ) void Gia_ManDupCofactor_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj )
{ {
if ( ~pObj->Value ) if ( ~pObj->Value )
return; return;
assert( Gia_ObjIsAnd(pObj) ); assert( Gia_ObjIsAnd(pObj) );
Gia_ManDupDfsRehash_rec( pNew, p, Gia_ObjFanin0(pObj) ); Gia_ManDupCofactor_rec( pNew, p, Gia_ObjFanin0(pObj) );
Gia_ManDupDfsRehash_rec( pNew, p, Gia_ObjFanin1(pObj) ); Gia_ManDupCofactor_rec( pNew, p, Gia_ObjFanin1(pObj) );
pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
} }
Gia_Man_t * Gia_ManDupDfsRehash( Gia_Man_t * p, int nSteps, int Value ) Gia_Man_t * Gia_ManDupCofactor( Gia_Man_t * p, int iVar, int Value )
{ {
Gia_Man_t * pNew, * pTemp; Gia_Man_t * pNew, * pTemp;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
int i; int i;
assert( iVar >= 0 && iVar < Gia_ManPiNum(p) );
assert( Value == 0 || Value == 1 );
pNew = Gia_ManStart( Gia_ManObjNum(p) ); pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName ); pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec ); pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManFillValue( p ); Gia_ManFillValue( p );
Gia_ManConst0(p)->Value = 0; Gia_ManConst0(p)->Value = 0;
Gia_ManForEachCi( p, pObj, i ) Gia_ManForEachCi( p, pObj, i )
pObj->Value = i < nSteps ? Value : Gia_ManAppendCi(pNew); pObj->Value = Gia_ManAppendCi(pNew);
Gia_ManPi( p, iVar )->Value = Value; // modification!
Gia_ManHashAlloc( pNew ); Gia_ManHashAlloc( pNew );
Gia_ManForEachCo( p, pObj, i ) Gia_ManForEachCo( p, pObj, i )
Gia_ManDupDfsRehash_rec( pNew, p, Gia_ObjFanin0(pObj) ); Gia_ManDupCofactor_rec( pNew, p, Gia_ObjFanin0(pObj) );
Gia_ManForEachCo( p, pObj, i ) Gia_ManForEachCo( p, pObj, i )
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) ); Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) ); Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
......
...@@ -92,6 +92,7 @@ void Gia_ManStop( Gia_Man_t * p ) ...@@ -92,6 +92,7 @@ void Gia_ManStop( Gia_Man_t * p )
Vec_WrdFreeP( &p->vSimsPi ); Vec_WrdFreeP( &p->vSimsPi );
Vec_FltFreeP( &p->vTiming ); Vec_FltFreeP( &p->vTiming );
Vec_VecFreeP( &p->vClockDoms ); Vec_VecFreeP( &p->vClockDoms );
Vec_IntFreeP( &p->vCofVars );
Vec_IntFreeP( &p->vLutConfigs ); Vec_IntFreeP( &p->vLutConfigs );
Vec_IntFreeP( &p->vUserPiIds ); Vec_IntFreeP( &p->vUserPiIds );
Vec_IntFreeP( &p->vUserPoIds ); Vec_IntFreeP( &p->vUserPoIds );
......
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
***********************************************************************/ ***********************************************************************/
#include <math.h>
#include "aig/gia/gia.h" #include "aig/gia/gia.h"
#include "aig/gia/giaAig.h" #include "aig/gia/giaAig.h"
#include "bdd/cudd/cuddInt.h" //#include "bdd/cudd/cuddInt.h"
#include "sat/cnf/cnf.h" #include "sat/cnf/cnf.h"
#include "sat/bsat/satStore.h" #include "sat/bsat/satSolver.h"
#include "misc/util/utilTruth.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -35,6 +37,8 @@ ABC_NAMESPACE_IMPL_START ...@@ -35,6 +37,8 @@ ABC_NAMESPACE_IMPL_START
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
#if 0 // BDD code
/**Function************************************************************* /**Function*************************************************************
Synopsis [Permute primary inputs.] Synopsis [Permute primary inputs.]
...@@ -109,6 +113,8 @@ void Gia_ManBuildBddTest( Gia_Man_t * p ) ...@@ -109,6 +113,8 @@ void Gia_ManBuildBddTest( Gia_Man_t * p )
Gia_ManDerefBdd( dd, vNodes ); Gia_ManDerefBdd( dd, vNodes );
} }
#endif // BDD code
/**Function************************************************************* /**Function*************************************************************
Synopsis [Permute primary inputs.] Synopsis [Permute primary inputs.]
...@@ -120,10 +126,9 @@ void Gia_ManBuildBddTest( Gia_Man_t * p ) ...@@ -120,10 +126,9 @@ void Gia_ManBuildBddTest( Gia_Man_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Gia_Man_t * Gia_PermuteSpecial( Gia_Man_t * p ) int * Gia_PermuteSpecialOrder( Gia_Man_t * p )
{ {
Vec_Int_t * vPerm; Vec_Int_t * vPerm;
Gia_Man_t * pNew;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
int i, * pOrder; int i, * pOrder;
Gia_ManCreateRefs( p ); Gia_ManCreateRefs( p );
...@@ -132,6 +137,13 @@ Gia_Man_t * Gia_PermuteSpecial( Gia_Man_t * p ) ...@@ -132,6 +137,13 @@ Gia_Man_t * Gia_PermuteSpecial( Gia_Man_t * p )
Vec_IntPush( vPerm, Gia_ObjRefNum(p, pObj) ); Vec_IntPush( vPerm, Gia_ObjRefNum(p, pObj) );
pOrder = Abc_QuickSortCost( Vec_IntArray(vPerm), Vec_IntSize(vPerm), 1 ); pOrder = Abc_QuickSortCost( Vec_IntArray(vPerm), Vec_IntSize(vPerm), 1 );
Vec_IntFree( vPerm ); Vec_IntFree( vPerm );
return pOrder;
}
Gia_Man_t * Gia_PermuteSpecial( Gia_Man_t * p )
{
Gia_Man_t * pNew;
Vec_Int_t * vPerm;
int * pOrder = Gia_PermuteSpecialOrder( p );
vPerm = Vec_IntAllocArray( pOrder, Gia_ManPiNum(p) ); vPerm = Vec_IntAllocArray( pOrder, Gia_ManPiNum(p) );
pNew = Gia_ManDupPerm( p, vPerm ); pNew = Gia_ManDupPerm( p, vPerm );
Vec_IntFree( vPerm ); Vec_IntFree( vPerm );
...@@ -207,29 +219,13 @@ static inline sat_solver * Cec_GiaDeriveSolver( Gia_Man_t * p, int nTimeOut ) ...@@ -207,29 +219,13 @@ static inline sat_solver * Cec_GiaDeriveSolver( Gia_Man_t * p, int nTimeOut )
Cnf_DataFree( pCnf ); Cnf_DataFree( pCnf );
return pSat; return pSat;
} }
static inline int Cnf_GiaSolveOne( Gia_Man_t * p, int nTimeOut, int nSize, int fVerbose ) static inline int Cnf_GiaSolveOne( Gia_Man_t * p, int nTimeOut, int fVerbose, int * pnVars, int * pnConfs )
{ {
static int Counter = 0; static int Counter = 0;
abctime clk = Abc_Clock();
sat_solver * pSat = Cec_GiaDeriveSolver( p, nTimeOut ); sat_solver * pSat = Cec_GiaDeriveSolver( p, nTimeOut );
int status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 ); int status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
if ( fVerbose ) *pnVars = sat_solver_nvars( pSat );
{ *pnConfs = sat_solver_nconflicts( pSat );
printf( "Iter%6d : ", Counter++ );
printf( "Size =%7d ", nSize );
printf( "Input = %3d ", Gia_ManPiNum(p) );
printf( "Var =%10d ", sat_solver_nvars(pSat) );
printf( "Clause =%10d ", sat_solver_nclauses(pSat) );
printf( "Conflict =%10d ", sat_solver_nconflicts(pSat) );
if ( status == l_Undef )
printf( "UNDECIDED " );
else if ( status == l_False )
printf( "UNSAT " );
else
printf( "SAT " );
Abc_PrintTime( 1, "Time", Abc_Clock()-clk );
//ABC_PRTr( "Time", Abc_Clock()-clk );
}
sat_solver_delete( pSat ); sat_solver_delete( pSat );
if ( status == l_Undef ) if ( status == l_Undef )
return -1; return -1;
...@@ -253,9 +249,9 @@ static inline int Cnf_GiaSolveOne( Gia_Man_t * p, int nTimeOut, int nSize, int f ...@@ -253,9 +249,9 @@ static inline int Cnf_GiaSolveOne( Gia_Man_t * p, int nTimeOut, int nSize, int f
} }
*/ */
} }
static inline int Cnf_GiaCheckOne( Vec_Ptr_t * vStack, Gia_Man_t * p, int nTimeOut, int nSize, int fVerbose ) static inline int Cnf_GiaCheckOne( Vec_Ptr_t * vStack, Gia_Man_t * p, int nTimeOut, int fVerbose, int * pnVars, int * pnConfs )
{ {
int status = Cnf_GiaSolveOne( p, nTimeOut, nSize, fVerbose ); int status = Cnf_GiaSolveOne( p, nTimeOut, fVerbose, pnVars, pnConfs );
if ( status == -1 ) if ( status == -1 )
{ {
Vec_PtrPush( vStack, p ); Vec_PtrPush( vStack, p );
...@@ -287,47 +283,111 @@ static inline void Cec_GiaSplitClean( Vec_Ptr_t * vStack ) ...@@ -287,47 +283,111 @@ static inline void Cec_GiaSplitClean( Vec_Ptr_t * vStack )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Cec_GiaSplitPrint( int nIter, int Depth, int nVars, int nConfs, int fSatUnsat, double Prog, abctime clk )
{
printf( "%6d : ", nIter );
printf( "Depth =%3d ", Depth );
printf( "SatVar =%10d ", nVars );
printf( "SatConf =%7d ", nConfs );
printf( "%s ", fSatUnsat ? "UNSAT " : "UNDECIDED" );
printf( "Progress = %.9f ", Prog );
Abc_PrintTime( 1, "Time", clk );
//ABC_PRTr( "Time", Abc_Clock()-clk );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Cec_GiaSplitTest( Gia_Man_t * p, int nTimeOut, int fVerbose ) int Cec_GiaSplitTest( Gia_Man_t * p, int nTimeOut, int fVerbose )
{ {
Gia_Man_t * pNew; abctime clk, clkTotal = Abc_Clock();
Vec_Ptr_t * vStack; Gia_Man_t * pPart0, * pPart1, * pLast;
Gia_Man_t * pPart0, * pPart1;
Gia_Obj_t * pObj; Gia_Obj_t * pObj;
int i, RetValue = -1; Vec_Ptr_t * vStack;
int * pOrder, RetValue = -1;
int nSatVars, nSatConfs, fSatUnsat;
int i, nIter, iVar, Depth;
double Progress = 0;
// create local copy
p = Gia_ManDup( p );
// reorder variables // reorder variables
pNew = Gia_PermuteSpecial( p ); pOrder = Gia_PermuteSpecialOrder( p );
if ( fVerbose ) if ( fVerbose )
{ {
Gia_ManCreateRefs( pNew ); Gia_ManForEachPi( p, pObj, i )
Gia_ManForEachPi( pNew, pObj, i ) printf( "%d ", Gia_ObjRefNum(p, pObj) );
printf( "%d ", Gia_ObjRefNum(pNew, pObj) ); printf( "\n" );
Gia_ManForEachPi( p, pObj, i )
printf( "%d ", Gia_ObjRefNum(p, Gia_ManPi(p, pOrder[i])) );
printf( "\n" ); printf( "\n" );
} }
// start cofactored variables
assert( p->vCofVars == NULL );
p->vCofVars = Vec_IntAlloc( 100 );
// start with the current problem // start with the current problem
vStack = Vec_PtrAlloc( 1000 ); vStack = Vec_PtrAlloc( 1000 );
if ( !Cnf_GiaCheckOne(vStack, pNew, nTimeOut, Vec_PtrSize(vStack), fVerbose) ) clk = Abc_Clock();
if ( !Cnf_GiaCheckOne(vStack, p, nTimeOut, fVerbose, &nSatVars, &nSatConfs) )
RetValue = 0; RetValue = 0;
else else
{ {
while ( Vec_PtrSize(vStack) > 0 ) if ( fVerbose )
Cec_GiaSplitPrint( 0, 0, nSatVars, nSatConfs, 0, 0, Abc_Clock() - clk );
for ( nIter = 1; Vec_PtrSize(vStack) > 0; nIter++ )
{ {
pNew = (Gia_Man_t *)Vec_PtrPop( vStack ); // get the last AIG
pLast = (Gia_Man_t *)Vec_PtrPop( vStack );
// determine cofactoring variable
Depth = Vec_IntSize(pLast->vCofVars);
iVar = pOrder[Depth];
// cofactor // cofactor
pPart0 = Gia_ManDupDfsRehash( pNew, 1, 0 ); pPart0 = Gia_ManDupCofactor( pLast, iVar, 0 );
if ( !Cnf_GiaCheckOne(vStack, pPart0, nTimeOut, Vec_PtrSize(vStack), fVerbose) ) // create variable
pPart0->vCofVars = Vec_IntAlloc( Vec_IntSize(pLast->vCofVars) + 1 );
Vec_IntAppend( pPart0->vCofVars, pLast->vCofVars );
Vec_IntPush( pPart0->vCofVars, Abc_Var2Lit(iVar, 1) );
// check this AIG
fSatUnsat = Vec_PtrSize(vStack);
clk = Abc_Clock();
if ( !Cnf_GiaCheckOne(vStack, pPart0, nTimeOut, fVerbose, &nSatVars, &nSatConfs) )
{ {
Gia_ManStop( pNew ); Gia_ManStop( pLast );
RetValue = 0; RetValue = 0;
break; break;
} }
fSatUnsat = (fSatUnsat == Vec_PtrSize(vStack));
if ( fSatUnsat )
Progress += 1.0 / pow(0.5, Depth + 1);
if ( fVerbose )
Cec_GiaSplitPrint( nIter, Depth, nSatVars, nSatConfs, fSatUnsat, Progress, Abc_Clock() - clk );
// cofactor // cofactor
pPart1 = Gia_ManDupDfsRehash( pNew, 1, 1 ); pPart1 = Gia_ManDupCofactor( pLast, iVar, 1 );
Gia_ManStop( pNew ); // create variable
if ( !Cnf_GiaCheckOne(vStack, pPart1, nTimeOut, Vec_PtrSize(vStack), fVerbose) ) pPart1->vCofVars = Vec_IntAlloc( Vec_IntSize(pLast->vCofVars) + 1 );
Vec_IntAppend( pPart1->vCofVars, pLast->vCofVars );
Vec_IntPush( pPart1->vCofVars, Abc_Var2Lit(iVar, 0) );
Gia_ManStop( pLast );
// check this AIG
fSatUnsat = Vec_PtrSize(vStack);
clk = Abc_Clock();
if ( !Cnf_GiaCheckOne(vStack, pPart1, nTimeOut, fVerbose, &nSatVars, &nSatConfs) )
{ {
RetValue = 0; RetValue = 0;
break; break;
} }
fSatUnsat = (fSatUnsat == Vec_PtrSize(vStack));
if ( fSatUnsat )
Progress += 1.0 / (Depth + 1);
if ( fVerbose )
Cec_GiaSplitPrint( nIter, Depth, nSatVars, nSatConfs, fSatUnsat, Progress, Abc_Clock() - clk );
// if ( Vec_PtrSize(vStack) > 2 ) // if ( Vec_PtrSize(vStack) > 2 )
// break; // break;
} }
...@@ -336,12 +396,14 @@ int Cec_GiaSplitTest( Gia_Man_t * p, int nTimeOut, int fVerbose ) ...@@ -336,12 +396,14 @@ int Cec_GiaSplitTest( Gia_Man_t * p, int nTimeOut, int fVerbose )
} }
Cec_GiaSplitClean( vStack ); Cec_GiaSplitClean( vStack );
if ( RetValue == 0 ) if ( RetValue == 0 )
printf( "Problem is SAT\n" ); printf( "Problem is SAT " );
else if ( RetValue == 1 ) else if ( RetValue == 1 )
printf( "Problem is UNSAT\n" ); printf( "Problem is UNSAT " );
else if ( RetValue == -1 ) else if ( RetValue == -1 )
printf( "Problem is UNDECIDED\n" ); printf( "Problem is UNDECIDED " );
else assert( 0 ); else assert( 0 );
ABC_FREE( pOrder );
Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
return RetValue; return RetValue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment