Skip to main content
QUICK REVIEW

[Paper Review] A Deep Learning Based Cost Model for Automatic Code Optimization

Mohamed Riyadh Baghdadi, Massinissa Merouani|arXiv (Cornell University)|Apr 11, 2021
Parallel Computing and Optimization TechniquesComputer Science26 citations
TL;DR

This paper presents a deep learning based cost model that predicts speedups from code transformations applied to full programs in the Tiramisu compiler, achieving ~16% mean absolute percentage error and enabling competitive automatic optimization without heavy feature engineering.

ABSTRACT

Enabling compilers to automatically optimize code has been a longstanding goal for the compiler community. Efficiently solving this problem requires using precise cost models. These models predict whether applying a sequence of code transformations reduces the execution time of the program. Building an analytical cost model to do so is hard in modern x86 architectures due to the complexity of the microarchitecture. In this paper, we present a novel deep learning based cost model for automatic code optimization. This model was integrated in a search method and implemented in the Tiramisu compiler to select the best code transformations. The input of the proposed model is a set of simple features representing the unoptimized code and a sequence of code transformations. The model predicts the speedup expected when the code transformations are applied. Unlike previous models, the proposed one works on full programs and does not rely on any heavy feature engineering. The proposed model has only 16% of mean absolute percentage error in predicting speedups on full programs. The proposed model enables Tiramisu to automatically find code transformations that match or are better than state-of-the-art compilers without requiring the same level of heavy feature engineering required by those compilers.

Motivation & Objective

  • Motivate automating code optimization in compilers using learned cost models to guide transformation search.
  • Develop a full-program, deep learning regression model that avoids heavy feature engineering.
  • Integrate the model with a search strategy to automatically identify high-performance code transformations.
  • Evaluate accuracy and effectiveness against state-of-the-art models and Baselines in real benchmarks.

Proposed method

  • Construct a data generator to create random Tiramisu programs and valid transformation sequences and measure actual speedups.
  • Represent programs via a compact AST-based Computation Vector including loop nests, assignments, and transformations.
  • Propose a hybrid neural architecture combining computation embeddings, a recursive loop embedding unit (two LSTMs + fusion), and a regression layer to predict speedups.
  • Train the model to minimize Mean Absolute Percentage Error (MAPE) using PyTorch and AdamW.
  • Use the learned model as an objective in tree-based search (Beam Search and Monte Carlo Tree Search) to explore code transformation sequences while accounting for model uncertainty.
  • Compare against a Halide-based cost model and analyze accuracy, ranking, and tradeoffs between search time and final performance.

Experimental results

Research questions

  • RQ1Can a deep learning model predict speedups from sequences of code transformations applied to full programs in a CPU context?
  • RQ2Does avoiding heavy hand-engineered features while operating on full programs degrade or preserve predictive accuracy and ranking quality?
  • RQ3How effectively can the learned model guide Beam Search and MCTS to discover high-performance transformation sequences in realistic benchmarks?
  • RQ4How does the proposed model compare to Halide’s cost model in accuracy and in facilitating automatic optimization across diverse workloads?

Key findings

  • MAPE of 16% on the test set for speedup prediction.
  • Pearson correlation of 0.90 and Spearman correlation of 0.95 between predicted and measured speedups/ranks.
  • The model enables Tiramisu to automatically find transformations that match or outperform state-of-the-art compilers in several benchmarks.
  • Beam Search with the cost model achieves substantial search-time speedups with modest degradation in final performance (average ~15%).
  • MCTS using the model offers competitive results and better handling of model imprecision in some benchmarks.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.