Pioneering Automatic Differentiation: Code Generation


Published 27/01/2023 By Johannes Lotz

Fastest runtimes yet with nAG’s Automatic Differentiation tool dco/c++

Many readers will be aware that Adjoint Automatic Differentiation (AAD) is a computer science technique for computing derivatives. Used correctly, AAD calculates derivatives much faster, and much more accurately than alternative methods. 

nAG continues to innovate in the area of Automatic Differentiation through its collaboration with leading computer scientists from RWTH Aachen and further afield with the latest update to its cutting-edge product. nAG provides a feature-rich, comprehensive, and powerful C++ AD header library, including Adjoint AD, called dco/c++ that has addressed client needs for more than a decade.

Code generation runtime
Fig. 1

nAG’s Automatic Differentiation tool dco/c++ now includes:

Code Generation

What is it?

A hybrid technology that combines the efficiency of source transformation with the flexibility and ease of use of an operator overloading tool, with support for primal, tangent and adjoint code. 

This means our latest AD technology supports all combinations of scalar and vector modes for computing first and higher derivatives and does so more efficiently than ever before. 

What does this mean?

Ultimately, this means first and higher-order derivatives 2-10x faster (see fig. 1 – taken from Faster Risk Calculation: Next Generation dco/c++ technical poster – here)  than with our previous versions and up to 36,000x faster than alternative methods. But how? 

Operator overloading techniques for C++ have proven to be successful, robust, and easy to use. This is because they rely on the C++ standard and work with the entire feature set of the language. The C++ compiler ensures applicability and long-term maintainability. 

Source transformation is an excellent way of generating extremely efficient derivative codes. Why? Source transformation tools have two advantages: in the transformation step and in the compilation step. In the transformation step, they can implement optimizations based on properties of the underlying differentiation rules. In addition, in the compilation step, the built-in optimization passes of steadily advancing compilers are simply inherited. Showstoppers usually: Applicability and maintainability. 

We have combined both approaches in our new dynamic code generation: we use overloading techniques to generate a representation of the program in memory, and unparse the various modes (primal, tangent, adjoint) into a C++ file. The dynamic nature of this approach (building the representation at run time) introduces an important constraint on the code to be differentiated – the control flow is not allowed to depend on input data. We overcome this constraint for branches with smart use of modern C++ features such as lambda expressions, in combination with classical elements from the preprocessor. With that, our advanced approach has made source transformation more accessible than ever. 

Users will benefit from the new method delivering robustness and computational efficiency, which in turn can mean a large computational time and cost saving. 

nAG continues to provide its customers with the most advanced, effective algorithmic methods, with unrivalled support. dco/c++ now provides accurate derivatives for optimization, risk, and many other medium to large-scale problems in almost any field, including Finance, Motorsport, Aerospace, Biomedical, Marine, and Civil Engineering.  

This solution delivers the speed and accuracy needed in complex problems for faster, auspicious, more confident decision-making. With nAG expertise and support you get the maximum value from dco/c++ , in the most rapid time frame.​ 

These updates are the result of more than 12 years of research and development and all our solutions are stringently tested, expertly supported, and backed by over 50 years of experience.

Contact us now to learn more about nAG’s Automatic Differentiation products and services, and talk to our experts about how it can help you. 

    Please provide your work email to access the free trial

    By clicking the button below you agree to our Privacy Policy

    This will close in 20 seconds

      Discover how we can help you in just a few clicks





      Discover how we can help you in just a few clicks

      Personal Information





      By clicking the button below you agree to our Privacy Policy

      This will close in 20 seconds