Presenter MaxAcademy Lecture Series – V1.0, September 2011 Elementary Functions.

Slides:



Advertisements
Similar presentations
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Advertisements

BellRigner – 1/30/2012 Match the graph to the function: f(x) = x 3 – 2x + 2 g(x) = -2x h(x) = x 4 – 2 i(x) = -x 3 – 1 A B C D.
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advanced Piloting Cruise Plot.
Extension Principle Adriano Cruz ©2002 NCE e IM/UFRJ
Chapter 6 Cost and Choice. Copyright © 2001 Addison Wesley LongmanSlide 6- 2 Figure 6.1 A Simplified Jam-Making Technology.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
Visualization Techniques -
ZMQS ZMQS
10.1 Trading Strategies Involving Options Chapter 10.
1 Gauss-Jordan Method. How To complete Problem 2.2 # 29 Produced by E. Gretchen Gascon.
Solve Multi-step Equations
Richmond House, Liverpool (1) 26 th January 2004.
©2004 Brooks/Cole FIGURES FOR CHAPTER 16 SEQUENTIAL CIRCUIT DESIGN Click the mouse to move to the next page. Use the ESC key to exit this chapter. This.
ABC Technology Project
Briana B. Morrison Adapted from William Collins
Function Evaluation Using Tables and Small Multipliers CS252A, Spring 2005 Jason Fong.
VOORBLAD.
Quadratic Inequalities
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Constant, Linear and Non-Linear Constant, Linear and Non-Linear
Squares and Square Root WALK. Solve each problem REVIEW:
Do you have the Maths Factor?. Maths Can you beat this term’s Maths Challenge?
Computer Graphics An Introduction. What’s this course all about? 05/10/2014 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
© 2012 National Heart Foundation of Australia. Slide 2.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Copyright © 2013, 2009, 2006 Pearson Education, Inc. 1 Section 5.4 Polynomials in Several Variables Copyright © 2013, 2009, 2006 Pearson Education, Inc.
Chapter 5 Test Review Sections 5-1 through 5-4.
SIMOCODE-DP Software.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
U1A L1 Examples FACTORING REVIEW EXAMPLES.
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
12 System of Linear Equations Case Study
©2004 Brooks/Cole FIGURES FOR CHAPTER 12 REGISTERS AND COUNTERS Click the mouse to move to the next page. Use the ESC key to exit this chapter. This chapter.
Copyright © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 15 2 k Factorial Experiments and Fractions.
A SMALL TRUTH TO MAKE LIFE 100%
1 Unit 1 Kinematics Chapter 1 Day
PSSA Preparation.
How Cells Obtain Energy from Food
Chapter 30 Induction and Inductance In this chapter we will study the following topics: -Faraday’s law of induction -Lenz’s rule -Electric field induced.
Presenter MaxAcademy Lecture Series – V1.0, September 2011 Dataflow Programming with MaxCompiler.
Presenter MaxAcademy Lecture Series – V1.0, September 2011 Loops and cyclic graphs.
Princess Sumaya University
Copyright 2008 Koren ECE666/Koren Part.9b.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
Presentation transcript:

Presenter MaxAcademy Lecture Series – V1.0, September 2011 Elementary Functions

Motivation How to evaluate functions Polynomial and rational approximation Table-based methods Shift and add methods 2 Lecture Overview

Elementary function are required for compute intensive applications, for example: – 2D/3D graphics: trigonometric functions – Image Processing: e.g. Gamma Function – Signal Processing, e.g. Fourier Transform – Speech input/output – Computer Aided Design (CAD): geometry calculations – and of course Scientific Applications: Physics, Biology, Chemistry, etc… 3 Motivation

3 steps to compute f(x) – Given argument x, find x’=g(x) with x’ in [a,b], and f(x) = h( f( g(x) )) – Step 1: Argument Reduction = g(x) – Step 2: Approximation over interval [a,b] I.e. compute f( g(x) ) – Step 3: Reconstruction: f(x) = h( f(g(x) ) ) 4 Evaluating Functions

Example: sin(float x) float sin(float x){ float y = x mod (π/2); // reduction float r1 = c0*y*y+c1*y+c2; float r2 = c3*y*y+c4*y+c5; return (r1/r2); // rational approx. } c0-c5 are coefficients of a rational approximation of sin(x) in [0, π/2 ]. (note: no reconstruction is needed) 5 Example: sin(x)

x / (0.5 ln 2) = N + r/(0.5 ln 2) x = N (0.5 ln 2) + r exp(x) = 2^ (0.5 N) *exp(r) Step 1: – N = integer quotient of x/(0.5 ln 2) – r = remainder of x/(0.5 ln 2) Step 2: – Compute exp(r) by approximation (e.g. polynomial) Step 3: – Compute exp(x) = 2^ (0.5 N) *exp(r) which is just a shift!! 6 Example f(x) = exp(x)

Polynomial and rational approximations 1 full lookup table Bipartite tables (2 tables + 1 add/sub) Piecewise affine approximation (tables + mult/add) Shift-and-add methods (with small tables) 7 2 nd Step: Approximations in [a,b]

Horner Rule transforms polynomial into a “Multiply- Add Structure” As a consequence, DSP Microprocessors have a Multiply-Add Instruction (Madd) by simply adding another row to an array multiplier. 8 Evaluating Polynomials

Polynomial and Rational Approximation 9 “Rational Approximation”“Polynomial Approximation”

Taylor series finds optimal coefficient for a specific point x=x0. We need optimal coefficient for an entire interval [a,b]. Software such as Maple computes optimal coefficients for polynomial and rational approximations with Remez’s method (a.k.a. minimax coefficients). Bottom line: we can find optimal coefficients for any function and any interval [a,b]. 10 Finding the Coefficients

Full table lookup: N-bit input, M-bit output – Lookup Table Size = M  2 N bits – Delay of a lookup in large tables increases with size! For N > 8 bits we need to use smaller tables: – Add elementary operations to reduce table size Tables + 1 Add/Sub Tables + Multiply Tables + Multiply-Add Tables + Shift-and-Add 11 Table-based Methods

Bi-Partite Tables 12 ̃̃ f(x) Adder Table a 0 (x 0,x 1 ) Table a 0 (x 0,x 1 ) Table a 1 (x 0,x 2 ) Table a 1 (x 0,x 2 ) x0x1x2x0x1x2 x0x1x2x0x1x2 n0n0 n1n1 n2n2 p0p0 p1p1 p

f(x)nn 0, n 1, n 2 SBTMStandardCompression 1/x167, 3, x x x /x208, 5, x x x /x249, 7, x x x √x√x165, 5, x x x √x√x206, 7, x x x √x√x248, 7, x x x sin (x)166, 4, x x x sin (x)207, 4, x x x sin (x)248, 8, x x x log 2 (x)167, 3, x x x log 2 (x)208, 5, x x x log 2 (x)249, 7, x x x x2x 165, 5, x x x x2x 206, 7, x x x x2x 248, 7, x x x Symmetric Bipartite Tables Sizes

f(x) = a  x+b with a,b stored in tables X m are leading bits of X which determine which linear piece of f(x) should be used. 14 Table + Multiply Add TABLE Mult Add x xmxm f(x)

Fixed shift in Hardware = shifted wiring  no cost Fixed shift = multiply by 2 x Modify Multiply-Add algorithms to only multiply by powers of 2. Is this possible ? How do we choose the k’s, c’s? 15 Shift-and-Add Methods

Iterations: e(i) = table lookup μ = {-1,0,1} di = ±sign(z(i)) 16 CORDIC z0 y x add/sub constant add Parallel CORDIC

CORDIC on Xilinx XC X Y X’ Y’ { X’, Y’ }

In general we trade area for speed. 18 Area-Time Tradeoff small fast Tables+Add/Sub Tables + Mult-Add Shift-and-Add

3 steps to compute f(x) –Step 1: Argument Reduction = g(x) –Step 2: Approximation over interval [a,b] 1.Lookup Table for a small number of bits. 2.Lookup Table + Add/Sub => Bi-partite tables 3.Lookup Table + Mult-Add => Piecewise Linear Approx. 4.Shift-and-Add Methods => e.g. CORDIC 5.Polynomial and Rational Approximations –Step 3: Reconstruction = h(x) 19 Summary

J.M. Muller, “Elementary Functions,” Birkhaeuser, Boston, Story, S. and Tang, P.T.P., "New algorithms for improved transcendental functions on IA-64," in Proceedings of 14th IEEE symposium on computer arithmetic, IEEE Computer Society Press, D.E. Knuth, “The Art of Computer Programming”, Vol 2, Seminumerical Algorithms, Addison-Wesley, Reading, Mass., C.T. Fike, “Computer evaluation of mathematical functions,” Englewood Cliffs, N.J., Prentice-Hall, L.A. Lyusternik, “Handbook for computing elementary functions”, available in english translation. 20 Further Reading on Function Evaluation

1.Write a MaxCompiler kernel which takes an input stream x and computes a polynomial approximation of sin(x). Draw the dataflow graph. 2.Write a MaxCompiler kernel that implements a CORDIC block. Vary the number of stages in the CORDIC and evaluate the impact on the result. 21 Exercises