TL;DR
This paper demonstrates that instruction scheduling—the "black art" of reordering computer code for maximum execution speed—can be automated using supervised machine learning. By training on optimal schedules for small code blocks, the researchers developed models that outperform traditional production compilers and approach the performance of highly optimized, hand-crafted heuristics.
What Problem Does This Paper Address?
Modern CPUs are incredibly complex; they don't just execute instructions one by one. They utilize internal parallelism (pipelines) and can often "dual-issue" (start two instructions at once) if the conditions are right. Because different instructions take varying amounts of time and rely on different hardware resources, the order in which they are presented to the processor can change execution speed by a factor of two or more.
Compilers use "instruction schedulers" to find the best order. Historically, these are built using hand-crafted heuristics—rules of thumb written by experts who spend months studying a specific processor's manual. This process is expensive, time-consuming, and must be repeated for every new chip architecture. The authors ask: Can we replace these human experts with a machine learning model that learns the "preference" for one instruction over another?
Methods
The authors treat scheduling as a supervised learning task. Specifically, they focus on "local scheduling" within basic blocks (sequences of code with no jumps or branches).
- The Greedy Approach: The scheduler builds a schedule one instruction at a time. At each step, it looks at all "available" instructions (those whose dependencies are met) and picks the "best" one.
- Learning Preferences: Instead of a complex scoring system, they learn a pairwise preference relation. Given a partial schedule and two candidate instructions, the model predicts which one should be scheduled first.
- Generating Ground Truth: For small blocks (10 instructions or fewer), the authors used exhaustive search to find the mathematically optimal schedule. They then extracted every possible pairwise choice from these optimal paths to create a massive dataset of "correct" decisions.
- Algorithms: They tested four different learning methods:
- Decision Trees (ITI): To learn logical rules.
- Table Lookup (TLU): A simple, discretized map of the feature space.
- ELF: A constructive function approximator.
- Neural Networks (NN): A standard feed-forward network with 10 hidden units.
Datasets
- Architecture: The models were targeted at the Digital Alpha 21064, a complex RISC processor of the era.
- Benchmarks: They used the SPEC95 suite, a standard set of 18 programs (written in C and FORTRAN) used to measure CPU performance.
- Scale: They extracted 447,127 basic blocks (over 2.2 million instructions). From the small blocks, they generated over 26 million preference triples for training.
Key Insights and Ideas
- Small Blocks are the Key: While scheduling is NP-complete (computationally "hard"), 92% of the blocks in real-world programs are 10 instructions or fewer. By mastering these "solvable" small cases, the models learned general principles that applied to much larger, more complex blocks.
- Feature Engineering Matters: The authors found that just five features were enough for near-optimal performance. These included things like the "Weighted Critical Path" (how many instructions depend on this one) and "Actual Dual" (whether this instruction can pair up with the previous one to run simultaneously).
- Simplicity Wins: Surprisingly, the Table Lookup (TLU) method performed the best among the ML techniques. Because the dataset was so large and the feature space was relatively small, the table could simply "remember" the best move for almost every situation without needing the complex abstractions of a neural network.
Key Results
- Beating the Compiler: All four ML models produced schedules that were faster than those generated by the original production compiler.
- Near-Human Performance: The ML models came remarkably close to the DEC scheduler, a high-end heuristic hand-tuned by the processor's own architects.
- High Accuracy: On small blocks, the ML models made the "optimal" choice over 98% of the time.
- Efficiency: The results showed that a few well-chosen features are sufficient for a real-world, modern processor, suggesting that the "black art" of scheduling is more systematic than previously thought.
Limitations and Future Work
- The "DEC" Gap: While the ML models beat the standard compiler, they didn't quite surpass the hand-tuned DEC heuristic. The authors suggest this might be because large blocks (where heuristics might shine) contribute disproportionately to execution time.
- Simulation vs. Reality: The primary results were measured using a simulator. While the authors mention later tests on real hardware were successful, simulators can sometimes miss subtle hardware "quirks."
- Scaling to Global Scheduling: This paper only looks at straight-line code. Real performance gains often come from "global scheduling"—moving instructions across branches and loops—which creates a much larger and more difficult search space for ML.
- Reinforcement Learning: The authors noted that Supervised Learning struggles when the search space explodes. They suggested that Reinforcement Learning (RL) might be the next step for more complex scheduling problems.
Summary updated