PolyBlocks自动优化AI模型代码,适配新芯片无需重写
PolyBlocks: A Compiler Infrastructure for AI Chips and Programming Frameworks
- 基于MLIR构建模块化编译器,通过轻量仿射分析优化循环嵌套
- 在NVIDIA GPU上生成代码性能媲美甚至超越厂商优化库
- 适合开发新AI芯片或自研框架的团队快速搭建编译系统
我们提出PolyBlocks,一个基于MLIR的模块化、可复用的AI编程框架与AI芯片编译基础设施。其核心是基于循环嵌套和SSA的转换流水线,主要依赖轻量级仿射访问分析;通过解析成本模型和启发式规则,将多种优化组合,实现高性能代码的自动生成。优化包括多级分块、算子融合、片上缓存使用、矩阵乘与卷积映射至矩阵单元、注意力层融合等,显著提升并行性与局部性。该设计使构建面向新芯片的编译器变得简单,可复用大部分基础设施。实验表明,基于PolyBlocks的JIT编译在PyTorch和JAX上对NVIDIA GPU的性能达到或超过Torch Inductor与XLA,后者依赖厂商库与代码生成。对于matmul、convolution等单个算子,生成代码性能可比肩最佳厂商调优库或手工内核。
原文摘要 · Abstract (English)
We present the design and implementation of PolyBlocks, a modular and reusable MLIR-based compiler infrastructure for AI programming frameworks and AI chips. PolyBlocks is based on pass pipelines that compose transformations on loop nests and SSA, primarily relying on lightweight affine access analysis; the transformations are stitched together in specialized ways to realize high-performance code automatically by the use of analytical cost models and heuristics. The optimizations in these passes include multi-level tiling, fusion, on-chip scratchpad usage, mapping matmuls and convolutions to matrix units, fusing the attention layer, and several other transformations for parallelism and locality. They have been developed in a way that makes it easy to build PolyBlocks-based compilers to target new chips, reusing much of the infrastructure. PolyBlocks' design and architecture enable fully automatic code generation from high-level frameworks to low-level target-specific intrinsics. Experimental results from evaluating PolyBlocks-powered just-in-time compilation for PyTorch and JAX targeting NVIDIA GPUs show that it is able to match or outperform Torch Inductor and XLA in several cases, although the latter rely on a combination of vendor libraries and code generation. For individual operators like matmuls and convolutions, PolyBlocks-generated code is competitive with the best vendor-tuned libraries or hand-written kernels.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。