Compilers for general-purpose languages have been shown to be at a disadvantage when it comes to specialized application domains as opposed to their Domain-Specific Language (DSL) counterparts. However, the field of DSL compilers features little consolidation in terms of compiler frameworks and adjacent software ecosystems. As a result, considerable work is duplicated, lost to maintenance issues, or remains undiscovered, and most DSLs are never considered "production-ready". One notable development is the introduction of the Multi-Level Intermediate Representation (MLIR), which promises a similar impact on DSL compilers as LLVM had on general-purpose tooling. In this work, we present a NumPy-like DSL made for offloading numeric tensor kernels that is entirely MLIR-native. In a first for open-source, it implements all frontend actions and semantic analyses directly within MLIR. Most notably, this is made possible by our new dialect-agnostic MLIR type checker, created for the future of DSLs in MLIR. We implement a simple, yet effective, parallel-first lowering scheme that connects our language to another MLIR dataflow dialect for seamless offloading. We show that our approach performs well in real-world use cases from the domain of weather modeling and Computational Fluid Dynamics (CFD) in Fortran.
翻译:通用编程语言的编译器在特定应用领域往往不如领域特定语言(DSL)编译器,但DSL编译器在编译器框架及配套软件生态系统方面缺乏整合。因此,大量工作重复、因维护问题丢失或未被发现,多数DSL从未达到"生产就绪"状态。一个显著进展是多级中间表示(MLIR)的引入,它有望对DSL编译器产生类似LLVM对通用工具链的影响。本文提出了一个完全基于MLIR原生的类似NumPy的DSL,专为数值张量核的卸载设计。作为开源领域的首次尝试,该DSL直接在MLIR内部实现所有前端动作和语义分析。最值得注意的是,这得益于我们为MLIR中DSL的未来而创建的新颖的方言无关型MLIR类型检查器。我们实现了一种简单而有效的并行优先降级方案,将我们的语言连接到另一个MLIR数据流方言以实现无缝卸载。实验表明,我们的方法在天气预报和Fortran计算流体力学(CFD)领域的实际应用中表现良好。