Proof: Synthesize cubes so that cube c k has n − i k literals and cubes c k and c l are disjoint, for any 0 ≤ k < l ≤ λ − 1. Weikang Qian and Marc D. Riedel Two-Level Logic Synthesis for Probabilistic Computation Abstract ECE Department, University of Minnesota Probabilistic Computation A classical problem in logic synthesis is to find a sum-of-product (SOP) Boolean expression with the minimum number of product terms that implements a Boolean function. In this work, we focus on a related yet different synthesis problem targeted toward probabilistic computation. In our scenario, we want to synthesize a Boolean function that covers an exact number of minterms, say m minterms. This is the only requirement; which m minterms are covered does not matter. The objective is to find a SOP Boolean expression with the minimum number of product terms with this property. Solving this problem provides a solution to the problem of generating arbitrary probability values from unbiased input probabilities values of 0.5 with combinational logic. We first show a method for constructing a set of product terms to cover exactly m minterms; this gives an upper bound. Then, as our major contribution, we propose a method for deriving a lower bound. We show that the problem of finding such a lower bound can be converted into an optimization problem which we call the optimal subtraction problem. We solve it with dynamic programming. Experiments on benchmarks show that for some numbers m, the lower bound meets the upper bound, indicating that the solution corresponding to the upper bound is optimal. For some other numbers m, the gap between the lower bound and the upper bound is small, indicating that the solution corresponding to the upper bound is nearly optimal. Digital circuit operating on random bit streams Transform probabilities into probabilities How to design it? Two-Level Logic Synthesis In test: Weighted random pattern generation Hardware implementation of probabilistic algorithm A Hard Question: Which m minterms to choose? P(z = 1) = P(x = 1) P(y = 1) P(x = 1) = 0.4 P(z = 1) = 0.2 P(y = 1) = 0.5 0,1,0,1,0,0,1,1,0,0 1,0,1,1,0,0,1,0,0,1 0,0,0,1,0,0,1,0,0,0 Probability Generator Deterministic Hardware 0, 1, 1, 0, 1, 0 1, 1, 0, 1, 0, 1 Stochastic Bit Streams: Probability 3/6 Probability 4/6 … Why need it? Random Sources Digital Circuit p2p2 p3p3 p1p1 q2q2 q1q1 q3q3 q4q4 Input Probabilities Other Probabilities Needed ? Problem: A Special One Independent Combinational Logic 0.5 q Each input combination has probability 1/2 n If the Boolean function has m minterms, then q = m/2 n Answer: q = m/2 n What is it? ? Question 1: What could q be? Question 2: How to implement q = m/2 n ? Answer: choose m minterms, BUT … Example: q = 7/ Ultimate Question: Given number of inputs n and integer m, find a SOP expression with the minimum number of products to cover m minterms. Optimization Flow λ = Lower bound on the number of cubes to cover m minterms Exists λ cubes to cover m interms? end Y λ = λ + 1 N Focus of this work Definitions and Preliminaries V( f ): number of minterms covered by f B(m): number of ones of binary number m B((1011) 2 ) = 3 Boolean product, also known as cube, denoted by c If cube c contains k literals, V(c) = 2 n − k How to count number of minterms? Inclusion-Exclusion Principle Upper Bound Theorem 1: If B(m) = λ, then an upper bound is λ Example: m = (1011) 2, n = 4 Mutually Disjoint Lower Bound and Optimal Subtraction Problem (OSP) Theorem 2: If there exists λ cubes to cover m minterms, then we can find a, b ≥ 0 such that: m = a − b; B(a) ≤ 2 λ − 1 ; B (b) ≤ 2 λ − 1 − 1 Proof: In equation of Inclusion-Exclusion Principle, put “plus” terms together to get a; put “minus” terms together to get b We can show B(a) ≤ 2 λ − 1, B (b) ≤ 2 λ − 1 − 1 m = a − b Lower bound is the minimum λ satisfying the above property Example: m = (101101) 2 a − b = (101101) 2 B(a) ≤ 2 λ − 1 = 2 B(b) ≤ 2 λ − 1 − 1 = 1 No solution! B(a) ≤ 2 λ − 1 = 4 B(b) ≤ 2 λ − 1 − 1 = 3 a = (110001) 2, b = (100) 2 Generalization of Optimal Subtraction Problem λ = 2 λ = 3 X Lower bound: λ = 3 Optimal Subtraction Problem Given m, t ≥ 0, find a, b ≥ 0 to minimize B(a) such that B(b) ≤ t m = a − b Find lower bound by solving optimal subtraction problem: Set t = 2 λ − 1 − 1 If min B(a) > 2 λ − 1, then lower bound > λ Experimental Results (… 000 m k …m 0 ) 2 + (… ??? b* k …b* 0 ) 2 Carry 0 Then, ??? = 000 Case 1: 0 & carry 0 (… 000 m k …m 0 ) 2 + (… ??? b* k …b* 0 ) 2 Carry 1 Then, ??? = 000 or 111 Case 2: 0 & carry 1 (… 111 m k …m 0 ) 2 + (… ??? b* k …b* 0 ) 2 Carry 0 Then, ??? = 000 or 001 Case 3: 1 & carry 0 (… 111 m k …m 0 ) 2 + (… ??? b* k …b* 0 ) 2 Carry 1 Then, ??? = 000 Case 4: 1 & carry 1 Observation of Optimal Solution of OSP (a*, b* denotes optimal solution) Optimization Problem Q Given m = (m d …m 0 ) 2, 0 ≤ i ≤ d, l, ξ in {0, 1}, define problem Q(i, l, ξ) as: Find a, b ≥ 0 to minimize B(a) such that B(b) ≤ l a = (m d …m i ) 2 + b + ξ Optimal solution a*(i, l, ξ) and b*(i, l, ξ). Optimal cost: A(i, l, ξ) = B(a*(i, l, ξ)) Optimal Subtraction Problem: Q(0, t, 0) Optimal Structure of Problem Q Treat m as alternating zeros and ones: Exist 0 = i 0 < i 1 < < i 2q = d + 1 m[i 2r + 1 − 1, i 2r ] = (1…1), m[i 2r + 2 − 1, i 2r + 1 ] = (0…0) Solving Optimal Subtraction Problem by Dynamic Programming Case (m j − 1 …m i ) = (0…0) Q(i, l, 0) Q(j, l, 0) Q(i, l, 1) Q(j, l, 0) Q(j, l − j + i, 1) Case (m j − 1 …m i ) = (1…1) Q(i, l, 1) Q(j, l, 1) Q(i, l, 0) Q(j, l, 0) Q(j, l − 1, 1) (A(i, l, 1) = min{A(j, l, 0) + 1, A(j, l − j + i, 1)}) (A(i, l, 0) = min{A(j, l, 0) + j − i, A(j, l − 1, 1)}) Q(i 2r, l, 0) Q(i 2r + 1, l, 0) Q(i 2r + 1, l − 1, 1) Q(i 2r + 2, l, 0) Q(i 2r − 1, l, 1) Q(i 2r, l, 0)Q(i 2r, l − i 2r + i 2r − 1, 1) Q(i 2r + 1, l − i 2r + i 2r − 1, 1) Case: m[i 2r + 2 − 1, i 2r + 1 ] = (0…0) m[i 2r + 1 − 1, i 2r ] = (1…1) Case: m[i 2r + 1 − 1, i 2r ] = (1…1) m[i 2r − 1, i 2r − 1 ] = (0…0) A(i 2r, l, 0) = min{A(i 2r + 1, l − 1, 1), A(i 2r + 2, l, 0) + i 2r + 1 − i 2r } A(i 2r − 1, l, 1) = min{A(i 2r, l, 0) + 1, A(i 2r + 1, l − i 2r + i 2r − 1, 1)} Recursive Relation 012…t 2q − 1111…1 2q − 2y11…1 2q − 3***…* 2q − 4***…* 0***…* Optimal Cost Table T Base Case: T(2q − 1, *) and T(2q − 2, *) General Cases: T(2r, l) = min{T(2r + 1, l − 1), T(2r + 2, l) + i 2r + 1 − i 2r } T(2r − 1, l) = min{T(2r, l) + 1, T(2r + 1, l − i 2r + i 2r − 1 )} T(2r, l) = A(i 2r, l, 0) T(2r − 1, l) = A(i 2r − 1, l, 1) Example: m = ( ) 2, t = q = 6 i 0 = 0, i 1 = 4, i 2 = 5, i 3 = 6, i 4 = 8, i 5 = 10 Optimal Cost: 2 b* = ( ) 2 a* = ( ) 2 Optimal Solution: circuit#cubes#inputs #minterms (hex) lower bound upper bound newapla exp shift21197FF01212 newcond in in bca x1dn802749E0D80310 ts FFF8216 Results on modified Espresso benchmarks: Upper Bound Optimal! Q(i 0, t, 0) Q(i 1, t 1, 1) Q(i 2, t 2, 0) Q(i 3, t 3, 1) Q(i 2q − 4, t 2q − 4, 0) Q(i 2q − 3, t 2q − 3, 1)Q(i 2q − 1, t 2q − 1, 1) Q(i 2q − 2, t 2q − 2, 0) Q(0, t, 0)