src/opt/res/resCore.c File Reference

#include "abc.h"
#include "resInt.h"
#include "kit.h"
#include "satStore.h"
Include dependency graph for resCore.c:

Go to the source code of this file.

Data Structures

struct  Res_Man_t_

Typedefs

typedef struct Res_Man_t_ Res_Man_t

Functions

Hop_Obj_tKit_GraphToHop (Hop_Man_t *pMan, Kit_Graph_t *pGraph)
Res_Man_tRes_ManAlloc (Res_Par_t *pPars)
void Res_ManFree (Res_Man_t *p)
void Res_UpdateNetwork (Abc_Obj_t *pObj, Vec_Ptr_t *vFanins, Hop_Obj_t *pFunc, Vec_Vec_t *vLevels)
int Abc_NtkResynthesize (Abc_Ntk_t *pNtk, Res_Par_t *pPars)

Variables

int s_ResynTime

Typedef Documentation

typedef struct Res_Man_t_ Res_Man_t

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

FileName [resCore.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Resynthesis package.]

Synopsis [Top-level resynthesis procedure.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 15, 2007.]

Revision [

Id
resCore.c,v 1.00 2007/01/15 00:00:00 alanmi Exp

] DECLARATIONS ///

Definition at line 30 of file resCore.c.


Function Documentation

int Abc_NtkResynthesize ( Abc_Ntk_t pNtk,
Res_Par_t pPars 
)

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

Synopsis [Entrace into the resynthesis package.]

Description []

SideEffects []

SeeAlso []

Definition at line 207 of file resCore.c.

00208 {
00209     ProgressBar * pProgress;
00210     Res_Man_t * p;
00211     Abc_Obj_t * pObj;
00212     Hop_Obj_t * pFunc;
00213     Kit_Graph_t * pGraph;
00214     Vec_Ptr_t * vFanins;
00215     unsigned * puTruth;
00216     int i, k, RetValue, nNodesOld, nFanins, nFaninsMax;
00217     int clk, clkTotal = clock();
00218 
00219     // start the manager
00220     p = Res_ManAlloc( pPars );
00221     p->nTotalNets = Abc_NtkGetTotalFanins(pNtk);
00222     p->nTotalNodes = Abc_NtkNodeNum(pNtk);
00223     nFaninsMax = Abc_NtkGetFaninMax(pNtk);
00224 
00225     // perform the network sweep
00226     Abc_NtkSweep( pNtk, 0 );
00227 
00228     // convert into the AIG
00229     if ( !Abc_NtkToAig(pNtk) )
00230     {
00231         fprintf( stdout, "Converting to BDD has failed.\n" );
00232         Res_ManFree( p );
00233         return 0;
00234     }
00235     assert( Abc_NtkHasAig(pNtk) );
00236 
00237     // set the number of levels
00238     Abc_NtkLevel( pNtk );
00239     Abc_NtkStartReverseLevels( pNtk, pPars->nGrowthLevel );
00240 
00241     // try resynthesizing nodes in the topological order
00242     nNodesOld = Abc_NtkObjNumMax(pNtk);
00243     pProgress = Extra_ProgressBarStart( stdout, nNodesOld );
00244     Abc_NtkForEachObj( pNtk, pObj, i )
00245     {
00246         Extra_ProgressBarUpdate( pProgress, i, NULL );
00247         if ( !Abc_ObjIsNode(pObj) )
00248             continue;
00249         if ( pObj->Id > nNodesOld )
00250             break;
00251 
00252         // create the window for this node
00253 clk = clock();
00254         RetValue = Res_WinCompute( pObj, p->pPars->nWindow/10, p->pPars->nWindow%10, p->pWin );
00255 p->timeWin += clock() - clk;
00256         if ( !RetValue )
00257             continue;
00258         p->nWinsTriv += Res_WinIsTrivial( p->pWin );
00259 
00260         if ( p->pPars->fVeryVerbose )
00261         {
00262             printf( "%5d (lev=%2d) : ", pObj->Id, pObj->Level );
00263             printf( "Win = %3d/%3d/%4d/%3d   ", 
00264                 Vec_PtrSize(p->pWin->vLeaves), 
00265                 Vec_PtrSize(p->pWin->vBranches),
00266                 Vec_PtrSize(p->pWin->vNodes), 
00267                 Vec_PtrSize(p->pWin->vRoots) );
00268         }
00269 
00270         // collect the divisors
00271 clk = clock();
00272         Res_WinDivisors( p->pWin, Abc_ObjRequiredLevel(pObj) - 1 );
00273 p->timeDiv += clock() - clk;
00274 
00275         p->nWins++;
00276         p->nWinNodes += Vec_PtrSize(p->pWin->vNodes);
00277         p->nDivNodes += Vec_PtrSize( p->pWin->vDivs);
00278 
00279         if ( p->pPars->fVeryVerbose )
00280         {
00281             printf( "D = %3d ", Vec_PtrSize(p->pWin->vDivs) );
00282             printf( "D+ = %3d ", p->pWin->nDivsPlus );
00283         }
00284 
00285         // create the AIG for the window
00286 clk = clock();
00287         if ( p->pAig ) Abc_NtkDelete( p->pAig );
00288         p->pAig = Res_WndStrash( p->pWin );
00289 p->timeAig += clock() - clk;
00290 
00291         if ( p->pPars->fVeryVerbose )
00292         {
00293             printf( "AIG = %4d ", Abc_NtkNodeNum(p->pAig) );
00294             printf( "\n" );
00295         }
00296  
00297         // prepare simulation info
00298 clk = clock();
00299         RetValue = Res_SimPrepare( p->pSim, p->pAig, Vec_PtrSize(p->pWin->vLeaves), 0 ); //p->pPars->fVerbose );
00300 p->timeSim += clock() - clk;
00301         if ( !RetValue )
00302         {
00303             p->nSimEmpty++;
00304             continue;
00305         }
00306 
00307         // consider the case of constant node
00308         if ( p->pSim->fConst0 || p->pSim->fConst1 )
00309         {
00310             p->nConstsUsed++;
00311 
00312             pFunc = p->pSim->fConst1? Hop_ManConst1(pNtk->pManFunc) : Hop_ManConst0(pNtk->pManFunc);
00313             vFanins = Vec_VecEntry( p->vResubsW, 0 );
00314             Vec_PtrClear( vFanins );
00315             Res_UpdateNetwork( pObj, vFanins, pFunc, p->vLevels );
00316             continue;
00317         }
00318 
00319 //        printf( " " );
00320 
00321         // find resub candidates for the node
00322 clk = clock();
00323         if ( p->pPars->fArea )
00324             RetValue = Res_FilterCandidates( p->pWin, p->pAig, p->pSim, p->vResubs, p->vResubsW, nFaninsMax, 1 );
00325         else
00326             RetValue = Res_FilterCandidates( p->pWin, p->pAig, p->pSim, p->vResubs, p->vResubsW, nFaninsMax, 0 );
00327 p->timeCand += clock() - clk;
00328         p->nCandSets += RetValue;
00329         if ( RetValue == 0 )
00330             continue;
00331 
00332 //        printf( "%d(%d) ", Vec_PtrSize(p->pWin->vDivs), RetValue );
00333 
00334         p->nWinsUsed++;
00335 
00336         // iterate through candidate resubstitutions
00337         Vec_VecForEachLevel( p->vResubs, vFanins, k )
00338         {
00339             if ( Vec_PtrSize(vFanins) == 0 )
00340                 break;
00341 
00342             // solve the SAT problem and get clauses
00343 clk = clock();
00344             if ( p->pCnf ) Sto_ManFree( p->pCnf );
00345             p->pCnf = Res_SatProveUnsat( p->pAig, vFanins );
00346             if ( p->pCnf == NULL )
00347             {
00348 p->timeSatSat += clock() - clk;
00349 //                printf( " Sat\n" );
00350 //                printf( "-" );
00351                 continue;
00352             }
00353 p->timeSatUnsat += clock() - clk;
00354 //            printf( "+" );
00355 
00356             p->nProvedSets++;
00357 //            printf( " Unsat\n" );
00358 //            continue;
00359 //            printf( "Proved %d.\n", k );
00360 
00361             // write it into a file
00362 //            Sto_ManDumpClauses( p->pCnf, "trace.cnf" );
00363 
00364             // interpolate the problem if it was UNSAT
00365 clk = clock();
00366             nFanins = Int_ManInterpolate( p->pMan, p->pCnf, 0, &puTruth );
00367 p->timeInt += clock() - clk;
00368             if ( nFanins != Vec_PtrSize(vFanins) - 2 )
00369                 continue;
00370             assert( puTruth );
00371 //            Extra_PrintBinary( stdout, puTruth, 1 << nFanins );  printf( "\n" );
00372 
00373             // transform interpolant into the AIG
00374             pGraph = Kit_TruthToGraph( puTruth, nFanins, p->vMem );
00375 
00376             // derive the AIG for the decomposition tree
00377             pFunc = Kit_GraphToHop( pNtk->pManFunc, pGraph );
00378             Kit_GraphFree( pGraph );
00379 
00380             // update the network
00381 clk = clock();
00382             Res_UpdateNetwork( pObj, Vec_VecEntry(p->vResubsW, k), pFunc, p->vLevels );
00383 p->timeUpd += clock() - clk;
00384             break;
00385         }
00386 //        printf( "\n" );
00387     }
00388     Extra_ProgressBarStop( pProgress );
00389     Abc_NtkStopReverseLevels( pNtk );
00390 
00391 p->timeSatSim += p->pSim->timeSat;
00392 p->timeSatTotal = p->timeSatSat + p->timeSatUnsat + p->timeSatSim;
00393 
00394     p->nTotalNets2 = Abc_NtkGetTotalFanins(pNtk);
00395     p->nTotalNodes2 = Abc_NtkNodeNum(pNtk);
00396 
00397     // quit resubstitution manager
00398 p->timeTotal = clock() - clkTotal;
00399     Res_ManFree( p );
00400 
00401 s_ResynTime += clock() - clkTotal;
00402     // check the resulting network
00403     if ( !Abc_NtkCheck( pNtk ) )
00404     {
00405         fprintf( stdout, "Abc_NtkResynthesize(): Network check has failed.\n" );
00406         return 0;
00407     }
00408     return 1;
00409 }

Hop_Obj_t* Kit_GraphToHop ( Hop_Man_t pMan,
Kit_Graph_t pGraph 
)

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

Synopsis [Strashes one logic node using its SOP.]

Description []

SideEffects []

SeeAlso []

Definition at line 76 of file kitHop.c.

00077 {
00078     Kit_Node_t * pNode = NULL;
00079     int i;
00080     // collect the fanins
00081     Kit_GraphForEachLeaf( pGraph, pNode, i )
00082         pNode->pFunc = Hop_IthVar( pMan, i );
00083     // perform strashing
00084     return Kit_GraphToHopInternal( pMan, pGraph );
00085 }

Res_Man_t* Res_ManAlloc ( Res_Par_t pPars  ) 

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

Synopsis [Allocate resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 93 of file resCore.c.

00094 {
00095     Res_Man_t * p;
00096     p = ALLOC( Res_Man_t, 1 );
00097     memset( p, 0, sizeof(Res_Man_t) );
00098     assert( pPars->nWindow > 0 && pPars->nWindow < 100 );
00099     assert( pPars->nCands > 0 && pPars->nCands < 100 );
00100     p->pPars = pPars;
00101     p->pWin = Res_WinAlloc();
00102     p->pSim = Res_SimAlloc( pPars->nSimWords );
00103     p->pMan = Int_ManAlloc( 512 );
00104     p->vMem = Vec_IntAlloc( 0 );
00105     p->vResubs  = Vec_VecStart( pPars->nCands );
00106     p->vResubsW = Vec_VecStart( pPars->nCands );
00107     p->vLevels  = Vec_VecStart( 32 );
00108     return p;
00109 }

void Res_ManFree ( Res_Man_t p  ) 

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

Synopsis [Deallocate resynthesis manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 122 of file resCore.c.

00123 {
00124     if ( p->pPars->fVerbose )
00125     {
00126         printf( "Reduction in nodes = %5d. (%.2f %%) ", 
00127             p->nTotalNodes-p->nTotalNodes2, 
00128             100.0*(p->nTotalNodes-p->nTotalNodes2)/p->nTotalNodes );
00129         printf( "Reduction in edges = %5d. (%.2f %%) ", 
00130             p->nTotalNets-p->nTotalNets2, 
00131             100.0*(p->nTotalNets-p->nTotalNets2)/p->nTotalNets );
00132         printf( "\n" );
00133 
00134         printf( "Winds = %d. ", p->nWins );
00135         printf( "Nodes = %d. (Ave = %5.1f)  ", p->nWinNodes, 1.0*p->nWinNodes/p->nWins );
00136         printf( "Divs = %d. (Ave = %5.1f)  ",  p->nDivNodes, 1.0*p->nDivNodes/p->nWins );
00137         printf( "\n" );
00138         printf( "WinsTriv = %d. ", p->nWinsTriv );
00139         printf( "SimsEmpt = %d. ", p->nSimEmpty );
00140         printf( "Const = %d. ", p->nConstsUsed );
00141         printf( "WindUsed = %d. ", p->nWinsUsed );
00142         printf( "Cands = %d. ", p->nCandSets );
00143         printf( "Proved = %d.", p->nProvedSets );
00144         printf( "\n" );
00145 
00146         PRTP( "Windowing  ", p->timeWin,      p->timeTotal );
00147         PRTP( "Divisors   ", p->timeDiv,      p->timeTotal );
00148         PRTP( "Strashing  ", p->timeAig,      p->timeTotal );
00149         PRTP( "Simulation ", p->timeSim,      p->timeTotal );
00150         PRTP( "Candidates ", p->timeCand,     p->timeTotal );
00151         PRTP( "SAT solver ", p->timeSatTotal, p->timeTotal );
00152         PRTP( "    sat    ", p->timeSatSat,   p->timeTotal );
00153         PRTP( "    unsat  ", p->timeSatUnsat, p->timeTotal );
00154         PRTP( "    simul  ", p->timeSatSim,   p->timeTotal );
00155         PRTP( "Interpol   ", p->timeInt,      p->timeTotal );
00156         PRTP( "Undating   ", p->timeUpd,      p->timeTotal );
00157         PRTP( "TOTAL      ", p->timeTotal,    p->timeTotal );
00158     }
00159     Res_WinFree( p->pWin );
00160     if ( p->pAig ) Abc_NtkDelete( p->pAig );
00161     Res_SimFree( p->pSim );
00162     if ( p->pCnf ) Sto_ManFree( p->pCnf );
00163     Int_ManFree( p->pMan );
00164     Vec_IntFree( p->vMem );
00165     Vec_VecFree( p->vResubs );
00166     Vec_VecFree( p->vResubsW );
00167     Vec_VecFree( p->vLevels );
00168     free( p );
00169 }

void Res_UpdateNetwork ( Abc_Obj_t pObj,
Vec_Ptr_t vFanins,
Hop_Obj_t pFunc,
Vec_Vec_t vLevels 
)

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

Synopsis [Incrementally updates level of the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 182 of file resCore.c.

00183 {
00184     Abc_Obj_t * pObjNew, * pFanin;
00185     int k;
00186     // create the new node
00187     pObjNew = Abc_NtkCreateNode( pObj->pNtk );
00188     pObjNew->pData = pFunc;
00189     Vec_PtrForEachEntry( vFanins, pFanin, k )
00190         Abc_ObjAddFanin( pObjNew, pFanin );
00191     // replace the old node by the new node
00192     // update the level of the node
00193     Abc_NtkUpdate( pObj, pObjNew, vLevels );
00194 }


Variable Documentation

Definition at line 37 of file abcPrint.c.


Generated on Tue Jan 5 12:19:30 2010 for abc70930 by  doxygen 1.6.1