NeuroVectorizer:端到端矢量化与深度强化学习
NeuroVectorizer: End-to-End Vectorization with Deep Reinforcement Learning
摘要:
当编译器为当今的SIMD兼容架构向量化循环时,出现的一个关键挑战是决定向量化或交织是否有益。然后,编译器必须确定要打包多少条指令以及要交错多少次循环迭代。如今的设计师们使用固定成本的模型,这些模型是基于循环的向量化决策。然而,这些模型无法捕获数据依赖性、计算图或指令的组织。或者,软件工程师经常手写每个循环的向量化因子。然而,这给他们带来了巨大的负担,因为它需要事先的经验,并大大增加了开发时间。在这项工作中,我们探索了一种处理循环向量化的新方法,并提出了一种使用深度强化学习(RL)的端到端解决方案。我们推测,深度RL可以捕获不同的指令、依赖关系和数据结构,从而能够学习一个复杂的模型,该模型可以更好地预测实际性能成本并确定最佳矢量化因子。我们开发了一个端到端的框架,从代码到向量化,它在LLVM编译器中集成了深度RL。我们提出的框架基准代码作为输入,并提取循环代码。然后,这些循环代码被馈送到循环嵌入生成器,该生成器学习这些循环的嵌入。最后,学习的嵌入被用作深度RL代理的输入,该代理确定所有循环的向量化因子。我们进一步扩展我们的框架,以支持多种监督学习方法。我们评估我们的方法对目前使用的LLVM矢量化和循环多面体优化技术。我们的实验显示,与基线相比,性能加速了1.29倍-4.73倍,在广泛的基准测试中,仅比蛮力搜索差3%。
英文摘要:
One of the key challenges arising when compilers vectorize loops for today's SIMD-compatible architectures is to decide if vectorization or interleaving is beneficial. Then, the compiler has to determine how many instructions to pack together and how many loop iterations to interleave. Compilers are designed today to use fixed-cost models that are based on heuristics to make vectorization decisions on loops. However, these models are unable to capture the data dependency, the computation graph, or the organization of instructions. Alternatively, software engineers often hand-write the vectorization factors of every loop. This, however, places a huge burden on them, since it requires prior experience and significantly increases the development time. In this work, we explore a novel approach for handling loop vectorization and propose an end-to-end solution using deep reinforcement learning (RL). We conjecture that deep RL can capture different instructions, dependencies, and data structures to enable learning a sophisticated model that can better predict the actual performance cost and determine the optimal vectorization factors. We develop an end-to-end framework, from code to vectorization, that integrates deep RL in the LLVM compiler. Our proposed framework takes benchmark codes as input and extracts the loop codes. These loop codes are then fed to a loop embedding generator that learns an embedding for these loops. Finally, the learned embeddings are used as input to a Deep RL agent, which determines the vectorization factors for all the loops. We further extend our framework to support multiple supervised learning methods. We evaluate our approaches against the currently used LLVM vectorizer and loop polyhedral optimization techniques. Our experiments show 1.29X-4.73X performance speedup compared to baseline and only 3% worse than the brute-force search on a wide range of benchmarks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。