arXiv:2510.14871cs.CLcs.AR2025-10被引 8

用新编译器框架让AI模型高效运行在AMD NPU上

From Loop Nests to Silicon: Mapping AI Workloads onto AMD NPUs with MLIR-AIR

  • 基于MLIR构建,用AIR方言显式控制计算与数据调度
  • 矩阵乘法最高达78.7%算力利用率,接近手工优化效果
  • 适合想高效部署AI模型到空间架构的工程师和研究者

通用编译器抽象了并行性、局部性和同步机制,难以发挥现代空间架构性能。随着现代计算架构越来越依赖对数据移动、执行顺序和计算放置的细粒度控制,编译器基础设施必须提供显式机制来协调计算与数据,以充分挖掘此类架构潜力。我们提出MLIR-AIR,一个基于MLIR的开源编译栈,弥合高层工作负载与细粒度空间架构(如AMD NPUs)之间的语义鸿沟。MLIR-AIR定义了AIR方言,为跨计算与内存资源的异步、分层操作提供结构化表示。AIR原语使编译器能够实现空间调度、跨硬件区域分配计算,并在无需临时运行时协调或手动调度的情况下重叠通信与计算。通过两个案例研究展示其能力:矩阵乘法和LLaMA 2中的多头注意力模块。对于矩阵乘法,MLIR-AIR达到最高78.7%的计算效率,生成的实现性能几乎与最先进的手写优化代码(使用低层、贴近硬件的MLIR-AIE框架)相当。对于多头注意力,我们展示了使用约150行代码即可实现融合计算,使得复杂工作负载可被高效映射到空间硬件。MLIR-AIR将高层结构化控制流转化为高效利用NPU计算阵列和内存层次结构的空间程序,通过编译器管理的异步执行、分块和通信重叠实现优化。

原文摘要 · Abstract (English)

General-purpose compilers abstract away parallelism, locality, and synchronization, limiting their effectiveness on modern spatial architectures. As modern computing architectures increasingly rely on fine-grained control over data movement, execution order, and compute placement for performance, compiler infrastructure must provide explicit mechanisms for orchestrating compute and data to fully exploit such architectures. We introduce MLIR-AIR, a novel, open-source compiler stack built on MLIR that bridges the semantic gap between high-level workloads and fine-grained spatial architectures such as AMD's NPUs. MLIR-AIR defines the AIR dialect, which provides structured representations for asynchronous and hierarchical operations across compute and memory resources. AIR primitives allow the compiler to orchestrate spatial scheduling, distribute computation across hardware regions, and overlap communication with computation without relying on ad hoc runtime coordination or manual scheduling. We demonstrate MLIR-AIR's capabilities through two case studies: matrix multiplication and the multi-head attention block from the LLaMA 2 model. For matrix multiplication, MLIR-AIR achieves up to 78.7% compute efficiency and generates implementations with performance almost identical to state-of-the-art, hand-optimized matrix multiplication written using the lower-level, close-to-metal MLIR-AIE framework. For multi-head attention, we demonstrate that the AIR interface supports fused implementations using approximately 150 lines of code, enabling tractable expression of complex workloads with efficient mapping to spatial hardware. MLIR-AIR transforms high-level structured control flow into spatial programs that efficiently utilize the compute fabric and memory hierarchy of an NPU, leveraging asynchronous execution, tiling, and communication overlap through compiler-managed scheduling.

编译器NPUMLIR算子优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。