TL;DR
Researchers have developed Certificate-Driven Evolutionary Search (CDES), an agentic framework that uses Large Language Models (LLMs) to automatically port and optimize legacy scientific code for GPUs. By recording failures as enforceable "certificates" of what not to do, the system achieves up to 23.54x speedups and even outperforms expert-written GPU implementations by nearly 15%.
What Problem Does This Paper Address?
Scientific software, like the widely used Geant4 particle simulation toolkit, often consists of millions of lines of C++ code written over decades. As hardware evolves toward GPU acceleration, rewriting these massive codebases manually is a "herculean task."
While LLMs are surprisingly good at translating code, they suffer from a "memory" problem during optimization loops: even when told a specific approach failed, they often repeat the same errors in subsequent attempts. This paper addresses the need for a reliable, self-improving system that can port code without repeating mistakes, ensuring the resulting programs are both fast and physically accurate.
Methods
The authors introduce CDES, which builds on top of existing evolutionary search algorithms (like AlphaEvolve). The standard loop involves an LLM proposing code mutations, which are then tested. CDES adds a critical "control logic" layer:
- Certificate Database: When a candidate program fails a check, the system generates a "certificate"—a record of the conflicting choices and the violated requirement.
- Conflict Checker and Analyzer: Before the LLM even sees a new proposal, this component checks it against stored certificates. If the new code repeats a known mistake, it is rejected or sent for targeted repair.
- Rigorous Evaluation Harness: Instead of simple unit tests, the authors use a multi-layered validation suite:
- Formal Analysis: Using tools like the Lean theorem prover and CBMC to prove memory safety and work-assignment rules.
- Physics Checks: Ensuring conservation laws (like energy and momentum) are maintained.
- GPU Safety: Using NVIDIA’s Compute Sanitizer to catch race conditions and memory errors.
Datasets
The study focuses on two critical functions from the Geant4 toolkit:
- Compton: Computes particle scattering (photon-electron interaction). This served as a benchmark against Celeritas, an existing expert-written GPU implementation.
- Fermi: Assigns energy and motion to nuclear fragments. This represented a "blind" test where no expert GPU implementation was previously available.
Evaluation was performed using approximately 250,000 inputs on an NVIDIA H100 GPU.
Key Insights and Ideas
- Enforceable Memory Beats Prompting: Simply putting error messages in a prompt isn't enough for LLMs. By turning failures into hard logical constraints (certificates), the system increased the correctness pass rate from 55% to 90%.
- AI Finds "Hidden" Optimizations: In the
Comptonfunction, the AI outperformed expert code by identifying that a specific value (the squared sine of an angle) was being recomputed unnecessarily. By reusing an earlier calculation, the AI squeezed out extra performance that human experts had overlooked. - Human-AI Collaboration: The best results came from a "Hybrid" approach—combining the expert's logic for energy selection with the AI's optimized direction calculations. This suggests that the future of scientific software isn't just "AI-written," but a collaborative refinement of expert kernels.
Key Results
The quantitative gains are significant, demonstrating that automated porting can rival or exceed manual effort:
- Speedups: CDES-generated code achieved 13.78x (Compton) and 23.54x (Fermi) speedups over the original CPU versions.
- Outperforming Experts: For the Compton function, the CDES implementation achieved a 14.9% higher throughput than the expert-written Celeritas implementation.
- Hybrid Gains: Combining Celeritas and CDES components resulted in a 16.1% total throughput gain over the expert baseline.
The ablation study highlights the efficiency of the certificate system. While it slightly increases the API cost per run, it drastically reduces the number of "wasted" candidates that fail basic correctness checks.
Limitations and Future Work
While successful, the authors note that this was a proof-of-concept on individual functions.
- Scaling: The next step is to see if this "function-by-function" optimization translates to speedups for the entire simulation codebase, where data movement between functions becomes a bottleneck.
- Complexity: Future work will explore how the cost and effectiveness of certificates change as the optimization tasks become more difficult or the functions become larger.
- Integration: The team aims to incorporate these automated tools directly into production projects like Celeritas to assist human developers in real-time.
Summary updated