abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkMan.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [nwkMan.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Logic network representation.]
8 
9  Synopsis [Network manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: nwkMan.c,v 1.1 2008/10/10 14:09:30 mjarvin Exp $]
18 
19 ***********************************************************************/
20 
21 #include "nwk.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Allocates the manager.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Nwk_Man_t * p;
48  p = ABC_ALLOC( Nwk_Man_t, 1 );
49  memset( p, 0, sizeof(Nwk_Man_t) );
50  p->vCis = Vec_PtrAlloc( 1000 );
51  p->vCos = Vec_PtrAlloc( 1000 );
52  p->vObjs = Vec_PtrAlloc( 1000 );
53  p->vTemp = Vec_PtrAlloc( 1000 );
54  p->nFanioPlus = 2;
56  p->pManHop = Hop_ManStart();
57  return p;
58 }
59 
60 /**Function*************************************************************
61 
62  Synopsis [Deallocates the manager.]
63 
64  Description []
65 
66  SideEffects []
67 
68  SeeAlso []
69 
70 ***********************************************************************/
72 {
73 // printf( "The number of realloced nodes = %d.\n", p->nRealloced );
74  if ( p->pName ) ABC_FREE( p->pName );
75  if ( p->pSpec ) ABC_FREE( p->pSpec );
76  if ( p->vCis ) Vec_PtrFree( p->vCis );
77  if ( p->vCos ) Vec_PtrFree( p->vCos );
78  if ( p->vObjs ) Vec_PtrFree( p->vObjs );
79  if ( p->vTemp ) Vec_PtrFree( p->vTemp );
80  if ( p->pManTime ) Tim_ManStop( p->pManTime );
81  if ( p->pMemObjs ) Aig_MmFlexStop( p->pMemObjs, 0 );
82  if ( p->pManHop ) Hop_ManStop( p->pManHop );
83  ABC_FREE( p );
84 }
85 
86 /**Function*************************************************************
87 
88  Synopsis [Prints stats of the manager.]
89 
90  Description []
91 
92  SideEffects []
93 
94  SeeAlso []
95 
96 ***********************************************************************/
98 {
99  Nwk_Obj_t * pObj;
100  int i, Counters[256] = {0};
101  Nwk_ManForEachNode( p, pObj, i )
102  Counters[Nwk_ObjFaninNum(pObj)]++;
103  printf( "LUTs by size: " );
104  for ( i = 0; i <= pLutLib->LutMax; i++ )
105  printf( "%d:%d ", i, Counters[i] );
106 }
107 
108 /**Function*************************************************************
109 
110  Synopsis [If the network is best, saves it in "best.blif" and returns 1.]
111 
112  Description [If the networks are incomparable, saves the new network,
113  returns its parameters in the internal parameter structure, and returns 1.
114  If the new network is not a logic network, quits without saving and returns 0.]
115 
116  SideEffects []
117 
118  SeeAlso []
119 
120 ***********************************************************************/
121 int Nwk_ManCompareAndSaveBest( Nwk_Man_t * pNtk, void * pNtl )
122 {
123 // extern void Ntl_WriteBlifLogic( Nwk_Man_t * pNtk, void * pNtl, char * pFileName );
124  extern void Nwk_ManDumpBlif( Nwk_Man_t * pNtk, char * pFileName, Vec_Ptr_t * vPiNames, Vec_Ptr_t * vPoNames );
125  static struct ParStruct {
126  char * pName; // name of the best saved network
127  int Depth; // depth of the best saved network
128  int Flops; // flops in the best saved network
129  int Nodes; // nodes in the best saved network
130  int nPis; // the number of primary inputs
131  int nPos; // the number of primary outputs
132  } ParsNew, ParsBest = { 0 };
133  // free storage for the name
134  if ( pNtk == NULL )
135  {
136  ABC_FREE( ParsBest.pName );
137  return 0;
138  }
139  // get the parameters
140  ParsNew.Depth = Nwk_ManLevel( pNtk );
141  ParsNew.Flops = Nwk_ManLatchNum( pNtk );
142  ParsNew.Nodes = Nwk_ManNodeNum( pNtk );
143  ParsNew.nPis = Nwk_ManPiNum( pNtk );
144  ParsNew.nPos = Nwk_ManPoNum( pNtk );
145  // reset the parameters if the network has the same name
146  if ( ParsBest.pName == NULL ||
147  strcmp(ParsBest.pName, pNtk->pName) ||
148  ParsBest.Depth > ParsNew.Depth ||
149  (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops > ParsNew.Flops) ||
150  (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops == ParsNew.Flops && ParsBest.Nodes > ParsNew.Nodes) )
151  {
152  ABC_FREE( ParsBest.pName );
153  ParsBest.pName = Abc_UtilStrsav( pNtk->pName );
154  ParsBest.Depth = ParsNew.Depth;
155  ParsBest.Flops = ParsNew.Flops;
156  ParsBest.Nodes = ParsNew.Nodes;
157  ParsBest.nPis = ParsNew.nPis;
158  ParsBest.nPos = ParsNew.nPos;
159  // write the network
160 // Ntl_WriteBlifLogic( pNtk, pNtl, "best.blif" );
161 // Nwk_ManDumpBlif( pNtk, "best_map.blif", NULL, NULL );
162  return 1;
163  }
164  return 0;
165 }
166 
167 /**Function*************************************************************
168 
169  Synopsis []
170 
171  Description []
172 
173  SideEffects []
174 
175  SeeAlso []
176 
177 ***********************************************************************/
178 char * Nwk_FileNameGeneric( char * FileName )
179 {
180  char * pDot, * pRes;
181  pRes = Abc_UtilStrsav( FileName );
182  if ( (pDot = strrchr( pRes, '.' )) )
183  *pDot = 0;
184  return pRes;
185 }
186 
187 /**Function*************************************************************
188 
189  Synopsis [Marks nodes for power-optimization.]
190 
191  Description []
192 
193  SideEffects []
194 
195  SeeAlso []
196 
197 ***********************************************************************/
199 {
200  extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
201  Vec_Int_t * vSwitching;
202  float * pSwitching;
203  Aig_Man_t * pAig;
204  Aig_Obj_t * pObjAig;
205  Nwk_Obj_t * pObjAbc;
206  float Result = (float)0;
207  int i;
208  // strash the network
209  // map network into an AIG
210  pAig = Nwk_ManStrash( pNtk );
211  vSwitching = Saig_ManComputeSwitchProbs( pAig, 48, 16, 0 );
212  pSwitching = (float *)vSwitching->pArray;
213  Nwk_ManForEachObj( pNtk, pObjAbc, i )
214  {
215  if ( (pObjAig = Aig_Regular((Aig_Obj_t *)pObjAbc->pCopy)) )
216  Result += Nwk_ObjFanoutNum(pObjAbc) * pSwitching[pObjAig->Id];
217  }
218  Vec_IntFree( vSwitching );
219  Aig_ManStop( pAig );
220  return Result;
221 }
222 
223 /**Function*************************************************************
224 
225  Synopsis [Prints stats of the manager.]
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
234 void Nwk_ManPrintStats( Nwk_Man_t * pNtk, If_LibLut_t * pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t * pNtl )
235 {
236 // extern int Ntl_ManLatchNum( Ntl_Man_t * p );
237 // extern void Ntl_ManWriteBlifLogic( Nwk_Man_t * pNtk, void * pNtl, char * pFileName );
238  if ( fSaveBest )
239  Nwk_ManCompareAndSaveBest( pNtk, pNtl );
240  if ( fDumpResult )
241  {
242  char Buffer[1000] = {0};
243  const char * pNameGen = pNtk->pSpec? Nwk_FileNameGeneric( pNtk->pSpec ) : "nameless_";
244  sprintf( Buffer, "%s_dump.blif", pNameGen );
245 // Ntl_ManWriteBlifLogic( pNtk, pNtl, Buffer );
246 // sprintf( Buffer, "%s_dump_map.blif", pNameGen );
247 // Nwk_ManDumpBlif( pNtk, Buffer, NULL, NULL );
248  if ( pNtk->pSpec ) ABC_FREE( pNameGen );
249  }
250 
251  pNtk->pLutLib = pLutLib;
252  printf( "%-15s : ", pNtk->pName );
253  printf( "pi = %5d ", Nwk_ManPiNum(pNtk) );
254  printf( "po = %5d ", Nwk_ManPoNum(pNtk) );
255  printf( "ci = %5d ", Nwk_ManCiNum(pNtk) );
256  printf( "co = %5d ", Nwk_ManCoNum(pNtk) );
257 // printf( "lat = %5d ", Ntl_ManLatchNum(pNtl) );
258  printf( "node = %5d ", Nwk_ManNodeNum(pNtk) );
259  printf( "edge = %5d ", Nwk_ManGetTotalFanins(pNtk) );
260  printf( "aig = %6d ", Nwk_ManGetAigNodeNum(pNtk) );
261  printf( "lev = %3d ", Nwk_ManLevel(pNtk) );
262 // printf( "lev2 = %3d ", Nwk_ManLevelBackup(pNtk) );
263  printf( "delay = %5.2f ", Nwk_ManDelayTraceLut(pNtk) );
264  if ( fPower )
265  printf( "power = %7.2f ", Nwl_ManComputeTotalSwitching(pNtk) );
266  Nwk_ManPrintLutSizes( pNtk, pLutLib );
267  printf( "\n" );
268 // Nwk_ManDelayTracePrint( pNtk, pLutLib );
269  fflush( stdout );
270 }
271 
272 ////////////////////////////////////////////////////////////////////////
273 /// END OF FILE ///
274 ////////////////////////////////////////////////////////////////////////
275 
276 
278 
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
ABC_DLL int Nwk_ManLevel(Nwk_Man_t *pNtk)
Definition: nwkDfs.c:215
ABC_DLL int Nwk_ManPoNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:135
static int Nwk_ManLatchNum(Nwk_Man_t *p)
Definition: nwk.h:128
void Nwk_ManFree(Nwk_Man_t *p)
Definition: nwkMan.c:71
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
char * pSpec
Definition: nwk.h:65
int LutMax
Definition: if.h:173
void Nwk_ManPrintStats(Nwk_Man_t *pNtk, If_LibLut_t *pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t *pNtl)
Definition: nwkMan.c:234
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
ABC_DLL Aig_Man_t * Nwk_ManStrash(Nwk_Man_t *p)
Definition: nwkStrash.c:99
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_MmFlex_t * pMemObjs
Definition: nwk.h:76
Vec_Ptr_t * vCos
Definition: nwk.h:68
char * pName
Definition: nwk.h:64
ABC_DLL int Nwk_ManGetAigNodeNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:155
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
void Hop_ManStop(Hop_Man_t *p)
Definition: hopMan.c:84
int strcmp()
Vec_Ptr_t * vCis
Definition: nwk.h:67
typedefABC_NAMESPACE_HEADER_START struct Ntl_Man_t_ Ntl_Man_t
INCLUDES ///.
Definition: ntlnwk.h:40
Hop_Man_t * pManHop
Definition: nwk.h:73
char * Nwk_FileNameGeneric(char *FileName)
Definition: nwkMan.c:178
Vec_Int_t * Saig_ManComputeSwitchProbs(Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:684
Definition: nwk.h:61
If_LibLut_t * pLutLib
Definition: nwk.h:75
ABC_DLL int Nwk_ManPiNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:115
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition: hopMan.c:45
Definition: aig.h:69
char * sprintf()
void Tim_ManStop(Tim_Man_t *p)
Definition: timMan.c:375
Tim_Man_t * pManTime
Definition: nwk.h:74
Vec_Ptr_t * vObjs
Definition: nwk.h:69
static int Nwk_ManCiNum(Nwk_Man_t *p)
MACRO DEFINITIONS ///.
Definition: nwk.h:125
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Vec_Ptr_t * vTemp
Definition: nwk.h:77
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
ABC_NAMESPACE_IMPL_START Nwk_Man_t * Nwk_ManAlloc()
DECLARATIONS ///.
Definition: nwkMan.c:45
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Nwk_ManCompareAndSaveBest(Nwk_Man_t *pNtk, void *pNtl)
Definition: nwkMan.c:121
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
ABC_DLL float Nwk_ManDelayTraceLut(Nwk_Man_t *pNtk)
Definition: nwkTiming.c:326
float Nwl_ManComputeTotalSwitching(Nwk_Man_t *pNtk)
Definition: nwkMan.c:198
ABC_DLL void Nwk_ManDumpBlif(Nwk_Man_t *p, char *pFileName, Vec_Ptr_t *vCiNames, Vec_Ptr_t *vCoNames)
Definition: nwkUtil.c:257
#define Nwk_ManForEachObj(p, pObj, i)
Definition: nwk.h:189
ABC_DLL int Nwk_ManGetTotalFanins(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:94
static int Nwk_ManNodeNum(Nwk_Man_t *p)
Definition: nwk.h:127
void Nwk_ManPrintLutSizes(Nwk_Man_t *p, If_LibLut_t *pLutLib)
Definition: nwkMan.c:97
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
char * strrchr()
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
int Id
Definition: aig.h:85
static int Nwk_ManCoNum(Nwk_Man_t *p)
Definition: nwk.h:126
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
static int Depth
Definition: dsdProc.c:56
int nFanioPlus
Definition: nwk.h:71