source: vis_dev/vis-2.3/src/amc/amcCmd.c @ 57

Last change on this file since 57 was 14, checked in by cecile, 13 years ago

vis2.3

File size: 19.0 KB
RevLine 
[14]1/**CFile***********************************************************************
2
3  FileName    [amcCmd.c]
4
5  PackageName [amc]
6
7  Synopsis    [Command interface for the amc package.]
8
9  Author      [Woohyuk Lee <woohyuk@duke.colorado.edu>]
10
11  Copyright [This file was created at the University of Colorado at Boulder.
12  The University of Colorado at Boulder makes no warranty about the suitability
13  of this software for any purpose.  It is presented on an AS IS basis.]
14
15******************************************************************************/
16
17#include "amcInt.h"
18
19static char rcsid[] UNUSED = "$Id: amcCmd.c,v 1.44 2005/05/19 02:36:36 awedh Exp $";
20
21
22/*---------------------------------------------------------------------------*/
23/* Constant declarations                                                     */
24/*---------------------------------------------------------------------------*/
25
26/*---------------------------------------------------------------------------*/
27/* Structure declarations                                                    */
28/*---------------------------------------------------------------------------*/
29
30/*---------------------------------------------------------------------------*/
31/* Type declarations                                                         */
32/*---------------------------------------------------------------------------*/
33
34/*---------------------------------------------------------------------------*/
35/* Variable declarations                                                     */
36/*---------------------------------------------------------------------------*/
37
38static jmp_buf timeOutEnv;
39
40/*---------------------------------------------------------------------------*/
41/* Macro declarations                                                        */
42/*---------------------------------------------------------------------------*/
43
44/**AutomaticStart*************************************************************/
45
46/*---------------------------------------------------------------------------*/
47/* Static function prototypes                                                */
48/*---------------------------------------------------------------------------*/
49
50static int CommandAmc(Hrc_Manager_t ** hmgr, int argc, char ** argv);
51static void ApproximateModelCheckUsage(void);
52static void TimeOutHandle(void);
53
54/**AutomaticEnd***************************************************************/
55
56
57/*---------------------------------------------------------------------------*/
58/* Definition of exported functions                                          */
59/*---------------------------------------------------------------------------*/
60
61/**Function********************************************************************
62
63  Synopsis    [Initializes the amc package.]
64
65  SideEffects []
66
67  SeeAlso     [Amc_End]
68
69******************************************************************************/
70void
71Amc_Init(void)
72{
73  Cmd_CommandAdd("approximate_model_check", CommandAmc, 0);
74/*  Cmd_CommandAdd("approximate_compute_reach", CommandApproxReach, 0); */
75}
76
77
78/**Function********************************************************************
79
80  Synopsis    [Ends the amc package.]
81
82  SideEffects []
83
84  SeeAlso     [Amc_Init]
85
86******************************************************************************/
87void
88Amc_End(void)
89{
90}
91
92
93/*---------------------------------------------------------------------------*/
94/* Definition of internal functions                                          */
95/*---------------------------------------------------------------------------*/
96
97
98/*---------------------------------------------------------------------------*/
99/* Definition of static functions                                            */
100/*---------------------------------------------------------------------------*/
101
102/**Function********************************************************************
103
104  Synopsis         [The approximate_model_check command.]
105
106  CommandName      [approximate_model_check]
107
108  CommandSynopsis  [perform ACTL model checking on an abstracted
109                   and flattened network]
110
111  CommandArguments [\[-h\] \[-v &lt;verbosity_level&gt;\] &lt;ctl_file&gt; ]
112 
113  CommandDescription [Performs ACTL model checking on an abstracted and
114  flattened network.  Predefined abstractions are performed prior to model
115  checking.  Before calling this command, the user should have initialized the
116  design by calling the command <a href="init_verifyCmd.html"> <code>
117  init_verify</code></a>.  <p>
118   
119  The command includes two dual algorithms. The user should set appropriate
120  environment parameters associated with the command to execute proper
121  algorithm.  By default, the command makes its effort to prove whether given
122  ACTL formula is positive. To check whether the ACTL formula is negative, user
123  should set the environment parameter <b>amc_prove_false</b> prior to
124  executing the command.  See <a href="#environment">below</a> for the
125  environment parameters associated with this command.  <p>
126
127  Properties to be verified should be provided as ACTL formulas in the file
128  <code>&lt;ctl_file&gt;</code>. The command only accepts ACTL formulas.
129  Mixed, ECTL expressions are not supported. 
130  ACTL formulas are those in which all quantifiers are universal and
131  negation is only allowed at the level of atomic propositions.
132  For the precise syntax of CTL formulas, see the <a href="../ctl/ctl/ctl.html">
133  VIS CTL and LTL syntax manual</a>.<p>
134
135  The command is designed to tackle the state explosion problem we encounter
136  when dealing with large and complex circuits. Based on the initial size of
137  the group, the command constructs over- or under-approximation of the
138  transition relation of the system. A group (subsystem) is a portion of
139  the original circuit containing a subset of the latches and
140  their next state functions.  The initial size of a group can be set with
141  the <a href="#sizeofgroup">amc_sizeof_group</a> environment variable.
142  These initial approximations may not contain every detail of the exact
143  system. However they may contain enough information to
144  determine whether the formula is positive or negative.  Starting from an
145  initial coarse approximation, the command makes its effort to prove whether
146  given ACTL formula is positive or negative. When the procedure fails to prove
147  correctness of the formula with initial approximations, it automatically
148  refines the approximations. It repeats the process until the algorithm
149  produces a reliable result or the available resources are exhausted.<p>
150
151  Due to the overhead procedures, for some circuits, the exact <a
152  href="model_checkCmd.html"><code>model_check</code> </a> method may evaluate
153  formulas faster with less resources.  If any formula evaluates to
154  <em>false</em>, a debug trace is reported.<p>
155
156  The command does not use fairness constraints even if they have been read
157  with the <a href="read_fairnessCmd.html"><code>read_fairness</code></a>
158  command. <p>
159
160   
161   <b>Command options: </b>
162   <p>
163
164   <dl>
165   
166   <dt><code> -h </code>
167   <dd> Print the command usage.
168
169   <p>
170         
171   <dt><code> -v  &lt;verbosity_level&gt; </code>
172   <dd> Specify verbosity level. <code> verbosity_level</code> must be one of
173   the following:
174   <p>
175
176         <code> 0 </code> : No feedback provided. This is the default. <br>
177         <code> 1 </code> : Some feedback. <br>
178         <code> 2 </code> : Lots of feedback.
179         <p>
180
181   <dt> -t  <code>&lt;timeOutPeriod&gt;</code>
182   <dd> Specify the time out period (in seconds) after which the command
183   aborts. By default this option is set to infinity.
184   <p>
185         
186   <dt> <code> &lt;ctl_file&gt; </code>
187   <dd> File containing ACTL formulas to be model checked.
188   <p>
189
190   </dl>
191
192   <b><A NAME="environment">Environment Parameters:</A></b>
193   <p>
194
195        Environment parameters should be set using the set command
196        from the VIS shell <br>
197        (e.g. <code>vis\> set amc_prove_false</code>).
198
199   <p>
200
201   <dl>
202
203   <dt> <b><code> amc_prove_false  </code></b>
204   <br>
205        When the parameter is set, the command makes its effort to prove
206        whether given ACTL formula is negative. The command constructs a set of
207        under-approximations of the transition relations of the system. When
208        the formula evaluates to <em>false</em>, a debug trace is reported by
209        default.  <p>
210
211   <dt> <b><code> amc_grouping_method &lt;grouping method&gt; </code></b>
212   <br>
213        Specifies grouping method. Grouping method is a method for grouping
214        number of latches into single subsystem. Two methods are supported.
215   <p>
216        <dd> <b>Grouping based on hierarchy<code>(default)</code></b> : The
217             method groups latches based on the hierarchy of the system.
218             Normally, complex circuits are designed in multiple
219             processes. Furthermore, processes form a hierarchy.  The method
220             uses this information provided by the original design.  When a
221             design described in high level description language is transformed
222             into low level BLIF format, the processes are transformed into
223             subcircuits. The method groups those latches that are within same
224             subcircuit.<p>
225
226        <dd> <b>Grouping based on latch dependencies(latch_dependency)</b>: The
227             method groups those latches
228             that are closely related. Closely related latches are those who has
229             many (transitive) connections between them.
230   <p>
231
232        When the parameter is not specified, the command by default uses
233        hierarchical grouping method.
234   <p>
235
236   <dt> <b><A NAME="sizeofgroup"><code> amc_sizeof_group &lt;integer value&gt; </code></A></b>
237   <br>
238        Determines the number of latches in each group(subsystem). The default
239        value is 8. The initial size of the subsystem determines the initial
240        degree of approximations of the transition relations. There's no proven
241        rule of setting the value. Some experimental results show that setting
242        the value to about 5-20% of overall number of latches is
243        reasonable(e.g.  if the system contains 100 latches set the value to
244        5-20).  However, the suggested range may not work well with some
245        examples.  <p>
246       
247   <dt> <b><code> amc_DC_level &lt;integer value&gt; </code></b>
248   <br>
249        Specifies don't care levels. Default level is 0. Absence of the
250        parameter sets the amc_DC_level to 0.
251   <br>
252          amc_DC_level must be one of the following:<p>
253     <dl>
254          <dt><code>0</code>: No don't cares are used. This is the default.<br>
255          <dt><code>1</code>: Use unreachable states as don't cares. <br>
256          <dt><code>2</code>: Aggressively use DC's to simplify MDD's in model
257          checking. <br>
258     </dl>
259   <p>
260
261        Using don't cares may take more time for some examples since the
262        approximate model checker computes the reachable states for each
263        subsystem. For some large circuits it is undesirable to set don't care
264        level.  <p>
265
266  <dt> Related "set" options: <p>
267  <dt> ctl_change_bracket &lt;yes/no&gt;
268  <dd> Vl2mv automatically converts "\[\]" to "&lt;&gt;" in node names,
269  therefore CTL parser does the same thing. However, in some cases a user
270  does not want to change node names in CTL parsing. Then, use this set
271  option by giving "no". Default is "yes".
272  <p>
273
274  <dt> See also commands : model_check, incremental_ctl_verification <p>
275
276  </dl>
277
278   <b>Examples:</b> <br>
279   Here are some example sequences of the VIS executions using the approximate
280   model checker.<br>
281   <p>
282
283   <code>
284        read_blif_mv abp/abp.mv <br>
285        flatten_hierarchy <br>
286        static_order <br>
287        build_partition_mdds <br>
288        set amc_sizeof_group 4 <br>
289        approximate_model_check abp/abpt.ctl <br>
290        time <br>
291        quit <br>
292  <p>
293
294        read_blif_mv coherence/coherence.mv <br>
295        flatten_hierarchy <br>
296        static_order <br>
297        build_partition_mdds <br>
298        set amc_sizeof_group 8 <br>
299        set amc_prove_false <br>
300        set amc_DC_level 0 <br>
301        approximate_model_check coherence/coherence2.ctl <br>
302        time <br>
303        quit <br>
304  <p>
305
306
307  The algorithm used by approximate_model_check is described in detail in
308  <a href="ftp://vlsi.colorado.edu/pub/iccad96.ps">
309  ftp://vlsi.colorado.edu/pub/iccad96.ps</a>
310  ]
311
312
313  SideEffects []
314
315******************************************************************************/
316static int
317CommandAmc(
318  Hrc_Manager_t ** hmgr,
319  int  argc,
320  char ** argv)
321{
322  static int            timeOutPeriod;    /* CPU seconds allowed */
323  char                  *ctlFileName;     /* Name of file containing formulas */
324  FILE                  *ctlFile;         /* File to read the formulas from */
325  Ntk_Network_t         *network;         /* Pointer to the current network */
326  array_t               *ctlFormulaArray; /* Array of read ctl formulas */
327  array_t               *ctlNormalForm;   /* Array of normal ctl formulas */
328  Ctlp_Formula_t        *currentFormula;  /* Formula being verified */
329  int                   c, i;
330  Amc_VerbosityLevel    verbosity;        /* Verbosity level */
331
332  long initialTime;
333  long finalTime;
334
335
336  /* Initialize Default Values */
337  timeOutPeriod   = 0;
338  ctlFileName     = NIL(char);
339  verbosity       = Amc_VerbosityNone_c;
340
341  /*
342   * Parse command line options.
343   */
344  util_getopt_reset();
345  while ((c = util_getopt(argc, argv, "ht:v:")) != EOF) {
346    switch(c) {
347      case 'h':
348        ApproximateModelCheckUsage();
349        return 1;
350      case 't':
351        timeOutPeriod = atoi(util_optarg);
352        break;
353      case 'v':
354        verbosity = (Amc_VerbosityLevel) atoi(util_optarg);
355        break;
356      default:
357        ApproximateModelCheckUsage();
358        return 1;
359    }
360  }
361
362  /* Make sure the CTL file has been provided */
363  if (argc == util_optind) {
364    ApproximateModelCheckUsage();
365    return 1;
366  }
367  else {
368    ctlFileName = argv[util_optind];
369  }
370
371  /*
372   * Obtain the network from the hierarchy manager
373   */
374  network = Ntk_HrcManagerReadCurrentNetwork(*hmgr);
375  if (network == NIL(Ntk_Network_t)) {
376    return 1;
377  }
378  /*
379   * Check whether the fairness was read.
380   */
381  {
382    Fsm_Fsm_t      *exactFsm = Fsm_NetworkReadOrCreateFsm(network);
383    Fsm_Fairness_t *fairCons =  Fsm_FsmReadFairnessConstraint(exactFsm);
384    int numOfDisjuncts = Fsm_FairnessReadNumDisjuncts(fairCons);
385    if (numOfDisjuncts > 1) {
386      /* non-Buchi */
387      fprintf(vis_stdout, "** amc warning: Fairness Constraint is not supported.\n");
388    }
389    else {
390      int numOfConj     = Fsm_FairnessReadNumConjunctsOfDisjunct(fairCons, 0);
391      if (numOfConj > 1) {
392        /* Buchi */
393        fprintf(vis_stdout, "** amc warning: Fairness Constraint is not supported.\n");
394      }
395    }
396  } 
397
398  /*
399   * Read in the array of CTL formulas provided in ctlFileName
400   */
401  ctlFile = Cmd_FileOpen(ctlFileName, "r", NIL(char *), 0);
402  if (ctlFile == NIL(FILE)) {
403    return 1;
404  }
405  ctlFormulaArray = Ctlp_FileParseFormulaArray(ctlFile);
406  fclose(ctlFile);
407
408  if (ctlFormulaArray == NIL(array_t)) {
409    (void) fprintf(vis_stderr, "** amc error: Error while parsing ctl formulas in file.\n");
410    return 1;
411  } 
412
413  ctlNormalForm = Ctlp_FormulaArrayConvertToExistentialFormTree(ctlFormulaArray);
414
415  /*
416   * Start the timer.
417   */
418  if (timeOutPeriod > 0) {
419    (void) signal(SIGALRM, (void (*)(int))TimeOutHandle);
420    (void) alarm(timeOutPeriod);
421
422    /* The second time setjmp is called, it returns here !!*/
423    if (setjmp(timeOutEnv) > 0) {
424      (void) fprintf(vis_stdout, "# AMC: timeout ocurred after %d seconds.\n",
425                     timeOutPeriod);
426      alarm(0);
427
428      /* Note that there is a huge memory leak here. */
429      Ctlp_FormulaArrayFree(ctlFormulaArray);
430      Ctlp_FormulaArrayFree(ctlNormalForm);
431      return 1;
432    } 
433  }
434
435
436  /*
437   * Loop over every CTL formula in the array
438   */
439  arrayForEachItem(Ctlp_Formula_t *, ctlNormalForm, i, currentFormula) {
440    boolean validFormula;
441
442    validFormula = FormulaTestIsForallQuantifier(currentFormula); 
443    if (!validFormula) {
444      fprintf(vis_stderr, "Formula ");
445      Ctlp_FormulaPrint(vis_stderr, currentFormula);
446      fprintf(vis_stderr, " is not a valid ACTL formula. Skipping it\n");
447    }
448    else if (!Mc_FormulaStaticSemanticCheckOnNetwork(currentFormula, network,
449                                                     FALSE)) {
450      (void) fprintf(vis_stdout, "\n** amc error: Error in parsing Atomic Formula:\n%s\n", error_string());
451      error_init();
452      Ctlp_FormulaFree( currentFormula );
453      continue;
454    }
455    else {
456      error_init();
457      initialTime = util_cpu_time();
458      Amc_AmcEvaluateFormula(network, currentFormula, verbosity);
459      finalTime = util_cpu_time();
460      if(verbosity == Amc_VerbosityVomit_c) {
461        (void) fprintf(vis_stdout, "\n%-20s%10ld\n", "analysis time =",
462                       (finalTime - initialTime) / 1000);
463      }
464      fprintf(vis_stdout, "\n");
465    }
466
467  } /* End of arrayForEachItem in ctlFormulaArray */
468
469
470
471  /* Deactivate the alarm */
472  alarm(0);
473
474
475  /* Clean up */
476  Ctlp_FormulaArrayFree(ctlFormulaArray);
477  Ctlp_FormulaArrayFree(ctlNormalForm);
478  error_cleanup();
479
480
481  /* normal exit */
482  return 0;
483}
484
485/**Function********************************************************************
486
487  Synopsis [Prints the usage of the approximate_model_checking command.]
488
489  SideEffects        []
490
491  SeeAlso            [CommandAmc]
492
493******************************************************************************/
494static void
495ApproximateModelCheckUsage(void)
496{
497  (void) fprintf(vis_stderr, "usage: approximate_model_check [-h] ");
498  (void) fprintf(vis_stderr, "[-t secs] [-v] ctlfile\n");
499  (void) fprintf(vis_stderr, "   -h        print the command usage\n");
500  (void) fprintf(vis_stderr, "   -t secs   Seconds allowed for computation\n");
501  (void) fprintf(vis_stderr, "   -v number verbosity level\n");
502  (void) fprintf(vis_stderr, "   ctlfile   File containing the ctl formulas\n");
503
504  return;
505} /* End of ApproximateModelCheckUsage */
506
507
508
509/**Function********************************************************************
510
511  Synopsis           [Tests recursively if a formula is a valid ACTL formula.]
512
513  Description [This function implements the recursive steps needed for the
514  function FormulaTestIsForallQuantifier.]
515
516  SideEffects        []
517
518  SeeAlso            [CommandAmc]
519
520******************************************************************************/
521boolean
522FormulaTestIsForallQuantifier(
523  Ctlp_Formula_t *formula)
524{
525  Ctlp_Formula_t    *newFormula;
526  boolean           converted; 
527  Ctlp_FormulaClass result;
528
529  if (!Ctlp_FormulaTestIsConverted(formula)) {
530    newFormula = Ctlp_FormulaConvertToExistentialForm(formula);
531    converted = TRUE;
532  }
533  else {
534    newFormula = formula;
535    converted = FALSE;
536  }
537
538  result = Ctlp_CheckClassOfExistentialFormula(newFormula);
539
540  if (converted) {
541    Ctlp_FormulaFree(newFormula);
542  } /* End of if */
543
544  return result == Ctlp_ACTL_c || result == Ctlp_QuantifierFree_c;
545
546} /* End of FormulaTestIsForallQuantifier */
547
548
549/**Function********************************************************************
550
551  Synopsis           [Handle the timeout signal.]
552
553  Description [This function is called when the time out occurs. In principle
554  it could do something smarter, but so far it just transfers control to the
555  point in the code where setjmp was called.]
556
557  SideEffects [This function gains control at any point in the middle of the
558  computation, therefore the memory allocated so far leaks.]
559
560******************************************************************************/
561static void
562TimeOutHandle(void)
563{
564  longjmp(timeOutEnv, 1);
565} /* End of TimeOutHandle */
Note: See TracBrowser for help on using the repository browser.