Introduction
Modern CPU simulators like llvm-mca are critical for performance engineering and architectural research. However, they rely on thousands of microarchitectural parameters—such as instruction latencies and port mappings—that are notoriously difficult to calibrate. These parameters often lack public documentation or fail to align with the abstract models used by simulators. DiffTune addresses this by using machine learning to automatically tune these parameters, outperforming expert-hand-tuned configurations.
The Challenge of Simulator Calibration
Calibrating a CPU simulator faces three primary hurdles:
- Astronomical Parameter Space: A single simulator can have a configuration space as large as $10^{19336}$, making manual tuning impossible.
- Proprietary Hardware Details: Internal microarchitectural details are often trade secrets, and measured latencies may not match the simulator's abstract logic.
- Non-Differentiability: Simulators are discrete software programs. Standard gradient-based optimization cannot be applied directly because there is no way to calculate a gradient through the simulator's source code.
Methodology: The DiffTune Pipeline
DiffTune overcomes the non-differentiability of simulators by introducing a three-step optimization pipeline centered around a differentiable surrogate model.
1. Training a Differentiable Surrogate
The first step is to create a neural network that mimics the behavior of the target CPU simulator. The authors utilize an architecture based on Ithemal, which uses LSTMs to process sequences of instructions.
The surrogate is trained on a synthetic dataset where inputs consist of code blocks and randomized parameters, and the target is the simulator's timing output. Once trained, this surrogate serves as a smooth, differentiable proxy for the simulator.
2. Parameter Optimization
With a differentiable surrogate in place, the authors use real-world "ground truth" execution data from the BHive dataset, which contains over 287,000 x86 basic blocks. They perform gradient descent on the input parameters of the surrogate to minimize the error between the surrogate's predictions and actual hardware measurements. Because the surrogate is a neural network, standard backpropagation can be used to find the optimal parameter values.
3. Parameter Extraction
Finally, the optimized parameters are extracted, rounded to integers where necessary, and plugged back into the original, non-differentiable simulator.
Results and Insights
The framework was evaluated across Intel (Ivy Bridge, Haswell, Skylake) and AMD (Zen 2) architectures, targeting simulators like llvm-mca and llvm_sim.
- Superior Accuracy: On Intel Haswell, DiffTune reduced the average error of
llvm-mcafrom 30.0% (expert-tuned) to 24.6%. - Robustness: Unlike black-box optimizers like
OpenTuner, which failed due to the vast search space, DiffTune's gradient-based approach successfully navigated the complexity. - Cross-Vendor Success: DiffTune successfully learned parameters for the AMD Zen 2 architecture, even though the underlying simulator was originally designed for Intel models.
A key insight is that DiffTune often learns "unphysical" parameters to compensate for structural inaccuracies in the simulator's model. While these values might not represent physical hardware reality, they significantly improve the simulator's predictive accuracy by masking modeling errors.
Conclusion
DiffTune demonstrates that differentiable surrogates can effectively bridge the gap between discrete simulators and continuous optimization. While currently limited to ordinal parameters and basic blocks, the approach provides a powerful automated alternative to the manual, error-prone process of microarchitectural parameter tuning.
Summary updated