Abstract
CAPSim is a novel CPU performance simulator that combines fast functional simulation with an attention-based neural network to predict execution time. By leveraging Transformer-like architectures and incorporating architectural "context" (register states), it achieves up to an 8.3x speedup over the industry-standard gem5 simulator while maintaining high accuracy across complex benchmarks.
Introduction
In computer architecture research, simulators are the primary tool for testing new CPU designs. However, researchers face a "simulation wall." Cycle-accurate simulators like gem5 are incredibly detailed but painfully slow, often taking weeks to run a standard benchmark suite like SPEC 2017.
While recent machine learning (ML) approaches have tried to speed this up, most are limited to predicting the performance of "basic blocks" (small, straight-line snippets of code). They struggle with full programs because they ignore the "context"—the complex web of data dependencies, memory states, and branch histories that actually determine how fast code runs on a modern out-of-order (O3) processor.
Methodology
CAPSim introduces a hybrid pipeline that replaces slow microarchitectural modeling with a deep learning predictor. The overall workflow is depicted in Figure 1.
Simulation Pipeline
- Functional Simulation: It uses gem5’s AtomicSimple CPU model to quickly generate an instruction trace of the program. This is much faster than a full O3 simulation but lacks timing accuracy.
- Trace Slicing & Sampling: The long instruction trace is sliced into "clips" (100–200 instructions). To keep training manageable, a sampler selects a representative subset of these clips.
Attention-Based Predictor
The core of CAPSim is its neural performance predictor, which utilizes an attention mechanism to model instruction interactions and architectural state.
- Instruction Encoder: Uses a Multi-Head Attention (MHA) mechanism to capture how instructions within a clip interact with each other.
- Context Matrix: This is a key innovation. CAPSim feeds the model the state of architectural registers (GPRs, VSRs, etc.) before the clip executes. This allows the model to "see" data dependencies and potential bottlenecks.
- Block Encoder: A second attention layer that relates the instruction features to the broader architectural context.
- Parallel Inference: Because the clips are independent, CAPSim can use a GPU to predict the timing of thousands of code fragments simultaneously, a feat traditional sequential simulators cannot match.
Experimental Setup
The authors evaluated CAPSim using the SPEC 2017 benchmark suite, a standard for measuring CPU performance.
- Training/Validation: Benchmarks were categorized into six sets based on their behavior (e.g., compute-intensive, memory-intensive, or control-intensive).
- Target Architecture: The model was trained to predict the performance of a high-performance out-of-order CPU based on the Power ISA.
Results and Discussion
Performance and Speedup
CAPSim achieved an average speedup of 4.9x, with a maximum of 8.3x compared to gem5’s O3 simulator. This gain is primarily due to shifting the heavy lifting to neural network inference, which is "embarrassingly parallel" on modern GPUs.
Accuracy and Generalization
The model showed a 9.5% to 21.2% improvement in accuracy over the LSTM-based Ithemal model. When tested on "unseen" benchmarks (programs not used in training), CAPSim maintained an average accuracy of 88.3%, proving it learns general architectural principles rather than just memorizing specific code. An ablation study confirmed that including "context information" (register states) improved accuracy by up to 9.6%, highlighting that hardware state is vital for performance prediction.
Key Insights
- Attention vs. Recurrence: CAPSim demonstrates that attention mechanisms (Transformers) are superior to LSTMs for code analysis because they capture long-range influences between instructions sharing data dependencies.
- Contextual Awareness: Simply looking at assembly code is insufficient. Including the Context Matrix allows the model to account for dynamic CPU behavior, such as memory address effects on cache performance.
Conclusion
While CAPSim offers significant speedups, it currently faces limitations regarding ISA specificity (Power ISA) and microarchitecture changes, which require retraining. Future work aims to develop "parameter-agnostic" models and better capture long-range memory effects. Despite these challenges, CAPSim represents a major step toward overcoming the simulation wall in computer architecture research.
Summary updated