ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bmcBmc.c File Reference
#include "proof/fra/fra.h"
#include "sat/cnf/cnf.h"
#include "sat/bsat/satStore.h"
#include "sat/satoko/satoko.h"
#include "bmc.h"
#include "misc/util/utilMem.h"
Include dependency graph for bmcBmc.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START Aig_Man_tSaig_ManFramesBmc (Aig_Man_t *pAig, int nFrames)
 DECLARATIONS ///.
 
int Saig_ManFramesCount_rec (Aig_Man_t *p, Aig_Obj_t *pObj)
 
Aig_Man_tSaig_ManFramesBmcLimit (Aig_Man_t *pAig, int nFrames, int nSizeMax)
 
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START int * Sat2_SolverGetModel (satoko_t *p, int *pVars, int nVars)
 
int Saig_ManBmcSimple (Aig_Man_t *pAig, int nFrames, int nSizeMax, int nConfLimit, int fRewrite, int fVerbose, int *piFrame, int nCofFanLit, int fUseSatoko)
 

Function Documentation

◆ Saig_ManBmcSimple()

int Saig_ManBmcSimple ( Aig_Man_t * pAig,
int nFrames,
int nSizeMax,
int nConfLimit,
int fRewrite,
int fVerbose,
int * piFrame,
int nCofFanLit,
int fUseSatoko )

Function*************************************************************

Synopsis [Performs BMC for the given AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 207 of file bmcBmc.c.

208{
209 extern Aig_Man_t * Gia_ManCofactorAig( Aig_Man_t * p, int nFrames, int nCofFanLit );
210 sat_solver * pSat = NULL;
211 satoko_t * pSat2 = NULL;
212 Cnf_Dat_t * pCnf;
213 Aig_Man_t * pFrames, * pAigTemp;
214 Aig_Obj_t * pObj;
215 int status, Lit, i, RetValue = -1;
216 abctime clk;
217
218 // derive the timeframes
219 clk = Abc_Clock();
220 if ( nCofFanLit )
221 {
222 pFrames = Gia_ManCofactorAig( pAig, nFrames, nCofFanLit );
223 if ( pFrames == NULL )
224 return -1;
225 }
226 else if ( nSizeMax > 0 )
227 {
228 pFrames = Saig_ManFramesBmcLimit( pAig, nFrames, nSizeMax );
229 nFrames = Aig_ManCoNum(pFrames) / Saig_ManPoNum(pAig) + ((Aig_ManCoNum(pFrames) % Saig_ManPoNum(pAig)) > 0);
230 }
231 else
232 pFrames = Saig_ManFramesBmc( pAig, nFrames );
233 if ( piFrame )
234 *piFrame = nFrames;
235 if ( fVerbose )
236 {
237 printf( "Running \"bmc\". AIG: PI/PO/Reg = %d/%d/%d. Node = %6d. Lev = %5d.\n",
238 Saig_ManPiNum(pAig), Saig_ManPoNum(pAig), Saig_ManRegNum(pAig),
239 Aig_ManNodeNum(pAig), Aig_ManLevelNum(pAig) );
240 printf( "Time-frames (%d): PI/PO = %d/%d. Node = %6d. Lev = %5d. ",
241 nFrames, Aig_ManCiNum(pFrames), Aig_ManCoNum(pFrames),
242 Aig_ManNodeNum(pFrames), Aig_ManLevelNum(pFrames) );
243 ABC_PRT( "Time", Abc_Clock() - clk );
244 fflush( stdout );
245 }
246 // rewrite the timeframes
247 if ( fRewrite )
248 {
249 clk = Abc_Clock();
250// pFrames = Dar_ManBalance( pAigTemp = pFrames, 0 );
251 pFrames = Dar_ManRwsat( pAigTemp = pFrames, 1, 0 );
252 Aig_ManStop( pAigTemp );
253 if ( fVerbose )
254 {
255 printf( "Time-frames after rewriting: Node = %6d. Lev = %5d. ",
256 Aig_ManNodeNum(pFrames), Aig_ManLevelNum(pFrames) );
257 ABC_PRT( "Time", Abc_Clock() - clk );
258 fflush( stdout );
259 }
260 }
261 // create the SAT solver
262 clk = Abc_Clock();
263 pCnf = Cnf_Derive( pFrames, Aig_ManCoNum(pFrames) );
264//if ( s_fInterrupt )
265//return -1;
266 if ( fUseSatoko )
267 {
268 satoko_opts_t opts;
269 satoko_default_opts(&opts);
270 opts.conf_limit = nConfLimit;
271 pSat2 = satoko_create();
272 satoko_configure(pSat2, &opts);
273 satoko_setnvars(pSat2, pCnf->nVars);
274 for ( i = 0; i < pCnf->nClauses; i++ )
275 if ( !satoko_add_clause( pSat2, pCnf->pClauses[i], pCnf->pClauses[i+1]-pCnf->pClauses[i] ) )
276 assert( 0 );
277 }
278 else
279 {
280 pSat = sat_solver_new();
281 sat_solver_setnvars( pSat, pCnf->nVars );
282 for ( i = 0; i < pCnf->nClauses; i++ )
283 if ( !sat_solver_addclause( pSat, pCnf->pClauses[i], pCnf->pClauses[i+1] ) )
284 assert( 0 );
285 }
286 if ( fVerbose )
287 {
288 printf( "CNF: Variables = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
289 ABC_PRT( "Time", Abc_Clock() - clk );
290 fflush( stdout );
291 }
292 status = pSat ? sat_solver_simplify(pSat) : 1;
293 if ( status == 0 )
294 {
295 if ( fVerbose )
296 {
297 printf( "The BMC problem is trivially UNSAT\n" );
298 fflush( stdout );
299 }
300 }
301 else
302 {
303 abctime clkPart = Abc_Clock();
304 Aig_ManForEachCo( pFrames, pObj, i )
305 {
306 Lit = toLitCond( pCnf->pVarNums[pObj->Id], 0 );
307 if ( fVerbose )
308 {
309 printf( "Solving output %2d of frame %3d ... \r",
310 i % Saig_ManPoNum(pAig), i / Saig_ManPoNum(pAig) );
311 }
312 clk = Abc_Clock();
313 if ( pSat2 )
314 status = satoko_solve_assumptions_limit( pSat2, &Lit, 1, nConfLimit );
315 else
316 status = sat_solver_solve( pSat, &Lit, &Lit + 1, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
317 if ( fVerbose && (i % Saig_ManPoNum(pAig) == Saig_ManPoNum(pAig) - 1) )
318 {
319 printf( "Solved %2d outputs of frame %3d. ",
320 Saig_ManPoNum(pAig), i / Saig_ManPoNum(pAig) );
321 printf( "Conf =%8.0f. Imp =%11.0f. ",
322 (double)(pSat ? pSat->stats.conflicts : satoko_conflictnum(pSat2)),
323 (double)(pSat ? pSat->stats.propagations : satoko_stats(pSat2)->n_propagations) );
324 ABC_PRT( "T", Abc_Clock() - clkPart );
325 clkPart = Abc_Clock();
326 fflush( stdout );
327 }
328 if ( status == l_False )
329 {
330/*
331 Lit = lit_neg( Lit );
332 RetValue = sat_solver_addclause( pSat, &Lit, &Lit + 1 );
333 assert( RetValue );
334 if ( pSat->qtail != pSat->qhead )
335 {
336 RetValue = sat_solver_simplify(pSat);
337 assert( RetValue );
338 }
339*/
340 }
341 else if ( status == l_True )
342 {
343 Vec_Int_t * vCiIds = Cnf_DataCollectPiSatNums( pCnf, pFrames );
344 int * pModel = pSat2 ? Sat2_SolverGetModel(pSat2, vCiIds->pArray, vCiIds->nSize) : Sat_SolverGetModel(pSat, vCiIds->pArray, vCiIds->nSize);
345 pModel[Aig_ManCiNum(pFrames)] = pObj->Id;
346 pAig->pSeqModel = Fra_SmlCopyCounterExample( pAig, pFrames, pModel );
347 ABC_FREE( pModel );
348 Vec_IntFree( vCiIds );
349
350 if ( piFrame )
351 *piFrame = i / Saig_ManPoNum(pAig);
352 RetValue = 0;
353 break;
354 }
355 else
356 {
357 if ( piFrame )
358 *piFrame = i / Saig_ManPoNum(pAig);
359 RetValue = -1;
360 break;
361 }
362 }
363 }
364 if ( pSat ) sat_solver_delete( pSat );
365 if ( pSat2 ) satoko_destroy( pSat2 );
366 Cnf_DataFree( pCnf );
367 Aig_ManStop( pFrames );
368 return RetValue;
369}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_FREE(obj)
Definition abc_global.h:267
ABC_NAMESPACE_IMPL_START Aig_Man_t * Dar_ManRwsat(Aig_Man_t *pAig, int fBalance, int fVerbose)
DECLARATIONS ///.
Definition darScript.c:71
int Aig_ManLevelNum(Aig_Man_t *p)
Definition aigDfs.c:500
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_True
Definition bmcBmcS.c:35
#define l_False
Definition bmcBmcS.c:36
ABC_NAMESPACE_IMPL_START Aig_Man_t * Saig_ManFramesBmc(Aig_Man_t *pAig, int nFrames)
DECLARATIONS ///.
Definition bmcBmc.c:49
Aig_Man_t * Saig_ManFramesBmcLimit(Aig_Man_t *pAig, int nFrames, int nSizeMax)
Definition bmcBmc.c:122
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START int * Sat2_SolverGetModel(satoko_t *p, int *pVars, int nVars)
Definition bmcBmc.c:186
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition cnfCore.c:165
Vec_Int_t * Cnf_DataCollectPiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfMan.c:104
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
Cube * p
Definition exorList.c:222
Abc_Cex_t * Fra_SmlCopyCounterExample(Aig_Man_t *pAig, Aig_Man_t *pFrames, int *pModel)
Definition fraSim.c:1123
Aig_Man_t * Gia_ManCofactorAig(Aig_Man_t *p, int nFrames, int nCofFanLit)
Definition giaAig.c:452
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
Definition satUtil.c:270
void satoko_setnvars(satoko_t *, int)
Definition solver_api.c:230
int satoko_conflictnum(satoko_t *)
Definition solver_api.c:640
struct satoko_opts satoko_opts_t
Definition satoko.h:37
int satoko_solve_assumptions_limit(satoko_t *s, int *plits, int nlits, int nconflim)
Definition solver_api.c:364
void satoko_default_opts(satoko_opts_t *)
Definition solver_api.c:161
int satoko_add_clause(satoko_t *, int *, int)
Definition solver_api.c:255
struct solver_t_ satoko_t
Definition satoko.h:35
void satoko_destroy(satoko_t *)
Definition solver_api.c:132
satoko_t * satoko_create(void)
Definition solver_api.c:88
void satoko_configure(satoko_t *, satoko_opts_t *)
Definition solver_api.c:196
int Id
Definition aig.h:85
int nVars
Definition cnf.h:59
int nLiterals
Definition cnf.h:60
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
stats_t stats
Definition satSolver.h:163
long conf_limit
Definition satoko.h:40
ABC_INT64_T conflicts
Definition satVec.h:156
ABC_INT64_T propagations
Definition satVec.h:156
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Saig_ManFramesBmc()

ABC_NAMESPACE_IMPL_START Aig_Man_t * Saig_ManFramesBmc ( Aig_Man_t * pAig,
int nFrames )

DECLARATIONS ///.

CFile****************************************************************

FileName [bmcBmc.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT-based bounded model checking.]

Synopsis [Simple BMC package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
bmcBmc.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Create timeframes of the manager for BMC.]

Description [The resulting manager is combinational. POs correspond to \ the property outputs in each time-frame.]

SideEffects []

SeeAlso []

Definition at line 49 of file bmcBmc.c.

50{
51 Aig_Man_t * pFrames;
52 Aig_Obj_t * pObj, * pObjLi, * pObjLo;
53 int i, f;
54 assert( Saig_ManRegNum(pAig) > 0 );
55 pFrames = Aig_ManStart( Aig_ManNodeNum(pAig) * nFrames );
56 // map the constant node
57 Aig_ManConst1(pAig)->pData = Aig_ManConst1( pFrames );
58 // create variables for register outputs
59 Saig_ManForEachLo( pAig, pObj, i )
60 pObj->pData = Aig_ManConst0( pFrames );
61 // add timeframes
62 for ( f = 0; f < nFrames; f++ )
63 {
64 // create PI nodes for this frame
65 Saig_ManForEachPi( pAig, pObj, i )
66 pObj->pData = Aig_ObjCreateCi( pFrames );
67 // add internal nodes of this frame
68 Aig_ManForEachNode( pAig, pObj, i )
69 pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
70 // create POs for this frame
71 Saig_ManForEachPo( pAig, pObj, i )
72 Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
73 if ( f == nFrames - 1 )
74 break;
75 // save register inputs
76 Saig_ManForEachLi( pAig, pObj, i )
77 pObj->pData = Aig_ObjChild0Copy(pObj);
78 // transfer to register outputs
79 Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
80 pObjLo->pData = pObjLi->pData;
81 }
82 Aig_ManCleanup( pFrames );
83 return pFrames;
84}
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
Aig_Obj_t * Aig_ObjCreateCo(Aig_Man_t *p, Aig_Obj_t *pDriver)
Definition aigObj.c:66
Aig_Man_t * Aig_ManStart(int nNodesMax)
DECLARATIONS ///.
Definition aigMan.c:47
#define Aig_ManForEachNode(p, pObj, i)
Definition aig.h:413
int Aig_ManCleanup(Aig_Man_t *p)
Definition aigMan.c:265
Aig_Obj_t * Aig_ObjCreateCi(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigObj.c:45
#define Saig_ManForEachLiLo(p, pObjLi, pObjLo, i)
Definition saig.h:101
#define Saig_ManForEachLi(p, pObj, i)
Definition saig.h:98
#define Saig_ManForEachPo(p, pObj, i)
Definition saig.h:93
#define Saig_ManForEachLo(p, pObj, i)
Definition saig.h:96
#define Saig_ManForEachPi(p, pObj, i)
Definition saig.h:91
void * pData
Definition aig.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Saig_ManFramesBmcLimit()

Aig_Man_t * Saig_ManFramesBmcLimit ( Aig_Man_t * pAig,
int nFrames,
int nSizeMax )

Function*************************************************************

Synopsis [Create timeframes of the manager for BMC.]

Description [The resulting manager is combinational. POs correspond to the property outputs in each time-frame. The unrolling is stopped as soon as the number of nodes in the frames exceeds the given maximum size.]

SideEffects []

SeeAlso []

Definition at line 122 of file bmcBmc.c.

123{
124 Aig_Man_t * pFrames;
125 Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjPo;
126 int i, f, Counter = 0;
127 assert( Saig_ManRegNum(pAig) > 0 );
128 pFrames = Aig_ManStart( nSizeMax );
129 Aig_ManIncrementTravId( pFrames );
130 // map the constant node
131 Aig_ManConst1(pAig)->pData = Aig_ManConst1( pFrames );
132 // create variables for register outputs
133 Saig_ManForEachLo( pAig, pObj, i )
134 pObj->pData = Aig_ManConst0( pFrames );
135 // add timeframes
136 Counter = 0;
137 for ( f = 0; f < nFrames; f++ )
138 {
139 // create PI nodes for this frame
140 Saig_ManForEachPi( pAig, pObj, i )
141 pObj->pData = Aig_ObjCreateCi( pFrames );
142 // add internal nodes of this frame
143 Aig_ManForEachNode( pAig, pObj, i )
144 pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
145 // create POs for this frame
146 Saig_ManForEachPo( pAig, pObj, i )
147 {
148 pObjPo = Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
149 Counter += Saig_ManFramesCount_rec( pFrames, Aig_ObjFanin0(pObjPo) );
150 }
151 if ( Counter >= nSizeMax )
152 {
153 Aig_ManCleanup( pFrames );
154 return pFrames;
155 }
156 if ( f == nFrames - 1 )
157 break;
158 // save register inputs
159 Saig_ManForEachLi( pAig, pObj, i )
160 pObj->pData = Aig_ObjChild0Copy(pObj);
161 // transfer to register outputs
162 Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
163 pObjLo->pData = pObjLi->pData;
164 }
165 Aig_ManCleanup( pFrames );
166 return pFrames;
167}
void Aig_ManIncrementTravId(Aig_Man_t *p)
DECLARATIONS ///.
Definition aigUtil.c:44
int Saig_ManFramesCount_rec(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition bmcBmc.c:97
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Saig_ManFramesCount_rec()

int Saig_ManFramesCount_rec ( Aig_Man_t * p,
Aig_Obj_t * pObj )

Function*************************************************************

Synopsis [Returns the number of internal nodes that are not counted yet.]

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file bmcBmc.c.

98{
99 if ( !Aig_ObjIsNode(pObj) )
100 return 0;
101 if ( Aig_ObjIsTravIdCurrent(p, pObj) )
102 return 0;
103 Aig_ObjSetTravIdCurrent(p, pObj);
104 return 1 + Saig_ManFramesCount_rec( p, Aig_ObjFanin0(pObj) ) +
105 Saig_ManFramesCount_rec( p, Aig_ObjFanin1(pObj) );
106}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sat2_SolverGetModel()

ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START int * Sat2_SolverGetModel ( satoko_t * p,
int * pVars,
int nVars )

Function*************************************************************

Synopsis [Returns a counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 186 of file bmcBmc.c.

187{
188 int * pModel;
189 int i;
190 pModel = ABC_CALLOC( int, nVars+1 );
191 for ( i = 0; i < nVars; i++ )
192 pModel[i] = satoko_read_cex_varvalue(p, pVars[i]);
193 return pModel;
194}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
int satoko_read_cex_varvalue(satoko_t *, int)
Definition solver_api.c:660
Here is the call graph for this function:
Here is the caller graph for this function: