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

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

Read Enabling RISC-V Vector Code Generation in MLIR through Custom xDSL Lowerings by Jie Lei, Héctor Martínez, Adrián Castelló (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2603-17800.txt.

Introduction

Lei, Martínez, and Castelló close a compiler gap for RISC-V vector code. MLIR lacks a working path from high-level code to RISC-V Vector intrinsics. Their xDSL stages translate operations into tuned C code that calls those intrinsics. Matrix multiply kernels then drop into existing apps without stack changes. On two real boards the kernels beat OpenBLAS, reaching 12.2 GFLOPS, they report. Gains ran 10 to 35 percent across workloads.

Catalog record

CREATORJie Lei, Héctor Martínez, Adrián Castelló
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE38193
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2603.17800

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Enabling RISC-V Vector Code Generation in MLIR through Custom xDSL Lowerings Jie Lei, Héctor Martínez, Adrián Castelló Abstract 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. 1 Introduction The growing adoption of RISC-V as a common Instruction Set Architecture (ISA) across domains ranging from Internet-of-Things (IoT) devices to high-performance computing (HPC) systems has introduced new challenges for software portability and optimization. In the HPC context, modern RISC-V processors increasingly implement the RISC-V Vector (RVV). extension in diverse configurations, including Simple-Instruction Multiple-Data (SIMD) floating-point units of varying widths, and long vector register architectures. Although these platforms share a common ISA, their microarchitectural diversity complicates the development of portable, high-performance software. Achieving high performance on RVV requires explicit management of vector-length–agnostic programming, intrinsic selection, and tile sizing. As the number and heterogeneity of RISC-V implementations continue to grow, maintaining hand-tuned kernels becomes increasingly impractical, even for regular HPC workloads such as dense linear algebra. Compiler infrastructures such as Halide [ 14 ] , MLIR [ 10 , 11 ] , Apache TVM [ 6 ] , or Exo [ 9 ] address this challenge by generating optimized, hardware-aware code from high-level representations. Among them, MLIR provides a powerful multi-level intermediate representation (IR) and extensible lowering framework. However, current MLIR distributions lack complete end-to-end lowering paths for RVV targets, particularly for mapping high-level vector abstractions to RVV intrinsics and hardware-aware C code. This limitation restricts MLIR’s applicability to production-ready RVV kernel generation. In this work, we bridge this gap by combining MLIR with xDSL [ 3 , 7 ] , a Python-native toolkit for designing domain-specific compilers, to enable systematic generation of C code targeting RVV intrinsics. Using xDSL, we implement the missing lowering stages and introduce IRs that explicitly model RVV semantics and vector-length–aware transformations. The resulting kernels are emitted as standalone C functions that can be directly integrated into existing applications. Taking advantage of the automatic code generation, we also benefit from generating a complete collection of different micro-kernels. The generated combinations are then used for fine-tuning HPC applications, making it possible to choose the best micro-kernel for each scenario, and in particular for deep learning (DL) models, the best micro-kernel for each layer and target architecture. Concretely, this paper makes the following contributions: • We analyze the limitations of MLIR for RVV code generation and identify the missing lowering stages. • We design and implement a hybrid MLIR–xDSL compilation pipeline that bridges these gaps through custom dialects and transformations. • We enable the generation of specialized, hardware-aware C micro-kernels for the General Matrix Multiplication ( gemm ), targeting RVV intrinsics. • We evaluate the generated C code and compare it against the highly optimized implementation of gemm in OpenBLAS [ 13 ] using different DL models. The rest of the paper is organized as follows. Section 2 summarizes a high-performance algorithm for gemm and introduces the MLIR and xDSL frameworks; Section 3 lists other approaches to automatic code generation and visits some existing work; Section 4 presents the complete workflow of our proposed solution; Section 5 evaluates and compares the auto-generated C code on gemm operations; Section 6 closes the paper with some concluding remarks. 2 Background 2.1 gemm in High-Performance Libraries Consider the gemm C\leftarrow C+AB , where A\in\mathbb{R}^{m\times k} , B\in\mathbb{R}^{k\times n} , and C\in\mathbb{R}^{m\times n} . High-performance implementations of gemm in modern BLAS libraries follow the algorithmic structure popularized by GotoBLAS [ 8 ] , with the computation organized as a hierarchy of loops and packing routines designed to exploit the memory hierarchy and SIMD units, as depicted in Figure 1 . ⬇ 1 for ( jc =0; jc < n ; jc += nc ) // Loop L1 2 for ( pc =0; pc < k ; pc += kc ) { // L2 3 Bc := B ( pc : pc + kc -1, jc : jc + nc -1); // Pack B 4 for ( ic =0; ic < m ; ic += mc ) { // L3 5 Ac := A ( ic : ic + mc -1, pc : pc + kc -1); // Pack A 6 for ( jr =0; jr < nc ; jr += nr ) // L4 7 for ( ir =0; ir < mc ; ir += mr ) // L5 8 // Micro-kernel 9 for ( pr =0; pr < kc ; pr ++) // L6 10 C ( ic + ir : ic + ir + mr -1, jc + jr : jc + jr + nr -1) 11 += Ac ( ir : ir + mr -1, pr ) * Bc ( pr , jr : jr + nr -1); 12 }} Figure 1 : Pseudo-code of the Goto-based BLIS gemm algorithm. In particular, at the outmost level, three nested loops iterate over the n -, k -, and m -dimensions using cache-aware blocking parameters n_{c} , k_{c} , and m_{c} . These loops define the macro-kernel , whose role is to partition the matrices into panels that fit different cache levels. Submatrices of A and B are reorganized and packed into contiguous buffers ( A_{c}\in\mathbb{R}^{m_{c}\times k_{c}} and B_{c}\in\mathbb{R}^{k_{c}\times n_{c}} ) to ensure predictable cache behavior. The actual and critical arithmetic is performed inside the micro-kernel , a component that is typically written in assembly or in C using vector intrinsics. The micro-kernel updates a small micro-tile of matrix C of size m_{r}\times n_{r} processing the problem across the k_{c} dimension, effectively performing a sequence of outer-product operations. The packed micro-panels A_{r}\in\mathbb{R}^{m_{r}\times k_{c}} and B_{r}\in\mathbb{R}^{k_{c}\times n_{r}} , which are part of A_{c} and B_{c} , are arranged to maximize register reuse, ensure unit-stride memory access, and improve SIMD efficiency. Adapting this structure to RISC-V with RVV requires careful handling of vector-length–agnostic execution, intrinsic selection, and tile sizing, which motivates systematic code generation approaches. 2.2 MLIR MLIR is a compiler

Read the complete text