10 likes | 159 Views
Identifying Active Variables to Improve the Performance of Operator Overloading Automatic Differentiation Drew Wicke Argonne National Laboratory. Materials and Methods. Results. INTRODUCTION.
E N D
Identifying Active Variables to Improve the Performance of Operator Overloading Automatic Differentiation Drew Wicke Argonne National Laboratory Materials and Methods Results INTRODUCTION Automatic Differentiation (AD) is a means of computing the derivative of a function within a computer program. AD can be performed by using the operator overloading approach which uses features of the programming language to alter the meaning of mathematical operators to compute the derivative. Operator overloading as a means of performing AD allows for maintainable code; however, speed of computation is sacrificed. The goal of this research was to use activity analysis to improve the performance of the calculation of derivatives using Sacado. Sacado is a package in the Trilinos framework and is an implementation in C++ of the operator overloading method of AD. The tool created to accomplish this combines the activity analysis of the source code analysis toolkit, OpenAnalysis, with the source-to-source transformation tool ROSE. After applying the tool to code that has variables with double type variables we get the generated code below. This code is efficient because only the active variables have the Sacado derivative type, DERIV_TYPE_double. • Vary variables are those whose value is computed using an independent variable. • Useful variables are used to compute the value of the dependent variable • Active variables are both vary and useful. typedefSacado::Fad::DFad<double> DERIV_TYPE_double; voidfoo(DERIV_TYPE_double *x, DERIV_TYPE_double *f){ # pragma $adic_indep,x// specify the independent # pragma $adic_dep,f// and dependent variables doublesquarePoly = ADValue((*x) * (*x)); doubletheConst = 3.14 * 2; DERIV_TYPE_double div = ((*x) / 2); if (squarePoly >= 100) (*f) = div * theConst; else (*f) = div * theConst + 100; } typedefSacado::Fad::DFad<double> DERIV_TYPE_double; // Sacado derivative type voidfoo(DERIV_TYPE_double *x, DERIV_TYPE_double *f){ DERIV_TYPE_doublesquarePoly= (*x) * (*x); DERIV_TYPE_doubletheConst= 3.14 * 2; DERIV_TYPE_double div = ((*x) / 2); if (squarePoly >= 100) (*f) = div * theConst; else (*f) = div * theConst + 100; } DERIV_TYPE operator* (DERIV_TYPE other) { this->val = this->val() * other.val(); this->dx = this->val() * other.dx() + other->val() * this->dx(); return *this; } The above code illustrates how a Sacado function can be written. All the variables have the Sacado derivative type DERIV_TYPE_double. Both the function and the derivative of the function are computed using overloaded operators, such as the example on the left, when the variables have the Sacado derivative type. Since active variables need only have the derivative type, the code is inefficient due to unnecessary memory allocation and function calls. Discussion Above is an example of an overloaded multiplication operator. Not only must the product be computed, but also the value of the derivative after applying the product rule. We encountered challenges in type changing. For example, to change the type of typedef active variables we must extract base type and all other types such as pointers to set to the derivative type. Activity Analysis Tool Flow 1. Input Code 2. ROSE AST 3. OpenAnalysisICFG int main(){ doubleval; val = 4.3; … return0; } // before: typedefdouble* fir; typedef fir* sec; sec test; // active // after: typedefdouble* fir; typedef fir* sec; DERIV_TYPE_double **test; Convert Convert Above code shows that we gather double and pointer data types to change the type of test to DERIV_TYPE_double**. 4. VaryAnalysis UsefulAnalysis ActivityAnalysis CONCLUSION/FUTURE STEPS 6. Output generated code • In conclusion our tool: • can be used with any operator overloading AD package • replaces the manual process, which is slow and overestimates the number active variables • successfully identifies active variables • can change the data type of active variables of most C data types • In the future we would like to: • Benchmark the tool • Add support for C++ 5. Change the type of active variables to derivative type int main(){ DERIV_TYPE_doubleval; val = 4.3; … return0; } The above diagram demonstrates the process through which our tool takes in order to change the types of active variables. Provide code that you want to run the tool on The tool converts the code to an abstract syntax tree (AST) with ROSE AST is converted to a interprocedural control flow graph (ICFG) for OpenAnalysis Using OpenAnalysis perform vary, useful and activity analysis to make a list of active variables Change the active variable’s type to the Sacado derivative type within the AST Output the generated code based off of the AST References: Automatic Differentiation: http://www.autodiff.org/ OpenAnalysis: http://openanalysis.berlios.de/ ROSE: http://www.rosecompiler.org/ Sacado: http://trilinos.sandia.gov/ The submitted manuscript has been created by UChicago Argonne, LLC, Operator of Argonne National Laboratory ("Argonne"). Argonne, a U.S. Department of Energy Office of Science laboratory, is operated under Contract No. DE-AC02-06CH11357. The U.S. Government retains for itself, and others acting on its behalf, a paid-up nonexclusive, irrevocable worldwide license in said article to reproduce, prepare derivative works, distribute copies to the public, and perform publicly and display publicly, by or on behalf of the Government