NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Optimization Method for High-performance Libraries Targeting RISC-V Vector Extension

Liutong Han, Hongbin Zhang, Mingjie Xing, Yanjun Wu, Chen ZhaoInt. J. Softw. Informatics 2025

Abstract

Modern high-performance libraries rely on Single Instruction, Multiple Data (SIMD) extensions to accelerate computationally intensive tasks. However, traditional fixed-length SIMD abstractions often fail to leverage the unique Vector Length Agnostic (VLA) capabilities of the RISC-V Vector (RVV) extension. This paper introduces a redesigned Hardware Abstraction Layer (HAL) that utilizes type aliasing and dynamic metadata querying to unlock RVV's full potential. Evaluation on OpenCV modules demonstrates a 3.93x performance boost, significantly outperforming standard auto-vectorization and previous fixed-length implementations.

Introduction

The demand for high-performance computing on edge devices has led to the widespread adoption of SIMD extensions. While established architectures like x86 (AVX) and ARM (Neon) utilize fixed-length registers, the RISC-V Vector (RVV) extension introduces a Vector Length Agnostic (VLA) paradigm. In VLA, the hardware register length (VLEN) is not fixed at design time, allowing software to scale across different hardware implementations without recompilation.

Despite this flexibility, existing software libraries like OpenCV often struggle to integrate RVV efficiently. Their internal Hardware Abstraction Layers (HALs), designed for fixed-length registers, impose a "performance tax" on RVV by wasting hardware resources and introducing unnecessary memory overhead.

The Challenge of Fixed-Length Abstractions

Traditional HAL designs, such as OpenCV’s "universal intrinsics," wrap vector types in fixed-length classes (e.g., 128-bit). When applied to RVV, this approach leads to two primary issues:

  1. Resource Underutilization: On hardware with registers larger than the abstraction (e.g., 512-bit), the majority of the vector unit remains idle.
  2. Memory Bottlenecks: The mismatch between abstract types and native RVV types necessitates frequent data copying between memory and registers, which can result in performance that is actually inferior to scalar code.

Proposed Optimization Framework

To address these challenges, the researchers developed a new optimization framework that aligns with the VLA nature of RISC-V.

Architecture of the proposed Hardware Abstraction Layer (HAL) for RISC-V Vector optimization.

Key Technical Innovations

  • Type Aliasing: Instead of using C++ wrapper classes, the framework employs type aliases to map universal intrinsics directly to native RVV types. This allows the compiler to optimize register allocation more effectively and eliminates redundant memory operations.
  • Trait Classes for Dynamic Metadata: Since vector length is determined at runtime, the framework uses "trait classes" to provide a unified interface for querying vector properties, such as the number of lanes (vlanes()).
  • LMUL Support: The framework integrates support for Register Grouping (LMUL), allowing multiple physical registers to be treated as a single virtual register, thereby increasing the data processed per instruction.
  • Automated Migration: A custom refactoring tool was used to migrate 90.6% of OpenCV’s existing universal intrinsic blocks to the new framework, ensuring broad compatibility.

Experimental Evaluation

The framework was evaluated using OpenCV’s standard performance test suites on two RISC-V platforms: the CanMV-K230 (128-bit VLEN) and the Banana Pi BPI-F3 (256-bit VLEN). The benchmarks included:

  • Core Module: Over 3,300 cases for basic arithmetic and matrix operations.
  • Image Processing (imgProc): Over 4,100 cases including filtering and blurring.
  • Real-world Scenarios: Gaussian blur, Canny edge detection, and QR code detection.

Results and Analysis

The proposed method achieved a significant performance leap over existing implementations. On the Banana Pi BPI-F3, the Core Module saw an average speedup of 3.93x. In contrast, the original fixed-length HAL implementation provided only a 0.77x speedup (slower than scalar code), while the compiler's auto-vectorization reached 2.16x.

In real-world scenarios, the benefits were equally pronounced. Gaussian blur operations were 5.71x faster, contributing to a 3.73x overall application speedup. QR code detection also saw a 4.05x improvement. These results highlight that designing for variable length allows the same code to scale automatically with hardware capabilities; the 256-bit board naturally outperformed the 128-bit board without code modifications.

Conclusion

This research demonstrates that moving from "Object-Oriented" wrappers to "Type-Oriented" aliases is essential for high-performance RISC-V software. By embracing the Vector Length Agnostic nature of RVV, developers can create libraries that are both portable and highly efficient. The framework has been integrated into the official OpenCV repository. Future work will extend these optimizations to other major libraries such as PyTorch, Eigen, and GGML for LLM inference.

Summary updated

BibTeX
@article{han2025optimization,
  author = {Liutong Han and Hongbin Zhang and Mingjie Xing and Yanjun Wu and Chen Zhao},
  title = {{Optimization Method for High-performance Libraries Targeting RISC-V Vector Extension}},
  journal = {Int. J. Softw. Informatics},
  year = {2025},
  doi = {10.21655/ijsi.1673-7288.00354},
}
Figure