A Multi-level Compiler Backend for Accelerated Micro-kernels Targeting RISC-V ISA Extensions

Alexandre Lopoukhine, Federico Ficarelli, Christos Vasiladiotis, Anton Lydike, Josse Van Delm, Alban Dutilleul, Luca Benini, Marian Verhelst, Tobias GrosserCGO 2025 · DOI · OpenReview

TL;DR

Traditional compiler backends act as an "hourglass" bottleneck, stripping away high-level intent just when specialized hardware needs it most. This paper introduces a multi-level backend using MLIR that preserves structural information—like loops and data streams—all the way down to the hardware. This approach enables automated code generation for RISC-V accelerators that achieves up to 90% peak performance without the need for hand-written assembly.

What Problem Does This Paper Address?

In the world of high-performance computing and Deep Learning (DL), we are seeing an explosion of specialized hardware. However, our compilers are struggling to keep up. Most modern compilers (like LLVM or GCC) use a "one-size-fits-all" approach: they translate high-level code into a generic, low-level Intermediate Representation (IR) before generating machine code.

The authors call this the "hourglass bottleneck." By the time the compiler reaches the backend, it has lost crucial context—such as the fact that a block of code is a nested loop or that data is being accessed in a predictable stream. For specialized accelerators like the RISC-V-based Snitch, which features custom hardware for streaming data and zero-overhead loops, this lost information is devastating. To get peak performance, developers are often forced to bypass the compiler entirely and write "expert-tuned" assembly by hand, which is difficult to maintain and scale.

Figure 3: Comparison between the traditional 'hourglass' compiler bottleneck and the proposed multi-level extensible approach.

Methods

The researchers built a prototype compiler backend using MLIR (Multi-Level Intermediate Representation). Instead of a single narrow entry point, their backend is "wide," meaning it can accept and process code at multiple levels of abstraction simultaneously. This allows the compiler to maintain high-level semantics until the final stages of code generation.

Key technical innovations include:

  • Progressive Lowering: The compiler moves code through a series of "dialects" (specialized IRs). It starts with high-level math (linalg), moves to memory stream abstractions (memref_stream), and finally to custom Snitch instructions.
  • Structured Register Allocation: Unlike traditional allocators that work on a flat list of instructions, this allocator works on "structured" IR. Because it understands the loop boundaries and data lifetimes from the high-level dialects, it can perform spill-free register allocation, avoiding the performance-killing practice of "spilling" variables to slow memory during computation.
  • Hardware-Matched Abstractions: They created specific IR operations that map directly to Snitch’s custom features: SSRs (Stream Semantic Registers) for automated data loading and FREP (Floating-point REPetition) for hardware-controlled loops.
Figure 6: Comparison of standard RISC-V assembly versus the optimized Snitch ISA extensions (SSRs and FREP) enabled by the multi-level backend.

Datasets and Evaluation

The authors evaluated their compiler on a suite of representative Deep Neural Network (DNN) micro-kernels, including:

  • Element-wise ops: Sum, Fill, and ReLU.
  • Spatial ops: 2D Convolution (Conv 3x3), Max Pooling, and Sum Pooling.
  • Linear Algebra: Matrix Multiplication (MatMul and MatMulT).

These kernels were tested across various input shapes to measure how the compiler handles different computational intensities and memory access patterns on the Snitch architecture.

Key Insights and Ideas

  • Breaking the Hourglass: The most significant insight is that backends shouldn't be target-agnostic. By allowing the backend to "see" high-level structures, we can automate optimizations that were previously only possible for humans writing assembly.
  • Decoupled Access-Execute: The paper demonstrates that explicitly modeling how data moves separately from how it is computed allows the compiler to perfectly utilize hardware features like streaming registers.
  • Predictability is Power: Because the target hardware (Snitch) is an in-order processor with a software-managed cache, its performance is highly predictable. The authors leveraged this to build a simple but highly effective scheduling pipeline that avoids complex, expensive search heuristics.

Key Results

  • Peak Efficiency: Micro-kernels generated by the compiler reached up to 95% FPU utilization for hand-written dialects and 90% utilization when compiled automatically from a high-level Domain Specific Language (DSL).
  • Outperforming Standard Flows: Standard LLVM and Clang flows, which cannot easily target Snitch's custom extensions, peaked at only ~42% utilization. The multi-level approach effectively doubled the performance.
  • Throughput: For Matrix Multiplication, the system achieved a sustained throughput of over 1.80 FLOPs/cycle (where the theoretical hardware peak is 2.0).
  • Zero Spilling: The structured register allocator successfully managed all tested kernels without a single memory spill, even as kernel complexity increased.

Limitations and Future Work

While the results are impressive for structured kernels, the authors note some areas for growth:

  • Kernel Complexity: As kernels become more complex (e.g., 32-bit SIMD variants), register pressure increases. The current "spill-free" guarantee might eventually require more sophisticated unrolling or scheduling heuristics.
  • Scope: The current work focuses on linear algebra and DNN micro-kernels. Extending this "wide backend" approach to more irregular or unstructured code remains a challenge.
  • Automation: Future work aims to improve the automatic selection of "unroll-and-jam" factors to perfectly balance pipeline depth with register usage across a broader range of hardware targets.

Summary updated

BibTeX
@inproceedings{lopoukhine2025multi,
  author = {Alexandre Lopoukhine and Federico Ficarelli and Christos Vasiladiotis and Anton Lydike and Josse Van Delm and Alban Dutilleul and Luca Benini and Marian Verhelst and Tobias Grosser},
  title = {{A Multi-level Compiler Backend for Accelerated Micro-kernels Targeting RISC-V ISA Extensions}},
  booktitle = {CGO},
  year = {2025},
  doi = {10.1145/3696443.3708952},
}
Figure