Skip to content

[C++] Add RISC-V Vector (RVV) support and dynamic dispatch - #51340

Open
zhanchangbao-sanechips wants to merge 8 commits into
apache:mainfrom
zhanchangbao-sanechips:rvvopt
Open

zhanchangbao-sanechips wants to merge 8 commits into
apache:mainfrom
zhanchangbao-sanechips:rvvopt

Conversation

@zhanchangbao-sanechips

@zhanchangbao-sanechips zhanchangbao-sanechips commented Sep 15, 2026 •

Copy link
Copy Markdown

Rationale for this change

Add initial RISC-V Vector (RVV) support to Arrow C++. This mirrors the existing SVE dynamic-dispatch support on AArch64, paves the way for upcoming RVV‑related optimizations, providing:

  • Runtime CPU capability detection for RVV and vector length (VLEN = 128/256/512 bits) on riscv64 Linux.
  • A DispatchLevel::RVV entry so RVV-optimized kernels can be compiled with -march=rv64gcv and selected at runtime.
  • CMake plumbing: ARROW_SIMD_LEVEL=RVV for compile-time RVV and ARROW_RUNTIME_SIMD_LEVEL=RVV|MAX for runtime dispatch, with graceful fallback (NONE) when the toolchain lacks RVV support.

What changes are included

  • cpp/src/arrow/util/cpu_info.h/.cc: add RVV/RVV128/RVV256/RVV512 hardware flags; detect V extension via getauxval(AT_HWCAP) and VLEN via the vlenb CSR on Linux/riscv64.
  • cpp/src/arrow/util/dispatch_internal.h: add DispatchLevel::RVV and ARROW_DISPATCH_TARGET_RVV macro, wired into
    DynamicDispatch::IsSupported.
  • cpp/cmake_modules/DefineOptions.cmake: add RVV to ARROW_SIMD_LEVEL and ARROW_RUNTIME_SIMD_LEVEL option lists.
  • cpp/cmake_modules/SetupCxxFlags.cmake: riscv64 handling — check -march=rv64gcv, set ARROW_HAVE_RVV (compile-time) / ARROW_HAVE_RUNTIME_RVV (runtime), default ARROW_SIMD_LEVEL=NONE.
  • cpp/src/arrow/util/simd.h: include <riscv_vector.h> when RVV is enabled.
  • cpp/src/arrow/util/io_util_test.cc: extend CpuInfo.Basic to assert RVV detection and a matching VLEN flag.

Are these changes tested?

Yes. Built and unit-tested on Sophgo SG2044 board with GCC 14.3.1.
Built with --DARROW_SIMD_LEVEL=RVV -DARROW_RUNTIME_SIMD_LEVEL=RVV, config passed.
All unittest passed.
20260915151437044

Are there any user-facing changes?

No user-facing API changes; adds build-time options ARROW_SIMD_LEVEL=RVV and ARROW_RUNTIME_SIMD_LEVEL=RVV|MAX for riscv64.
GitHub Issue: #51334

…patch

Adds support for the RISC‑V Vector (RVV) extension in the C++ runtime SIMD dispatch machinery, analogous to the existing NEON/SVE support for AArch64, and paves the way for upcoming RVV‑related optimizations.
@github-actions github-actions Bot added the awaiting review Awaiting review label Sep 15, 2026
@github-actions

Copy link
Copy Markdown

Thanks for opening a pull request!

This pull request has been automatically converted to a draft because its title doesn't match Arrow's required format.

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

After updating the title, you can mark the pull request as ready for review.

See also:

@github-actions
github-actions Bot marked this pull request as draft September 15, 2026 08:12
@zhanchangbao-sanechips
zhanchangbao-sanechips marked this pull request as ready for review September 15, 2026 08:42
@pitrou

pitrou commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Hi @zhanchangbao-sanechips , as you probably have in seen the SVE-handling code above your changes, we are using xsimd for instruction set detection. Can we ask you to do that for RVV too?

(you may need to contribute the required additions to xsimd if not already available)

@zhanchangbao-sanechips

Copy link
Copy Markdown
Author

Hi @zhanchangbao-sanechips , as you probably have in seen the SVE-handling code above your changes, we are using xsimd for instruction set detection. Can we ask you to do that for RVV too?

(you may need to contribute the required additions to xsimd if not already available)

I referred to my previous PR: apache/orc#2639. I will follow the same approach as the SVE handling and use xsimd for RVV instruction set detection.

…patch

Use xsimd's cpu_features for RVV detection in cpu_info.cc, mirroring the existing SVE handling. The bundled xsimd 14.2.0 already provides rvv()/rvv_size_bytes().
@pitrou

pitrou commented Sep 21, 2026

Copy link
Copy Markdown
Member

@zhanchangbao-sanechips Is this ready for review?

@zhanchangbao-sanechips

Copy link
Copy Markdown
Author

@zhanchangbao-sanechips Is this ready for review?

Not ready yet. Some CI failures are unresolved. I was tied up with other work these days.

@zhanchangbao-sanechips
zhanchangbao-sanechips marked this pull request as draft September 28, 2026 06:23
Fix trailing whitespace in DefineOptions.cmake and reformat the
CpuInfo RVV test in io_util_test.cc to satisfy pre-commit
(clang-format / cmake-format).
@zhanchangbao-sanechips
zhanchangbao-sanechips marked this pull request as ready for review October 26, 2026 06:51
@zhanchangbao-sanechips

Copy link
Copy Markdown
Author

@zhanchangbao-sanechips Is this ready for review?

I've been busy with other matters recently, as well as preparing for the ORC port to RISC-V and its performance optimization for a talk at this year's RISC-V Summit, which caused some delays. I'm now back to the work on porting and optimizing Arrow on RISC-V. Please take some time to review it when you can. Thank you.

Comment thread cpp/src/arrow/util/dispatch_internal.h Outdated
#endif

#if defined(ARROW_HAVE_RVV) || defined(ARROW_HAVE_RUNTIME_RVV)
# define ARROW_DISPATCH_TARGET_RVV(func) \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is right, we want per-vector width macros just like for SVE.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is right, we want per-vector width macros just like for SVE.

Thank you for your review,you're right, and I've split RVV into per-vector-width macros to match SVE.

Comment thread cpp/cmake_modules/SetupCxxFlags.cmake Outdated
elseif(ARROW_CPU_FLAG STREQUAL "riscv64")
set(ARROW_RVV_MARCH "rv64gcv")
check_cxx_compiler_flag("-march=${ARROW_RVV_MARCH}" CXX_SUPPORTS_RVV)
if(CXX_SUPPORTS_RVV AND ARROW_RUNTIME_SIMD_LEVEL MATCHES "^(RVV|MAX)$")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like SVE, we probably want RVV128 etc.

Comment thread cpp/cmake_modules/DefineOptions.cmake Outdated
"SVE128" # fixed size SVE
"SVE256" # "
"SVE512" # "
"RVV"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like SVE, we probably want RVV128 etc.

Split the single RVV SIMD dispatch target into per-vector-width
RVV128/RVV256/RVV512, mirroring the existing SVE handling.

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me now, a couple suggestions.

string(REGEX MATCH "[0-9]+" RVV_VECTOR_BITS ${ARROW_SIMD_LEVEL})
if(RVV_VECTOR_BITS)
set(ARROW_HAVE_RVV${RVV_VECTOR_BITS} ON)
add_definitions(-DARROW_HAVE_RVV${RVV_VECTOR_BITS})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also enable a compiler option for the given vector size, as in SVE above?

set(ARROW_HAVE_RVV${RVV_VECTOR_BITS} ON)
add_definitions(-DARROW_HAVE_RVV${RVV_VECTOR_BITS})
else()
set(ARROW_HAVE_RVV ON)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps call it ARROW_HAVE_RVV_SIZELESS just like SVE above?

message(WARNING "ARROW_SIMD_LEVEL=${ARROW_SIMD_LEVEL} not supported by Arm.")
endif()
endif()
if(ARROW_CPU_FLAG STREQUAL "riscv64")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add line break as above.

Suggested change
if(ARROW_CPU_FLAG STREQUAL "riscv64")
if(ARROW_CPU_FLAG STREQUAL "riscv64")

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants