The Einstein Engine: A Modular Code Generator for GPU Simulations in the Modern Era
Abstract
Implementing code that fully exploits modern GPU hardware is challenging. For scientific applications of sufficient complexity, this demands an in-depth understanding of hardware specifics, optimization techniques, and one or several domain-specific, idiosyncratic frameworks. We present the Einstein Engine, a modular scientific code generation system with powerful capabilities for exploring optimization spaces, built on a three-phase architecture inspired by modern compilers such as LLVM. Each phase can be developed and extended independently, empowering scientists to implement new domain-specific input formats or framework-tailored code generation targets while automatically benefiting from the intermediate optimization layer. To demonstrate the Einstein Engine’s effectiveness, we have implemented a full pipeline tailored for general relativity that transforms an approachable, high-level simulation description into highly optimized, efficient C++ code for GPUs. With this pipeline we created Cottonmouth, a suite of codes for solving Einstein’s field equations that has been incorporated into the 2026 Einstein Toolkit release. Across five platforms spanning NVIDIA and AMD GPUs, Cottonmouth matches the accuracy of well-established codes while evaluating its core kernels up to 6 times faster.