FLOLAC 20151 Boolean Satisfiability and Synthesis Applications Jie-Hong Roland Jiang 江介宏...

140
FLOLAC 2015 1 Boolean Satisfiability and Synthesis Applications Jie-Hong Roland Jiang 江江江 Department of Electrical Engineering National Taiwan University

Transcript of FLOLAC 20151 Boolean Satisfiability and Synthesis Applications Jie-Hong Roland Jiang 江介宏...

  • FLOLAC 2015*Boolean Satisfiability and Synthesis Applications

    Jie-Hong Roland Jiang

    Department of Electrical EngineeringNational Taiwan University

    FLOLAC 2015

  • FLOLAC 2015*OutlineLogic synthesisBoolean function representationPropositional satisfiability & logic synthesisFunctional dependencyDecoder synthesisQuantified satisfiability & logic synthesisBoolean matchingBoolean relation determinization

    FLOLAC 2015

  • FLOLAC 2015*IC Design FlowHDL spec.logic synthesislogic netlistcircuit netlistlayout /maskchipRTL synthesisphysical designfab.

    FLOLAC 2015

  • FLOLAC 2015*Logic SynthesisLogic SynthesisBoolean Function ExpressionOptimized Logic NetlistBoolean/Temporal ConstraintsSolution Circuit

    FLOLAC 2015

  • FLOLAC 2015**Logic SynthesisDxyGiven: Functional description of finite-state machine F(Q,X,Y,,) where:Q: Set of internal statesX: Input alphabetY: Output alphabet: X x Q Q (next state function): X x Q Y (output function)Target:Circuit C(G, W) where:G: set of circuit components g {gates, FFs, etc.}W: set of wires connecting G

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationLogic synthesis translates Boolean functions into circuits

    We need representations of Boolean functions for two reasons:to represent and manipulate the actual circuit that we are implementingto facilitate Boolean reasoning

    FLOLAC 2015

  • FLOLAC 2015**Boolean SpaceB = {0,1}B2 = {0,1}{0,1} = {00, 01, 10, 11}

    Karnaugh Maps:Boolean Lattices:

    FLOLAC 2015

  • FLOLAC 2015**Boolean FunctionA Boolean function f over input variables: x1, x2, , xm, is a mapping f: Bm Y, where B = {0,1} and Y = {0,1,d}E.g. The output value of f(x1, x2, x3), say, partitions Bm into three sets:on-set (f =1)E.g. {010, 011, 110, 111} (characteristic function f1 = x2 )off-set (f = 0) E.g. {100, 101} (characteristic function f0 = x1 x2 )dont-care set (f = d) E.g. {000, 001} (characteristic function fd = x1 x2 )

    f is an incompletely specified function if the dont-care set is nonempty. Otherwise, f is a completely specified functionUnless otherwise said, a Boolean function is meant to be completely specified

    FLOLAC 2015

  • FLOLAC 2015**Boolean FunctionA Boolean function f: Bn B over variables x1,,xn maps each Boolean valuation (truth assignment) in Bn to 0 or 1

    Examplef(x1,x2) with f(0,0) = 0, f(0,1) = 1, f(1,0) = 1, f(1,1) = 0

    FLOLAC 2015

  • FLOLAC 2015**Boolean FunctionOnset of f, denoted as f1, is f1= {v Bn | f(v)=1}If f1 = Bn, f is a tautologyOffset of f, denoted as f0, is f0= {v Bn | f(v)=0}If f0 = Bn, f is unsatisfiable. Otherwise, f is satisfiable.f1 and f0 are sets, not functions!Boolean functions f and g are equivalent if v Bn. f(v) = g(v) where v is a truth assignment or Boolean valuationA literal is a Boolean variable x or its negation x (or x, x) in a Boolean formula

    x3x1x2x1x2x3f(x1, x2, x3) = x1f(x1, x2, x3) = x1

    FLOLAC 2015

  • FLOLAC 2015**Boolean FunctionThere are 2n vertices in BnThere are 22n distinct Boolean functions Each subset f1 Bn of vertices in Bn forms a distinct Boolean function f with onset f1

    x1x2x3 f0 0 0 10 0 1 00 1 0 10 1 1 01 0 0 11 0 1 01 1 0 11 1 1 0x1x2x3

    FLOLAC 2015

  • FLOLAC 2015**Boolean OperationsGiven two Boolean functions:f : Bn Bg : Bn B

    h = f g from AND operation is defined ash1 = f1 g1; h0 = Bn \ h1

    h = f g from OR operation is defined ash1 = f1 g1; h0 = Bn \ h1

    h = f from COMPLEMENT operation is defined as h1 = f0; h0 = f1

    FLOLAC 2015

  • FLOLAC 2015**Cofactor and QuantificationGiven a Boolean function:f : Bn B, with the input variable (x1,x2,,xi,,xn)

    Positive cofactor on variable xi h = fxi is defined as h = f(x1,x2,,1,,xn)

    Negative cofactor on variable xi h = fxi is defined as h = f(x1,x2,,0,,xn)

    Existential quantification over variable xi h = $xi. f is defined as h = f(x1,x2,,0,,xn) f(x1,x2,,1,,xn)

    Universal quantification over variable xi h = "xi. f is defined as h = f(x1,x2,,0,,xn) f(x1,x2,,1,,xn)

    Boolean difference over variable xi h = f/xi is defined as h = f(x1,x2,,0,,xn) f(x1,x2,,1,,xn)

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationSome common representations:Truth tableBoolean formulaSOP (sum-of-products, or called disjunctive normal form, DNF) POS (product-of-sums, or called conjunctive normal form, CNF)BDD (binary decision diagram)Boolean network (consists of nodes and wires)Generic Boolean networkNetwork of nodes with generic functional representations or even subcircuitsSpecialized Boolean networkNetwork of nodes with SOPs (PLAs)And-Inv Graph (AIG)

    Why different representations?Different representations have their own strengths and weaknesses (no single data structure is best for all applications)

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationTruth TableTruth table (function table for multi-valued functions):The truth table of a function f : Bn B is a tabulation of its value at each of the 2n vertices of Bn.

    In other words the truth table lists all mintemsExample: f = abcd + abcd + abcd + abcd + abcd + abcd + abcd + abcd

    The truth table representation is- impractical for large n- canonicalIf two functions are the equal, then their canonical representations are isomorphic.

    abcd f0 0000 01 0001 12 0010 03 0011 14 0100 05 0101 16 0110 07 0111 0 abcd f 8 1000 0 9 1001 110 1010 011 1011 112 1100 013 1101 114 1110 115 1111 1

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean FormulaA Boolean formula is defined inductively as an expression with the following formation rules (syntax):

    formula ::= ( formula ) | Boolean constant (true or false) | |formula + formula(OR operator) |formula formula(AND operator) | formula(complement)

    Examplef = (x1 x2) + (x3) + ((x4 (x1)))typically is omitted and (, ) are omitted when the operator priority is clear, e.g., f = x1 x2 + x3 + x4 x1

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean Formula in SOPAny function can be represented as a sum-of-products (SOP), also called sum-of-cubes (a cube is a product term), or disjunctive normal form (DNF)

    Example j = ab + ac + bc

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean Formula in POSAny function can be represented as a product-of-sums (POS), also called conjunctive normal form (CNF)Dual of the SOP representation

    Example j = (a+b+c) (a+b+c) (a+b+c) (a+b+c)

    Exercise: Any Boolean function in POS can be converted to SOP using De Morgans law and the distributive law, and vice versa

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBinary Decision DiagramBDD a graph representation of Boolean functionsA leaf node represents constant 0 or 1A non-leaf node represents a decision node (multiplexer) controlled by some variableCan make a BDD representation canonical by imposing the variable ordering and reduction criteria (ROBDD)

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBinary Decision DiagramAny Boolean function f can be written in term of Shannon expansion f = v fv + v fvPositive cofactor: fxi = f(x1,,xi=1,, xn)Negative cofactor: fxi = f(x1,,xi=0,, xn)

    BDD is a compressed Shannon cofactor tree:The two children of a node with function f controlled by variable v represent two sub-functions fv and fv

    v01ffvfv

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBinary Decision DiagramReduced and ordered BDD (ROBDD) is a canonical Boolean function representationOrdered: cofactor variables are in the same order along all pathsxi1 < xi2 < xi3 < < xinReduced:any node with two identical children is removedtwo nodes with isomorphic BDDs are mergedThese two rules make any node in an ROBDD represent a distinct logic function

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBinary Decision DiagramFor a Boolean function, ROBDD is unique with respect to a given variable orderingDifferent orderings may result in different ROBDD structures

    abbccd01c+bdbroot nodec+dcdf = ab+ac+bcdacdb01c+bddbb10leaf node

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean NetworkA Boolean network is a directed graph C(G,N) where G are the gates and N (GG) are the directed edges (nets) connecting the gates.

    Some of the vertices are designated:Inputs: I GOutputs: O G I O =

    Each gate g is assigned a Boolean function fg which computes the output of the gate in terms of its inputs.

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean NetworkThe fanin FI(g) of a gate g are the predecessor gates of g:FI(g) = {g | (g,g) N} (N: the set of nets)

    The fanout FO(g) of a gate g are the successor gates of g:FO(g) = {g | (g,g) N}

    The cone CONE(g) of a gate g is the transitive fanin (TFI) of g and g itself

    The support SUPPORT(g) of a gate g are all inputs in its cone:SUPPORT(g) = CONE(g) I

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationBoolean NetworkExampleIO6FI(6) = {2,4}FO(6) = {7,9}CONE(6) = {1,2,4,6}SUPPORT(6) = {1,2}Every node may have its own function15347892

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationAnd-Inverter GraphAND-INVERTER graphs (AIGs)vertices: 2-input AND gates edges: interconnects with (optional) dots representing INVs

    Hash table to identify and reuse structurally isomorphic circuits

    fggf

    FLOLAC 2015

  • FLOLAC 2015**Boolean Function RepresentationTruth tableCanonicalUseful in representing small functionsSOPUseful in two-level logic optimization, and in representing local node functions in a Boolean networkPOSUseful in SAT solving and Boolean reasoning Rarely used in circuit synthesis (due to the asymmetric characteristics of NMOS and PMOS)ROBDDCanonicalUseful in Boolean reasoningBoolean networkUseful in multi-level logic optimizationAIGUseful in multi-level logic optimization and Boolean reasoning

    FLOLAC 2015

  • FLOLAC 2015**Circuit to CNF ConversionNaive conversion of circuit to CNF:Multiply out expressions of circuit until two level structureExample: y = x1 x2 x2 ... xn (Parity function)circuit size is linear in the number of variables

    generated chess-board Karnaugh mapCNF (or DNF) formula has 2n-1 terms (exponential in #vars)

    Better approach:Introduce one variable per circuit vertexFormulate the circuit as a conjunction of constraints imposed on the vertex values by the gatesUses more variables but size of formula is linear in the size of the circuit

    FLOLAC 2015

  • FLOLAC 2015**Circuit to CNF ConversionExampleSingle gate:

    Circuit of connected gates:

    bac(a + b + c)(a + c)(b + c)AND(1 + 2 + 4)(1 + 4)(2 + 4)(2 + 3 + 5)(2 + 5)(3 + 5)(2 + 3 + 6)(2 + 6)(3 + 6)(4 + 5 + 7)(4 + 7)(5 + 7)(5 + 6 + 8)(5 + 8)(6 + 8)(7 + 8 + 9)(7 + 9)(8 + 9)(9)Justify to 1Is output always 0 ?

    FLOLAC 2015

  • FLOLAC 2015**Circuit to CNF ConversionCircuit to CNF conversion can be done in linear size (with respect to the circuit size) if intermediate variables can be introducedmay grow exponentially in size if no intermediate variables are allowed

    FLOLAC 2015

  • FLOLAC 2015*Propositional Satisfiability

    FLOLAC 2015

  • FLOLAC 2015*Normal FormsA literal is a variable or its negationA clause (cube) is a disjunction (conjunction) of literalsA conjunctive normal form (CNF) is a conjunction of clauses; a disjunctive normal form (DNF) is a disjunction of cubes

    E.g.,CNF: (a+b+c)(a+c)(b+d)(a)(a) is a unit clause, d is a pure literalDNF: abc + ac + bd + a

    FLOLAC 2015

  • FLOLAC 2015*SatisfiabilityThe satisfiability (SAT) problem asks whether a given CNF formula can be true under some assignment to the variables

    In theory, SAT is intractableThe first shown NP-complete problem [Cook, 1971]

    In practice, modern SAT solvers work mysteriously well on application CNFs with ~100,000 variables and ~1,000,000 clausesIt enables various applications, and inspires QBF and SMT (Satisfiability Modulo Theories) solver development

    FLOLAC 2015

  • FLOLAC 2015*SAT Competitionhttp://www.satcompetition.org/PoS11/

    FLOLAC 2015

  • FLOLAC 2015*SAT Solving Ingredients of modern SAT solvers:DPLL-style search [Davis, Putnam, Logemann, Loveland, 1962]Conflict-driven clause learning (CDCL)[Marques-Silva, Sakallah, 1996 (GRASP)]Boolean constraint propagation (BCP) with two-literal watch[Moskewicz, Modigan, Zhao, Zhang, Malik, 2001 (Chaff)]Decision heuristics using variable activity[Moskewicz, Modigan, Zhao, Zhang, Malik, 2001 (Chaff)]RestartPreprocessingSupport for incremental solving[Een, Sorensson, 2003 (MiniSat)]

    FLOLAC 2015

  • FLOLAC 2015*Pre-Modern SAT ProcedureAlgorithm DPLL(){while there is a unit clause {l} in = BCP(, l); while there is a pure literal l in = assign(, l); if all clauses of satisfied return true; if has a conflicting clause return false; l := choose_literal(); return DPLL(assign(,l)) DPLL(assign(,l));}

    FLOLAC 2015

  • FLOLAC 2015*DPLL ProcedureChorological backtrack

    E.g. abc00011T{a,e}{a,b,c}{c,d}{a,b,d}{d,e}{c,d,e}

    FLOLAC 2015

  • FLOLAC 2015*Modern SAT Procedure Algorithm CDCL(){while(1) while there is a unit clause {l} in = BCP(, l); while there is a pure literal l in = assign(, l); if contains no conflicting clause if all clauses of are satisfied return true; l := choose_literal(); assign(,l); else if conflict at top decision level return false; analyze_conflict(); undo assignments; := add_conflict_clause(); }

    FLOLAC 2015

  • FLOLAC 2015*Conflict Analysis & Clause LearningThere can be many learnt clauses from a conflictClause learning admits non-chorological backtrackE.g.,{x10587, x10588, x10592}{x10374, x10582, x10578, x10373, x10629}{x10646, x9444, x10373, x10635, x10637}Courtesy of Niklas EenBox: decision nodeOval: implication nodeInside: literal (decision level)

    FLOLAC 2015

  • FLOLAC 2015*Clause Learning as ResolutionResolution of two clauses C1x and C2x: C1x C2x C1C2where x is the pivot variable and C1C2 is the resolvant, i.e., C1C2 = x.(C1x)(C2x)

    A learnt clause can be obtained from a sequence of resolution stepsExercise: Find a resolution sequence leading to the learnt clause {x10374, x10582, x10578, x10373, x10629} in the previous slides

    FLOLAC 2015

  • FLOLAC 2015*ResolutionResolution is complete for SAT solvingA CNF formula is unsatisfiable if and only if there exists a resolution sequence leading to the empty clause

    Example(abc)(ac)(bd)(c)(cd)(bc)(cd)(d)(d)()

    FLOLAC 2015

  • FLOLAC 2015*SAT CertificationTrue CNFSatisfying assignment (model)Verifiable in linear time

    False CNFResolution refutationPotentially of exponential size

    FLOLAC 2015

  • FLOLAC 2015*Craig Interpolation[Craig Interpolation Thm, 1957]If AB is UNSAT for formulae A and B, there exists an interpolant I of A such that

    1. AI2. IB is UNSAT3. I refers only to the common variables of A and BBAII is an abstraction of A

    FLOLAC 2015

  • FLOLAC 2015*Interpolant and Resolution ProofSAT solver may produce the resolution proof of an UNSAT CNF For = AB specified, the corresponding interpolant can be obtained in time linear in the resolution proofAB(abc)(ac)(bd)(c)(cd)(bc)(cd)(d)(d)()(bc)(c)(1)(1)(1)= (bc)[McMillan, 2003]

    FLOLAC 2015

  • FLOLAC 2015*Incremental SAT SolvingTo solve, in a row, multiple CNF formulae, which are similar except for a few clauses, can we reuse the learnt clauses? What if adding a clause to ?What if deleting a clause from ?

    FLOLAC 2015

  • FLOLAC 2015*Incremental SAT SolvingMiniSat APIvoid addClause(Vec clause)bool solve(Vec assumps)bool readModel(Var x) for SAT resultsbool assumpUsed(Lit p) for UNSAT results

    The method solve() treats the literals in assumps as unit clauses to be temporary assumed during the SAT-solving.More clauses can be added after solve() returns, then incrementally another SAT-solving executed.Courtesy of Niklas Een

    FLOLAC 2015

  • FLOLAC 2015*SAT & Logic SynthesisFunctional Dependency

    FLOLAC 2015

  • FLOLAC 2015*Functional Dependencyf(x) functionally depends on g1(x), g2(x), , gm(x) if f(x) = h(g1(x), g2(x), , gm(x)), denoted h(G(x))Under what condition can function f be expressed as some function h over a set G={g1,,gm} of functions ?h exists a,b such that f(a)f(b) and G(a)=G(b)

    i.e., G is more distinguishing than f

    FLOLAC 2015

  • FLOLAC 2015*MotivationApplications of functional dependencyResynthesis/rewiringRedundant register removal BDD minimizationVerification reduction

    fg4g3g2g1target functionbase functionshBoolean Network

    FLOLAC 2015

  • FLOLAC 2015*BDD-Based ComputationBDD-based computation of hhon = {y Bm : y = G(x) and f(x) = 1, x Bn} hoff = {y Bm : y = G(x) and f(x) = 0, x Bn}BnBmGf(x) = 1f(x) = 0hon = x.(yG)fhoff = x.(yG)f

    FLOLAC 2015

  • FLOLAC 2015*BDD-Based ComputationProsExact computation of hon and hoffBetter support for dont care minimization

    Cons2 image computations for every choice of GInefficient when |G| is large or when there are many choices of G

    FLOLAC 2015

  • FLOLAC 2015*SAT-Based Computationh exists a,b such that f(a)f(b) and G(a)=G(b),i.e., (f(x)f(x*))(G(x)G(x*)) is UNSAT

    How to derive h? How to select G?

    FLOLAC 2015

  • FLOLAC 2015*SAT-Based Computation(f(x)f(x*))(G(x)G(x*)) is UNSAT

    FLOLAC 2015

  • FLOLAC 2015*Deriving h with Craig InterpolationClause set A: CDFNon, y0Clause set B: CDFNoff, y0*, (yiyi*) for i =1,,mI is an overapproximation of Img( fon ) and is disjoint from Img( foff )I only refers to y1,, ymTherefore, I corresponds to a feasible implementation of h===10DFNoffDFNonABImg(fon)Img(foff)

    FLOLAC 2015

  • FLOLAC 2015*Incremental SAT SolvingControlled equality constraints (yiyi*) (yi yi* ai)(yi yi* ai) with auxiliary variables ai

    Fast switch between target and base functions by unit assumptions over control variablesFast enumeration of different base functionsShare learned clauses

    ai = true ith equality constraint is disabled

    FLOLAC 2015

  • FLOLAC 2015*SAT vs. BDDSATProsDetect multiple choices of G automaticallyScalable to large |G|Fast enumeration of different target functions fFast enumeration of different base functions GConsSingle feasible implementation of h

    BDDConsDetect one choice of G at a timeLimited to small |G|Slow enumeration of different target functions fSlow enumeration of different base functions GProsAll possible implementations of h

    FLOLAC 2015

  • FLOLAC 2015*Practical EvaluationSAT vs. BDD

    OriginalRetimedSAT (original)BDD (original)SAT (retimed)BDD (retimed)Circuit#Nodes#FF.#Dep-S#Dep-B#FF.#Dep-S#Dep-BTimeMemTimeMemTimeMemTimeMems5378279417952253982831731.2181.6200.618751s9234.1559721146x4593012014.119xx1.719194.6149s13207.180226381901361930802x15.62231.47815.322xxs15850.19785534189907402x23.32282.6947.922xxs359321606517280--20261170--176.727111716478.127----s3841722397163695--5016243--270.330----123.132----s3858419407145224--43502569--166.521----99.4301117164b129461214217066330.151712.8380.13172.542b1498472452--2452--3.322----5.222----b1583674490--1134793--5.822----5.822----b173077714150--39672350--119.128----161.742----b1811124133205--92545723--1414100----2842.6100----b1922462466420--7164337--8184.8217----11040.6234----b20196824904--16041167--25.728----3630----b21200274904--19501434--24.629----36.331----b22291627356--30132217--73.436----90.637----

    FLOLAC 2015

  • FLOLAC 2015*Practical Evaluationcircuit size vs. runtime

    FLOLAC 2015

  • FLOLAC 2015*Practical EvaluationIncremental SAT

    FLOLAC 2015

  • FLOLAC 2015*Practical Evaluation#total input vs. #redundant inputs

    FLOLAC 2015

  • FLOLAC 2015*Practical Evaluationinterpolant size vs. support size

    FLOLAC 2015

  • FLOLAC 2015*SummaryFunctional dependency is computable with pure SAT solving (with the help of Craig interpolation)Compared to BDD-based computation, it is much scalable to large designs

    FLOLAC 2015

  • FLOLAC 2015*SAT & Logic SynthesisDecoder Synthesis

    FLOLAC 2015

  • FLOLAC 2015*IntroductionEncoder0,1,1,0,0,1,0,1,0,1,Decoder

    FLOLAC 2015

  • FLOLAC 2015*IntroductionDecoding process under a bounded observation window, ok, ok+1, ok+2, ok+3, ok+4, ok+5, EncoderDecoderijij+1ij+1ij+2

    FLOLAC 2015

  • FLOLAC 2015*IntroductionExample1/10/00/11/0q0q11/10/01/00/1q0q1

    OutputInput00...00... or 110101 or 101000 or 111101 or 10

    OutputInput00...?001?110?111?0

    FLOLAC 2015

  • FLOLAC 2015*IntroductionEncoding/decoding scheme plays key roles in various applications, includingCommunication,Signal processing,Cryptography,

    Designing a decoder can be more difficult than designing an encoder

    Automatic decoder synthesis helps a designer effectively and correctly implement his/her system

    FLOLAC 2015

  • FLOLAC 2015*IntroductionBasic assumptions:Encoder can be sequentialCombinational encoder is a special case Can be decoded with observation window of size 1Steady state behavior is of main concernInitial transient behavior is neglected

    Decoder has finite memoryBounded observation window

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingNotationTxyss'inputoutputcurrent statenext statetransition relation

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingDecoder exists under window (-n,p) iff

    is UNSATT0T1 T1TpTnT*0T*1 T*1T*pT*n

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingDecoder does not exist iff

    is SAT for some n and p, where

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingDecoder does not exist iff

    is SAT for some n and p, where

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingT0T1 T1TpTnT*0T*1 T*1T*pT*nLLL

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence Checkingencodersolve M(n,p)SAT?yesnodecoder existsreturn (n, p)solve M(n,p)(L(LL))SAT?yesno decoderreturn counterexample non := n+1p := p+1n := 0p := 0

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingIncremental timeframe expansionExpand from outsideT0T1 T*0T*1 T2T*2

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence CheckingIncremental timeframe expansionExpand from insideT0T*0

    FLOLAC 2015

  • FLOLAC 2015*Decoder Existence Checkingencodersolve M(n,p)SAT?yesnodecoder existsreturn (n, p)solve M(n,p)(L(LL))SAT?yesno decoderreturn counterexample non := n+1p := p+1n := 0p := 0

    FLOLAC 2015

  • FLOLAC 2015*Decoder SynthesisCraig interpolation theorem:For (A B) UNSAT, there exists an interpolant I such that1. A I2. B I UNSAT3. I refers only to the common variables of A and BBAI

    FLOLAC 2015

  • FLOLAC 2015*Decoder Synthesis with Craig InterpolationThe interpolant corresponds to the desired decoderT0T1 T1TpTnT*0T*1 T*1T*pT*n10AB

    FLOLAC 2015

  • FLOLAC 2015*Experimental ResultsOur decoding system Decosy implemented in ABC using C language

    Experiments conducted on Linux machine with Xeon 2.53 GHz CPU and 48GB RAM

    Final circuits mapped into mcnc.genlib library

    FLOLAC 2015

  • FLOLAC 2015*Experimental ResultsComparison on decoder generation time*Prior work [14] implemented in OCaml.

    circuit[14]*Decosyarea ratiodelay ratioarea/delaytimearea/delaytimeXGXS269/7.41.23286/7.30.081.060.99XFI5697/14.4492.583978/14.34.020.700.99Scrambler736/3.81.88640/3.80.250.871PCIE171/5.81.04190/6.60.081.111.14T2Ethernet299/7.522.67583/9.01.471.951.20HM(7,4)255/7.30.12255/7.30.0811HM(15,11)4232/13.856.823279/13.21.330.770.96

    FLOLAC 2015

  • FLOLAC 2015*Experimental ResultsComparison on decoder existence checking and decoder generation*Prior work [14] implemented in OCaml.

    circuit[15]*Decosyarea ratiodelay Ratioarea/delaytimearea/delaytimeXGXS293/7.52.70295/7.10.101.010.95XFI5697/14.41144.323913/12.57.520.690.87Scrambler736/3.810.46640/3.80.500.871PCIE163/6.13.91190/6.60.141.171.08T2Ethernet269/6.9113.89526/9.712.381.961.41HM(7,4)255/7.30.12 255/7.30.0811HM(15,11)4232/13.856.92 3279/13.21.940.770.96

    FLOLAC 2015

  • FLOLAC 2015*Experimental ResultsComparison on decoder inexistence checking*Prior work [15] implemented in OCaml.

    circuit (w/o decoder)[15]* time (s)Decosy time (s)XGXS_err2.170.01 XFI_err39.710.01 Scrambler_err3.960.08 PCIE_err2.940.01 T2Ethernet_err128.730.04 HM(7,4)_err1.350.01 HM(15,11)_err23.250.39 AD>60000.01

    FLOLAC 2015

  • FLOLAC 2015*SummaryDecoder synthesis can be computed effectively with SAT and Craig interpolationExtension to decoders with feedbacks is possible [DAC13]

    FLOLAC 2015

  • FLOLAC 2015*Quantified Satisfiability

    FLOLAC 2015

  • FLOLAC 2015*Quantified Boolean FormulaA quantified Boolean formula (QBF) is often written in prenex form (with quantifiers placed on the left) as

    Q1 x1, , Qn xn.

    for Qi {, } and a quantifier-free formula If is further in CNF, the corresponding QBF is in the so-called prenex CNF (PCNF), the most popular QBF representationAny QBF can be converted to PCNFprefixmatrix

    FLOLAC 2015

  • FLOLAC 2015*Quantified Boolean FormulaQuantification order matters in a QBFA variable xi in (Q1 x1,, Qi xi,, Qn xn. ) is of level k if there are k quantifier alternations (i.e., changing from to or from to ) from Q1 to Qi. Examplea b c d e. level(a)=0, level(b)=1, level(c)=2, level(d)=2, level(e)=3

    FLOLAC 2015

  • FLOLAC 2015*Quantified Boolean FormulaMany decision problems can be compactly encoded in QBFs

    In theory, QBF solving (QSAT) is PSPACE completeThe more the quantifier alternations, the higher the complexity in the Polynomial Hierarchy

    In practice, solvable QBFs are typically of size ~1,000 variables

    FLOLAC 2015

  • FLOLAC 2015*QBF SolverQBF solver choicesData structures for formula representationPrenex vs. non-prenexNormal form vs. non-normal formCNF, NNF, BDD, AIG, etc.Solving mechanismsSearch, Q-resolution, Skolemization, quantifier elimination, etc.Preprocessing techniques

    Standard approachSearch-based PCNF formula solving (similar to SAT)Both clause learning (from a conflicting assignment) and cube learning (from a satisfying assignment) are performedExample a b c d e. (a+c)(a+c)(b+c+e)(b)(c+d+e)(c+e)(d+e)from 00101, we learn cube abcd (can be further simplified to a)

    FLOLAC 2015

  • FLOLAC 2015*QBF SolvingExample

    FLOLAC 2015

  • FLOLAC 2015*Q-ResolutionQ-resolution on PCNF is similar to resolution on CNF, except that the pivots are restricted to existentially quantified variables and the additional rule of -reduction C1x C2x

    -RED(C1C2)where operator -RED removes from C1C2 the universally () quantified variables whose quantification levels are greater than any of the existentially () quantified variables in C1C2 E.g., prefix: a b c d e -RED(a+b+c+d) = (a+b)

    Q-resolution is complete for QBF solvingA PCNF formula is unsatisfiable if and only if there exists a Q-resolution sequence leading to the empty clause

    FLOLAC 2015

  • FLOLAC 2015*Q-ResolutionExample (contd)

    FLOLAC 2015

  • FLOLAC 2015*SkolemizationSkolemization and Skolem normal formExistentially quantified variables are replaced with function symbolsQBF prefix contains only two quantification levels function symbols, variables

    Examplea b c d. (a+b)(b+c+d)(b+c+d)(a+b+c)

    Fb(a) Fd(a,c) a c.(a+Fb)(Fb+c+Fd)(Fb+c+Fd)(a+Fb+c)Skolem functions

    FLOLAC 2015

  • FLOLAC 2015*QBF CertificationQBF certificationEnsure correctness and, more importantly, provide useful informationCertificatesTrue QBF: term-resolution proof / Skolem-function (SF) modelSF model is more useful in practical applications False QBF: clause-resolution proof / Herbrand-function (HF) countermodelHF countermodel is more useful in practical applications

    Solvers and certificatesTo date, only Skolemization-based solvers (e.g., sKizzo, squolem, Ebddres) can provide SFs Search-based solvers (e.g., QuBE) are the most popular and can be instrumented to provide resolution proofs

    FLOLAC 2015

  • FLOLAC 2015*QBF CertificationSolvers and certificates

    SolverAlgorithmCertificateTrue QBFFalse QBFQuBE-certsearchCube resolutionClause resolutionyQuafflesearchCube resolutionClause resolutionEbddresSkolemizationSkolem functionClause resolutionsKizzoSkolemizationSkolem function-squolemSkolemizationSkolem functionClause resolution

    FLOLAC 2015

  • FLOLAC 2015*QBF CertificationIncomplete picture of QBF certification

    Recent progressHerbrand-function countermodel [Balabanov, J, 2011 (ResQu)]Syntactic to semantic certificate conversion Linear time [Balabanov, J, 2011 (ResQu)]

    Syntactic CertificateSemantic CertificateTrue QBFCube-resolution proofSkolem-function modelFalse QBFClause-resolution proof?

    FLOLAC 2015

  • FLOLAC 2015*QBF CertificationUnified QBF certification

    FLOLAC 2015

  • FLOLAC 2015*ResQuA Skolem-function model (Herbrand-function countermodel) for a true (false) QBF can be derived from its cube (clause) resolution proof

    A Right-First-And-Or (RFAO) formulais recursively defined as follows. := clause | cube | clause | cube E.g., (a+b) ac (b+c) bc = ((a+b) (ac ((b+c) bc)))

    FLOLAC 2015

  • FLOLAC 2015*ResQu

    FLOLAC 2015

  • FLOLAC 2015*ResQuExampleaxbyc

    FLOLAC 2015

  • FLOLAC 2015*QBF CertificationApplications of Skolem/Herbrand functionsProgram synthesisWinning strategy synthesis in two player gamesPlan derivation in AILogic synthesis...

    FLOLAC 2015

  • FLOLAC 2015*QSAT & Logic Synthesis Boolean Matching

    FLOLAC 2015

  • FLOLAC 2015*IntroductionCombinational equivalence checking (CEC)Known input correspondencecoNP-completeWell solved in practical applications x1x2xnfgy1y2yn

    FLOLAC 2015

  • FLOLAC 2015*IntroductionBoolean matching P-equivalenceUnknown input permutationO(n!) CEC iterationsNP-equivalenceUnknown input negation and permutationO(2nn!) CEC iterationsNPN-equivalenceUnknown input negation, input permutation, and output negationO(2n+1n!) CEC iterations

    x1x2xnfgy1y2ynPNN

    FLOLAC 2015

  • FLOLAC 2015*IntroductionExamplegfx1x2x3=

    FLOLAC 2015

  • FLOLAC 2015*IntroductionMotivationsTheoreticallyComplexity in between coNP (for all ) and 2 (there exists for all ) in the Polynomial Hierarchy (PH)Special candidate to test PH collapseKnown as Boolean congruence/isomorphism dating back to the 19th century

    PracticallyBroad applicationsLibrary bindingFPGA technology mappingDetection of generalized symmetryLogic verificationDesign debugging/rectificationFunctional engineering change orderIntensively studied over the last two decades

    FLOLAC 2015

  • FLOLAC 2015*IntroductionPrior methodsCS: completely specifiedIS: incompletely specified

    Complete ?Function typeEquivalence typeSolution typeScalabilitySpectral methodsyesCSmostly Pone Signature based methodsnomostly CSP/NPN/A ~ ++Canonical-form based methodsyesCSmostly Pone+SAT based methodsyesCSmostly Pone/all+

    BooM(QBF/SAT-like)yesCS / ISNPNone/all++

    FLOLAC 2015

  • FLOLAC 2015*BooM: A Fast Boolean MatcherFeatures of BooMGeneral computation frameworkEffective search space reduction techniquesDynamic learning and abstractionTheoretical SAT-iteration upper-bound:

    O(2nn!)O(22n)

    FLOLAC 2015

  • FLOLAC 2015*FormulationReduce NPN-equiv to 2 NP-equiv checksMatching f and g; matching f and g

    2nd order formula of NP-equivalence

    fc and gc are the care conditions of f and g, respectively

    Need 1st order formula instead for SAT solving

    ,x ((fc(x) gc((x))) (f(x) g((x))))

    FLOLAC 2015

  • FLOLAC 2015*Formulation0-1 matrix representation of

    FLOLAC 2015

  • FLOLAC 2015*FormulationQuantified Boolean formula (QBF) for NP-equivalence

    C: cardinality constraintA: /\i,j (aij (yi xj)) (bij (yi xj))

    Look for an assignment to a- and b-variables that satisfies C and makes the miter constraint = A (f g) fc gc unsatisfiable

    Refine C iteratively in a sequence 0, 1, , k, for i+1 i through conflict-based learning

    a,b,x,y (C A ((fc gc) (f g))

    FLOLAC 2015

  • FLOLAC 2015*BooM Flowf (and fc)g (and gc)Preprocess(sig., abs.)Solve mapping i SAT?Solve miter SAT?No matchMatch foundAdd learned clause to i i characterizes all matchesHow to compute all matches?Solve i i=0yesnoi=i+1noyes

    FLOLAC 2015

  • FLOLAC 2015*NP-EquivalenceConflict-based LearningObservation 0 1 1 fg 1 0 1 10 1 0 1 From SAT 1How to avoid these 6 mappings at once?

    FLOLAC 2015

  • FLOLAC 2015*Learnt clause generation( a11 b12 a13 b21 a22 b23 b31 a32 b33 )

    NP-EquivalenceConflict-based Learningfg10101011101

    FLOLAC 2015

  • FLOLAC 2015*NP-EquivalenceConflict-based LearningProposition: If f(u) g(v) with v = (u) for some satisfying i, then the learned clause \/ij lij for literalslij = (vi uj) ? aij : bijexcludes from i the mappings { | (u) = (u)}

    Proposition:The learned clause prunes n! infeasible mappings

    Proposition:The refinement process 0, 1, , k is bounded by 22n iterations

    FLOLAC 2015

  • FLOLAC 2015*NP-EquivalenceAbstractionAbstract Boolean matchingAbstract f(x1,,xk,xk+1,,xn) to f(x1,,xk,z,,z) = f*(x1,,xk,z) Match g(y1,,yn) against f*(x1,,xk,z)Infeasible matching solutions of f* and g are also infeasible for f and g

    PN

    FLOLAC 2015

  • FLOLAC 2015*NP-EquivalenceAbstractionAbstract Boolean matchingSimilar matrix representation of negation/permutation

    Similar cardinality constraints, except for allowing multiple y-variables mapped to z =1

    FLOLAC 2015

  • FLOLAC 2015*NP-EquivalenceAbstractionUsed for preprocessing

    Information learned for abstract model is valid for concrete model

    Simplified matching in reduced Boolean space

    FLOLAC 2015

  • FLOLAC 2015*P-EquivalenceConflict-based LearningProposition: If f(u) g(v) with v = (u) for some satisfying i, then the learned clause \/ij lij for literalslij = (vi=0 and uj=1) ? aij : excludes from i the mappings { | (u) = (u)}

    FLOLAC 2015

  • FLOLAC 2015*P-EquivalenceAbstractionAbstraction enforces search in biased truth assignments and makes learning strongFor f* having k support variables, a learned clause converted back to the concrete model consists of at most (k1)(nk+1) literals

    FLOLAC 2015

  • FLOLAC 2015*Practical EvaluationBooM implemented in ABC using MiniSATA function is matched against its synthesized, and input-permuted/negated versionMatch individual output functions of MCNC, ISCAS, ITC benchmark circuits717 functions with 10~39 support variables and 15~2160 AIG nodesTime-limit 600 secondsBaseline preprocessing exploits symmetry, unateness, and simulation for initial matching

    FLOLAC 2015

  • FLOLAC 2015*Practical Evaluation(P-equivalence; find all matches)LearningAbstraction

    FLOLAC 2015

  • FLOLAC 2015*Practical EvaluationP-equivalenceNP-equivalence

    FLOLAC 2015

  • FLOLAC 2015*Practical Evaluation(runtime after same preprocessing;P-equivalence; find one match)BooM vs. DepQBF

    FLOLAC 2015

  • FLOLAC 2015*ConclusionsBooM, a dedicated decision procedure for Boolean matchingEffective learning and abstraction Far faster than state-of-the-art QBF solverTheoretical upper bound reduced from O(2nn!) to O(22n)Empirically exponent ~7 times less for P, ~3 times less for NPGeneral computation framework Handles NPN-equivalence, incompletely specified functionsAllows easy integration with signature based methods

    Anticipate BooM to be a common platform for other Boolean matching developments and to facilitate practical applications

    FLOLAC 2015

  • FLOLAC 2015*QSAT & Logic Synthesis Relation Determinization

    FLOLAC 2015

  • FLOLAC 2015*Relation vs. FunctionRelation R(X, Y)Allow one-to-many mappingsCan describe non-deterministic behaviorMore generic than functions

    Function F(X)Disallow one-to-many mappings Can only describe deterministic behaviorA special case of relation

    f1 = x1 x2f2 = x1 x2

    FLOLAC 2015

  • FLOLAC 2015*RelationTotal relationEvery input element is mapped to at least one output element

    Partial relationSome input element is not mapped to any output element

    FLOLAC 2015

  • FLOLAC 2015*RelationA partial relation can be totalizedAssume that the input element not mapped to any output element is a dont carePartial relationTotalizeTotal relationT(X, y) = R(X, y) y. R(X, y)

    FLOLAC 2015

  • FLOLAC 2015*MotivationApplications of Boolean relationIn high-level design, Boolean relations can be used to describe (nondeterministic) specificationsIn gate-level design, Boolean relations can be used to characterize the flexibility of sub-circuitsBoolean relations are more powerful than traditional dont-care representationsSystem Spec.x1x2y1y2

    FLOLAC 2015

  • FLOLAC 2015*MotivationRelation determinizationFor hardware implement of a system, we need functions rather than relationsPhysical realization are deterministic by natureOne input stimulus results in one output responseTo simplify implementation, we can explore the flexibilities described by a relation for optimization

    FLOLAC 2015

  • FLOLAC 2015*MotivationExample

    FLOLAC 2015

  • FLOLAC 2015*Relation DeterminizationGiven a nondeterministic Boolean relation R(X, Y), how to determinize and extract functions from it?

    For a deterministic total relation, we can uniquely extract the corresponding functions

    FLOLAC 2015

  • FLOLAC 2015*Relation DeterminizationApproaches to relation determinizationIterative method (determinize one output at a time)BDD- or SOP-based representationNot scalableBetter optimization AIG representationFocus on scalability with reasonable optimization qualityNon-iterative method (determinize all ouputs at once)QBF solving

    FLOLAC 2015

  • FLOLAC 2015*Iterative Relation DeterminizationSingle-output relationFor a single-output total relation R(X, y), we derive a function f for variable y using interpolationA : R(X,0)Minimal care onset of fB : R(X,1) Minimal care offset of f R(X,0) R(X,1) UNSAT

    FLOLAC 2015

  • FLOLAC 2015*Iterative Relation DeterminizationMulti-output relationTwo-phase computation:Backward reductionReduce to single-output case R(X, y1, , yn) y2, , yn. R(X, y1, , yn)Forward substitutionExtract functions

    FLOLAC 2015

  • FLOLAC 2015*Iterative Relation DeterminizationExamplePhase1: (expansion reduction)y3.R(X, y1, y2 , y3) R(3)(X, y1, y2)y2.R(3)(X, y1, y2) R(2)(X, y1) y1y2Xy3RR(3)R(2)Phase2:R(2)(X, y1) y1 = f1 (X)R(3)(X, y1, y2) R(3)(X, f1(X), y2) y2 = f2 (X)R(X, y1, y2 , y3) R(X, f1(X), f2(X), y2) y3 = f3 (X)

    FLOLAC 2015

  • FLOLAC 2015*Non-Iterative Relation DeterminizationSolve QBF x1,,xm,y1,,yn. R(x1,,xm, y1, , yn)

    The Skolem functions of variables y1, , yn correspond to the functions we want

    FLOLAC 2015

  • FLOLAC 2015*SummaryRelation determinization correspond to solving a QBF problemIterative and non-iterative methods can be applied to extract functions from a Boolean relation

    FLOLAC 2015

  • FLOLAC 2015*Thanks for Your Attention

    FLOLAC 2015

    *Unit clause (~a), pure literal (d), Boolean constraint propagation*SAT is one of the most fundamental problems in computer science

    The success has enabled practical solutions to various synthesis and verification problems, and inspires QBF and SMT development*****************