GRANITE: A Graph Neural Network Model for Basic Block Throughput Estimation

Ondrej Sýkora, Phitchaya Mangpo Phothilimthana, Charith Mendis, Amir Yazdanbakhsh · DOI

Abstract

Accurate throughput estimation of basic blocks is essential for modern compiler optimizations and performance analysis. Traditional analytical simulators struggle to keep pace with the complexity of modern out-of-order execution and hidden hardware internals. This paper introduces GRANITE (GRAph Neural network model for basIc block Throughput Estimation), a novel machine learning approach that treats code as a dependency graph rather than a linear sequence. By leveraging Graph Neural Networks (GNNs) and multi-task learning, GRANITE achieves a state-of-the-art average error rate of 6.9% across multiple Intel microarchitectures, while providing a 3x speedup in training and GPU inference compared to previous sequential models.

1. Introduction

In the realm of software optimization, compilers must evaluate the execution speed of various instruction sequences, known as basic blocks, to make informed optimization decisions. Historically, this task was performed by hand-tuned analytical simulators. However, the increasing complexity of modern CPUs—characterized by sophisticated out-of-order execution and proprietary internal structures—has made manual modeling increasingly difficult and error-prone.

Recent efforts have turned to machine learning to automate this process. Early models, such as Ithemal, treated code as a sequence of tokens, utilizing Long Short-Term Memory (LSTM) networks. While innovative, these models often fail to capture the intricate data and structural dependencies inherent in low-level code. GRANITE addresses these limitations by explicitly modeling the relational structure of instructions using Graph Neural Networks.

2. Methodology

2.1 Graph-Based Code Representation

The primary innovation of GRANITE lies in its "inductive bias": it represents a basic block as a directed dependency graph. Unlike sequential models that must infer relationships between distant instructions, GRANITE's graph structure explicitly defines them:

  • Nodes: Represent instruction mnemonics (e.g., ADD, MOV) and values, including registers, memory locations, and constants.
  • Edges: Represent the functional relationships between nodes, such as an instruction consuming a value as an input or producing a value as an output.

2.2 GNN Architecture

GRANITE utilizes a "full GN block" architecture. Through iterative rounds of message passing, the model updates the internal representations of nodes and edges based on their neighbors. This process allows each instruction to incorporate the context of its data dependencies and the broader structural logic of the hardware. To ensure numerical stability when training on high-dynamic-range throughput values, the authors found that the inclusion of Layer Normalization was critical; without it, error rates increased by over 12%.

2.3 Multi-task Learning

Rather than training isolated models for every specific CPU generation, GRANITE employs a multi-task learning strategy. The model uses a shared GNN backbone to learn a general "language" of code-hardware interaction, followed by small, independent decoder heads for specific microarchitectures (e.g., Intel Haswell, Skylake). This approach not only improves efficiency but also enhances accuracy, as the shared representation captures fundamental performance properties that apply across different hardware generations.

3. Experimental Evaluation

3.1 Datasets and Setup

The model was evaluated using two primary x86-64 datasets:

  • Ithemal Dataset: Over 1.4 million basic blocks.
  • BHive: A benchmark suite containing over 300,000 basic blocks.

Ground-truth throughput measurements were collected across three Intel microarchitectures: Ivy Bridge, Haswell, and Skylake.

3.2 Performance Results

GRANITE demonstrated significant improvements over the previous state-of-the-art (Ithemal):

  • Accuracy: The model achieved an average test error of 6.9%, representing a 1.7% absolute reduction in error compared to Ithemal.
  • Efficiency: Due to the highly parallelizable nature of GNNs on hardware accelerators, GRANITE is 3.0x faster than LSTM-based models for both training and inference when running on a GPU.
  • Reliability: Qualitative heatmap analysis indicated that GRANITE effectively mitigates the "underestimation" bias common in previous models, providing more balanced predictions across the performance spectrum.

4. Discussion and Limitations

While GRANITE represents a significant step forward, several areas for future work remain. The current study focused exclusively on the x86-64 instruction set; while the GNN approach is theoretically generalizable, its performance on ARM or RISC-V architectures has yet to be verified. Additionally, as a basic block model, GRANITE does not account for system-level behaviors such as branch prediction or multi-level cache misses that occur across block boundaries. Finally, while GRANITE excels on GPUs, it is approximately 27% slower than LSTMs when performing inference on standard CPUs, suggesting a trade-off between throughput and hardware-specific deployment.

5. Conclusion

GRANITE demonstrates that explicitly modeling the structural dependencies of code through Graph Neural Networks leads to more accurate and efficient throughput estimation. By moving away from sequential text-based models and embracing the relational nature of hardware execution, GRANITE provides a robust foundation for the next generation of performance-aware compilers and optimization tools.

Summary updated

BibTeX
@inproceedings{sykora2022granite,
  author = {Ondrej Sýkora and Phitchaya Mangpo Phothilimthana and Charith Mendis and Amir Yazdanbakhsh},
  title = {{GRANITE: A Graph Neural Network Model for Basic Block Throughput Estimation}},
  booktitle = {IISWC},
  year = {2022},
  doi = {10.1109/iiswc55918.2022.00012},
}
Figure