This paper, presented at Onward! 2021, explores the emerging frontier of "Neural Surrogate Programming." By treating neural networks not just as standalone models, but as functional proxies for existing code, the authors provide a roadmap for building faster, more accurate, and more tunable software systems.
TL;DR
The authors formalize a taxonomy of three design patterns—surrogate compilation, adaptation, and optimization—that use neural networks to mimic and improve complex programs. Using a 10,000-line CPU simulator as a case study, they demonstrate that these patterns can achieve a 1.6x speedup, reduce simulation error by 50%, and outperform expert-tuned parameters.
What Problem Does This Paper Address?
Modern software often includes complex components like simulators, physics engines, or compilers that are computationally expensive, difficult to tune, or slightly inaccurate compared to the real world. While researchers often train machine learning models to replace these components, the approaches are usually ad-hoc.
There is a lack of a unifying "programming methodology" for building these models. Furthermore, most programs are non-differentiable (you can't use gradient descent to find the best inputs or parameters), making them "black boxes" for optimization. This paper seeks to bridge the gap between traditional software engineering and machine learning by formalizing how we can use neural "surrogates" to solve these challenges.
Methods
The authors introduce a Neural Surrogate Programming Methodology consisting of seven key design questions (covering architecture, capacity, data, loss, training, hardware, and environment). They apply this to three specific design patterns:
- Surrogate Compilation: Training a model to replicate a program's behavior exactly. The goal is to deploy the fast model in place of the slow original code.
- Surrogate Adaptation: A transfer learning approach. A model is first trained to mimic a simulator, then "fine-tuned" on a small amount of real-world ground-truth data. This allows the surrogate to correct for the simulator's inherent biases.
- Surrogate Optimization: Training a surrogate that takes program parameters as input. Because the neural network is differentiable, you can use gradient descent to find the optimal parameters for the original (non-differentiable) program.
For their case study, they use llvm-mca, a CPU throughput simulator. They utilize BERT-based Transformer architectures for sequence modeling of x86 assembly and LSTMs for parameter-aware modeling.
Datasets
- BHive: A large-scale dataset of x86 basic blocks (sequences of assembly instructions) paired with ground-truth throughput measurements taken on real Intel Haswell CPUs.
- Synthetic Simulator Data: Generated by running
llvm-mcaon BHive blocks to provide the "labels" for the initial surrogate training.
Key Insights and Ideas
- The Differentiability "Killer App": One of the most powerful insights is that surrogates provide a "smooth" approximation of "jagged," discrete code. This allows developers to use standard ML optimization tools (like PyTorch's gradient descent) to tune parameters that were previously only adjustable by human experts or slow, "gradient-free" search algorithms.
- Data Efficiency via Adaptation: The paper shows that pre-training a model on a simulator makes it much better at learning from scarce real-world data. The simulator provides a "warm start" that captures the general logic, while the real-world data provides the final "polish."
- Surrogates as Intermediate Artifacts: In the optimization pattern, the neural network isn't even the final product. It's just a temporary bridge used to find better settings for the original C++ code.
Key Results
- Speed: The compiled surrogate ran 1.6x faster than the original
llvm-mcasimulator while maintaining a deviation of less than 10%. - Accuracy: Through surrogate adaptation, the authors created a model with 50% less error than the original simulator when predicting real-world CPU timings.
- Tuning: Surrogate optimization found CPU parameters that were 5% more accurate than those manually tuned by LLVM experts. In contrast, standard automated tuning tools (like OpenTuner) failed to find any viable parameters within the same computational budget.
Limitations and Future Work
- Generalization: Like all neural networks, surrogates struggle to extrapolate. If a surrogate sees a type of code it wasn't trained on, its predictions may become unreliable.
- Interpretability: Replacing 10,000 lines of C++ with a neural network turns a "white box" into a "black box," making it harder for engineers to reason about why a specific prediction was made.
- Automation: The authors note that their methodology is currently manual. Future work should focus on "mechanizing" this process—essentially creating a "compiler for surrogates" that automatically chooses the best architecture and training regime based on the source code of the original program.
Summary updated