mpmMan.c 7.08 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/**CFile****************************************************************

  FileName    [mpm.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Configurable technology mapper.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 1, 2013.]

  Revision    [$Id: mpm.c,v 1.00 2013/06/01 00:00:00 alanmi Exp $]

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

#include "mpmInt.h"

ABC_NAMESPACE_IMPL_START


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

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Mpm_Man_t * Mpm_ManStart( Mig_Man_t * pMig, Mpm_Par_t * pPars )
{
    Mpm_Man_t * p;
    int i;
    assert( sizeof(Mpm_Uni_t) % sizeof(word) == 0 );      // aligned info to word boundary
    assert( pPars->nNumCuts <= MPM_CUT_MAX );
Alan Mishchenko committed
51 52
    assert( !pPars->fUseTruth || pPars->pLib->LutMax <= 16 );
    assert( !pPars->fUseDsd || pPars->pLib->LutMax <= 6 );
Alan Mishchenko committed
53
    Mig_ManSetRefs( pMig );
Alan Mishchenko committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    // alloc
    p = ABC_CALLOC( Mpm_Man_t, 1 );
    p->pMig      = pMig;
    p->pPars     = pPars;
    p->pLibLut   = pPars->pLib;
    p->nLutSize  = pPars->pLib->LutMax;
    p->nTruWords = pPars->fUseTruth ? Abc_Truth6WordNum(p->nLutSize) : 0;
    p->nNumCuts  = pPars->nNumCuts;
    // cuts
    assert( Mpm_CutWordNum(32) < 32 ); // using 5 bits for word count
    p->pManCuts  = Mmr_StepStart( 13, Abc_Base2Log(Mpm_CutWordNum(p->nLutSize) + 1) );
    Vec_PtrGrow( &p->vFreeUnits, p->nNumCuts + 1 );
    for ( i = p->nNumCuts; i >= 0; i-- )
        Vec_PtrPush( &p->vFreeUnits, p->pCutUnits + i );
    p->vTemp     = Vec_PtrAlloc( 1000 );
    // mapping attributes
    Vec_IntFill( &p->vCutBests, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vCutLists, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vMigRefs, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vMapRefs, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vEstRefs, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vRequireds, Mig_ManObjNum(pMig), ABC_INFINITY );
    Vec_IntFill( &p->vTimes, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vAreas, Mig_ManObjNum(pMig), 0 );
    Vec_IntFill( &p->vEdges, Mig_ManObjNum(pMig), 0 );
    // start DSD manager
Alan Mishchenko committed
80
    assert( !p->pPars->fUseTruth || !p->pPars->fUseDsd );
Alan Mishchenko committed
81
    if ( p->pPars->fUseTruth )
Alan Mishchenko committed
82
    { 
Alan Mishchenko committed
83 84
        p->vTtMem = Vec_MemAlloc( p->nTruWords, 12 ); // 32 KB/page for 6-var functions
        Vec_MemHashAlloc( p->vTtMem, 10000 );
Alan Mishchenko committed
85 86 87
        p->funcCst0 = Vec_MemHashInsert( p->vTtMem, p->Truth );
        Abc_TtUnit( p->Truth, p->nTruWords );
        p->funcVar0 = Vec_MemHashInsert( p->vTtMem, p->Truth );
Alan Mishchenko committed
88
    }
Alan Mishchenko committed
89 90 91
    else if ( p->pPars->fUseDsd )
    {
        Mpm_ManPrecomputePerms( p );
Alan Mishchenko committed
92
        p->funcVar0 = 1;
Alan Mishchenko committed
93 94 95 96
    }
    // finish
    p->timeTotal = Abc_Clock();
    pMig->pMan = p;
Alan Mishchenko committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    return p;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mpm_ManStop( Mpm_Man_t * p )
{
Alan Mishchenko committed
113
    if ( p->pPars->fUseTruth && p->pPars->fVeryVerbose )
Alan Mishchenko committed
114 115 116 117 118
    {
        char * pFileName = "truths.txt";
        FILE * pFile = fopen( pFileName, "wb" );
        Vec_MemDump( pFile, p->vTtMem );
        fclose( pFile );
Alan Mishchenko committed
119
        printf( "Dumped %d %d-var truth tables into file \"%s\" (%.2f MB).\n", 
Alan Mishchenko committed
120 121 122
            Vec_MemEntryNum(p->vTtMem), p->nLutSize, pFileName,
            (16.0 * p->nTruWords + 1.0) * Vec_MemEntryNum(p->vTtMem) / (1 << 20) );
    }
Alan Mishchenko committed
123
    if ( p->pPars->fUseDsd && p->pPars->fVerbose )
Alan Mishchenko committed
124
        Mpm_ManPrintDsdStats( p );
Alan Mishchenko committed
125 126 127 128 129
    if ( p->vTtMem ) 
    {
        Vec_MemHashFree( p->vTtMem );
        Vec_MemFree( p->vTtMem );
    }
Alan Mishchenko committed
130 131 132 133 134 135 136 137
    if ( p->pHash )
    {
        Vec_WrdFree( p->vPerm6 );
        Vec_IntFree( p->vMap2Perm );
        Vec_IntFree( p->vConfgRes );
        Vec_IntFree( p->pHash->vData );
        Hsh_IntManStop( p->pHash );
    }
Alan Mishchenko committed
138
    Vec_WecFreeP( &p->vNpnConfigs );
Alan Mishchenko committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    Vec_PtrFree( p->vTemp );
    Mmr_StepStop( p->pManCuts );
    ABC_FREE( p->vFreeUnits.pArray );
    // mapping attributes
    ABC_FREE( p->vCutBests.pArray );
    ABC_FREE( p->vCutLists.pArray );
    ABC_FREE( p->vMigRefs.pArray );
    ABC_FREE( p->vMapRefs.pArray );
    ABC_FREE( p->vEstRefs.pArray );
    ABC_FREE( p->vRequireds.pArray );
    ABC_FREE( p->vTimes.pArray );
    ABC_FREE( p->vAreas.pArray );
    ABC_FREE( p->vEdges.pArray );
    ABC_FREE( p );
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Mpm_ManPrintStatsInit( Mpm_Man_t * p )
{
Alan Mishchenko committed
168
    printf( "K = %d.  C = %d.  Cand = %d. XOR = %d. MUX = %d. Choice = %d.  CutMin = %d. Truth = %d. DSD = %d.\n", 
Alan Mishchenko committed
169 170
        p->nLutSize, p->nNumCuts, Mig_ManCandNum(p->pMig), 
        Mig_ManXorNum(p->pMig), Mig_ManMuxNum(p->pMig), p->pMig->nChoices, 
Alan Mishchenko committed
171
        p->pPars->fCutMin, p->pPars->fUseTruth, p->pPars->fUseDsd );
Alan Mishchenko committed
172 173 174 175 176 177 178 179 180 181
}
void Mpm_ManPrintStats( Mpm_Man_t * p )
{
    printf( "Memory usage:  Mig = %.2f MB  Map = %.2f MB  Cut = %.2f MB    Total = %.2f MB.  ", 
        1.0 * Mig_ManObjNum(p->pMig) * sizeof(Mig_Obj_t) / (1 << 20), 
        1.0 * Mig_ManObjNum(p->pMig) * 48 / (1 << 20), 
        1.0 * Mmr_StepMemory(p->pManCuts) / (1 << 17), 
        1.0 * Mig_ManObjNum(p->pMig) * sizeof(Mig_Obj_t) / (1 << 20) + 
        1.0 * Mig_ManObjNum(p->pMig) * 48 / (1 << 20) +
        1.0 * Mmr_StepMemory(p->pManCuts) / (1 << 17) );
Alan Mishchenko committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    if ( p->timeDerive )
    {
        printf( "\n" );
        p->timeTotal = Abc_Clock() - p->timeTotal;
        p->timeOther = p->timeTotal - p->timeDerive;

        Abc_Print( 1, "Runtime breakdown:\n" );
        ABC_PRTP( "Complete cut computation   ", p->timeDerive , p->timeTotal );
        ABC_PRTP( "- Merging cuts             ", p->timeMerge  , p->timeTotal );
        ABC_PRTP( "- Evaluting cut parameters ", p->timeEval   , p->timeTotal );
        ABC_PRTP( "- Checking cut containment ", p->timeCompare, p->timeTotal );
        ABC_PRTP( "- Adding cuts to storage   ", p->timeStore  , p->timeTotal );
        ABC_PRTP( "Other                      ", p->timeOther  , p->timeTotal );
        ABC_PRTP( "TOTAL                      ", p->timeTotal  , p->timeTotal );
    }
    else
        Abc_PrintTime( 1, "Time", Abc_Clock() - p->timeTotal );
Alan Mishchenko committed
199 200 201 202 203 204 205 206 207
}

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


ABC_NAMESPACE_IMPL_END