|
| 1 | +--- |
| 2 | +title: "Exploring Automatic Differentiation with CHEF-FP for Floating-Point Error Analysis" |
| 3 | +layout: post |
| 4 | +excerpt: "In High-Performance Computing (HPC), where precision and performance are |
| 5 | +critically important, the seemingly counter-intuitive concept of Approximate |
| 6 | +Computing (AC) has gradually emerged as a promising tool to boost |
| 7 | +computational throughput. There is a lot of interest in techniques that work |
| 8 | +with reduced floating-point (FP) precision (also referred to as mixed |
| 9 | +precision). Mixed Precision Tuning involves using higher precision when |
| 10 | +necessary to maintain accuracy, while using lower precision at other times, |
| 11 | +especially when performance can be improved." |
| 12 | +sitemap: false |
| 13 | +permalink: blogs/exploring-ad-with-chef-fp/ |
| 14 | +date: 2023-04-13 |
| 15 | +--- |
| 16 | + |
| 17 | + |
| 18 | +> Note: Following is a high-level blog post based on the research paper: [Fast |
| 19 | +> And Automatic Floating Point Error Analysis With CHEF-FP] |
| 20 | +
|
| 21 | +In High-Performance Computing (HPC), where precision and performance are |
| 22 | +critically important, the seemingly counter-intuitive concept of Approximate |
| 23 | +Computing (AC) has gradually emerged as a promising tool to boost |
| 24 | +computational throughput. There is a lot of interest in techniques that work |
| 25 | +with reduced floating-point (FP) precision (also referred to as mixed |
| 26 | +precision). Mixed Precision Tuning involves using higher precision when |
| 27 | +necessary to maintain accuracy, while using lower precision at other times, |
| 28 | +especially when performance can be improved. |
| 29 | + |
| 30 | +As long as there are tools and techniques to identify regions of the code that |
| 31 | +are amenable to approximations and their impact on the application output |
| 32 | +quality, developers can employ selective approximations to trade-off accuracy |
| 33 | +for performance. |
| 34 | + |
| 35 | +### Introducing CHEF-FP |
| 36 | + |
| 37 | +CHEF-FP is one such source-code transformation tool for analyzing |
| 38 | +approximation errors in HPC applications. It focuses on using Automatic |
| 39 | +Differentiation (AD) and its application in analyzing floating-point errors to |
| 40 | +achieve sizable performance gains. This is accomplished by using Clad, an |
| 41 | +efficient AD tool (built as a plugin to the Clang compiler), as a backend for |
| 42 | +the presented framework. |
| 43 | + |
| 44 | +CHEF-FP automates error estimation by injecting error calculation code into |
| 45 | +the generated derivatives, enhancing analysis time and reducing memory usage. |
| 46 | +The framework's ability to provide Floating-Point error analysis and generate |
| 47 | +optimized code contributes to significant speed-ups in the analysis time. |
| 48 | + |
| 49 | +### Modeling Floating-Point Errors |
| 50 | + |
| 51 | +The error model describes a metric that can be used in the error estimation |
| 52 | +analysis. This metric is applied to all assignment operations in the |
| 53 | +considered function, and the results from its evaluation are accumulated into |
| 54 | +the total floating point error of the left-hand side of the assignment. This |
| 55 | +error model is sufficient for most smaller cases and can produce loose upper |
| 56 | +bounds of the maximum permissible FP error in programs. |
| 57 | + |
| 58 | +### Automatic Differentiation (AD) Basics |
| 59 | + |
| 60 | +With increasingly better language support, AD is becoming a much more |
| 61 | +attractive tool for researchers. AD takes as input any program code that has |
| 62 | +meaningful differentiable properties and then it produces a new code that is |
| 63 | +augmented with pushforward (forward mode AD) or pullback (reverse mode AD) |
| 64 | +operators. |
| 65 | + |
| 66 | +The Reverse Mode AD in particular provides an efficient way to compute the |
| 67 | +function’s gradient with relative time complexity, which is independent of |
| 68 | +the size of the input. Among AD techniques, the Source Transformation approach |
| 69 | +has better performance, since it does as much as possible at compile time to |
| 70 | +create the derivative only once. |
| 71 | + |
| 72 | +### AD-Based Floating-Point Error Estimation Using CHEF-FP |
| 73 | + |
| 74 | +An important part of dealing with floating-point applications with high |
| 75 | +precision requirements is identifying the sensitive (more error-prone) areas |
| 76 | +to implement suitable mitigation strategies. This is where AD-based |
| 77 | +sensitivity analysis can be very useful. It can find specific variables or |
| 78 | +regions of code with a high contribution to the overall FP error in the |
| 79 | +application. |
| 80 | + |
| 81 | +The CHEF-FP framework requires less manual integration work and comes packaged |
| 82 | +with Clad, taking away the tedious task of setting up long tool chains. The |
| 83 | +tool’s proximity to the compiler (and the fact that the floating-point error |
| 84 | +annotations are built into the code’s derivatives) allows for powerful |
| 85 | +compiler optimizations that provide significant improvements in the analysis |
| 86 | +time. Another upside of using a source-level AD tool like Clad as the backend |
| 87 | +is that it provides important source insights (variable names, IDs, source |
| 88 | +location, etc.). Clad can also identify special constructs (such as loops, |
| 89 | +lambdas, functions, if statements, etc.) and fine-tune the error code |
| 90 | +generation accordingly. |
| 91 | + |
| 92 | +### Implementation |
| 93 | + |
| 94 | +CHEF-FP's implementation involves registering an API in Clad for calculating |
| 95 | +the floating-point errors in desired functions using the default error |
| 96 | +estimation models. |
| 97 | + |
| 98 | +While CHEF-FP provides an API that is useful for building simple expressions, |
| 99 | +it becomes challenging to implement complex models based on just a single |
| 100 | +expression. Therefore, calls to external functions are built as a valid error |
| 101 | +model, as long as the function has a compatible return type for the variable |
| 102 | +being assigned the error. This means that users can define their error models |
| 103 | +as regular C++ functions, enabling the implementation of more computationally |
| 104 | +complex models. |
| 105 | + |
| 106 | +### Conclusion |
| 107 | + |
| 108 | +The research illustrates the power of CHEF-FP in automating Floating-Point |
| 109 | +Error Analysis, guiding developers in optimizing various precision |
| 110 | +configurations for enhanced performance. By utilizing AD techniques and |
| 111 | +source-level insights, CHEF-FP presents a scalable and efficient solution for |
| 112 | +error estimation in HPC applications, paving the way for better computational |
| 113 | +efficiency. |
| 114 | + |
| 115 | + |
| 116 | +[Fast And Automatic Floating Point Error Analysis With CHEF-FP]: https://arxiv.org/abs/2304.06441 |
0 commit comments