Ithemal: Accurate, Portable and Fast Basic Block Throughput Estimation using Deep Neural Networks

Charith Mendis, Saman P. Amarasinghe, Michael Carbin

TL;DR

This paper introduces Ithemal, a novel deep learning system that accurately predicts the execution throughput of basic blocks of x86-64 assembly instructions. Ithemal significantly outperforms existing analytical models in accuracy and is as fast, offering a more portable and less labor-intensive solution for performance analysis and compiler optimization.

What Problem Does This Paper Address?

Predicting how many clock cycles a sequence of instructions will take to execute (its "throughput") is crucial for optimizing software performance. This is particularly challenging for modern x86-64 processors due to their complex microarchitectures, which involve intricate optimizations like pipelining, out-of-order execution, and micro-op fusion. Traditionally, this prediction is done using analytical models, which are built by hand. However, these models are notoriously difficult to create, error-prone, and require significant effort to adapt to new processor generations or microarchitectures. This manual process is tedious, often relies on incomplete or incorrect documentation, and makes it hard to achieve high accuracy across diverse processor designs.

Methods

Ithemal tackles this problem with a data-driven approach using a hierarchical Long Short-Term Memory (LSTM) based deep neural network. The process involves three main stages:

  1. Canonicalization: Raw assembly instructions are first parsed into a structured token format, breaking them down into opcodes, operands, and delimiters.
  2. Embedding: A hierarchical LSTM network processes these tokens. A "token layer" creates embeddings for individual tokens, and an "instruction layer" then uses a sequential LSTM to generate a fixed-size embedding for each instruction within the basic block. This hierarchical structure is key, as it allows the model to process instructions at different granularities and reduces the computational path length for backpropagation.
  3. Prediction: A final "prediction layer," also an LSTM, takes the sequence of instruction embeddings and outputs a single real-valued number representing the predicted throughput. This prediction layer is trained independently from the instruction layer.

The core novelty lies in using a deep neural network to learn the complex, non-linear relationships between instruction sequences and their execution times, rather than explicitly modeling processor microarchitectural details.

Datasets

The researchers collected a dataset of basic blocks from various sources, including Linux Shared Libraries, SPEC benchmarks, NAS, Polybench, TSVC, CortexSuite, and end-user applications. They compiled these applications using GCC 4.9.4 with -O3 optimization targeting Intel Haswell processors. Basic blocks were extracted using dynamic binary instrumentation with DynamoRIO. To ensure comparability with analytical models, the throughput of these blocks was measured by executing them in a loop 100 times to reach steady-state behavior. This process was repeated for three microarchitectures: Intel Ivy Bridge, Haswell, and Skylake. The final de-duplicated dataset for Haswell contained 1,416,473 unique basic blocks.

Key Insights and Ideas

  • Data-Driven Dominance: The paper strongly suggests that deep learning models can surpass hand-crafted analytical models in accuracy for complex tasks like throughput prediction, by learning directly from observed performance data.
  • Hierarchical Structure is Key: The hierarchical LSTM architecture, processing tokens and then instructions, proved significantly more effective than simpler sequential models or graph-based approaches (like DAG-RNNs). This highlights the importance of capturing different levels of abstraction in instruction sequences.
  • Implicit Microarchitectural Learning: Ithemal learns salient microarchitectural details contributing to throughput without explicit programming or knowledge of specific processor optimizations, demonstrating the power of end-to-end learning.
  • Portability Advantage: Unlike analytical models that require extensive re-engineering for each new processor, Ithemal's learned model shows remarkable portability, achieving high accuracy across different microarchitectures with minimal or no retraining.

Key Results

  • Accuracy: Ithemal achieved significantly higher accuracy than state-of-the-art analytical models (LLVM's llvm-mca and Intel's IACA). It reduced the mean absolute percentage error by more than 50% across benchmarks. For instance, on the Haswell test set, Ithemal's predictions were closer to the ground truth than both IACA and llvm-mca in 74% of the blocks.
  • Speed: Ithemal's prediction speed was comparable to llvm-mca and IACA, processing approximately 500-600 instructions per second. This is orders of magnitude faster than empirical execution-based evaluation.
  • Portability: Ithemal demonstrated strong performance across Intel Ivy Bridge, Haswell, and Skylake microarchitectures, with a maximum average error of 0.089, outperforming the minimum average error of 0.167 for hand-written models.

Limitations and Future Work

  • Limitations: The paper notes that all estimators, including Ithemal, struggle with certain blocks that exhibit special microarchitectural optimizations not easily captured by general models. The authors hypothesize these might correspond to specific, undocumented optimizations. While Ithemal performs better, it still shows some difficulty with these rare cases.
  • Future Work: The authors suggest that Ithemal's success demonstrates the potential for data-driven techniques to augment or even replace manually developed throughput estimators in future compiler and performance engineering tools. They also highlight the portability of their approach as a significant advantage for future work. The open-source nature of their implementation encourages further research and improvement.

Summary updated

BibTeX
@inproceedings{mendis2019ithemal,
  author = {Charith Mendis and Saman P. Amarasinghe and Michael Carbin},
  title = {{Ithemal: Accurate, Portable and Fast Basic Block Throughput Estimation using Deep Neural Networks}},
  booktitle = {International Conference on Machine Learning},
  year = {2019},
}
Figure