Efficient Implementation of a Higher-Order Language with Built-In AD

Jeffrey Mark Siskind, Barak A. PearlmutterarXiv 2016

Introduction

Numerical programming has long been bifurcated between high-level dynamic languages, which offer expressivity and ease of use, and low-level languages like Fortran, which provide the performance necessary for large-scale computation. This divide is particularly evident in Automatic Differentiation (AD). While high-level languages can treat AD operators as first-class citizens, they often suffer from significant runtime overhead. Conversely, low-level tools rely on static source-to-source preprocessors that struggle with nested derivatives and complex control flow. This paper presents VLAD, a functional language for AD, and Stalin∇, an optimizing compiler that bridges this gap by migrating runtime AD transformations to compile-time.

Methodology: The Stalin∇ Compiler

The core of the proposed system is the Stalin∇ compiler, which employs several advanced optimization techniques to eliminate the overhead of dynamic AD.

Polyvariant Flow Analysis

Stalin∇ utilizes a whole-program, inter-procedural polyvariant flow analysis. This analysis allows the compiler to specialize functions based on their specific call sites and argument types. By duplicating and specializing code, the compiler can resolve dynamic dispatch and higher-order function calls at compile-time.

Union-Free Abstract Interpretation

The compiler's analysis is designed to be union-free, meaning it can determine the exact type and structure of every value in the program. By unrolling finite recursive data structures and eliminating the need for runtime tags or boxing, Stalin∇ generates code that operates directly on raw floating-point data, mimicking the memory layout of optimized Fortran or C.

AD as First-Class Reflection

VLAD introduces AD primitives that perform source-to-source transformations via runtime reflection. Through partial evaluation driven by the flow analysis, these reflective operations are resolved during compilation. This "callee-derives" approach maintains the expressivity of dynamic AD while achieving the performance of static transformation.

Experimental Results

The performance of Stalin∇ was evaluated against a suite of benchmarks, including physics simulations (particle, saddle) and neural network training (backprop). These benchmarks were tested across a wide range of languages and AD tools.

Table 1: Normalized runtimes of various AD implementations across benchmarks. All values are normalized to the runtime of Stalin∇ (VLAD).

As shown in Figure 1, Stalin∇ consistently outperforms both low-level AD tools and high-level language implementations. On the backprop benchmark, Stalin∇ is approximately 12x to 22x faster than established C and C++ tools like ADOL-C and ADIC. In scenarios involving nested derivatives, such as the saddle benchmark, Stalin∇ maintains a 5x to 8x performance advantage over Fortran tools like ADIFOR and Tapenade. Furthermore, the performance gap between Stalin∇ and other high-level functional languages (e.g., OCaml, Haskell, Scheme) is often several orders of magnitude, demonstrating the effectiveness of the compiler's optimization pipeline in stripping away dynamic overhead.

Conclusion

The results demonstrate that high-level, higher-order languages with built-in AD can achieve and even exceed the performance of traditional low-level tools. By leveraging aggressive polyvariant flow analysis and partial evaluation, Stalin∇ eliminates the "abstraction penalty" typically associated with dynamic functional languages. While current limitations include a lack of native array support and constraints on recursive patterns, the underlying techniques offer a promising path for integrating first-class AD into mainstream programming environments.

Summary updated

BibTeX
@misc{siskind2016efficient,
  author = {Jeffrey Mark Siskind and Barak A. Pearlmutter},
  title = {{Efficient Implementation of a Higher-Order Language with Built-In AD}},
  year = {2016},
  eprint = {1611.03416},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1611.03416},
}
Figure