560 likes | 664 Views
Verification & Synthesis of Arithmetic Datapaths using Finite Ring Algebra. Priyank Kalla Electrical and Computer Engineering University of Utah Salt Lake City, UT-84112. Research Group Members. Graduate Students : Namrata Shekhar – PhD RTL Verification of Arithmetic Datapaths
E N D
Verification & Synthesis of Arithmetic Datapaths using Finite Ring Algebra Priyank Kalla Electrical and Computer Engineering University of Utah Salt Lake City, UT-84112
Research Group Members • Graduate Students: • Namrata Shekhar – PhD • RTL Verification of Arithmetic Datapaths • Sivaram Gopalakrishnan – PhD • RTL Synthesis of Arithmetic Datapaths • Vijay Durairaj – PhD + Chris Condrat – BS/MS • SAT & SAT-based Decision Procedures • Collaborators: • Prof.Florian Enescu + Brandon • Mathematics & Statistics, Georgia State Univ.
Outline • Introducing the Problems • Equivalence Verification & High-Level Synthesis • Applications: Fixed Point Arithmetic, Polynomial Signal Processing, Audio/Video/Multimedia DSP • Modeling: Poly-Functions over Finite Integer Rings • Previous Work: CAD & Symbolic Computer Algebra • Contributions • Vanishing Polynomials, Canonical Forms for Verification • Polynomial Reduction + Decomposition for Synthesis • Algorithm Design & Experimental Results • Open Problems & Challenges: CAD + Algebra
Polynomials over Bit-Vectors? • Quadratic filter design for polynomial signal processing • y = a0 . x12 + a1 . x1 + b0 . x02 + b1 . x0 + c . x0 . x1
Bit-Vector Arithmetic = %2m Algebra • Represent integers as a vector of bits • Bit x0represents values 0 or 1 • Vector X[1:0] = {x1, x0} represents integers • 00, 01, 10, 11 (4 values from 0 to 3) • Bit-vector of size m: integer values in 0,…, 2m-1 • Vector X[m-1 : 0] represents integers reduced % 2m 2-bit 2-bit + * 3-bit 4-bit 2-bit 2-bit ADDER MULTIPLIER
16-bit 8-bit * 32-bit * 8-bit Fixed-size (m) bit-vector arithmetic Polynomials reduced %2m Algebra over the ring Z2m Fixed-Size (m) Data-path: Modeling • Control the datapath size: Fixed size bit-vectors (m) 16-bit 16-bit * 16-bit * 16-bit • Bit-vector of size m: integer values in 0,…, 2m-1
Fixed-Size Data-path: Implementation • Signal Truncation • Keep lower order m-bits, ignore higher bits • f % 2m≡ g % 2m • Fractional Arithmetic with rounding • Keep higher order m-bits, round lower order bits • f - f %2m≡ g - g%2m 2m 2m • Saturation Arithmetic • Saturate at overflow • If( x[7:0] > 255 ) then x[7:0] = 255; • Used in image-processing applications
DFF Example: Anti-Aliasing Function • F = 1 = 1 = 2√a2 + b2 2√x [Peymandoust et al, TCAD‘03] • Expand into Taylor series • F ≈ 1 x6 – 9 x5 + 115 x4 64 32 64 – 75 x3 + 279 x2 – 81 x 16 64 32 + 85 64 • Scale coefficients; Implement as bit-vectors coefficients coefficients a b x = a2 + b2 x MAC F
Example: Anti-Aliasing Function • F1[15:0], F2[15:0], x[15:0] • F1 = 156x6 + 62724x5 + 17968x4 + 18661x3 + 43593 x2 + 40244x +13281 • F2 = 156x6 + 5380x5 + 1584x4 + 10469x3 + 27209 x2 + 7456x + 13281 • F1≠ F2 ; F1[15:0] = F2[15:0]; F1 % 216 = F2 % 216 • Transform the problem • F1 - F2 = 57344x5 + 16384x4 + 8192x3 + 16384x2 + 32768x ≡ 0 % 216 • F1 - F2 : Vanishing polynomial
20-bit 8-bit * 32-bit * 12-bit Multiple Word-Length Operands • Bit-vector operands with different word-lengths • Input variables : {x1,…, xd} Output variables: f, g • Input bit-widths: {n1,…, nd} Output width : m • Model as polynomial function
Example: Digital Image Rejection Unit inputA[11:0], B[7:0]; outputY1[15:0], Y2[15:0]; Y1 ≠ Y2 • Y1[15:0] = Y2[15:0] • Y1 % 216 ≡ Y2 % 216
Previous Work: Function Representations • Boolean Representations (f: B → B) • BDDs, MTBDDs, ADDs etc. • Moment Diagrams (f: B → Z) • BMDs, K*BMDs, HDDs etc. • Canonical DAGs for Polynomials (f: Z → Z) • Taylor Expansion Diagrams (TEDs) • Required: Representation for f: Z2m → Z2m
Previous Work: Others • SAT and MILP-based techniques • Suitable for linear/multi-linear forms • Word-level ATPG, congruence closure, co-operative decision procedures • Solve linear congruences under modulo arithmetic • Theorem-Proving (HOL), term-rewriting • Abstract away the data-path size using data independence, symmetry, other abstractions • Here, datapath size (m) defines ring cardinality (Z2m)
Previous Work: Symbolic Algebra • Galois Field Decomposition of Boolean Functions:GF(2m) [Pradhan, 1978 + recent work] • Symbolic Algebra Tools: Singular, Macaulay, Maple, Mathematica, ZEN, NTL, CoCoA • Polynomial equivalence over R, Q, C, Zp • Unique Factorization Domains (UFDs) : Uniquely factorize into irreducibles • Match corresponding coefficients to prove equivalence
Symbolic Algebra in CAD • MODD: DAG representation of polynomials over GF(2m)[Pradhan, IWLS 05, DATE 04] • Guiding Synthesis engines using Groebner’s basis [De Micheli, TCAD 02] • Given polynomial F and Library elements <I1, …, In> • F = h1 I1 + …… + hn In • Again, works over UFDs • Approximate RTL as polynomials over Reals • Theorem Proving [Clarke et al.] • HOL + Mathematica = Analytica
Why is the Problem Difficult? • Z2mis a non-UFD • f = x2 + 6xinZ8can be factorized as f f x x+6 x+2 x+4 • Atypical approach required to prove equivalence
Problem Formulations + Solutions • f (x1, …, xd) % n≡g(x1, …, xd) % n • Proving equivalence is NP-hard [Ibarra, J. ACM ’83] • Vanishing polynomials [ICCD ’05, DATE’06] • f(x) – g(x) ≡ 0 % 2m : Zero Equivalence • An instance of Ideal Membership Testing • Efficient solutions over fields (Groebner’s bases): Z2m[x1,…, xd] ? • Canonical forms [ICCAD ’05] • Unique representations for polyfunctionsover Z2m • Equivalence by coefficient matching • Concepts from Hungerbuhler etal. [J. Sm. Not., ‘06 ]
h: % 2m Ideal x x % 2m 0 f g f – g ? Ideal Membership Testing Z2m Z2m[x1, …, xd] • ( f – g )% 2m = 0 or ( f – g )vanishes % 2m • Membership in the Ideal of all Vanishing Polynomials in Z2m • Grobner's basis? Buchberger's algorithm? • Generate the Ideal!
Ideal Membership Testing in Zp • Fermat’s Little Theorem: • x p≡ x (mod p) or • x p – x ≡ 0 (mod p) • x p –xgenerates the vanishing ideal in Zp[x] • f(x) = 0 % p iff f(x) = (xp-x)g(x) • Zp: Principal Ideal Domain • This does not followin Z2m • Generalize the result from: • %p to %pm to % (any integer) n
h: % 2m Ideal x x % 2m f g f – g ? Ideal Membership Testing 0 Q P • Generate the idealof vanishing polynomials % 2m ? • Vanishing Ideal is finitely generated [Niven et al, Am. Math. Soc., ‘57] • Need an algorithm for membership testing • Representative expression for members of this ideal [Singmaster, J. Num. Th ‘74]
Results From Number Theory • (f-g) % 2m = 0 means that 2m | (f-g) • n! divides a product of n consecutive numbers. • 4! divides 99X 100 X 101 X 102 • Find least n such that 2m|n! • Smarandache Function (SF). • SF(23) = 4, since 23|4! • 2mdivides the product of n = SF(2m) consecutive numbers
Results From Number Theory • f ≡ gin Z23or(f - g) ≡ 0 % 23 • 23|(f - g)inZ23 • 23|4! • 4! divides the product of 4 consecutive numbers Write (f-g) as a product of SF(23) = 4 consecutive numbers • A polynomial as a product of 4 consecutive numbers? • (x+1)
Results From Number Theory • f ≡ gin Z23or(f - g) ≡ 0 % 23 • 23|(f - g)inZ23 • 23|4! • 4! divides the product of 4 consecutive numbers Write (f-g) as a product of SF(23) = 4 consecutive numbers • A polynomial as a product of 4 consecutive numbers? • (x+1)(x+2)
Results From Number Theory • f ≡ gin Z23or(f - g) ≡ 0 % 23 • 23|(f - g)inZ23 • 23|4! • 4! divides the product of 4 consecutive numbers Write (f-g) as a product of SF(23) = 4 consecutive numbers • A polynomial as a product of 4 consecutive numbers? • (x+1)(x+2)(x+3)
Results From Number Theory • f ≡ gin Z23or(f - g) ≡ 0 % 23 • 23|(f - g)inZ23 • 23|4! • 4! divides the product of 4 consecutive numbers Write (f-g) as a product of SF(23) = 4 consecutive numbers • A polynomial as a product of 4 consecutive numbers? • (x+1)(x+2)(x+3)(x+4)
Basis for factorization • S0(x) = 1 • S1(x) = (x + 1) • S2(x) = (x + 1)(x + 2) = Product of 2 consecutive numbers • S3(x) = (x + 1)(x + 2)(x + 3) = Product of 3 consecutive numbers • … • … • Sn(x) = (x + n) Sn-1(x) = Product of n consecutive numbers Rule 1: Factorize into atleast Sn(x) to vanish, where n = SF(2m).
Example: Vanishing polynomial • 4th degree polynomial p in Z23 ; SF(23) = 4 • p = x4 +2x3 + 3x2 + 2x • p can be written as a product of 4 consecutive numbers. • or p = (x+1)(x+2)(x+3)(x+4) = S4(x) inZ23. • p is a vanishing polynomial.
Example: Vanishing polynomial module fixed_bit_width (x, f, g); input [2:0] x; output [2:0] f, g; assign f[2:0] = x2 + 6x – 3; assign g[2:0] = 5x2 + 2x + 5; • h(x) = f(x) – g(x) = 4x2 + 4x • h(x) ≡0 for all values of x in {0,…,7} • 4x2+4x not equal to (x+1)(x+2)(x+3)(x+4) • Required: To show that h(x) is a vanishing polynomial in Z23
Constraints on the Coefficient • h(x) = 4x2 + 4x = 4(x+1)(x+2) • In Z23, SF(23) = 4. Product of 4 consecutive numbers: • S4(x) = (x+1) (x+2) (x+3) (x+4) Rule 2: Coefficient has to be a multiple of bk =2m/gcd(k!, 2m) • Here, Coefficient of h(x) = 4, Degree of h(x) = 2 • b2 = 23/gcd(2!, 23) = 4 is a multiple of the coefficient
Constraints on the Coefficient • h(x) = 4x2 + 4x = 4(x+1)(x+2) compensated by constant • In Z23, SF(23) = 4. Product of 4 consecutive numbers: • S4(x) = (x+1) (x+2) (x+3) (x+4) missing factors Rule 2: Coefficient has to be a multiple of bk=2m/gcd(k!, 2m) • Here, Coefficient of h(x) = 4, Degree of h(x) = k = 2 • b2 =23/gcd(2!, 23) = 4 is a multiple of the coefficient
Deciding Vanishing Polynomials • Polynomial F in Z2m vanishes if • n = SF(2m),i.e. the least n such that 2m|n! • Fn is an arbitrary polynomial in Z2m[x] • akis an arbitrary integer • bk = 2m/gcd(k!,2m) F = FnSn + Σn-1ak bk Sk k=0 Rule 1 Rule 2
Input: poly, 2m Calculate n = SF(2m) k = n: Reduce according to Rule 1 Divide by Sn If remainder is zero, F = FnSn, else Continue poly = 4x2 + 4xin Z23 n = SF(23) = 4 k = 4: Divide by S4 Degree (poly) = 2 < degree(S4) = 4 quo = 0, rem = 4x2 + 4x F4 = 0; Continue Algorithm Example 1 • F = FnSn + Σn-1ak bk Sk • k=0
Input: poly, 2m Calculate n = SF(2m) k = n: Reduce according to Rule 1 Divide by Sn If remainder is zero, F = FnSn, else Continue poly = 4x2 + 4xin Z23 n = SF(23) = 4 k = 4: Divide by S4 Degree (poly) = 2 < degree(S4) = 4 quo = 0, rem = 4x2 + 4x F4 = 0; Continue Algorithm Example 1 • F = FnSn + Σn-1ak bk Sk • k=0
Reduce according to Rule 2. Divide by Sn-1to S0 Check if quotient is a multiple of bk = 2m/gcd(k!,2m) If remainder is zero, stop. Else, continue k = 3: Divide by S3 degree (poly) = 2 < degree(S3) = 3 quo= 0, rem = 4x2 + 4xcontinue k = 2: Divide by S2 quo = 4; rem = 0 b2 = 23/gcd(2!,23) = 4 a2 = quo/ b2 = 1 ЄZ Algorithm Example 1 • F = FnSn + Σn-1ak bk Sk • k=0 poly = a2.b2.S2 = 1.4.(x+1)(x+2) ≡ 0 in Z23
Reduce according to Rule 2. Divide by Sn-1to S0 Check if quotient is a multiple of bk = 2m/gcd(k!,2m) If remainder is zero, stop. Else, continue k = 3: Divide by S3 degree (poly) = 2 < degree(S3) = 3 quo= 0, rem = 4x2 + 4xcontinue k = 2: Divide by S2 quo = 4; rem = 0 b2 = 23/gcd(2!,23) = 4 a2 = quo/ b2 = 1 ЄZ Algorithm Example 1 • F = FnSn + Σn-1ak bk Sk • k=0 poly = a2.b2.S2 = 1.4.(x+1)(x+2) ≡ 0 in Z23
Example 2 • poly = 5x2 + 3x+ 7 in Z23 • n = SF(23) = 4 • degree (poly) = 2 < n. Skip Rule 1, try Rule 2 • Divide by S2 • quo = 5; rem = 5 + 4x • b2 = 23/gcd(2!,23) = 4 • a2 = quo/ b2 = 5/4 is not inZ • poly does not satisfy Rule 2 • poly is not a vanishing polynomial inZ23
Status of our Work - Extensions • Multiple Variables: Z2m[x1, …, xd] • Given polynomials (f, g) d variables x = <x1, …, xd> over Z2m • Prove that (f-g) = 0 % 2m • What if word-lengths are different too? • x1 Z2n1 , …… , xd Z2nd • No problems! • Straight-forward extensions of previousconcepts • Other approach: Canonical forms of poly-functions
Equivalence classes F1 G1 Polyfunctions over Z2m f F2 g G2 Z2m[x1, …, xd] Z2m • Polynomials over Z2m[x1, …, xd] • Represented by polyfunctions from Z2m[x1, …, xd] to Z2m • F1 % 2m≡ F2 % 2m=> they have thesame underlying polyfunction (f ) • Use equivalence classes of polynomials • Derive representative for each class: Canonical form
Motivating our Approach module fixed_bit_width (x, f, g); input [2:0] x; output [2:0] f, g; assign f[2:0] = 5x2 + 6x - 3; assign g[2:0] = x2 + 2x + 5; • f (x) = 5x2 + 6x - 3 = (x2 + 2x + 5) + (4x2 + 4x) • f (x) = g(x) + V (x) in Z23 • V (x) = 4x2 + 4x ≡ 0 % 23 ; for x in {0,…,7} • f (x) = g (x) + 0 in Z23 • Required: To identify and eliminate such redundant sub-expressions (vanishing)
Vanishing Polynomials for Reducibility • In Z23, sayf (x) = 4x2 • f (x) = f (x) - V(x) • Generate V(x) of degree 2 • V(x) = 4x2 + 4x ≡ 0 % 23 • Reduce by subtraction: • 4x2f (x) – 4x2 + 4x V(x) = - 4x = - 4x % 8 = 4x • 4x2can be reduced to 4x • Degree reduction
Degree Reduction: Requirement • Generate appropriate vanishing polynomial , V(x) • f (x) = axk + a1xk-1 + … V(x) = axk + a2xk-1 + … f (x) – V(x) = bxk-1 + … • V(x):axkis the leading term • Identify constraints on • Degree : k; Coefficient : a • f (x) = axk + … If 2m|ak!, then V(x) = ak! x + k ≡ 0 % 2m k = axk + a1xk-1…..
Coefficient Reduction: Example • Degree is not always reducible • In Z23, f (x) = 6x2 • a = 6, k = 2 • 8 does not divide 6 × 2! • Divide and subtract • 6x2 = 2x2 + 4x2 % 23 • 4x2 can bereduced to 4x • f (x) = 2x2 + 4x : Lower Coefficient
Our Approach • Say f (x) = akxk + ak-1xk-1 + …+ a0 • In decreasing lexicographic order • Required: f (x)in reduced, minimal, unique form • Check if degree can be reduced • Check if coefficient can be reduced • Perform corresponding reductions • Repeat for all monomials …
Experimental Setup • Distinct RTL designs are input to GAUT [U. de LESTER] • Extract data-flow graphs for RTL designs • Construct the corresponding polynomial representations (f, g) • Extract bit-vector size • Find the difference (f-g) and invoke the zero-testing algorithm • Reduce f, g to canonical forms…. • Algorithm implemented in MAPLE • Compare with BMD, SAT and MILP • Complexity: O(kd)
Limitations: Mathematics versus CAD • Finite Ring Algebra = Cannot DIVIDE! • Right shift breaks the model • Overflow arithmetic versus Saturation • Comparators = non-polynomial? • Internal bit-vectors of arbitrary word-lengths • Only Yes/No Equivalence? Find bugs too! • Couple Verification with Simulation! • Arithmetic interfaced with Boolean……
Intermediate Signal Truncation a[7:0] b[7:0] c[7:0] a[7:0] b[7:0] c[7:0] + + ≠ t1[7:0] t2[7:0] + + f1[8:0] f2[8:0] a = 127 b = 1 f1 = 383 c = 255 a = 127 b = 1 f2 = 127 c = 255
Canonize Canonize Canonize Canonize Proposed Solution a[7:0] b[7:0] c[7:0] a[7:0] b[7:0] c[7:0] + + ≠ t1[7:0] t2[7:0] + + f1[8:0] f2[8:0] • Required: Algorithm for reduction to canonical form over
Polynomial Abstraction from RTL If (x > 2b’10) then y = x * x * x Else y = x*x • Traditional modeling • . • Proposed modeling: y as a polyfunction from • : Unique representation • Issues with the proposed abstraction: • Scalability