abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cutMan.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cutMan.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [K-feasible cut computation package.]
8 
9  Synopsis [Cut 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: cutMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cutInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 extern void Npn_StartTruth8( uint8 uTruths[][32] );
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Starts the cut manager.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
48 {
49  Cut_Man_t * p;
50 // extern int nTruthDsd;
51 // nTruthDsd = 0;
52  assert( pParams->nVarsMax >= 3 && pParams->nVarsMax <= CUT_SIZE_MAX );
53  p = ABC_ALLOC( Cut_Man_t, 1 );
54  memset( p, 0, sizeof(Cut_Man_t) );
55  // set and correct parameters
56  p->pParams = pParams;
57  // prepare storage for cuts
58  p->vCutsNew = Vec_PtrAlloc( pParams->nIdsMax );
59  Vec_PtrFill( p->vCutsNew, pParams->nIdsMax, NULL );
60  // prepare storage for sequential cuts
61  if ( pParams->fSeq )
62  {
63  p->pParams->fFilter = 1;
64  p->vCutsOld = Vec_PtrAlloc( pParams->nIdsMax );
65  Vec_PtrFill( p->vCutsOld, pParams->nIdsMax, NULL );
66  p->vCutsTemp = Vec_PtrAlloc( pParams->nCutSet );
67  Vec_PtrFill( p->vCutsTemp, pParams->nCutSet, NULL );
68  if ( pParams->fTruth && pParams->nVarsMax > 5 )
69  {
70  pParams->fTruth = 0;
71  printf( "Skipping computation of truth tables for sequential cuts with more than 5 inputs.\n" );
72  }
73  }
74  // entry size
75  p->EntrySize = sizeof(Cut_Cut_t) + pParams->nVarsMax * sizeof(int);
76  if ( pParams->fTruth )
77  {
78  if ( pParams->nVarsMax > 14 )
79  {
80  pParams->fTruth = 0;
81  printf( "Skipping computation of truth table for more than %d inputs.\n", 14 );
82  }
83  else
84  {
85  p->nTruthWords = Cut_TruthWords( pParams->nVarsMax );
86  p->EntrySize += p->nTruthWords * sizeof(unsigned);
87  }
88  p->puTemp[0] = ABC_ALLOC( unsigned, 4 * p->nTruthWords );
89  p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
90  p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
91  p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
92  }
93  // enable cut computation recording
94  if ( pParams->fRecord )
95  {
96  p->vNodeCuts = Vec_IntStart( pParams->nIdsMax );
97  p->vNodeStarts = Vec_IntStart( pParams->nIdsMax );
98  p->vCutPairs = Vec_IntAlloc( 0 );
99  }
100  // allocate storage for delays
101  if ( pParams->fMap && !p->pParams->fSeq )
102  {
103  p->vDelays = Vec_IntStart( pParams->nIdsMax );
104  p->vDelays2 = Vec_IntStart( pParams->nIdsMax );
105  p->vCutsMax = Vec_PtrStart( pParams->nIdsMax );
106  }
107  // memory for cuts
109  p->vTemp = Vec_PtrAlloc( 100 );
110  return p;
111 }
112 
113 /**Function*************************************************************
114 
115  Synopsis [Stops the cut manager.]
116 
117  Description []
118 
119  SideEffects []
120 
121  SeeAlso []
122 
123 ***********************************************************************/
125 {
126  if ( p->vCutsNew ) Vec_PtrFree( p->vCutsNew );
127  if ( p->vCutsOld ) Vec_PtrFree( p->vCutsOld );
128  if ( p->vCutsTemp ) Vec_PtrFree( p->vCutsTemp );
129  if ( p->vFanCounts ) Vec_IntFree( p->vFanCounts );
130  if ( p->vTemp ) Vec_PtrFree( p->vTemp );
131 
132  if ( p->vCutsMax ) Vec_PtrFree( p->vCutsMax );
133  if ( p->vDelays ) Vec_IntFree( p->vDelays );
134  if ( p->vDelays2 ) Vec_IntFree( p->vDelays2 );
135  if ( p->vNodeCuts ) Vec_IntFree( p->vNodeCuts );
136  if ( p->vNodeStarts ) Vec_IntFree( p->vNodeStarts );
137  if ( p->vCutPairs ) Vec_IntFree( p->vCutPairs );
138  if ( p->puTemp[0] ) ABC_FREE( p->puTemp[0] );
139 
141  ABC_FREE( p );
142 }
143 
144 /**Function*************************************************************
145 
146  Synopsis []
147 
148  Description []
149 
150  SideEffects []
151 
152  SeeAlso []
153 
154 ***********************************************************************/
156 {
157  if ( p->pReady )
158  {
159  Cut_CutRecycle( p, p->pReady );
160  p->pReady = NULL;
161  }
162  printf( "Cut computation statistics:\n" );
163  printf( "Current cuts = %8d. (Trivial = %d.)\n", p->nCutsCur-p->nCutsTriv, p->nCutsTriv );
164  printf( "Peak cuts = %8d.\n", p->nCutsPeak );
165  printf( "Total allocated = %8d.\n", p->nCutsAlloc );
166  printf( "Total deallocated = %8d.\n", p->nCutsDealloc );
167  printf( "Cuts filtered = %8d.\n", p->nCutsFilter );
168  printf( "Nodes saturated = %8d. (Max cuts = %d.)\n", p->nCutsLimit, p->pParams->nKeepMax );
169  printf( "Cuts per node = %8.1f\n", ((float)(p->nCutsCur-p->nCutsTriv))/p->nNodes );
170  printf( "The cut size = %8d bytes.\n", p->EntrySize );
171  printf( "Peak memory = %8.2f MB.\n", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
172  printf( "Total nodes = %8d.\n", p->nNodes );
173  if ( p->pParams->fDag || p->pParams->fTree )
174  {
175  printf( "DAG nodes = %8d.\n", p->nNodesDag );
176  printf( "Tree nodes = %8d.\n", p->nNodes - p->nNodesDag );
177  }
178  printf( "Nodes w/o cuts = %8d.\n", p->nNodesNoCuts );
179  if ( p->pParams->fMap && !p->pParams->fSeq )
180  printf( "Mapping delay = %8d.\n", p->nDelayMin );
181 
182  ABC_PRT( "Merge ", p->timeMerge );
183  ABC_PRT( "Union ", p->timeUnion );
184  ABC_PRT( "Filter", p->timeFilter );
185  ABC_PRT( "Truth ", p->timeTruth );
186  ABC_PRT( "Map ", p->timeMap );
187 // printf( "Nodes = %d. Multi = %d. Cuts = %d. Multi = %d.\n",
188 // p->nNodes, p->nNodesMulti, p->nCutsCur-p->nCutsTriv, p->nCutsMulti );
189 // printf( "Count0 = %d. Count1 = %d. Count2 = %d.\n\n", p->Count0, p->Count1, p->Count2 );
190 }
191 
192 
193 /**Function*************************************************************
194 
195  Synopsis [Prints some interesting stats.]
196 
197  Description []
198 
199  SideEffects []
200 
201  SeeAlso []
202 
203 ***********************************************************************/
204 void Cut_ManPrintStatsToFile( Cut_Man_t * p, char * pFileName, abctime TimeTotal )
205 {
206  FILE * pTable;
207  pTable = fopen( "cut_stats.txt", "a+" );
208  fprintf( pTable, "%-20s ", pFileName );
209  fprintf( pTable, "%8d ", p->nNodes );
210  fprintf( pTable, "%6.1f ", ((float)(p->nCutsCur))/p->nNodes );
211  fprintf( pTable, "%6.2f ", ((float)(100.0 * p->nCutsLimit))/p->nNodes );
212  fprintf( pTable, "%6.2f ", (float)p->nCutsPeak * p->EntrySize / (1<<20) );
213  fprintf( pTable, "%6.2f ", (float)(TimeTotal)/(float)(CLOCKS_PER_SEC) );
214  fprintf( pTable, "\n" );
215  fclose( pTable );
216 }
217 
218 /**Function*************************************************************
219 
220  Synopsis []
221 
222  Description []
223 
224  SideEffects []
225 
226  SeeAlso []
227 
228 ***********************************************************************/
230 {
231  p->vFanCounts = vFanCounts;
232 }
233 
234 /**Function*************************************************************
235 
236  Synopsis []
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
245 void Cut_ManSetNodeAttrs( Cut_Man_t * p, Vec_Int_t * vNodeAttrs )
246 {
247  p->vNodeAttrs = vNodeAttrs;
248 }
249 
250 /**Function*************************************************************
251 
252  Synopsis []
253 
254  Description []
255 
256  SideEffects []
257 
258  SeeAlso []
259 
260 ***********************************************************************/
262 {
263  return p->pParams->nVarsMax;
264 }
265 
266 /**Function*************************************************************
267 
268  Synopsis []
269 
270  Description []
271 
272  SideEffects []
273 
274  SeeAlso []
275 
276 ***********************************************************************/
278 {
279  return p->pParams;
280 }
281 
282 /**Function*************************************************************
283 
284  Synopsis []
285 
286  Description []
287 
288  SideEffects []
289 
290  SeeAlso []
291 
292 ***********************************************************************/
294 {
295  return p->vNodeAttrs;
296 }
297 
298 /**Function*************************************************************
299 
300  Synopsis []
301 
302  Description []
303 
304  SideEffects []
305 
306  SeeAlso []
307 
308 ***********************************************************************/
310 {
311  p->nNodesDag++;
312 }
313 
314 ////////////////////////////////////////////////////////////////////////
315 /// END OF FILE ///
316 ////////////////////////////////////////////////////////////////////////
317 
318 
320 
char * memset()
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
ABC_NAMESPACE_IMPL_START void Npn_StartTruth8(uint8 uTruths[][32])
DECLARATIONS ///.
abctime timeTruth
Definition: cutInt.h:97
Vec_Int_t * vFanCounts
Definition: cutInt.h:52
Vec_Ptr_t * vCutsMax
Definition: cutInt.h:79
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
Definition: cutMan.c:229
Vec_Ptr_t * vTemp
Definition: cutInt.h:64
void Cut_ManStop(Cut_Man_t *p)
Definition: cutMan.c:124
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
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
static int Cut_TruthWords(int nVarsMax)
Definition: cutInt.h:125
int nTruthWords
Definition: cutInt.h:61
void Extra_MmFixedStop(Extra_MmFixed_t *p)
void Cut_ManPrintStatsToFile(Cut_Man_t *p, char *pFileName, abctime TimeTotal)
Definition: cutMan.c:204
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_NAMESPACE_HEADER_START typedef unsigned char uint8
Definition: extra.h:71
int nCutsDealloc
Definition: cutInt.h:86
Vec_Int_t * vNodeStarts
Definition: cutInt.h:76
#define CUT_SIZE_MAX
Definition: cut.h:39
Vec_Int_t * vNodeAttrs
Definition: cutInt.h:53
int nNodesNoCuts
Definition: cutInt.h:93
Cut_Params_t * Cut_ManReadParams(Cut_Man_t *p)
Definition: cutMan.c:277
struct Cut_CutStruct_t_ Cut_Cut_t
Definition: cut.h:50
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
abctime timeMerge
Definition: cutInt.h:95
Cut_Cut_t * pReady
Definition: cutInt.h:63
Extra_MmFixed_t * pMmCuts
Definition: cutInt.h:59
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition: cutMan.c:47
Vec_Int_t * vCutPairs
Definition: cutInt.h:77
Vec_Int_t * vDelays
Definition: cutInt.h:80
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
int nCutsAlloc
Definition: cutInt.h:85
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
abctime timeFilter
Definition: cutInt.h:98
Vec_Ptr_t * vCutsTemp
Definition: cutInt.h:57
Vec_Ptr_t * vCutsOld
Definition: cutInt.h:56
void Cut_ManPrintStats(Cut_Man_t *p)
Definition: cutMan.c:155
Vec_Int_t * Cut_ManReadNodeAttrs(Cut_Man_t *p)
Definition: cutMan.c:293
void Cut_CutRecycle(Cut_Man_t *p, Cut_Cut_t *pCut)
Definition: cutCut.c:72
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Cut_ManIncrementDagNodes(Cut_Man_t *p)
Definition: cutMan.c:309
Vec_Int_t * vDelays2
Definition: cutInt.h:81
int Cut_ManReadVarsMax(Cut_Man_t *p)
Definition: cutMan.c:261
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
abctime timeUnion
Definition: cutInt.h:96
Vec_Int_t * vNodeCuts
Definition: cutInt.h:75
Cut_Params_t * pParams
Definition: cutInt.h:51
#define assert(ex)
Definition: util_old.h:213
unsigned * puTemp[4]
Definition: cutInt.h:73
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
int nCutsFilter
Definition: cutInt.h:89
Vec_Ptr_t * vCutsNew
Definition: cutInt.h:55
abctime timeMap
Definition: cutInt.h:100
int nCutsLimit
Definition: cutInt.h:90
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Cut_ManSetNodeAttrs(Cut_Man_t *p, Vec_Int_t *vNodeAttrs)
Definition: cutMan.c:245