Multi-Level Intermediate Representation (MLIR) is a novel compiler infrastructure that aims to provide modular and extensible components to facilitate building domain specific compilers. However, since MLIR models programs at an intermediate level of abstraction, and most extant frontends are at a very high level of abstraction, the semantics and mechanics of the fundamental transformations available in MLIR are difficult to investigate and employ in and of themselves. To address these challenges, we have developed \texttt{nelli}, a lightweight, Python-embedded, domain-specific, language for generating MLIR code. \texttt{nelli} leverages existing MLIR infrastructure to develop Pythonic syntax and semantics for various MLIR features. We describe \texttt{nelli}'s design goals, discuss key details of our implementation, and demonstrate how \texttt{nelli} enables easily defining and lowering compute kernels to diverse hardware platforms.
翻译:多级中间表示(MLIR)是一种新型编译器基础设施,旨在提供模块化、可扩展的组件以简化领域专用编译器的构建。然而,由于MLIR在中间抽象层级上建模程序,而现有前端大多处于极高的抽象层级,导致难以直接研究和运用MLIR中基本变换的语义与机制。为应对这些挑战,我们开发了\texttt{nelli}——一种轻量级的、内嵌于Python的领域专用语言,用于生成MLIR代码。\texttt{nelli}利用现有MLIR基础设施,为多种MLIR特性构建了符合Python风格的语法与语义。本文阐述了\texttt{nelli}的设计目标,讨论了实现中的关键细节,并展示了\texttt{nelli}如何轻松定义计算内核并将其降级到多样化的硬件平台。