fraMan.c 11.2 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [fraMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [New FRAIG package.]

  Synopsis    [Starts the FRAIG manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 30, 2007.]

  Revision    [$Id: fraMan.c,v 1.00 2007/06/30 00:00:00 alanmi Exp $]

***********************************************************************/

#include "fra.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Sets the default solving parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ParamsDefault( Fra_Par_t * pPars )
{
    memset( pPars, 0, sizeof(Fra_Par_t) );
Alan Mishchenko committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
    pPars->nSimWords        =       32;  // the number of words in the simulation info
    pPars->dSimSatur        =    0.005;  // the ratio of refined classes when saturation is reached
    pPars->fPatScores       =        0;  // enables simulation pattern scoring
    pPars->MaxScore         =       25;  // max score after which resimulation is used
    pPars->fDoSparse        =        1;  // skips sparse functions
//    pPars->dActConeRatio    =     0.05;  // the ratio of cone to be bumped
//    pPars->dActConeBumpMax  =      5.0;  // the largest bump of activity
    pPars->dActConeRatio    =      0.3;  // the ratio of cone to be bumped
    pPars->dActConeBumpMax  =     10.0;  // the largest bump of activity
    pPars->nBTLimitNode     =      100;  // conflict limit at a node
    pPars->nBTLimitMiter    =   500000;  // conflict limit at an output
    pPars->nFramesK         =        0;  // the number of timeframes to unroll
    pPars->fConeBias        =        1;
    pPars->fRewrite         =        0;
Alan Mishchenko committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
}

/**Function*************************************************************

  Synopsis    [Sets the default solving parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ParamsDefaultSeq( Fra_Par_t * pPars )
{
    memset( pPars, 0, sizeof(Fra_Par_t) );
Alan Mishchenko committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
    pPars->nSimWords        =        1;  // the number of words in the simulation info
    pPars->dSimSatur        =    0.005;  // the ratio of refined classes when saturation is reached
    pPars->fPatScores       =        0;  // enables simulation pattern scoring
    pPars->MaxScore         =       25;  // max score after which resimulation is used
    pPars->fDoSparse        =        1;  // skips sparse functions
    pPars->dActConeRatio    =      0.3;  // the ratio of cone to be bumped
    pPars->dActConeBumpMax  =     10.0;  // the largest bump of activity
    pPars->nBTLimitNode     = 10000000;  // conflict limit at a node
    pPars->nBTLimitMiter    =   500000;  // conflict limit at an output
    pPars->nFramesK         =        1;  // the number of timeframes to unroll
    pPars->fConeBias        =        0;
    pPars->fRewrite         =        0;
    pPars->fLatchCorr       =        0;
} 
Alan Mishchenko committed
92 93 94 95 96 97 98 99 100 101 102 103

/**Function*************************************************************

  Synopsis    [Starts the fraiging manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
104
Fra_Man_t * Fra_ManStart( Aig_Man_t * pManAig, Fra_Par_t * pPars )
Alan Mishchenko committed
105 106
{
    Fra_Man_t * p;
Alan Mishchenko committed
107 108
    Aig_Obj_t * pObj;
    int i;
Alan Mishchenko committed
109
    // allocate the fraiging manager
Alan Mishchenko committed
110
    p = ABC_ALLOC( Fra_Man_t, 1 );
Alan Mishchenko committed
111 112 113
    memset( p, 0, sizeof(Fra_Man_t) );
    p->pPars      = pPars;
    p->pManAig    = pManAig;
Alan Mishchenko committed
114
    p->nSizeAlloc = Aig_ManObjNumMax( pManAig );
Alan Mishchenko committed
115
    p->nFramesAll = pPars->nFramesK + 1;
Alan Mishchenko committed
116
    // allocate storage for sim pattern
117
    p->nPatWords  = Abc_BitWordNum( (Aig_ManCiNum(pManAig) - Aig_ManRegNum(pManAig)) * p->nFramesAll + Aig_ManRegNum(pManAig) );
Alan Mishchenko committed
118
    p->pPatWords  = ABC_ALLOC( unsigned, p->nPatWords ); 
Alan Mishchenko committed
119
    p->vPiVars    = Vec_PtrAlloc( 100 );
Alan Mishchenko committed
120 121
    // equivalence classes
    p->pCla       = Fra_ClassesStart( pManAig );
Alan Mishchenko committed
122
    // allocate other members
Alan Mishchenko committed
123
    p->pMemFraig  = ABC_ALLOC( Aig_Obj_t *, p->nSizeAlloc * p->nFramesAll );
Alan Mishchenko committed
124
    memset( p->pMemFraig, 0, sizeof(Aig_Obj_t *) * p->nSizeAlloc * p->nFramesAll );
Alan Mishchenko committed
125
    // set random number generator
Alan Mishchenko committed
126 127
//    srand( 0xABCABC );
    Aig_ManRandom(1);
Alan Mishchenko committed
128 129 130
    // set the pointer to the manager
    Aig_ManForEachObj( p->pManAig, pObj, i )
        pObj->pData = p;
Alan Mishchenko committed
131 132 133 134 135
    return p;
}

/**Function*************************************************************

Alan Mishchenko committed
136 137 138 139 140 141 142 143 144
  Synopsis    [Starts the fraiging manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
145
void Fra_ManClean( Fra_Man_t * p, int nNodesMax )
Alan Mishchenko committed
146
{
Alan Mishchenko committed
147 148 149
    int i;
    // remove old arrays
    for ( i = 0; i < p->nMemAlloc; i++ )
Alan Mishchenko committed
150 151
        if ( p->pMemFanins[i] && p->pMemFanins[i] != (void *)1 )
            Vec_PtrFree( p->pMemFanins[i] );
Alan Mishchenko committed
152 153 154 155
    // realloc for the new size
    if ( p->nMemAlloc < nNodesMax )
    {
        int nMemAllocNew = nNodesMax + 5000;
Alan Mishchenko committed
156 157
        p->pMemFanins = ABC_REALLOC( Vec_Ptr_t *, p->pMemFanins, nMemAllocNew );
        p->pMemSatNums = ABC_REALLOC( int, p->pMemSatNums, nMemAllocNew );
Alan Mishchenko committed
158 159 160 161 162
        p->nMemAlloc = nMemAllocNew;
    }
    // prepare for the new run
    memset( p->pMemFanins, 0, sizeof(Vec_Ptr_t *) * p->nMemAlloc );
    memset( p->pMemSatNums, 0, sizeof(int) * p->nMemAlloc );
Alan Mishchenko committed
163 164 165 166
}

/**Function*************************************************************

Alan Mishchenko committed
167
  Synopsis    [Prepares the new manager to begin fraiging.]
Alan Mishchenko committed
168 169 170 171 172 173 174 175

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
176
Aig_Man_t * Fra_ManPrepareComb( Fra_Man_t * p )
Alan Mishchenko committed
177
{
Alan Mishchenko committed
178
    Aig_Man_t * pManFraig;
Alan Mishchenko committed
179
    Aig_Obj_t * pObj;
Alan Mishchenko committed
180
    int i;
Alan Mishchenko committed
181 182
    assert( p->pManFraig == NULL );
    // start the fraig package
Alan Mishchenko committed
183
    pManFraig = Aig_ManStart( Aig_ManObjNumMax(p->pManAig) );
184 185
    pManFraig->pName = Abc_UtilStrsav( p->pManAig->pName );
    pManFraig->pSpec = Abc_UtilStrsav( p->pManAig->pSpec );
Alan Mishchenko committed
186 187
    pManFraig->nRegs    = p->pManAig->nRegs;
    pManFraig->nAsserts = p->pManAig->nAsserts;
Alan Mishchenko committed
188
    // set the pointers to the available fraig nodes
Alan Mishchenko committed
189
    Fra_ObjSetFraig( Aig_ManConst1(p->pManAig), 0, Aig_ManConst1(pManFraig) );
190 191
    Aig_ManForEachCi( p->pManAig, pObj, i )
        Fra_ObjSetFraig( pObj, 0, Aig_ObjCreateCi(pManFraig) );
Alan Mishchenko committed
192 193 194
    // set the pointers to the manager
    Aig_ManForEachObj( pManFraig, pObj, i )
        pObj->pData = p;
Alan Mishchenko committed
195 196
    // allocate memory for mapping FRAIG nodes into SAT numbers and fanins
    p->nMemAlloc = p->nSizeAlloc;
Alan Mishchenko committed
197
    p->pMemFanins = ABC_ALLOC( Vec_Ptr_t *, p->nMemAlloc );
Alan Mishchenko committed
198
    memset( p->pMemFanins, 0, sizeof(Vec_Ptr_t *) * p->nMemAlloc );
Alan Mishchenko committed
199
    p->pMemSatNums = ABC_ALLOC( int, p->nMemAlloc );
Alan Mishchenko committed
200
    memset( p->pMemSatNums, 0, sizeof(int) * p->nMemAlloc );
Alan Mishchenko committed
201 202 203
    // make sure the satisfying assignment is node assigned
    assert( pManFraig->pData == NULL );
    return pManFraig;
Alan Mishchenko committed
204 205 206 207
}

/**Function*************************************************************

Alan Mishchenko committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221
  Synopsis    [Finalizes the combinational miter after fraiging.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ManFinalizeComb( Fra_Man_t * p )
{
    Aig_Obj_t * pObj;
    int i;
    // add the POs
222 223
    Aig_ManForEachCo( p->pManAig, pObj, i )
        Aig_ObjCreateCo( p->pManFraig, Fra_ObjChild0Fra(pObj,0) );
Alan Mishchenko committed
224 225 226 227 228 229 230
    // postprocess
    Aig_ManCleanMarkB( p->pManFraig );
}


/**Function*************************************************************

Alan Mishchenko committed
231 232 233 234 235 236 237 238 239 240 241
  Synopsis    [Stops the fraiging manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ManStop( Fra_Man_t * p )
{
Alan Mishchenko committed
242 243
    if ( p->pPars->fVerbose )
        Fra_ManPrint( p );
Alan Mishchenko committed
244 245 246 247
    // save mapping from original nodes into FRAIG nodes
    if ( p->pManAig )
    {
        if ( p->pManAig->pObjCopies )
Alan Mishchenko committed
248
            ABC_FREE( p->pManAig->pObjCopies );
Alan Mishchenko committed
249 250 251
        p->pManAig->pObjCopies = p->pMemFraig;
        p->pMemFraig = NULL;
    }
Alan Mishchenko committed
252
    Fra_ManClean( p, 0 );
Alan Mishchenko committed
253 254 255 256
    if ( p->vTimeouts ) Vec_PtrFree( p->vTimeouts );
    if ( p->vPiVars )   Vec_PtrFree( p->vPiVars );
    if ( p->pSat )      sat_solver_delete( p->pSat );
    if ( p->pCla  )     Fra_ClassesStop( p->pCla );
Alan Mishchenko committed
257
    if ( p->pSml )      Fra_SmlStop( p->pSml );
Alan Mishchenko committed
258
    if ( p->vCex )      Vec_IntFree( p->vCex );
Alan Mishchenko committed
259
    if ( p->vOneHots )  Vec_IntFree( p->vOneHots );
Alan Mishchenko committed
260 261 262 263 264
    ABC_FREE( p->pMemFraig );
    ABC_FREE( p->pMemFanins );
    ABC_FREE( p->pMemSatNums );
    ABC_FREE( p->pPatWords );
    ABC_FREE( p );
Alan Mishchenko committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
}

/**Function*************************************************************

  Synopsis    [Prints stats for the fraiging manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ManPrint( Fra_Man_t * p )
{
Alan Mishchenko committed
280
    double nMemory = 1.0*Aig_ManObjNumMax(p->pManAig)*(p->pSml->nWordsTotal*sizeof(unsigned)+6*sizeof(void*))/(1<<20);
281
    printf( "SimWord = %d. Round = %d.  Mem = %0.2f MB.  LitBeg = %d.  LitEnd = %d. (%6.2f %%).\n", 
Alan Mishchenko committed
282 283 284
        p->pPars->nSimWords, p->pSml->nSimRounds, nMemory, p->nLitsBeg, p->nLitsEnd, 100.0*p->nLitsEnd/(p->nLitsBeg?p->nLitsBeg:1) );
    printf( "Proof = %d. Cex = %d. Fail = %d. FailReal = %d. C-lim = %d. ImpRatio = %6.2f %%\n", 
        p->nSatProof, p->nSatCallsSat, p->nSatFails, p->nSatFailsReal, p->pPars->nBTLimitNode, Fra_ImpComputeStateSpaceRatio(p) );
Alan Mishchenko committed
285
    printf( "NBeg = %d. NEnd = %d. (Gain = %6.2f %%).  RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n", 
Alan Mishchenko committed
286 287
        p->nNodesBeg, p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/(p->nNodesBeg?p->nNodesBeg:1), 
        p->nRegsBeg, p->nRegsEnd, 100.0*(p->nRegsBeg-p->nRegsEnd)/(p->nRegsBeg?p->nRegsBeg:1) );
Alan Mishchenko committed
288 289
    if ( p->pSat )             Sat_SolverPrintStats( stdout, p->pSat );
    if ( p->pPars->fUse1Hot )  Fra_OneHotEstimateCoverage( p, p->vOneHots );
Alan Mishchenko committed
290 291
    ABC_PRT( "AIG simulation  ", p->pSml->timeSim  );
    ABC_PRT( "AIG traversal   ", p->timeTrav );
Alan Mishchenko committed
292 293
    if ( p->timeRwr )
    {
Alan Mishchenko committed
294
    ABC_PRT( "AIG rewriting   ", p->timeRwr  );
Alan Mishchenko committed
295
    }
Alan Mishchenko committed
296 297 298 299 300 301 302
    ABC_PRT( "SAT solving     ", p->timeSat  );
    ABC_PRT( "    Unsat       ", p->timeSatUnsat );
    ABC_PRT( "    Sat         ", p->timeSatSat   );
    ABC_PRT( "    Fail        ", p->timeSatFail  );
    ABC_PRT( "Class refining  ", p->timeRef   );
    ABC_PRT( "TOTAL RUNTIME   ", p->timeTotal );
    if ( p->time1 ) { ABC_PRT( "time1           ", p->time1 ); }
Alan Mishchenko committed
303
    if ( p->nSpeculs )
Alan Mishchenko committed
304
    printf( "Speculations = %d.\n", p->nSpeculs );
Alan Mishchenko committed
305
    fflush( stdout );
Alan Mishchenko committed
306 307 308 309 310 311 312
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


313 314
ABC_NAMESPACE_IMPL_END