icing
play

Icing Supporting Fast-Math Style Optimizations in a Verified - PowerPoint PPT Presentation

Icing Supporting Fast-Math Style Optimizations in a Verified Compiler Heiko Becker , Eva Darulova, Magnus Myreen, Zachary Tatlock How we develop programs readability over performance 2 How we develop programs readability over performance


  1. Icing Supporting Fast-Math Style Optimizations in a Verified Compiler Heiko Becker , Eva Darulova, Magnus Myreen, Zachary Tatlock

  2. How we develop programs readability over performance 2

  3. How we develop programs readability over performance compiler should make program fast 2

  4. How we develop programs readability over performance Compiler optimizations are compiler should make program fast a vital part of the development process 2

  5. The need for understandable optimizations 3

  6. The need for understandable optimizations 3

  7. The need for understandable optimizations 3

  8. The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4

  9. The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; CompCert C compiler Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4

  10. The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; CompCert C compiler Formal Verification of a Realistic Compiler 2019: Lööw et al ; CakeML & Silver Verified Compilation on a Verified Processor 4

  11. The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Where are floating-points? Formal Verification of a Realistic Compiler 2019: Lööw et al ; Verified Compilation on a Verified Processor 4

  12. The long road of compiler verification 1967: McCarthy, Painter ; Correctness of a Compiler for Arithmetic Expressions (Integer’s only) 2009: Leroy ; Formal Verification of a Realistic Compiler 2015: Boldo et al. ; Verified Compilation of Floating-Point Programs 2019: Lööw et al ; Verified Compilation on a Verified Processor 4

  13. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) 5

  14. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations 5

  15. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • do not preserve IEEE754 semantics 5

  16. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • do not preserve IEEE754 semantics • give no guarantees on the result 5

  17. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • give no guarantees on the result 5

  18. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics • give no guarantees on the result 5

  19. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics • give no guarantees on the result • guarantee preserving literal meaning 5

  20. The state-of-the-art for fast-math Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • apply aggressive optimizations • apply no floating-point optimizations We need a semantics to • do not preserve IEEE754 semantics • fully preserve IEEE754 semantics handle fast-math optimizations • give no guarantees on the result • guarantee preserving literal meaning in verified compilers 5

  21. Contributions Icing , a nondeterministic semantics for floating-points: • Support for subset of gcc’s fast-math optimizations • Optimization with fine-grained control • Implementation of three optimizers • Verification in HOL4 • Connection to CakeML 6

  22. Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7

  23. Optimizations in Icing Example Optimizations: Commutativity Source Target 𝑏 + 𝑐 𝑐 + 𝑏 (preserves IEEE754) 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7

  24. Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 Associativity 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) (no IEEE754) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7

  25. Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) FMA introduction (locally more accurate) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7

  26. Optimizations in Icing Example Optimizations: Source Target 𝑏 + 𝑐 𝑐 + 𝑏 𝑐 × 𝑏 𝑏 × 𝑐 𝑏 + 𝑐 + 𝑑 𝑏 + (𝑐 + 𝑑) s t 𝑏 × 𝑐 × 𝑑 𝑏 × (𝑐 × 𝑑) 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 7

  27. Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 8

  28. Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 floating-point word 8

  29. Floating-Point Values in Icing IEEE754: Icing: 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 8

  30. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 8

  31. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 8

  32. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 3.5 + (2.0 + 1.5) = 12.25 8

  33. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = 8

  34. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition + 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = + 3.5 2.0 1. 5 8

  35. Floating-Point Values in Icing IEEE754: Icing: + 3.5 + 2.0 = 5.5 3.5 + 2.0 = floating-point word 3.5 2.0 value tree for addition + 3.5 + (2.0 + 1.5) = 12.25 3.5 + (2.0 + 1.5) = + 3.5 2.0 1. 5 8

  36. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) 9

  37. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) 9

  38. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control 9

  39. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control F𝑁𝐵 + + 𝑦 𝑧 𝑧 × 𝑧 × 2.4 2.4 𝑦 𝑦 2.4 9

  40. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 opt:(x * 2.4 + y) fine-grained control + F𝑁𝐵 + + 𝑦 𝑧 𝑧 𝑧 × × 𝑧 × 2.4 𝑦 2.4 2.4 𝑦 𝑦 2.4 9

  41. Icing’s semantics Allowed Optimization: 𝑏 × 𝑐 + 𝑑 𝐺𝑁𝐵(𝑏, 𝑐, 𝑑) Included in the semantics 𝑐 × 𝑏 𝑏 × 𝑐 Icing: a direct fit for fast-math opt:(x * 2.4 + y) fine-grained control with fine-grained control and support for different optimizations + F𝑁𝐵 + + 𝑦 𝑧 𝑧 𝑧 × × 𝑧 × 2.4 𝑦 2.4 2.4 𝑦 𝑦 2.4 9

  42. Modelling the state-of-the-art Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • aggressive optimizations • no floating-point optimizations • no IEEE754 semantics • IEEE754 semantics • no guarantees on the result • introduces no new behaviour Icing provides: IEEE754 Translator greedy optimizer 10

  43. Modelling the state-of-the-art Unverified Compilers (gcc, clang, ….) Verified Compilers (CakeML, ...) • aggressive optimizations • no floating-point optimizations • no IEEE754 semantics • IEEE754 semantics • no guarantees on the result • introduces no new behaviour Icing provides: greedy optimizer   IEEE754 Translator 10

Recommend


More recommend