arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2603.17800cs.AR
收藏

通过自定义xDSL降低实现RISC-V向量代码生成

Enabling RISC-V Vector Code Generation in MLIR through Custom xDSL Lowerings

Universitat Politècnica de València(瓦伦西亚理工大学);Universidad de Córdoba(科尔多瓦大学)

Jie Lei, Héctor Martínez, Adrián Castelló

AI总结:

本文通过结合MLIR与xDSL,解决RISC-V向量扩展代码生成中缺乏的降低阶段,展示如何通过定制中间表示和转换传递,将高级操作转换为硬件感知的C代码,生成高性能RISC-V内核。

摘要:

随着RISC-V在高性能和科学计算中的广泛应用,对面向RISC-V向量(RVV)扩展的性能可移植代码的需求增加。然而,当前编译器基础设施在从高级表示到低级实现的端到端支持方面有限。特别是现有MLIR分布缺乏将高级抽象映射到RVV内建函数的实用降低路径,限制了其在生产级RISC-V内核中的应用。本文提出了一种结合MLIR与xDSL的编译方法,通过定制的中间表示和xDSL实现的转换传递,系统地将高级操作转换为调用RVV内建函数的专用、硬件感知的C代码。生成的内核作为可移植的C函数直接集成到现有应用中,实现逐步采用而无需修改周围软件栈。本文在通用矩阵乘法(GEMM)内核上展示该方法,并在两个真实的RISC-V平台K230和BananaPi F3上评估生成的微内核,与OpenBLAS进行比较。当集成到矩阵乘法内核中时,所提出的方法在平方矩阵基准和基于BERT-Large模型的变换器工作负载上均优于OpenBLAS,达到最高12.2 GFLOPS,比基准线5.1 GFLOPS提升10-35%。这些结果表明,结合MLIR与xDSL为RISC-V平台提供了可行的可移植、优化代码生成路径。

英文摘要:

The growing adoption of RISC-V in high-performance and scientific computing has increased the need for performance-portable code targeting the RISC-V Vector (RVV) extension. However, current compiler infrastructures provide limited end-to-end support for generating optimized RVV code from high-level representations to low-level implementations. In particular, existing MLIR distributions lack practical lowering paths that map high-level abstractions to RVV intrinsics, limiting their applicability for production-ready RISC-V kernels. This paper presents a compilation approach that combines MLIR with xDSL to bridge the missing lowering stages required for RVV code generation. Using custom intermediate representations and transformation passes implemented in xDSL, we systematically translate high-level operations into specialized, hardware-aware C code invoking RVV intrinsics. The resulting kernels are emitted as portable C functions that can be directly integrated into existing applications, enabling incremental adoption without modifying surrounding software stacks. We demonstrate the approach on the General Matrix Multiplication (GEMM) kernel and evaluate the generated micro-kernels on two real RISC-V platforms, the K230 and the BananaPi F3, comparing against OpenBLAS for both square-matrix benchmarks and transformer-based workloads derived from the BERT-Large model. When integrated into a matrix multiplication kernel, the proposed approach consistently outperforms OpenBLAS, reaching up to 12.2 GFLOPS compared to the baseline's 5.1 GFLOPS and providing performance improvements between 10--35\% across the evaluated workloads. These results demonstrate that combining MLIR with xDSL provides a practical pathway to portable, optimized code generation for RISC-V platforms.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑