Docsity

Stimulus Generation for Constrained Random Simulation | EECS 578, Papers of Electrical and Electronics Engineering

Toggle sidebar
bg1
Stimulus Generation for Constrained Random Simulation
Nathan Kitchen1Andreas Kuehlmann1,2
1University of California at Berkeley, CA, USA
2Cadence Research Labs, Berkeley, CA, USA
Abstract
Constrained random simulation is the main workhorse in to-
day’s hardware verification flows. It requires the random genera-
tion of input stimuli that obey a set of declaratively specified input
constraints, which are then applied to validate given design prop-
erties by simulation. The efficiency of the overall flow depends crit-
ically on (1) the performance of the constraint solver and (2) the
distribution of the generated solutions. In this paper we discuss the
overall problem of efficient constraint solving for stimulus gener-
ation for mixed Boolean/integer variable domains and propose a
new hybrid solver based on Markov-chain Monte Carlo methods
with good performance and distribution.
1 Introduction
Many contemporary verification flows in industry have adopted
a combination of formal property checking and constrained ran-
dom testing. Most research in the area of functional verification
has focused on formal methods, and considerable theoretical and
practical progress has been made in this field in the past 15 years.
On the other hand, constrained random simulation has attracted
significantly less attention, despite its importance in practical ver-
ification flows due to limited scalability of formal methods. At
their core, both approaches require efficient constraint solving, but
formal verification typically seeks out a single solution, whereas
stimulus generation requires repeated generation of solutions with
a good distribution (e.g., uniform) over the solution space.
In constrained random verification (CRV), the testbench for the
design under test (DUT) includes (1) a generator of random stimuli,
(2) monitors that check the correctness of the behavior, and (3) cov-
erage analyzers for measuring which parts of the state space have
been verified. Figure 1 depicts the structure of a CRV testbench,
including these components.
Constraints (DUT)
under Test
Design
Coverage
Analyzer
Monitor
Biases
Generator
Stimulus
Testbench
Figure 1: Structure of a setup for constrained random verification.
In order to avoid generating invalid stimuli that might lead to
false negative verification results, the stimulus generator must obey
input constraints. For example, the implementation of a protocol
interface may only be correct for data packets with valid headers,
so the input constraints would exclude invalid headers. The con-
straints may be implicit in the generator code, or they may be given
explicitly as input to the generator.
Specific languages used in practice for specifying testbenches
include SystemC [1], SystemVerilog [2], and e[3]. An example of
constraints for an 8-bit ALU, written in S ystemVerilog, is shown in
Figure 2. The constraints specify input values such that the output
cis computed without overflow or divide-by-zero exceptions.
(a)
ALU c
op
b
a8
8
2
8
rand enum { ADD, SUB, MUL, DIV } op;
rand bit signed [7:0] a, b;
constraint valid {
op == ADD -> (-128 <= a + b && a + b <= 127);
op == SUB -> (-128 <= a - b && a - b <= 127);
op == MUL -> (-128 <= a *b && a *b <= 127);
op == DIV -> (b != 0);
}
(b)
Figure 2: An example DUT—an 8-bit ALU: (a) block diagram,
(b) constraints in SystemVerilog.
The distribution of the generated input vectors has a direct ef-
fect on the amount of time it takes to meet the coverage goals. In
order to achieve coverage as quickly as possible, the input distri-
bution should closely match the distribution of coverage points,
e.g. the firing conditions for the transitions in the state-transition
graph. In the absence of information about the distribution of cov-
erage points, the best choice for the input distribution is the one
with maximum entropy—i.e., the uniform distribution—so as to
maximize the level of “surprise” and thus the chance of entering
an unexplored region of the state space. When many of the cov-
erage points lie in the corners of the state space, it is better to use
a distribution with increased probability at the corners, such as a
piecewise-uniform distribution, which may be specified by the use
of biases on the input variables.
The efficiency of the constraint solver is as important as the
quality of the stimulus distribution. An inefficient solver impacts
the overall verification effort by long runtimes for stimulus gen-
eration, whereas a highly skewed distribution can dramatically in-
crease the number of simulation steps required to execute a tar-
get transition of the design. This dual challenge is particularly de-
manding as the search for a single solution is already NP-hard for
non-trivial Boolean constraints. Thus far little research has been
focused on this problem despite its high relevance to practical ver-
ification methods. The difficulty of the problem is reflected in the
limitations of state-of-the-art tools for CRV. Some tools generate
random values efficiently, but from highly non-uniform value dis-
tributions, resulting in increased time to achieve coverage. More-
over, the distributions are unstable—they vary significantly with
1-4244-1382-6/07/$25.00 ©2007 IEEE 258
pf3
pf4
pf5
pf8

Partial preview of the text

Download Stimulus Generation for Constrained Random Simulation | EECS 578 and more Papers Electrical and Electronics Engineering in PDF only on Docsity!

Stimulus Generation for Constrained Random Simulation

Nathan Kitchen^1 Andreas Kuehlmann^1 ,^2

1 University of California at Berkeley, CA, USA

2 Cadence Research Labs, Berkeley, CA, USA

Abstract

Constrained random simulation is the main workhorse in to- day’s hardware verification flows. It requires the random genera- tion of input stimuli that obey a set of declaratively specified input constraints, which are then applied to validate given design prop- erties by simulation. The efficiency of the overall flow depends crit- ically on (1) the performance of the constraint solver and (2) the distribution of the generated solutions. In this paper we discuss the overall problem of efficient constraint solving for stimulus gener- ation for mixed Boolean/integer variable domains and propose a new hybrid solver based on Markov-chain Monte Carlo methods with good performance and distribution.

1 Introduction

Many contemporary verification flows in industry have adopted a combination of formal property checking and constrained ran- dom testing. Most research in the area of functional verification has focused on formal methods, and considerable theoretical and practical progress has been made in this field in the past 15 years. On the other hand, constrained random simulation has attracted significantly less attention, despite its importance in practical ver- ification flows due to limited scalability of formal methods. At their core, both approaches require efficient constraint solving, but formal verification typically seeks out a single solution, whereas stimulus generation requires repeated generation of solutions with a good distribution (e.g., uniform) over the solution space. In constrained random verification (CRV), the testbench for the design under test ( DUT ) includes (1) a generator of random stimuli, (2) monitors that check the correctness of the behavior, and (3) cov- erage analyzers for measuring which parts of the state space have been verified. Figure 1 depicts the structure of a CRV testbench, including these components.

Constraints (DUT)

under Test

Design Coverage Analyzer

Monitor

Biases

Generator

Stimulus

Testbench

Figure 1: Structure of a setup for constrained random verification.

In order to avoid generating invalid stimuli that might lead to false negative verification results, the stimulus generator must obey input constraints. For example, the implementation of a protocol interface may only be correct for data packets with valid headers, so the input constraints would exclude invalid headers. The con- straints may be implicit in the generator code, or they may be given explicitly as input to the generator.

Specific languages used in practice for specifying testbenches include SystemC [1], SystemVerilog [2], and e [3]. An example of constraints for an 8-bit ALU, written in SystemVerilog, is shown in Figure 2. The constraints specify input values such that the output c is computed without overflow or divide-by-zero exceptions.

(a)

ALU c

op

b

a^8 8 2

8

rand enum { ADD, SUB, MUL, DIV } op; rand bit signed [7:0] a, b; constraint valid { op == ADD -> (-128 <= a + b && a + b <= 127); op == SUB -> (-128 <= a - b && a - b <= 127); op == MUL -> (-128 <= a (^) * b && a (^) * b <= 127); op == DIV -> (b != 0); } (b)

Figure 2: An example DUT—an 8-bit ALU: (a) block diagram, (b) constraints in SystemVerilog.

The distribution of the generated input vectors has a direct ef- fect on the amount of time it takes to meet the coverage goals. In order to achieve coverage as quickly as possible, the input distri- bution should closely match the distribution of coverage points, e.g. the firing conditions for the transitions in the state-transition graph. In the absence of information about the distribution of cov- erage points, the best choice for the input distribution is the one with maximum entropy—i.e., the uniform distribution—so as to maximize the level of “surprise” and thus the chance of entering an unexplored region of the state space. When many of the cov- erage points lie in the corners of the state space, it is better to use a distribution with increased probability at the corners, such as a piecewise-uniform distribution, which may be specified by the use of biases on the input variables. The efficiency of the constraint solver is as important as the quality of the stimulus distribution. An inefficient solver impacts the overall verification effort by long runtimes for stimulus gen- eration, whereas a highly skewed distribution can dramatically in- crease the number of simulation steps required to execute a tar- get transition of the design. This dual challenge is particularly de- manding as the search for a single solution is already NP-hard for non-trivial Boolean constraints. Thus far little research has been focused on this problem despite its high relevance to practical ver- ification methods. The difficulty of the problem is reflected in the limitations of state-of-the-art tools for CRV. Some tools generate random values efficiently, but from highly non-uniform value dis- tributions, resulting in increased time to achieve coverage. More- over, the distributions are unstable—they vary significantly with

1-4244-1382-6/07/$25.00 ©2007 IEEE 258

small changes in the specification, such as changes in variable dec- laration order. Other approaches generate values uniformly but rely on methods (e.g., binary decision diagrams) that do not scale well to large designs.

2 Related Work

In previous work, there are various methods proposed for gen- erating stimuli from a declarative description. In the following, we give a quick overview. Weighted Binary Decision Diagram (BDD) sampling was proposed in [4, 5]. The idea is to build a BDD from the input con- straints and to weight the branches of the vertices in such a way that a simple linear walk procedure from the root to the terminal vertex generates stimuli with a desired distribution [4, 5]. The weighted BDD approach is quite adequate to sample from control-dominated input constraints as long as they are not too complex. However, for integer constraints originating from arithmetic operations that have conflicting variable assignments, contain multiplications, or have complex select functions, the BDDs easily blow up and make this approach unusable. Section 5 provides a detailed analysis of a BDD-based sampler with the method proposed in this paper. Another BDD-based approach [6] involves building a circuit whose structure matches the constraint BDD. This method does not require the variables to be ordered, and so it may avoid the common memory blowups, but its output distribution may be highly skewed. Interval-propagation-based sampling is a technique that is used in multiple industrial applications such as [7]. It applies an iterative process where an interval of possible values is maintained for each variable. Each variable is successively assigned a ran- domly chosen value from its interval, and the intervals of the re- maining variables are subsequently refined. The advantage of the interval-propagation sampling algorithm is its simplicity and rel- atively high performance. However, the sampling distribution of this algorithm is highly non-uniform. This results in a non-optimal stimulus entropy which reduces the overall coverage in the ver- ification setup. To illustrate this problem, Figure 3 depicts the skewed sampling distribution for 505000 samples for an integer re- gion given by: y 1 + y 2 ≤ 101; y 1 , y 2 ≥ 1. Moreover, it can be shown that for an n -dimensional simplex of the form (^) ∑ ni = 1 yi ≤ c there is a gap between the expected number of samples for ( 0 , 0 ,... , 0 ) and any corner ( 0 ,... , c ,... , 0 ) that is exponential in n. DPLL-based sampling utilizes CNF-based DPLL-style SAT solvers [8, 9, 10] to generate stimuli from constraints. The advan- tage is their fairly good scalability for a large set of practical con- straints. A random pre-assignment of variables is used to attempt a good distribution for the generated samples. Starting from this ran- dom variable assignment, a DPLL-style search is then applied. At the first conflict, the solver goes into backtracking mode, effectively finding a smallest cube that contains both the pre-assignment and a solution. The problem with SAT-based methods is that, depend- ing on the constraints, the distribution can be highly non-uniform. Furthermore, their runtime can be slow, especially for constraints involving arithmetic. In Section 5 we report a detailed comparison of our proposed solver with a DPLL-style approach. Random-walk sampling for Boolean constraints was achieved in SAMPLESAT [11] by combining Metropolis sampling steps [12] with greedy steps from WALKSAT [13]. This method works well for small constraint sets, but due to the incomplete and greedy na- ture of the WALKSAT search its performance quickly deteriorates for larger constraint sets, especially for constraints that have been generated from data paths.

20 40 60 80 100

20

40

60

80

100

y 1

y^2

0 20 40 60 80 100

(^2000) 400600

(^1000800)

y 1

Expected #of samples

y 2 = 5

20 40 60 80 100

20

40

60

80

100

y 1

y^2

0 20 40 60 80 100

(^1000) 200300

400500

y 1

Expected #of samples

y 2 = 5 y 2 = (^80) y 2 = 50

y 2 = 90

(a) (b) Figure 3: Distribution of 505000 samples when using interval- propagation-based sampling for sampling y 1 + y 2 ≤ 101; y 1 , y 2 ≥ 1: (a) using fixed sampling order y 1 , y 2 , (b) using random sampling or- der. The lower parts show the expected number of samples for each y 1 for fixed values of y 2. The dashed lines indicate the expected values for uniform distribution.

Another line of research [14, 15] converts the constraints into belief networks and performs approximately uniform sampling based on estimating the size of the solution space. As reported in [15], the performance of this method does not match that achieved by SAMPLESAT, despite some improvements adopted from modern constraint solvers. Various specialized stimulus generators [16, 17] have been developed for specific verification domains utilizing particular do- main knowledge for constraint specification and solving. In this paper we first introduce a general normal form for con- straint specification, the Mixed Boolean/integer constraint normal form. We then present a constraint solver that utilizes multiple concepts from previous work for solving the Boolean domain and combines it with a new solver based on Markov-chain Monte Carlo (MCMC) methods [12, 18] for the integer domain. Specifically, we use the combination of Metropolis and WALKSAT steps suggested in SAMPLESAT for gaining a good distribution for the Boolean part but improve its performance by switching to a DPLL-style search for samples that “time out”. For the integer part we use a sam- pler that was inspired by the Gibbs method [19, 20] which provides excellent performance and a flexible control of the distribution. The presented stimulus generator offers a key component for contemporary random simulation methodologies but is also part of a larger line of research which attempts to combine formal methods with simulation [21, 22] and coverage-driven verification flows.

3 Constraint Specification In this section we discuss the specification of random stimuli. The presented approach is sufficiently expressive for many prac- tical applications, but also lends itself to efficient algorithms for approximately uniform sampling. Reflecting the typical applica- tion for hardware verification, we use a combination of Boolean variables and integer variables of bounded domain (i.e., of fixed bit-width) for the inputs of the DUT. As constraints we support a combination of Boolean constraints and restricted classes of in- equalities on the integers.

Boolean identity ( g ′( x ) ⇒ g ′′( y )) ⇔ (¬ g ′( x ) ∨ g ′′( y )). For the ALU example of Figure 2 the MBINF is as follows:

( x 1 ∨ x 2 ∨ [− y 1 − y 2 − 128 ≤ 0 ]) ∧ ( x 1 ∨ x 2 ∨ [ y 1 + y 2 − 127 ≤ 0 ]) ∧ ( x 1 ∨ ¬ x 2 ∨ [− y 1 + y 2 − 128 ≤ 0 ]) ∧ ( x 1 ∨ ¬ x 2 ∨ [ y 1 − y 2 − 127 ≤ 0 ]) ∧ (¬ x 1 ∨ x 2 ∨ [− y 1 y 2 − 128 ≤ 0 ]) ∧ (¬ x 1 ∨ x 2 ∨ [ y 1 y 2 − 127 ≤ 0 ]) ∧ (¬ x 1 ∨ ¬ x 2 ∨ [ y 2 ≤ − 1 ] ∨ [− y 2 ≤ − 1 ])

Note that this form is general and allows the expression of arbi- trary combination of constraints on the x and y variables within the expressiveness of the g ( x )( y ). For example, a clause may contain multiple inequality literals which supports the encoding of multiple y regions for particular x values as well as non-convex regions.

4 Sampling with Boolean and Integer Constraints

In the following we present an algorithm which generates for a given MBINF a set of valid solutions with approximately uniform distribution. We do not cover the handling of biases, i.e., how the sampling can be adjusted to obey user-specified densities for the x regions. However, the algorithms presented can be applied in a straightforward manner to obtain piecewise-uniform distributions. Our sampler includes ingredients from Markov-chain Monte Carlo (MCMC) methods (including Metropolis-Hastings [12, 18] and Gibbs sampling [19, 20]) and WALKSAT [13]. The Metropolis algorithm is widely used in the statistics and computational physics communities to generate samples from distributions that are dif- ficult to sample directly. In each iteration, it proposes a random change to the current assignment and accepts it with a probability that depends on the relative weights of the current and proposed assignments. In the limit, i.e., as the number of samples goes to infinity, the distribution converges to the desired distribution. Gibbs sampling [19, 20] is a special case of Metropolis sam- pling that can be applied when the conditional distribution of each variable can be computed. The sampler may move across the en- tire range of a variable in a single step, so it can travel through the sample space faster than other versions of the Metropolis algorithm that use only local moves. There are three main issues that need to be addressed for adapt- ing Gibbs sampling to stimulus generation:

  • Gibbs sampling works only for fully connected sampling re- gions, which is generally not the case for Boolean constraints and in the limit also not for integer constraints. For example, the region given by y 1 + y 2 = 100; 0 ≤ y 1 , y 2 ≤ 100 cannot be handled by Gibbs since a change of only y 1 or y 2 is not sufficient to move from one valid assignment to another. We address this by allowing invalid values with nonzero probabil- ity. As a result, some moves leave the valid sampling region. When such an excursion occurs, we use a fast search to get back to a legal assignment.
  • Related to the problem above, while sampling an MBINF, a change of a Boolean variable xk may cause a switch from one y region to another causing that the current y assignment be- comes illegal. We utilize the same search mechanism men- tioned above to get back to a legal y assignment.
  • Successive samples are highly correlated as they often differ in the assignment of a single variable only. To use them in

a verification flow, this correlation must be removed. We ap- ply a mixing queue which stores the generated samples in an array and draws randomly from it in each iteration. In our ex- periments we found that most of the correlation for practical verification constraints can be removed with a short queue.

4.1 Overview of MBINF Sampler

Our sampling algorithm uses the framework of the Metropolis- Hasting algorithm with the relaxed Gibbs step described in the pre- vious section. Each new sample ( x ′, y ′) is generated from the pre- vious sample ( x , y ) by the following main steps:

  1. Variable selection: Select uniformly at random a variable xk ∈ x or yk ∈ y.
  2. Metropolis move: Make a random change for the selected variable. For a Boolean variable the assignment for xk is flipped, i.e., x ′ k = ¬ xk ; for an integer variable a new assignment y ′ k is selected for yk with uniform probability from all valid ranges and ex- ponentially decaying probability from the ranges adjacent to them. Depending on the change in the number of satisfied clauses, the change is then accepted or not.
  3. Recovery move: If the new assignment ( x ′, y ′) is illegal, i.e., violates at least one constraint of the MBINF, then apply a recovery move to get back to a legal region. The recovery move is composed of a sequence of greedy and Metropolis steps. The greedy steps is a generalization of the WALKSAT step [13] by applying a generalized literal flip. Boolean literals are flipped in the usual manner, whereas flipping of an inequality literal involves the attempt to satisfy the corresponding constraint. We limit the number of generalized WALKSAT steps and utilize a DPLL- style search on the Boolean variable after that limit is reached. This allows to bound the time spend in the recovery phase without significantly impacting the sampling distribution.

We notice that for the recovery from an illegal assignment ( x , y ), we could attempt to directly solve the corresponding set of inequal- ities that are active for the given x assignment. However, the dis- crete nature of the problem can make such approach expensive and would further restrict the type of supported inequalities beyond the fairly weak limitation of “explicit resolvability” for the yk.

4.2 Metropolis Move

The Metropolis move selects an x or y variable at random, changes its assignment and then accepts the move with a proba- bility that is dependent on the change in the number of satisfied clauses Ci. Changing a Boolean variable xk is straightforward. For an integer variables yk the change is more complex, consisting of a Gibbs-style step to propose a new value. For given values ( x , y ) the new assignment for the selected yk is obtained by first project- ing the constraints { Ci } onto the current assignments x and y \ yk , leading to a general set of constraints { C i ′ } on yk of the form: ∧

i

∨

j

g ′ i j ( yk )

The { C i ′ } can be computed quickly by scanning through the clauses Ci , dropping the ones with at least one true Boolean lit- eral and collecting the inequality literals for the remaining ones. Following up on the introductory discussion of Section 3.1, for lin- ear and multilinear constraints, the g ′ i j ( yk ) can be analyzed quickly

by simply evaluating the precompiled inequalities resolved for yk. This converts the g ′ i j ( yk ) into a set of constraints yk ≤ c or yk ≥ c. We then compose a density function P ( yk ) that defines the proposal distribution of yk :

P ( yk ) ∝ min i

max j

Pi j ( yk ) (2)

The Pi j ( yk ) are computed for the inequalities of the form yk ≤ c ( yk ≥ c ) as follows:

Pi j ( yk ) =

1 if yk ≤ c ( yk ≥ c ) e −| c − yk^ |/ T^ otherwise (3)

where T is a parameter called the temperature. Figure 4 provides three illustrations of the computation of the proposal density. The purpose of the exponentially decaying dis- tribution for the invalid range is to address the shortcomings of the Gibbs sampler discussed earlier by allowing moves out of the legal regions. Specifically, the definition of the distribution for an empty valid range for yk (see Figure 4(b)) is chosen to heuristically mini- mize the effort to get back to a valid assignment after a flip of an xi changes the valid region for y. Figure 5 illustrates this case.

yk ≤ c 1 yk ≥ c 2

yk

(a)

P ( yk )

yk ≤ c 1 yk ≥ c 2 yk ≤ c 1 yk ≥ c 2

P ( yk ) (^) P ( y k )

yk yk (b) (c)

Figure 4: Example for distribution function computed by (2) and (3): (a) [ yk ≤ c 1 ] ∧ [ yk ≥ c 2 ] with c 1 > c 2 , (b) [ yk ≤ c 1 ] ∧ [ yk ≥ c 2 ] with c 1 < c 2 , and (c) [ yk ≤ c 1 ] ∨ [ yk ≥ c 2 ].

We sample from the distribution defined by P ( yk ) by separating the density function into uniform and exponential segments, select- ing a segment at random, and sampling a value within the segment. To select a segment, we compute the total weight w ( si ) of each segment si , then select segment s (^) j with probability w ( s (^) j )/ (^) ∑ i w ( si ). The sampling procedure is linear in the number of segments be- cause the weight of each segment and the sampling probabilities within segments can be expressed with closed-form expressions. One consequence of including exponential segments in the den- sity function is that the proposal distribution is not symmetric; i.e., if Q ( yk , y ′ k ) is the probability of proposing a move from yk to y ′ k , Q ( yk , y ′ k ) 6 = Q ( y ′ k , yk ) in general. In order to guarantee convergence to the right distribution with an asymmetric proposal distribution, it is necessary to use the Hastings extension of the Metropolis algo- rithm [18], in which the probability of accepting a move is weighted by the ratio of the proposal probabilities.

4.3 Core Sampling Algorithm

Algorithm 1 provides the pseudo-code for the top level of the presented sampling algorithm. It starts from a random assignment

( x ′, y ′) ( x , y )

( x ′′, y ′′)

x = 0

x = 1

y 2

y 1 Figure 5: Motivation for the sampling distribution illustrated in Figure 4(b): A switch of the y region through a change from x = 0 to x = 1 resulted in an empty valid range for y 1. The chosen dis- tribution enables a quick return to a valid region with few recovery moves (e.g. the two moves shown).

to x and y which may or may not satisfy the constraints { Ci }. It then fills the mixing queue by generating a sufficient number of samples using the SAMPLE procedure. Once the queue is warmed up, the sampler generates one sample per iteration and applies the mixing queue to shuffle them.

Algorithm 1 Mixed Boolean/integer sampler 1: {Given: clauses { Ci }; number of samples N ; length of mixing queue M ; parameter t ; decimation period K } 2: ( x , y ) := random assignment 3: for j := 1 to M do {warm up queue} 4: for k := 1 to t do 5: ( x , y ) := SAMPLE( x , y ) 6: QUEUE [ j ] := ( x , y ) 7: for j := 1 to N do {generate samples} 8: for k := 1 to K do {decimate sample stream} 9: ( x , y ) := SAMPLE( x , y ) 10: select r ∈ { 1 ,... , M } uniformly at random 11: ( x ′, y ′) := QUEUE [ r ] 12: QUEUE [ r ] := ( x , y ) 13: output ( x ′, y ′)

The pseudo-code for the individual sampling step is given in Al- gorithm 2. It starts with a METROPOLISMOVE. which generates, with a certain probability, a new assignment for ( x , y ). If the new assignment is not valid, the algorithm executes a recovery move by first performing a fixed number ( R ) of METROPOLISMOVES or WALKSATMOVES. If no valid solution is found during these moves, the algorithm finishes with a DPLLMOVE that searches for a valid x assignment. In Section 5 we demonstrate that for practi- cal constraints the number of steps necessary for recovery is typ- ically small, which validates the overall effectiveness of the pro- posed Metropolis-style sampling approach.

Algorithm 3 provides the details of the METROPOLISMOVE for mixed Boolean/integer constraints. It either flips a Boolean literal x (line 5), or it changes the assignment of a single variable yk using a GIBBS step (line 10). Depending on the impact on the number of satisfied clauses and the proposal probabilities, the step is then accepted (line 17) or rejected (line 19).

MBINF BDD Boolean CNF Test Bool int case vars vars cls lits mult vars nodes vars cls T1 2 2 11 26 2 34 * 2634 7855 T2 10 4 33 60 0 46 6073 330 961 T3 5 67 146 162 0 539 84530 6640 18347 I1 0 6 30 30 0 116 143848 879 2444 I2 1 9 28 34 6 127 * 29290 87684 I3 0 30 214 455 0 232 * 1080 2954 I4 0 213 497 514 0 244 565977 7428 21827

Table 1: Characteristics of benchmarks: Columns 2–6 describe the mixed Boolean/integer constraints in MBINF. Columns 7–8 de- scribe the BDDs for Boolean versions of the constraints (*=mem- ory blowup). Columns 9–10 describe the Boolean versions in CNF.

approach as well. This provides a major boost in terms of sampler efficiency.

5 Experimental Evaluation of Proposed Sampler

We implemented our sampling algorithm for Boolean and inte- ger variables with multilinear constraints in a random-value gen- erator called Ambigen (A mixed Boolean/integer generator). For comparison, we also implemented the BDD- and DPLL-based sam- pling algorithms described in Section 2. We selected these two approaches because of their complementary characteristics: The BDD-based method is fast and its distribution is uniform, while the DPLL-based method is more robust. In this section we compare the performance, robustness, and distribution of both methods with our algorithm. To compare the algorithms, we used each of them to generate solutions to several benchmark constraint sets. We derived a few of our benchmarks (T1–T3) from simple verification scenarios, such as the ALU in Figure 2, and extracted the others (I1–I4) from in- dustrial verification instances. For the BDD- and DPLL-based sam- plers, we converted the mixed Boolean/integer constraints to purely Boolean form by synthesizing circuits that evaluate the constraints. We used OpenAccess Gear [25] for synthesis. For the BDD sampler, we built BDDs for the output functions of the constraint evaluation circuits. In the variable order of each BDD, we put the control variables first and interleaved the bits of the data variables, with the least significant bits first. We used CUDD [26] as our BDD package. For the DPLL sampler, we converted the circuits, with their out- puts asserted, to Boolean CNF. To generate each sample, we se- lected an ordered pre-assignment at random and used its values at decision points. When the solver found a conflict, we allowed it to backtrack and find a solution using its usual decision heuristic. We used MiniSat [27] as our SAT solver. The characteristics of each version of the benchmarks are given in Table 1. For the benchmarks in MBINF, the table lists the num- bers of Boolean variables, integer variables, clauses, literals (both Boolean and integer inequalities), and multiplicative (i.e., nonlin- ear) inequalities. For the constraint BDDs, the table lists the num- ber of variables and the number of nodes. Each entry with a * indi- cates that the BDD could not be built with a memory limit of 1 GB. For the constraints in Boolean CNF, the table lists the numbers of variables and clauses. We used each sampling algorithm to generate 1 million solu- tions for each benchmark, with a time limit of 10000 seconds. The results of these experiments are shown in Table 2. For Ambigen, the table lists the runtime, the number of unique solutions, and the number of moves per solution (both Metropolis and WALKSAT- style). For the BDD-based sampler, the table lists the total runtime

Ambigen BDD-based DPLL-based Avg Test Time #moves/ Time Build Time Case (sec) #uniq solution (sec) time (sec) #samples T1 35 975627 1.11 * * 2091 1000000 T2 49 858590 1.56 41 < 1 423 1000000 T3 193 999986 1.05 382 70 10000 16845 I1 112 992391 1.40 111 1 4409 1000000 I2 59 999995 1.00 * * 10000 252495 I3 179 999979 1.19 * * 10000 854484 I4 586 920922 1.58 453 20 10000 726645 Table 2: Results of generating N = 1000000 solutions to constraints with a time limit of 10,000 sec and a memory limit of 1 GB. The parameters for Ambigen are M = 1, t = 1, K = 5, R = ∞, p , q = 0 .5, T = 1.

and the time needed to build the BDD. Entries with *’s in columns 5 and 6 indicate that no solutions were generated because of memory blowup. For the DPLL-based sampler, the table lists the runtime and the total number of samples generated. The number of unique samples for the BDD- and DPLL-based samplers is not reported because almost all the solutions generated were unique; there were duplicate solutions in only three cases, and at most 100 duplicates in each of these. A comparison of the runtimes shows that Ambigen has similar performance to the BDD-based sampler, and that both of these are faster than the DPLL-based algorithm by 1–3 orders of magnitude. However, Ambigen is more robust than the BDD-based algorithm, because it does not suffer from memory blowup. Note that the memory blowup is not limited to benchmarks with multiplicative constraints. In preliminary experiments, we found this was true even for other variable orders. Column 4 of Table 2 lists the average number of moves per so- lution. We computed this value as the ratio of the total number of moves to the total number of solutions, including those that were decimated (thus the denominator is K × 106 ). This value is an im- portant measure of Ambigen’s ability to move through the solution space. For each benchmark, the number of moves per solution is close to 1 (at most 1.58), indicating that the sampler is most often able to find a legal solution in the initial Metropolis move; recovery moves are usually not needed. The experiments described above are not well suited for com- paring the sampling distributions of the algorithms. Each of the benchmarks has a solution space many orders of magnitude larger than the number of samples, so each solution could not be expected to occur more than once in a uniformly generated set of samples. Ambigen’s distribution seems be skewed because it generates some duplicates. However, some duplication should be expected, given the local-walk nature of the algorithm. This does not contradict the theory on the convergence to the uniform distribution, since the time for convergence can be very long for a large sample space. Decimation is one of the easiest ways to reduce the number of duplicate samples, i.e, reporting only every K th sample. To inves- tigate the effect of decimation, we increased K from 1 to 10 for the benchmark T2, which had the least unique samples in Table 2. The results are shown in Figure 6. Increasing K from 1 to 5 raises the percentage of unique samples from 32% to 81%, while the run- time increases by 1.5x. Continued increases of K bring diminishing returns—increasing K to 9 yields an additional 9% unique samples at the cost of 2x the original runtime. Given appropriate choices for the parameters and enough time to converge, the output distribution of our algorithm can be brought arbitrarily close to uniformity. In general, this is not the case for the DPLL-based algorithm. If the number of solutions is not a power

0%

20%

40%

60%

80%

100%

1 2 3 4 5 6 7 8 9 10

% unique solutions

Decimation period (K)

Percentage of unique solutions generated for T2 by Ambigen

(32 sec)

(40 sec)

(49 sec)

(56 sec) (63 sec)

Figure 6: Percentage of unique solutions generated for test case T2 by Ambigen and selected runtimes.

0

200

400

600

800

1000

1200

0 500 1000 1500 2000

Frequency

Solution # (sorted by frequency from DPLL)

Solution Frequencies for 6-bit Sum Constraint

Ambigen

DPLL

Figure 7: Frequencies of samples from 2-dimensional simplex for Ambigen and DPLL-based sampler.

of 2, the backtracking style of DPLL cannot map the full Boolean space—from which the pre-assignments are uniformly selected— into the solution space in a uniform manner. Depending on the par- ticular constraints, the mapping may not even be close to uniform. For example, we generated solutions to a small set of constraints similar to the example in Figure 3. The resulting distributions of sample frequencies for Ambigen and the DPLL-based sampler is shown in Figure 7.

6 Conclusions

We proposed a normal form, MBINF, for specifying constraints on Boolean and integer variables. It is a generalization of Boolean CNF with integer inequalities as generalized literals. The con- straint formulation is expressive enough to cover many practical verification needs and also lends itself to efficient algorithms for sampling. We proposed a new sampling algorithm that combines concepts from the Metropolis-Hastings algorithm, Gibbs sampling, and WALKSAT to efficiently generate solutions to the constraints with an approximately uniform distribution. Our algorithm is sig- nificantly faster than a sampler based on Boolean DPLL and sub- stantially more robust than BDD-based sampling. Future work will include adding feedback from coverage analysis to dynamically bias input distributions.

References [1] T. Gr¨otker, S. Liao, G. Martin, and S. Swan, System Design with SystemC. Boston: Kluwer Academic, 2002. [2] S. Sutherland, S. Davidmann, and P. Flake, SystemVerilog for Design: A guide to using SystemVerilog for hardware design and modeling. Norwell, MA, USA: Kluwer Academic, 2003.

[3] S. Iman and S. Joshi, The e Hardware Verification Language. Norwell, MA, USA: Kluwer Academic, 2004. [4] J. Yuan, K. Shultz, C. Pixley, H. Miller, and A. Aziz, “Modeling design constraints and biasing in simulation using BDDs,” in Digest Tech. Papers IEEE/ACM Int’l Conf. Computer-Aided Design , pp. 584–589, Nov. 1999. [5] J. Yuan, A. Aziz, C. Pixley, and K. Albin, “Simplifying Boolean constraint solv- ing for random simulation-vector generation,” IEEE Trans. Computer-Aided De- sign of Integrated Circuits and Systems , vol. 23, pp. 412–420, Mar. 2004. [6] J. H. Kukula and T. R. Shiple, “Building circuits from relations,” in Proc. 12th Int’l Conf. Computer-Aided Verif. (CAV) , pp. 113–123, Springer-Verlag, 2000. [7] M. A. Iyer, “RACE: A word-level ATPG-based constraints solver system for smart random simulation,” in IEEE International Test Conference (ITC) , (Char- lotte, NC, United States), pp. 299–308, Sept. 2003. [8] M. Davis and H. Putnam, “A computing procedure for quantification theory,” J. ACM , vol. 7, pp. 201–215, 1960. [9] M. Davis, G. Logemann, and D. Loveland, “A machine program for theorem proving,” Comms. ACM , vol. 5, pp. 394–397, July 1962. [10] M. W. Moskewicz, C. F. Madigan, Y. Zhao, L. Zhang, and S. Malik, “Chaff: En- gineering an efficient SAT solver,” in Proc. 38th ACM/IEEE Design Automation Conf. , pp. 530–535, June 2001. [11] W. Wei, J. Erenrich, and B. Selman, “Towards efficient sampling: Exploiting random walk strategies,” in Proc. Nat’l Conf. Artificial Intelligence , pp. 670– 676, Jul. 2004. [12] N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller, and E. Teller, “Equations of state calculations by fast computing machines,” J. Chem. Phys. , vol. 21, pp. 1087–1092, June 1953. [13] B. Selman, H. A. Kautz, and B. Cohen, “Local search strategies for satisfiability testing,” in Proc. 2nd DIMACS Challenge on Cliques, Coloring, and Satisfiabil- ity (M. Trick and D. S. Johnson, eds.), (Providence RI), 1993. [14] R. Dechter, K. Kask, E. Bin, and R. Emek, “Generating random solutions for constraint satisfaction problems,” in 18th Nat’l Conf. Artificial Intelligence (AAAI02) , pp. 15–21, July 2002. [15] V. Gogate and R. Dechter, “A new algorithm for sampling CSP solutions uni- formly at random,” tech. rep., School of Information and Computer Science, University of California, Irvine, May 2006. [16] A. Chandra, V. Iyengar, D. Jameson, R. Jawalekar, I. Nair, B. Rosen, M. Mullen, J. Yoon, R. Armoni, D. Geist, and Y. Wolfsthal, “AVPGEN— a test generator for architectural verification,” IEEE Trans. Very Large Scale Integration , vol. 3, no. 2, pp. 188–200, 1995. [17] K. Shimizu and D. L. Dill, “Deriving a simulation input generator and a cover- age metric from a formal specification,” in Proc. 39th Design Automation Conf. , (New Orleans, LA, United States), pp. 801–806, Jun 2002. [18] W. K. Hastings, “Monte Carlo sampling methods using Markov chains and their applications,” Biometrika , vol. 57, pp. 97–109, 1970. [19] S. Geman and D. Geman, “Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images,” IEEE Trans. Pattern Analysis and Machine In- telligence , vol. 6, pp. 721–741, Nov. 1984. [20] A. E. Gelfand and A. F. M. Smith, “Sampling-based approaches to calculating marginal densities,” J. Amer. Statist. Assoc. , vol. 85, no. 410, pp. 398–409, 1990. [21] P.-H. Ho, T. Shiple, K. Harer, J. Kukula, R. Damiano, V. Bertacco, J. Taylor, and J. Long, “Smart simulation using collaborative formal and simulation engines,” in Digest Tech. Papers IEEE/ACM Int’l Conf. Computer-Aided Design , pp. 120– 126, Nov. 2000. [22] S. Shyam and V. Bertacco, “Distance-guided hybrid verification with GUIDO,” in Design Automation and Test in Europe , Mar. 2006. [23] R. E. Bryant, “Graph-based algorithms for Boolean function manipulation,” IEEE Trans. Computers , vol. 35, pp. 677–691, Aug. 1986. [24] “Property specification language, reference manual, version 1.1,” Accellera Or- ganization, June 2004. [25] Z. Xiu, D. A. Papa, P. Chong, C. Albrecht, A. Kuehlmann, R. A. Rutenbar, and I. L. Markov, “Early research experience with OpenAccess Gear: An open source development environment for physical design,” in Proc. ACM Int’l Symp. Phys. Design (ISPD) , pp. 94–100, Apr. 2005. [26] F. Somenzi, CUDD: CU Decision Diagram Package, Release 2.4.0. University of Colorado at Boulder, 2005. [27] N. E´en and N. S¨orensson, “An extensible SAT-solver,” in Proc. 6th Int’l Conf. Theory & Appl. Satisfiability Testing (SAT) , pp. 502–518, May 2003.