Automatic Generation of Staged Geometric Predicates Aleksandar Nanevski, Guy Blelloch and Robert Harper PSCICO project

Slides:



Advertisements
Similar presentations
Roundoff and truncation errors
Advertisements

Fabián E. Bustamante, Spring 2007 Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time.
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
Fast Algorithms For Hierarchical Range Histogram Constructions
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
CENG536 Computer Engineering Department Çankaya University.
Type Checking.
Floating Point Numbers
1cs542g-term CS542G - Breadth in Scientific Computing.
University of Washington Today Topics: Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties.
12 April 2013Lecture 2: Intervals, Interval Arithmetic and Interval Functions1 Intervals, Interval Arithmetic and Interval Functions Jorge Cruz DI/FCT/UNL.
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2007 Geometric Modeling.
Carnegie Mellon Adaptive Mapping of Linear DSP Algorithms to Fixed-Point Arithmetic Lawrence J. Chang Inpyo Hong Yevgen Voronenko Markus Püschel Department.
Floating-Point and High-Level Languages Programming Languages Spring 2004.
1 Foundations of Interval Computation Trong Wu Phone: Department of Computer Science Southern Illinois University Edwardsville.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Simple Data Type Representation and conversion of numbers
Numerical Computations in Linear Algebra. Mathematically posed problems that are to be solved, or whose solution is to be confirmed on a digital computer.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Lecture 2 Number Representation and accuracy
CISE301_Topic11 CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4:
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
Computer Science Engineering B.E.(4 th sem) c omputer system organization Topic-Floating and decimal arithmetic S ubmitted to– Prof. Shweta Agrawal Submitted.
Round-off Errors.
Algorithms and Algorithm Analysis The “fun” stuff.
CSC 221 Computer Organization and Assembly Language
P.1 Real Numbers. 2 What You Should Learn Represent and classify real numbers. Order real numbers and use inequalities. Find the absolute values of real.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2010 Shewchuck 2D Triangular Meshing.
Copyright © Cengage Learning. All rights reserved. Fundamental Concepts of Algebra 1.1 Real Numbers.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
CMSC 330: Organization of Programming Languages Operational Semantics.
Sources of Computational Errors FLP approximates exact computation with real numbers Two sources of errors to understand and counteract: 1. Representation.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
William Stallings Computer Organization and Architecture 8th Edition
Introduction to Numerical Analysis I
Types CSCE 314 Spring 2016.
Topics IEEE Floating Point Standard Rounding Floating Point Operations
CS 232: Computer Architecture II
PROGRAMME F1 ARITHMETIC.
Chapter 2 ERROR ANALYSIS
Classroom Examples of Robustness Problems in Geometric Computations
Introduction to Scientific Computation
Objective of This Course
Arithmetic Logical Unit
ECEG-3202 Computer Architecture and Organization
Chapter 7 Expressions and Assignment Statements.
Classroom Examples of Robustness Problems in Geometric Computations
CS213 Floating Point Topics IEEE Floating Point Standard Rounding
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

Automatic Generation of Staged Geometric Predicates Aleksandar Nanevski, Guy Blelloch and Robert Harper PSCICO project

2 Geometric Predicates does C lie left/right/on the line AB? does D lie in/out/on the circle ABC? Orientation test ( in convex hull ) Incircle test ( in Delaunay triangulation ) C A B A B C D Programs need to test relative positions of points based on their coordinates. Simple examples (in 2D):

3 Geometric Predicates (cont’d) Orientation(A, B, C) = We only consider the sign of an expression involving +, - and £

4 Convex Hull Miscomputed A B C A B C Using Orientation Predicate in exact arithmetic Using Orientation Predicate in floating-point arithmetic D E D E !! Floating point arithmetic errs inconsistently !!

5 Floating-point Filters let F = E (X) in floating point if F > error bound then 1 else if –F > error bound then –1 else increase precision and repeat or switch to exact arithmetic Get correct sign (-1, 0 or 1) of an exact expression E using floating-point! “filters out” the easy cases If the correct result is 0, must go to exact phase

6 Current Methods Interval arithmetic (R.E. Moore, U. Kulisch) +little modification to the source program -does not perform well in low degrees Single-phase filters (Fortune & Van Wyk, LEDA) +compiler available -surpassed by multi-phase filters

7 Current Methods (cont’d) Multi-phase filters (J. Shewchuk) four phases of increasing precision +re-use of results from earlier phases +between 8-35% slower than fp implementation -requires estimating rounding errors -involved and hard to implement: Shewchuk’s Insphere C implementation >500 lines of code -only existing are 2D and 3D Orientation and Insphere predicates, but we need more

8 Functional program COMPILER numerical analysis Staged geometric predicate

9 Contributions Source language expression involving +, -, £ arithmetic to be perceived as exact nested anonymous functions (staging) Compiler to ML (or C) multi-phase target code error bounds estimated automatically formally specified (so, can argue correctness)

10 Staging A C To test a set of points for position with respect to line AC: -compute as much as possible knowing only A and C -return the remaining work as function -apply this function to each of the points

11 Overview Introduction  Arbitrary precision arithmetic and computing in phases Stage compilation Performance Conclusions and Future Work Overview

12 Notation Exact Floating point +-£©ª­ Operations: Precision p = #bits in mantissa Machine Epsilon - if operation result is 1.0, then the rounding error is smaller than

13 Error recovery Theorem. (Knuth) If x = a © b, the rounding error of x can be recovered by floating-point operations. If  is the rounding error, and c = x ª a then So exactly.

14 How to Increase Precision? (D. Priest) Sorted list of fp-numbers arbitrary precision £ £ £ 2 10 Knuth’s theorem: Pair (x,  ) twice the precision. Expansion = list of magnitude decreasing non- overlapping floats

15 Phases and re-use (J. Shewchuk) Arbitrary precision arithmetic phases can reuse the results of their predecessors. Example: Let a 1 – b 1 = x 1 +  1 and a 2 – b 2 = x 2 +  2. Expand E as

16 Phases and re-use (cont’d) Strategy for finding the sign of Evaluate E in phases, increasing precision on demand. Example: floating point phase exact phase

17 Reusing results

18 Reusing results

19 Reusing results

20 Reusing results

21 Overview Introduction  Arbitrary precision arithmetic and computing in phases  Stage compilation Performance Conclusion and Future Work Overview

22 Source Language Basic arithmetic operations: +, -, £, unary -, sq Assignments: val x = some expression Nested anonymous functions Example: Implicit sign test at the last assignment.

23 Stage compilation Every stage compiled into: -floating-point code (phase A) -code for estimating the rounding error Later phases (B, C and D) “suspended” until explicitly executed

24 Stage 1 Helper code: - -modules for arbitrary precision arithmetic Compiler output: A B C D

25 Stage 2 B A C D

26 Overview Introduction  Arbitrary precision arithmetic and computing in phases  Stage compilation  Performance Conclusion and Future Work Overview

27 Performance Experiments to match Shewchuk’s hand-generated predicates Target language C No staging! Uniform Random Point Distribution Shewchuk’s version Automatically generated version Slowdown Orient2D0.208 ms0.249 ms1.20 Orient3D0.707 ms0.772 ms1.09 InCircle6.440 ms5.600 ms0.87 InSphere ms ms2.39

28 Performance (cont’d) 2D Delaunay Triangulation Shewchuk’s version Automatically generated version Slowdown uniform random 1187 ms1410 ms1.19 tilted grid 2060 ms3678 ms1.78 co-circular1190 ms1578 ms1.33 Between 1 and 2.4 times slower than hand-generated code Possibility for improvement with a better translation to C

29 Future Work Extend the language: -multiplication by 2 n doesn’t introduce errors. -summation of more than 2 elements can be done quicker. Evaluate the effects of staging. Allow better control over the FP arithmetic in SML. -processor flags -precision of internal FP registers Design a language that can compile and run the predicates -run-time code generation and meta-programming -application: robust solid modeler

30 Conclusions Automated conversion of exact predicates into floating point code: preserves correctness of computation despite rounding compile-time error analysis nested anonymous functions (staging) performance of generated predicates close to hand-generated code Formal specification of the compiler. More control needed over floating point in SML. -processor flags -precision of internal FP registers Compiler can be found at

31 Operations on Expansions ( arbitrary precision arithmetic ) Example: Adding two expansions

32 Source Language Basic arithmetic operations: +, -, £, sq, unary – Assignments: val x = some expression Nested anonymous functions (staging)

33 A B C D Compiling a Program

34 Compiling a Program (cont’d) A reused

35 Here goes example for Orient2D in SML or C type pnt=real*real fun orient(A:pnt, B:pnt, C:pnt)= let val (a1, a2) = A val (b1, b2) = B val (c1, c2) = C val d = (c1-a1)*(c2-b2) - (c2-a2)*(c1-b1) in if d > 0 then Left else if d < 0 then Right else On end Nothing! They are just often mistaken for real numbers.

36 What’s Wrong With Floating Point Numbers? Floats are unevenly distributed on the real axis, thus introducing rounding errors in the computation.

37 What’s Wrong? (cont’d) Example: Assume precision of 2 decimal digits. Denote © the operation of (rounded) addition on floats. Floats are a subset but NOT a subtype of rationals and reals.

38 Types of Numbers Real numbers Usually assumed when developing or proving algorithms Basic operations not computable + - Rational numbers Closed under basic operations Slow + - Floating-point numbers Fast Not closed under basic arithmetic operations (rounding errors) Do not satisfy usual laws like associativity, distributivity + - -

39 Phase A Compilation Judgment. Selected rules

40 Phase B Compilation Judgment. Selected rules

41 Operations on Expansions Example: Adding a double to an expansion.

42 Overlapping and Machine  … … …000.10… …01011 p bits  and x do not overlap  · 2 -p x. In IEEE double precision, p=53.

43 Phases of Increasing Precision let R = F (X) in floating point if abs(R) > estimated error bound then sign(R) else increase precision and repeat or switch to exact arithmetic floating point phase intermediate phases exact phase Finitely many intermediate phases!

44 Arithmetic Rational numbers + exact - slow Floating-point numbers - inexact + fast

45 Non-overlapping. 0000…………… …………… … … …000.10… …01011 The rounded sum x and its rounding error  do not overlap. Mathematically,

46 Expansions and Compiler let R = F (X) in floating point if R > error bound then 1 else if –R > error bound then –1 else increase precision and repeat or switch to exact arithmetic “filters out” the easy cases compilation Exact expression F Use expansions for more precise computations

47 Phases and Compiler let R = F (X) in floating point if R > error bound then 1 else if –R > error bound then –1 else R2 = phase B if abs(R2) > error bound then sign(R2) else R3 = phase C if abs(R3) > error bound then sign(R3) else R4 = phase D; (* exact phase *) sign (R4) compilation Exact expression F

48 Bounding the Rounding Error Floating-point operations are correctly rounded. Consequence: for any operation ¢ 2 {+, -, £ } Notice:  is static part of the error while |x ¯ y| is dynamic.

49 Bounding Error of Composite Expressions If X 1 = x 1 §  1 p 1 and X 2 = x 2 §  2 p 2 then

50 Error Bounds and Compilation Static error bound -Obtained EXACTLY in compile-time. -Rounded and then emitted into the target program as a floating-point constant. Dynamic error bound -Code must be generated for its computation and emitted into the target program.

51 Error Bounds and Compilation (cont’d) let R = F (X) in floating point dynamic_error = D (X) error = static_error * dynamic_error if R > error then 1 else if –R > error then –1 else jump to phases B, C and D compilation Exact expression F

52 Compilation example Source expression c – (a + b) 2 Target Standard ML program:

53 Source Language Basic arithmetic operations: +, -, £, sq, unary - Assignments: val x = some expression Nested anonymous functions

54 Staging (cont’d)

55 Overview Introduction Arbitrary precision arithmetic and computing in phases Multi-stage filters Performance Conclusion and Future Work