EN FR
Homepage Inria website


Section: New Results

AD-adjoints and C dynamic memory management

Participants : Laurent Hascoët, Raphaël Couronné, Sri Hari Krishna Narayanan [Argonne National Lab. (Illinois, USA)] , Mathieu Morlighem [University of California at Irvine (USA)] .

One of the current frontiers of AD research is the definition of an adjoint AD model that can cope with dynamic memory management. This research is central in our ongoing effort towards adjoint AD of C, and more remotely towards AD of C++. This research is conducted in collaboration with the MCS department of Argonne National Lab. Our partnership is formalized by joint participation in the Inria joint lab JLESC, and partly funded by the Partner University Fund (PUF) of the French embassy in the USA.

Adjoint AD must reproduce in reversed order the control decisions of the original code. In languages such as C, allocation of dynamic memory and pointer management form a significant part of these control decisions. Reproducing memory (de)allocation in reverse means reallocating memory, possibly receiving a different memory chunk. Reproducing pointer addresses in reverse thus require to convert addresses in the former memory chunks into equivalent addresses in the new reallocated chunks. Together with Krishna Narayanan from Argonne, we experiment on real applications to find the most efficient solution to this address conversion problem. We jointly develop a library (called ADMM, ADjoint Memory Management) whose primitives can be used in AD adjoint code to handle this address conversion. Using this library together with Tapenade, we could obtain a correct AD adjoint code of a medium-size industrial code (“Multibody", structural mechanics) that exhibits a typical usage of C pointer arithmetic. This year, the same effort was conducted with the OpenAD AD tool, leading us to an ADMM library less dependent on the particular target AD tool. A joint publication with our colleagues from Argonne is in preparation.

In parallel, we investigate alternative implementation strategies for ADMM, one of which could be to build our own memory (de)allocation mechanism, This should ultimately rely on the standard C library. As a result, management of adjoint memory addresses could be done deeper in the system and therefore with a smaller overhead, at the cost of some additional portability issues.

We pursue our objective of improving reliability of the AD adjoint model for C codes to a similar level as achieved for Fortran. To this end we apply Tapenade to increasingly larger and complex C codes. In addition to the already mentioned “Multibody" application, we initiated differentiation of two new complex applications:

  • “BLN" is a code developed by the Inria team ABS, that computes the potential energy of possible conformations of a macromolecule. Its gradient is used to explore the local minima in the energy landscape of these conformations. The AD adjoint of a Fortran implementation of BLN has been built by Tapenade and successfully validated. The adjoint of the C implementation is a challenge that helps us clarify the adjoint AD model that we use in Tapenade. The C version of BLN that we are considering is actually a (partly mechanical) translation of the actual C++ source. This makes this code an even more appealing and challenging test case. This work was mostly conducted by Raphaël Couronné as a part of his summer internship with us.

  • “SEISM" is a code developed by Mathieu Morlighem from UC Irvine, jointly with Eric Larour from JPL. This is a glaciology code closely related to the larger “ISSM" code, in C++. One objective, addressed mostly by Mathieu Morlighem, is to clarify recommendations on the C programming style (again very much inspired here from the C++ style) that allows AD to perform better. The other objective, adressed mostly by our team, it to experiment with quite intricate data structures, where Tapenade's static pointer destination analysis is used intensively.