Enzyme is a compiler plugin that differentiates LLVM and MLIR code automatically. Developers call enzymeautodiff on functions to obtain gradients without hand-written derivative code.
Overview
Enzyme performs automatic differentiation on statically analyzable LLVM and MLIR. It takes existing optimized intermediate representation, runs analyses to determine which values affect derivatives, and replaces calls to enzymeautodiff with generated gradient functions.
Because differentiation happens after optimization in the LLVM pipeline, Enzyme is designed to produce efficient derivatives for code already tuned by the compiler. It can target programs originating from C, C++, Swift, Julia, Rust, Fortran, TensorFlow, and other front ends that lower to LLVM, using one toolchain rather than per-language AD rewrites.
The implementation includes optional preprocessing, interprocedural type analysis for memory, activity analysis, and an optimization pass that synthesizes derivative functions. Julia, Rust, and Fortran bindings are available. Installation paths mentioned in project materials include package managers such as Homebrew, Spack, and Nix, plus documentation on the project website and a Compiler Explorer instance for experiments.
Key features
- AD on LLVM and MLIR IR
- enzymeautodiff call interface
- Differentiation after LLVM optimization
- Activity and type analyses for AD
- Multi-language front-end compatibility
- Julia, Rust, and Fortran bindings
- GPU and parallel program support
- Compiler Explorer demo instance
Use cases
- Gradients for scientific simulation code
- ML and HPC kernel differentiation
- Research prototypes in C or Julia
- GPU reverse-mode AD via LLVM
- Avoiding manual derivative implementations