Skip to main content
QUICK 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 Science被引用 26
一句话总结

本论文提出一种基于深度学习的成本模型,预测在 Tiramisu 编译器对完整程序应用代码变换后的加速,达到约 16% 的平均绝对百分比误差,并实现无需大量特征工程的竞争性自动优化。

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.

研究动机与目标

  • 以学习得到的成本模型来引导变换搜索,推动编译器中代码优化的自动化。
  • 开发一个针对完整程序的深度学习回归模型,避免繁重的特征工程。
  • 将模型与搜索策略整合,自动识别高性能的代码变换。
  • 在真实基准测试中评估与最先进模型及基线的准确性和有效性。

提出的方法

  • 构建一个数据生成器,用于创建随机的 Tiramisu 程序和有效的变换序列,并测量实际加速比。
  • 通过紧凑的基于 AST 的 Computation Vector 表征程序,其中包括循环嵌套、赋值和变换。
  • 提出一种混合神经网络架构,结合计算嵌入、一个递归循环嵌入单元(两个 LSTM+融合),以及一个回归层来预测加速比。
  • 使用 PyTorch 和 AdamW 训练模型,使目标最小化 Mean Absolute Percentage Error (MAPE)。
  • 将学习到的模型用作基于树的搜索的目标函数(束搜索和蒙特卡洛树搜索),在考虑模型不确定性的同时探索代码变换序列。
  • 与基于 Halide 的成本模型进行比较,分析准确性、排序以及搜索时间与最终性能之间的权衡。

实验结果

研究问题

  • RQ1深度学习模型是否能够从应用于完整程序的代码变换序列中预测加速比,在 CPU 场景下?
  • RQ2在对完整程序进行操作时,避免繁重的人工特征是否会降低还是保留预测准确性和排序质量?
  • RQ3所学模型在现实基准测试中引导束搜索和 MCTS 发现高性能变换序列的有效性如何?
  • RQ4在准确性和促进跨多样化工作负载的自动优化方面,所提出的模型与 Halide 的成本模型相比如何?

主要发现

  • 测试集的速度提升预测 MAPE 为 16%。
  • 预测速度提升与实际速度提升/排名之间的皮尔逊相关系数为 0.90,斯皮尔曼相关系数为 0.95。
  • 该模型使 Tiramisu 能够在若干基准测试中自动找到与最先进编译器相匹配或超过其性能的变换。
  • 结合成本模型的束搜索在搜索时间上实现显著加速,同时最终性能的下降有限(平均约 15%)。
  • 使用该模型的蒙特卡洛树搜索在某些基准测试中提供具有竞争力的结果,并且对模型不确定性有更好的处理。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。