absPth.c 6.18 KB
Newer Older
1 2
/**CFile****************************************************************

3
  FileName    [absPth.c]
4 5 6

  SystemName  [ABC: Logic synthesis and verification system.]

7
  PackageName [Abstraction package.]
8 9 10 11 12 13 14 15 16

  Synopsis    [Interface to pthreads.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

17
  Revision    [$Id: absPth.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 19 20

***********************************************************************/
 
21
#include "abs.h"
22
#include "proof/pdr/pdr.h"
23
#include "proof/ssw/ssw.h"
24

Alan Mishchenko committed
25 26


27

28
// comment out this line to disable pthreads
29
#define ABC_USE_PTHREADS
30 31 32 33 34 35 36 37 38 39 40 41

#ifdef ABC_USE_PTHREADS

#ifdef WIN32
#include "../lib/pthread.h"
#else
#include <pthread.h>
#include <unistd.h>
#endif

#endif

42
ABC_NAMESPACE_IMPL_START 
43 44 45 46 47 48 49

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

#ifndef ABC_USE_PTHREADS

50 51 52
void Gia_GlaProveAbsracted( Gia_Man_t * p, int fSimpProver, int fVerbose ) {}
void Gia_GlaProveCancel( int fVerbose )                                    {}
int  Gia_GlaProveCheck( int fVerbose )                                     { return 0; }
53 54 55

#else // pthreads are used

56
// information given to the thread
57
typedef struct Abs_ThData_t_
58
{
59 60 61
    Aig_Man_t * pAig;
    int         fVerbose;
    int         RunId;
62
} Abs_ThData_t;
63

64 65 66 67
// mutext to control access to shared variables
pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
static volatile int g_nRunIds = 0;             // the number of the last prover instance
static volatile int g_fAbstractionProved = 0;  // set to 1 when prover successed to prove
68

69 70
// call back procedure for PDR
int Abs_CallBackToStop( int RunId ) { assert( RunId <= g_nRunIds ); return RunId < g_nRunIds; }
71

72
// test procedure to replace PDR
73 74 75 76 77 78 79 80 81 82 83 84
int Pdr_ManSolve_test( Aig_Man_t * pAig, Pdr_Par_t * pPars, Abc_Cex_t ** ppCex )
{
    char * p = ABC_ALLOC( char, 111 );
    while ( 1 )
    {
        if ( pPars->pFuncStop && pPars->pFuncStop(pPars->RunId) )
            break;
    }
    ABC_FREE( p );
    return -1;
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Create one thread]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
100 101
void * Abs_ProverThread( void * pArg )
{
102
    Abs_ThData_t * pThData = (Abs_ThData_t *)pArg;
103
    Pdr_Par_t Pars, * pPars = &Pars;
104
    int RetValue, status;
105 106 107 108 109
    // call PDR
    Pdr_ManSetDefaultParams( pPars );
    pPars->fSilent   = 1;
    pPars->RunId     = pThData->RunId;
    pPars->pFuncStop = Abs_CallBackToStop;
110
    RetValue = Pdr_ManSolve( pThData->pAig, pPars );
111 112 113 114 115 116 117 118 119
    // update the result
    if ( RetValue == 1 )
    {
        status = pthread_mutex_lock(&g_mutex);  assert( status == 0 );
        g_fAbstractionProved = 1;
        status = pthread_mutex_unlock(&g_mutex);  assert( status == 0 );
    }
    // quit this thread
    if ( pThData->fVerbose )
120
    {
121
        if ( RetValue == 1 )
122
            Abc_Print( 1, "Proved abstraction %d.\n", pThData->RunId );
123
        else if ( RetValue == 0 )
124
            Abc_Print( 1, "Disproved abstraction %d.\n", pThData->RunId );
125
        else if ( RetValue == -1 )
126
            Abc_Print( 1, "Cancelled abstraction %d.\n", pThData->RunId );
127
        else assert( 0 );
128
    }
129 130
    // free memory
    Aig_ManStop( pThData->pAig );
131
    ABC_FREE( pThData );
132 133 134 135 136
    // quit this thread
    pthread_exit( NULL );
    assert(0);
    return NULL;
}
137
void Gia_GlaProveAbsracted( Gia_Man_t * pGia, int fSimpProver, int fVerbose )
138
{
139
    extern Aig_Man_t * Dar_ManRwsat( Aig_Man_t * pAig, int fBalance, int fVerbose );
140
    Abs_ThData_t * pThData;
141 142
    Ssw_Pars_t Pars, * pPars = &Pars;
    Aig_Man_t * pAig, * pTemp;
143
    Gia_Man_t * pAbs;
144
    pthread_t ProverThread;
145
    int status;
146
    // disable verbosity
147
//    fVerbose = 0;
148 149 150 151 152 153
    // create abstraction 
    assert( pGia->vGateClasses != NULL );
    pAbs = Gia_ManDupAbsGates( pGia, pGia->vGateClasses );
    Gia_ManCleanValue( pGia );
    pAig = Gia_ManToAigSimple( pAbs );
    Gia_ManStop( pAbs );
154
    // simplify abstraction
155 156 157 158 159
    if ( fSimpProver )
    {
        Ssw_ManSetDefaultParams( pPars );
        pPars->nFramesK = 4;
        pAig = Ssw_SignalCorrespondence( pTemp = pAig, pPars );
160 161 162
//printf( "\n" );
//Aig_ManPrintStats( pTemp );
//Aig_ManPrintStats( pAig );
163 164
        Aig_ManStop( pTemp );
    }
165
    // synthesize abstraction
166 167
//    pAig = Dar_ManRwsat( pTemp = pAig, 0, 0 ); 
//    Aig_ManStop( pTemp );
168 169 170 171 172 173
    // reset the proof 
    status = pthread_mutex_lock(&g_mutex);  assert( status == 0 );
    g_fAbstractionProved = 0;
    status = pthread_mutex_unlock(&g_mutex);  assert( status == 0 );
    // collect thread data
    pThData = ABC_CALLOC( Abs_ThData_t, 1 );
174
    pThData->pAig = pAig;
175 176 177 178
    pThData->fVerbose = fVerbose;
    status = pthread_mutex_lock(&g_mutex);  assert( status == 0 );
    pThData->RunId = ++g_nRunIds;
    status = pthread_mutex_unlock(&g_mutex);  assert( status == 0 );
179
    // create thread
180 181 182
    if ( fVerbose )  Abc_Print( 1, "\nTrying to prove abstraction %d.\n", pThData->RunId );
    status = pthread_create( &ProverThread, NULL, Abs_ProverThread, pThData );
    assert( status == 0 );
183
}
184
void Gia_GlaProveCancel( int fVerbose )
185
{
186 187
    int status;
    status = pthread_mutex_lock(&g_mutex);  assert( status == 0 );
188
    g_nRunIds++;
189
    status = pthread_mutex_unlock(&g_mutex);  assert( status == 0 );
190
}
191
int Gia_GlaProveCheck( int fVerbose )
192
{
193 194 195 196 197 198 199
    int status;
    if ( g_fAbstractionProved == 0 )
        return 0;
    status = pthread_mutex_lock(&g_mutex);  assert( status == 0 );
    g_fAbstractionProved = 0;
    status = pthread_mutex_unlock(&g_mutex);  assert( status == 0 );
    return 1;
200 201 202 203 204 205 206 207 208 209 210
}

#endif

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


ABC_NAMESPACE_IMPL_END