The Synthesis of Combinational Logic to Generate Probabilities Weikang Qian Marc Riedel Kia Bazargan David Lilja Electrical & Computer Engineering University of Minnesota A C B Motivation • Randomness and noise in nanoscale circuits o Traditional view: impediment o A novel view: resources for probabilistic computation 2 Motivation • Random sources: Generate probabilities needed by probabilistic algorithms Stochastic Bit Streams: Probability 3/6 0, 1, 1, 0, 1, 0 … Random Sources Deterministic Hardware 1, 1, 0, 1, 0, 1 Probability 4/6 Issue: Costly to generate many different probabilities directly from random sources! Solution: Synthesize combinational logic to generate probabilities! 3 Basic Problem Other Probabilities Needed Set S of Input Probabilities (|S| small) p1 Random Sources p2 p3 Choose Set S ? Logic Circuit ? q1 q2 q3 q4 4 Assumptions • All signals in the circuit are random Boolean variables. • Elements of set S can be used many times. • All inputs are independent. Independent p1 p1 p2 p2 p3 p3 p3 logic circuit q 5 Conventions • “Probability”: Probability of a signal being logical one • “Synthesize probability q”: Synthesize the circuit generating probability q 6 Example 0.4 0.5 P(x P(x==1)1)==0.4 0.4 0,0,1,0,1,0,1,0,1,0 0,1,0,1,0,0,1,1,0,0 P(x = 1) = 0.4 xxx y y 1,0,1,1,0,1,0,0,0,0 1,0,1,1,0,0,1,0,0,1 1,0,0,1,1,0,0,1,1,0 0.2 Logic Circuit 0.3 0.6 P(z 1) 0.2 P(z===1) 1)===0.3 0.6 P(z zz z 0,0,0,1,0,0,1,0,0,0 0,1,0,0,1,0,1,1,1,1 0,1,0,0,0,1,0,0,0,1 AND NOR P(y= =1)1)==0.5 0.5 P(y P(z = 1) = P(x = 0) P(z==1)1)==P(x P(x==1)0)P(y P(y==1)0) P(z 7 Generating Decimal Probabilities Decimal Probabilities Choose Set S = {p1, p2, p3} p1 p2 p3 Large Cost! |S| Small! Logic Circuit • Found Set S for o |S| = 2 o |S| = 1 q1 q2 q3 q4 8 Generating Decimal Probabilities Theorem 1: With S = {0.4, 0.5}, we can synthesize arbitrary decimal output probabilities. Example: Synthesize q = 0.757 (Black dots are inverters) 0.4 0.5 0.5 0.4 0.5 0.5 0.5 0.4 0.6 AND 0.7 AND 0.35 0.86 AND AND 0.43 AND 0.785 AND 0.6075 AND 0.757 9 Proof of Theorem 1 • Constrain design to AND gates and inverters o AND gates: x ∙ y o Inverters: 1 − x • Constructive proof o Induction on the number of digits n • Base case 0.1 = 0.4 × 0.5 × 0.5, 0.2 = 0.4 × 0.5 0.3 = (1 − 0.4) × 0.5 0.6 / 0.7 / 0.8 / 0.9 = 1 − 0.4 / 0.3 / 0.2 / 0.1 • Inductive step o Assume true for (n − 1). Show true for n. 10 Proof of Inductive Step q: n digits; w: (n−1) digits; u = 10nq, numerator of q 0 ≤ q ≤ 0.2, u = 2k conversions w = 5q q = 0.4 × 0.5 × w 0 ≤ q ≤ 0.1, u = 2k+1 w = 10q q = 0.4×0.5×0.5×w 0.1 < q ≤ 0.2, u = 2k+1 w = 2 − 10q q = (1−0.5w)×0.4×0.5 0.2 < q ≤ 0.4, u = 4k w = 2.5q q = 0.4 × w cases q … 11 Algorithm from Theorem 1 Example: Synthesize q = 0.757 from S = {0.4, 0.5} 0.757 1− 0.243 ×0.4 0.6075 1 − 0.3925 ×0.5 0.785 1 − 0.215 ×0.5 0.43 0.4 1− 0.6 ×0.5 0.3 1− 0.7 ×0.5 ×0.4 0.14 1 − 0.86 ×0.5 0.35 Base case cases 0 ≤ q ≤ 0.2, u = 2k 0 ≤ q ≤ 0.1, u = 2k+1 … 0.2 < q ≤ 0.3, u = 2k+1 0.3 < q ≤ 0.4, u = 2k+1 0.4 < q ≤ 0.5 0.5 < q ≤ 1 conversions w = 5q w = 10q … w = 10q − 2 w = 4 − 10q w = 1 − 2q w = 1− q 12 Circuit Synthesized 0.4 0.757 1− 1− 0.6 0.243 (Black dots are inverters) ×0.5 ×0.4 0.3 1− 0.6075 0.4 0.5 0.5 0.4 0.5 0.5 0.5 0.4 0.7 1− ×0.5 ×0.4 0.14 1 − 0.86 ×0.5 0.35 0.3925 0.6 AND ×0.5 0.785 1− ×0.5 0.43 0.7 AND 0.35 0.86 AND AND 0.215 0.43 AND 0.785 AND 0.6075 AND 0.757 13 Generating Decimal Probabilities Question: Does there exist a set S of size one which can generate arbitrary decimal probabilities? p p p combinational circuit q p Yes! 14 Proof • There exists a p (≈ 0.1295) in the unit interval such that • Boolean function with , has output probability • Boolean function with , has output probability • Thus, 0.4 and 0.5 can be generated from p. (Use Theorem 1.) 15 Implementation • Focus on generating decimal probability form S = {0.4, 0.5}. • Goal: Reduce circuit depth. 0.4 0.5 0.5 0.4 0.5 0.5 0.5 0.4 0.6 AND 0.7 AND 0.35 0.86 AND AND 0.43 AND 0.785 AND 0.6075 AND 0.757 16 Balancing • Logic Level Optimization: Balancing Fanin Cone Fanin Cone AND AND a AND ... a b ... AND b Before Balancing After Balancing (a and b are primary inputs) 17 Factorization of Fractions • High Level Optimization: Factorization of Fractions Example: Synthesize q = 0.49 from S = {0.4, 0.5} Basic Factor 0.4 0.5 0.5 0.5 0.4 0.5 0.4 AND AND 0.2 0.25 AND AND AND 0.1 AND AND 0.49 0.7 AND 0.4 0.5 0.5 0.98 0.49 0.7 18 Factorization of Fractions • Quality of factor pair a = al × ar – Heuristic: Max{Digits(al), Digits (ar)} – Digits(x) ↑ Depth of the circuit for fraction x ↑ Example: 0.1764 = 0.252×0.7 = 0.63×0.28 0.252 Sub-Ckt 1 AND Sub-Ckt 1 0.1764 0.63 AND 0.7 Sub-Ckt 2 better! 0.1764 0.28 Sub-Ckt 2 19 Factorization of Fractions • Consider both q and 1 − q – Example: q = 0.37, then 1 − q = 0.63 has better factor pair 0.7×0.9 • When both q and 1 − q cannot be factorized – Use conversions from Theorem 1 to get w with one less digit than q. – Factorize w. 20 Experimental Results • ‘Basic’: Algorithm based on Theorem 1 + Balancing • ‘Factor’: Algorithm based on Factorization + Balancing • Compare number of AND gates and depth of synthesized circuits • Present average results for different numbers of digits n 21 Experimental Results Average number of AND gates vs. number of digits n 22 Experimental Results Average depth vs. number of digits n 23 Summary • Considered the problem of generating required decimal probabilities. • Gave a pair of probabilities / a single probability for generating arbitrary decimal probabilities. • Proposed implementation based on balancing and factorization of fractions to reduce the depth of the circuit. • Also considered synthesis with different assumptions: – Whether the probabilities are duplicable or not. – Whether we are free to choose set S. 24 Future Work • Tradeoff between circuit area and approximation error – Synthesize q = 0.251: an AND gate realizing 0.25 but with error 0.001? • Correlation on input probabilities • Accuracy of input probabilities – p1 = 0.4 becomes 0.4 + δ 25 Thank You! 26 Problem Flavors • Set S: pre-determined / free to choose • Elements: duplicable / non-duplicable Independent p1 p1 p2 p2 p3 p3 p3 Independent p1 logic circuit q p2 logic circuit q p3 Duplicable Non-Duplicable 27 Problem Variations Generate Decimal Probability Set S Elements Determined? Duplicable? Case One No Yes Case Two Yes No Case Three No No Case Four Yes Yes 28 Case Two • Set S given, elements non-duplicable • Essentially to fill in the output column of the truth table • We know the probability of input combination – e.g., r2 = (1 − p1) p2 (1 − p3) p1 x1 p x2 2 p3 x3 logic circuit unknown known z q 29 Case Two: Solution • If z0 = z3 = z6 = 1, the output probability is po = r0 + r3 + r6 • In general, • Generally, a target probability q cannot be realized exactly. Find least error approximation Given q, we try to find zi’s to be either 0 or 1 to minimize the objective function --- solved by linear programming 30 Case Three • Set S not Given and Elements non-Duplicable p1 x1 p x2 2 p3 x3 logic circuit z q Question: What is the optimal set S = {p1, p2, p3}? An optimal set S is 31