cutMan.c 9.44 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    [cutMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [K-feasible cut computation package.]

  Synopsis    [Cut manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: cutMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

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

#include "cutInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
30 31
extern void Npn_StartTruth8( uint8 uTruths[][32] );

Alan Mishchenko committed
32
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
33
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Starts the cut manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Cut_Man_t * Cut_ManStart( Cut_Params_t * pParams )
{
    Cut_Man_t * p;
Alan Mishchenko committed
50 51 52
//    extern int nTruthDsd;
//    nTruthDsd = 0;
    assert( pParams->nVarsMax >= 3 && pParams->nVarsMax <= CUT_SIZE_MAX );
Alan Mishchenko committed
53
    p = ABC_ALLOC( Cut_Man_t, 1 );
Alan Mishchenko committed
54 55 56
    memset( p, 0, sizeof(Cut_Man_t) );
    // set and correct parameters
    p->pParams = pParams;
Alan Mishchenko committed
57 58 59 60
    // prepare storage for cuts
    p->vCutsNew = Vec_PtrAlloc( pParams->nIdsMax );
    Vec_PtrFill( p->vCutsNew, pParams->nIdsMax, NULL );
    // prepare storage for sequential cuts
Alan Mishchenko committed
61 62
    if ( pParams->fSeq )
    {
Alan Mishchenko committed
63 64 65 66 67 68 69 70 71 72
        p->pParams->fFilter = 1;
        p->vCutsOld = Vec_PtrAlloc( pParams->nIdsMax );
        Vec_PtrFill( p->vCutsOld, pParams->nIdsMax, NULL );
        p->vCutsTemp = Vec_PtrAlloc( pParams->nCutSet );
        Vec_PtrFill( p->vCutsTemp, pParams->nCutSet, NULL );
        if ( pParams->fTruth && pParams->nVarsMax > 5 )
        {
            pParams->fTruth = 0;
            printf( "Skipping computation of truth tables for sequential cuts with more than 5 inputs.\n" );
        }
Alan Mishchenko committed
73 74
    }
    // entry size
Alan Mishchenko committed
75 76 77 78 79 80 81 82 83 84 85 86 87
    p->EntrySize = sizeof(Cut_Cut_t) + pParams->nVarsMax * sizeof(int);
    if ( pParams->fTruth )
    {
        if ( pParams->nVarsMax > 14 )
        {
            pParams->fTruth = 0;
            printf( "Skipping computation of truth table for more than %d inputs.\n", 14 );
        }
        else
        {
            p->nTruthWords = Cut_TruthWords( pParams->nVarsMax );
            p->EntrySize += p->nTruthWords * sizeof(unsigned);
        }
Alan Mishchenko committed
88
        p->puTemp[0] = ABC_ALLOC( unsigned, 4 * p->nTruthWords );
Alan Mishchenko committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
        p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
        p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
    }
    // enable cut computation recording
    if ( pParams->fRecord )
    {
        p->vNodeCuts   = Vec_IntStart( pParams->nIdsMax );
        p->vNodeStarts = Vec_IntStart( pParams->nIdsMax );
        p->vCutPairs   = Vec_IntAlloc( 0 );
    }
    // allocate storage for delays
    if ( pParams->fMap && !p->pParams->fSeq )
    {
        p->vDelays = Vec_IntStart( pParams->nIdsMax );
        p->vDelays2 = Vec_IntStart( pParams->nIdsMax );
        p->vCutsMax = Vec_PtrStart( pParams->nIdsMax );
    }
Alan Mishchenko committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    // memory for cuts
    p->pMmCuts = Extra_MmFixedStart( p->EntrySize );
    p->vTemp = Vec_PtrAlloc( 100 );
    return p;
}

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

  Synopsis    [Stops the cut manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_ManStop( Cut_Man_t * p )
{
Alan Mishchenko committed
126 127 128 129 130 131 132 133 134 135 136 137
    if ( p->vCutsNew )    Vec_PtrFree( p->vCutsNew );
    if ( p->vCutsOld )    Vec_PtrFree( p->vCutsOld );
    if ( p->vCutsTemp )   Vec_PtrFree( p->vCutsTemp );
    if ( p->vFanCounts )  Vec_IntFree( p->vFanCounts );
    if ( p->vTemp )       Vec_PtrFree( p->vTemp );

    if ( p->vCutsMax )    Vec_PtrFree( p->vCutsMax );
    if ( p->vDelays )     Vec_IntFree( p->vDelays );
    if ( p->vDelays2 )    Vec_IntFree( p->vDelays2 );
    if ( p->vNodeCuts )   Vec_IntFree( p->vNodeCuts );
    if ( p->vNodeStarts ) Vec_IntFree( p->vNodeStarts );
    if ( p->vCutPairs )   Vec_IntFree( p->vCutPairs );
Alan Mishchenko committed
138
    if ( p->puTemp[0] )   ABC_FREE( p->puTemp[0] );
Alan Mishchenko committed
139 140

    Extra_MmFixedStop( p->pMmCuts );
Alan Mishchenko committed
141
    ABC_FREE( p );
Alan Mishchenko committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_ManPrintStats( Cut_Man_t * p )
{
Alan Mishchenko committed
157 158 159 160 161
    if ( p->pReady )
    {
        Cut_CutRecycle( p, p->pReady );
        p->pReady = NULL;
    }
Alan Mishchenko committed
162 163 164 165 166
    printf( "Cut computation statistics:\n" );
    printf( "Current cuts      = %8d. (Trivial = %d.)\n", p->nCutsCur-p->nCutsTriv, p->nCutsTriv );
    printf( "Peak cuts         = %8d.\n", p->nCutsPeak );
    printf( "Total allocated   = %8d.\n", p->nCutsAlloc );
    printf( "Total deallocated = %8d.\n", p->nCutsDealloc );
Alan Mishchenko committed
167 168
    printf( "Cuts filtered     = %8d.\n", p->nCutsFilter );
    printf( "Nodes saturated   = %8d. (Max cuts = %d.)\n", p->nCutsLimit, p->pParams->nKeepMax );
Alan Mishchenko committed
169 170
    printf( "Cuts per node     = %8.1f\n", ((float)(p->nCutsCur-p->nCutsTriv))/p->nNodes );
    printf( "The cut size      = %8d bytes.\n", p->EntrySize );
171
    printf( "Peak memory       = %8.2f MB.\n", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
Alan Mishchenko committed
172 173 174 175 176 177 178 179 180 181
    printf( "Total nodes       = %8d.\n", p->nNodes );
    if ( p->pParams->fDag || p->pParams->fTree )
    {
    printf( "DAG nodes         = %8d.\n", p->nNodesDag );
    printf( "Tree nodes        = %8d.\n", p->nNodes - p->nNodesDag );
    }
    printf( "Nodes w/o cuts    = %8d.\n", p->nNodesNoCuts );
    if ( p->pParams->fMap && !p->pParams->fSeq )
    printf( "Mapping delay     = %8d.\n", p->nDelayMin );

Alan Mishchenko committed
182 183 184 185 186
    ABC_PRT( "Merge ", p->timeMerge );
    ABC_PRT( "Union ", p->timeUnion );
    ABC_PRT( "Filter", p->timeFilter );
    ABC_PRT( "Truth ", p->timeTruth );
    ABC_PRT( "Map   ", p->timeMap );
Alan Mishchenko committed
187 188 189
//    printf( "Nodes = %d. Multi = %d.  Cuts = %d. Multi = %d.\n", 
//        p->nNodes, p->nNodesMulti, p->nCutsCur-p->nCutsTriv, p->nCutsMulti );
//    printf( "Count0 = %d. Count1 = %d. Count2 = %d.\n\n", p->Count0, p->Count1, p->Count2 );
Alan Mishchenko committed
190 191
}

Alan Mishchenko committed
192 193 194 195 196 197 198 199 200 201 202 203
    
/**Function*************************************************************

  Synopsis    [Prints some interesting stats.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
204
void Cut_ManPrintStatsToFile( Cut_Man_t * p, char * pFileName, clock_t TimeTotal )
Alan Mishchenko committed
205 206 207 208 209 210 211 212 213 214 215 216
{
    FILE * pTable;
    pTable = fopen( "cut_stats.txt", "a+" );
    fprintf( pTable, "%-20s ", pFileName );
    fprintf( pTable, "%8d ", p->nNodes );
    fprintf( pTable, "%6.1f ", ((float)(p->nCutsCur))/p->nNodes );
    fprintf( pTable, "%6.2f ", ((float)(100.0 * p->nCutsLimit))/p->nNodes );
    fprintf( pTable, "%6.2f ", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
    fprintf( pTable, "%6.2f ", (float)(TimeTotal)/(float)(CLOCKS_PER_SEC) );
    fprintf( pTable, "\n" );
    fclose( pTable );
}
Alan Mishchenko committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_ManSetFanoutCounts( Cut_Man_t * p, Vec_Int_t * vFanCounts )
{
    p->vFanCounts = vFanCounts;
}

Alan Mishchenko committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_ManSetNodeAttrs( Cut_Man_t * p, Vec_Int_t * vNodeAttrs )
{
    p->vNodeAttrs = vNodeAttrs;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Cut_ManReadVarsMax( Cut_Man_t * p )
{
    return p->pParams->nVarsMax;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Cut_Params_t * Cut_ManReadParams( Cut_Man_t * p )
{
    return p->pParams;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Cut_ManReadNodeAttrs( Cut_Man_t * p )
{
    return p->vNodeAttrs;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cut_ManIncrementDagNodes( Cut_Man_t * p )
{
    p->nNodesDag++;
}

Alan Mishchenko committed
314 315 316 317 318
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


319 320
ABC_NAMESPACE_IMPL_END