Commit 191a9ccd by Alan Mishchenko

Updates for the new BMC engine.

parent 92c7c6f7
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
***********************************************************************/ ***********************************************************************/
#include "bmc.h" #include "bmc.h"
#include "sat/bsat/satStore.h"
#include "sat/cnf/cnf.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -27,6 +29,19 @@ ABC_NAMESPACE_IMPL_START ...@@ -27,6 +29,19 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
typedef struct Bmc_Mna_t_ Bmc_Mna_t;
struct Bmc_Mna_t_
{
Gia_Man_t * pFrames; // time frames
Vec_Int_t * vId2Var; // maps GIA IDs into SAT vars
Vec_Int_t * vInputs; // inputs of the cone
Vec_Int_t * vOutputs; // outputs of the cone
Vec_Int_t * vNodes; // internal nodes of the cone
sat_solver * pSat; // SAT solver
int nSatVars; // the counter of SAT variables
abctime clkStart; // starting time
};
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -42,20 +57,111 @@ ABC_NAMESPACE_IMPL_START ...@@ -42,20 +57,111 @@ ABC_NAMESPACE_IMPL_START
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Gia_ManCountUnmarked_rec( Gia_Obj_t * pObj ) Bmc_Mna_t * Bmc_MnaAlloc()
{
Bmc_Mna_t * p;
p = ABC_CALLOC( Bmc_Mna_t, 1 );
p->vId2Var = Vec_IntAlloc( 0 );
p->vInputs = Vec_IntAlloc( 1000 );
p->vOutputs = Vec_IntAlloc( 1000 );
p->vNodes = Vec_IntAlloc( 10000 );
p->pSat = sat_solver_new();
p->nSatVars = 1;
p->clkStart = Abc_Clock();
return p;
}
void Bmc_MnaFree( Bmc_Mna_t * p )
{
Vec_IntFreeP( &p->vId2Var );
Vec_IntFreeP( &p->vInputs );
Vec_IntFreeP( &p->vOutputs );
Vec_IntFreeP( &p->vNodes );
sat_solver_delete( p->pSat );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Returns 1 if all outputs are trivial.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManBmcCheckOutputs( Gia_Man_t * pFrames, int iStart )
{
int i;
for ( i = iStart; i < Gia_ManPoNum(pFrames); i++ )
if ( Gia_ObjChild0(Gia_ManPo(pFrames, i)) != Gia_ManConst0(pFrames) )
return 0;
return 1;
}
/**Function*************************************************************
Synopsis [Collects new nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManBmcAndCone_rec( Bmc_Mna_t * p, Gia_Obj_t * pObj )
{ {
if ( !Gia_ObjIsAnd(pObj) || pObj->fMark0 ) int iObj;
return 0; if ( pObj->fMark0 )
return;
pObj->fMark0 = 1; pObj->fMark0 = 1;
return 1 + Gia_ManCountUnmarked_rec( Gia_ObjFanin0(pObj) ) + iObj = Gia_ObjId( p->pFrames, pObj );
Gia_ManCountUnmarked_rec( Gia_ObjFanin1(pObj) ); if ( Gia_ObjIsAnd(pObj) && Vec_IntEntry(p->vId2Var, iObj) == 0 )
{
Gia_ManBmcAndCone_rec( p, Gia_ObjFanin0(pObj) );
Gia_ManBmcAndCone_rec( p, Gia_ObjFanin1(pObj) );
Vec_IntPush( p->vNodes, iObj );
}
else
Vec_IntPush( p->vInputs, iObj );
} }
int Gia_ManCountUnmarked( Gia_Man_t * p, int iStart ) void Gia_ManBmcAndCone( Bmc_Mna_t * p, int iStart )
{ {
int i, Counter = 0; Gia_Obj_t * pObj;
for ( i = iStart; i < Gia_ManPoNum(p); i++ ) int i;
Counter += Gia_ManCountUnmarked_rec( Gia_ObjFanin0(Gia_ManPo(p, i)) ); Vec_IntClear( p->vNodes );
return Counter; Vec_IntClear( p->vInputs );
Vec_IntClear( p->vOutputs );
Vec_IntFillExtra( p->vId2Var, Gia_ManObjNum(p->pFrames), 0 );
for ( i = iStart; i < Gia_ManPoNum(p->pFrames); i++ )
{
pObj = Gia_ManPo(p->pFrames, i);
if ( Gia_ObjChild0(pObj) == Gia_ManConst0(p->pFrames) )
continue;
Gia_ManBmcAndCone_rec( p, Gia_ObjFanin0(pObj) );
Vec_IntPush( p->vOutputs, Gia_ObjId(p->pFrames, pObj) );
}
// clean attributes and create new variables
Gia_ManForEachObjVec( p->vInputs, p->pFrames, pObj, i )
{
int iObj = Vec_IntEntry(p->vInputs, i);
pObj->fMark0 = 0;
if ( Vec_IntEntry( p->vId2Var, iObj ) == 0 )
Vec_IntWriteEntry( p->vId2Var, iObj, p->nSatVars++ );
}
Gia_ManForEachObjVec( p->vNodes, p->pFrames, pObj, i )
{
int iObj = Vec_IntEntry(p->vNodes, i);
pObj->fMark0 = 0;
assert( Vec_IntEntry( p->vId2Var, iObj ) == 0 );
Vec_IntWriteEntry( p->vId2Var, iObj, p->nSatVars++ );
}
// extend the SAT solver
if ( p->nSatVars > sat_solver_nvars(p->pSat) )
sat_solver_setnvars( p->pSat, p->nSatVars );
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -71,46 +177,44 @@ int Gia_ManCountUnmarked( Gia_Man_t * p, int iStart ) ...@@ -71,46 +177,44 @@ int Gia_ManCountUnmarked( Gia_Man_t * p, int iStart )
***********************************************************************/ ***********************************************************************/
int Gia_ManBmcPerform( Gia_Man_t * pGia, Bmc_AndPar_t * pPars ) int Gia_ManBmcPerform( Gia_Man_t * pGia, Bmc_AndPar_t * pPars )
{ {
Unr_Man_t * p; Unr_Man_t * pUnroll;
Gia_Man_t * pFrames; Bmc_Mna_t * p = Bmc_MnaAlloc();
abctime clk = Abc_Clock();
int nFramesMax = pPars->nFramesMax ? pPars->nFramesMax : ABC_INFINITY; int nFramesMax = pPars->nFramesMax ? pPars->nFramesMax : ABC_INFINITY;
int i, f, iStart, status = -1;//, Counter = 0; int f, iStart, status = -1;
p = Unr_ManUnrollStart( pGia, pPars->fVeryVerbose ); pUnroll = Unr_ManUnrollStart( pGia, pPars->fVeryVerbose );
for ( f = 0; f < nFramesMax; f++ ) for ( f = 0; f < nFramesMax; f++ )
{ {
pFrames = Unr_ManUnrollFrame( p, f ); p->pFrames = Unr_ManUnrollFrame( pUnroll, f );
assert( Gia_ManPoNum(pFrames) == (f + 1) * Gia_ManPoNum(pGia) );
iStart = f * Gia_ManPoNum(pGia); iStart = f * Gia_ManPoNum(pGia);
for ( i = iStart; i < Gia_ManPoNum(pFrames); i++ ) if ( Gia_ManBmcCheckOutputs(p->pFrames, iStart) )
if ( Gia_ObjChild0(Gia_ManPo(pFrames, i)) != Gia_ManConst0(pFrames) )
break;
if ( i == Gia_ManPoNum(pFrames) )
{ {
if ( pPars->fVerbose ) if ( pPars->fVerbose )
{ {
printf( "Frame %4d : PI =%9d. AIG =%9d. Trivally UNSAT. Mem =%7.1f Mb ", printf( "%4d : PI =%9d. AIG =%9d. Var =%8d. Trivially UNSAT. Mem =%7.1f Mb ",
f, Gia_ManPiNum(pFrames), Gia_ManAndNum(pFrames), Gia_ManMemory(pFrames) ); f, Gia_ManPiNum(p->pFrames), Gia_ManAndNum(p->pFrames),
Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); p->nSatVars-1, Gia_ManMemory(p->pFrames) );
Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
} }
continue; continue;
} }
// create another slice
Gia_ManBmcAndCone(p, iStart);
if ( pPars->fVerbose ) if ( pPars->fVerbose )
{ {
printf( "Frame %4d : PI =%9d. AIG =%9d. And =%9d. Mem =%7.1f Mb ", printf( "%4d : PI =%9d. AIG =%9d. Var =%8d. In =%6d. And =%9d. Mem =%7.1f Mb ",
f, Gia_ManPiNum(pFrames), Gia_ManAndNum(pFrames), Gia_ManCountUnmarked(pFrames, iStart), Gia_ManMemory(pFrames) ); f, Gia_ManPiNum(p->pFrames), Gia_ManAndNum(p->pFrames),
Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); p->nSatVars-1, Vec_IntSize(p->vInputs), Vec_IntSize(p->vNodes), Gia_ManMemory(p->pFrames) );
Abc_PrintTime( 1, "Time", Abc_Clock() - p->clkStart );
} }
// if ( ++Counter == 10 )
// break;
} }
// dump unfolded frames // dump unfolded frames
pFrames = Gia_ManCleanup( pFrames ); p->pFrames = Gia_ManCleanup( p->pFrames );
Gia_AigerWrite( pFrames, "frames.aig", 0, 0 ); Gia_AigerWrite( p->pFrames, "frames.aig", 0, 0 );
printf( "Dumped unfolded frames into file \"frames.aig\".\n" ); printf( "Dumped unfolded frames into file \"frames.aig\".\n" );
Gia_ManStop( pFrames ); Gia_ManStop( p->pFrames );
// cleanup // cleanup
Unr_ManFree( p ); Unr_ManFree( pUnroll );
Bmc_MnaFree( p );
return status; return status;
} }
......
...@@ -408,6 +408,7 @@ Gia_Man_t * Unr_ManUnrollFrame( Unr_Man_t * p, int f ) ...@@ -408,6 +408,7 @@ Gia_Man_t * Unr_ManUnrollFrame( Unr_Man_t * p, int f )
hStart += Unr_ObjSize( pUnrObj ); hStart += Unr_ObjSize( pUnrObj );
} }
assert( p->pObjs + hStart == p->pEnd ); assert( p->pObjs + hStart == p->pEnd );
assert( Gia_ManPoNum(p->pFrames) == (f + 1) * Gia_ManPoNum(p->pGia) );
return p->pFrames; return p->pFrames;
} }
Gia_Man_t * Unr_ManUnroll( Gia_Man_t * pGia, int nFrames ) Gia_Man_t * Unr_ManUnroll( Gia_Man_t * pGia, int nFrames )
......
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