diff --git a/.gitignore b/.gitignore index 83458ab2057b..14ddc1ff1e71 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ python/doc/ .vscode .idea/ +.icodemate/ .pytest_cache/ pkgs docker_cache diff --git a/cpp/cmake_modules/DefineOptions.cmake b/cpp/cmake_modules/DefineOptions.cmake index b58ab3cd3810..a61cfc2a4e09 100644 --- a/cpp/cmake_modules/DefineOptions.cmake +++ b/cpp/cmake_modules/DefineOptions.cmake @@ -171,6 +171,10 @@ takes precedence over ccache if a storage backend is configured" ON) "SVE128" # fixed size SVE "SVE256" # " "SVE512" # " + "RVV" # size agnostic RVV + "RVV128" # fixed size RVV + "RVV256" # " + "RVV512" # " "DEFAULT") define_option_string(ARROW_RUNTIME_SIMD_LEVEL @@ -183,6 +187,9 @@ takes precedence over ccache if a storage backend is configured" ON) "SVE128" # fixed size SVE "SVE256" # " "SVE512" # " + "RVV128" # fixed size RVV + "RVV256" # " + "RVV512" # " "MAX") define_option(ARROW_ALTIVEC "Build with Altivec if compiler has support" ON) diff --git a/cpp/cmake_modules/SetupCxxFlags.cmake b/cpp/cmake_modules/SetupCxxFlags.cmake index 750e3bef29c0..99e2e3b165cb 100644 --- a/cpp/cmake_modules/SetupCxxFlags.cmake +++ b/cpp/cmake_modules/SetupCxxFlags.cmake @@ -167,6 +167,30 @@ elseif(ARROW_CPU_FLAG STREQUAL "aarch64") if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT") set(ARROW_SIMD_LEVEL "NEON") endif() +elseif(ARROW_CPU_FLAG STREQUAL "riscv64") + # RISC-V compiler flags, gcc/clang only + set(ARROW_RVV_MARCH "rv64gcv") + # Fixed-size RVV is compiled with a zvl extension plus -mrvv-vector-bits=zvl, + # matching xsimd (see xsimd_get_riscv64_arch_flags in xsimd's Architecture.cmake). + set(ARROW_RVV128_FLAGS "-march=${ARROW_RVV_MARCH}_zvl128b" "-mrvv-vector-bits=zvl") + set(ARROW_RVV256_FLAGS "-march=${ARROW_RVV_MARCH}_zvl256b" "-mrvv-vector-bits=zvl") + set(ARROW_RVV512_FLAGS "-march=${ARROW_RVV_MARCH}_zvl512b" "-mrvv-vector-bits=zvl") + check_cxx_compiler_flag("-march=${ARROW_RVV_MARCH}" CXX_SUPPORTS_RVV) + if(CXX_SUPPORTS_RVV AND ARROW_RUNTIME_SIMD_LEVEL MATCHES "^(RVV128|RVV256|RVV512|MAX)$") + set(ARROW_HAVE_RUNTIME_RVV128 ON) + add_definitions(-DARROW_HAVE_RUNTIME_RVV128) + endif() + if(CXX_SUPPORTS_RVV AND ARROW_RUNTIME_SIMD_LEVEL MATCHES "^(RVV256|RVV512|MAX)$") + set(ARROW_HAVE_RUNTIME_RVV256 ON) + add_definitions(-DARROW_HAVE_RUNTIME_RVV256) + endif() + if(CXX_SUPPORTS_RVV AND ARROW_RUNTIME_SIMD_LEVEL MATCHES "^(RVV512|MAX)$") + set(ARROW_HAVE_RUNTIME_RVV512 ON) + add_definitions(-DARROW_HAVE_RUNTIME_RVV512) + endif() + if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT") + set(ARROW_SIMD_LEVEL "NONE") + endif() endif() # Support C11 @@ -548,6 +572,32 @@ if(ARROW_CPU_FLAG STREQUAL "aarch64") endif() endif() +if(ARROW_CPU_FLAG STREQUAL "riscv64") + if(ARROW_SIMD_LEVEL MATCHES "RVV") + if(NOT CXX_SUPPORTS_RVV) + message(FATAL_ERROR "RVV required but compiler doesn't support it.") + endif() + string(REGEX MATCH "[0-9]+" RVV_VECTOR_BITS ${ARROW_SIMD_LEVEL}) + if(RVV_VECTOR_BITS) + set(ARROW_RVV_FIXED_FLAGS + "-march=${ARROW_RVV_MARCH}_zvl${RVV_VECTOR_BITS}b" "-mrvv-vector-bits=zvl") + check_cxx_compiler_flag("${ARROW_RVV_FIXED_FLAGS}" CXX_SUPPORTS_RVV_FIXED) + if(NOT CXX_SUPPORTS_RVV_FIXED) + message(FATAL_ERROR "Fixed-width RVV (zvl${RVV_VECTOR_BITS}b) required but compiler doesn't support it.") + endif() + set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} ${ARROW_RVV_FIXED_FLAGS}") + set(ARROW_HAVE_RVV${RVV_VECTOR_BITS} ON) + add_definitions(-DARROW_HAVE_RVV${RVV_VECTOR_BITS}) + else() + set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -march=${ARROW_RVV_MARCH}") + set(ARROW_HAVE_RVV_SIZELESS ON) + add_definitions(-DARROW_HAVE_RVV_SIZELESS) + endif() + elseif(NOT ARROW_SIMD_LEVEL STREQUAL "NONE") + message(WARNING "ARROW_SIMD_LEVEL=${ARROW_SIMD_LEVEL} not supported by riscv64.") + endif() +endif() + if(NOT WIN32 AND NOT APPLE) if(ARROW_USE_MOLD) find_program(LD_MOLD ld.mold) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index e71d92fdb880..b38b5c3307a2 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -390,6 +390,35 @@ macro(append_runtime_sve512_src SRCS SRC) endif() endmacro() +macro(append_runtime_rvv128_src SRCS SRC) + if(ARROW_HAVE_RUNTIME_RVV128) + list(APPEND ${SRCS} ${SRC}) + set(_flags ${ARROW_RVV128_FLAGS}) + set_property(SOURCE ${SRC} + APPEND + PROPERTY COMPILE_OPTIONS ${_flags}) + endif() +endmacro() + +macro(append_runtime_rvv256_src SRCS SRC) + if(ARROW_HAVE_RUNTIME_RVV256) + list(APPEND ${SRCS} ${SRC}) + set(_flags ${ARROW_RVV256_FLAGS}) + set_property(SOURCE ${SRC} + APPEND + PROPERTY COMPILE_OPTIONS ${_flags}) + endif() +endmacro() + +macro(append_runtime_rvv512_src SRCS SRC) + if(ARROW_HAVE_RUNTIME_RVV512) + list(APPEND ${SRCS} ${SRC}) + set(_flags ${ARROW_RVV512_FLAGS}) + set_property(SOURCE ${SRC} + APPEND + PROPERTY COMPILE_OPTIONS ${_flags}) + endif() +endmacro() # Write out compile-time configuration constants string(REPLACE "${CMAKE_SOURCE_DIR}" "" REDACTED_CXX_FLAGS ${CMAKE_CXX_FLAGS}) @@ -599,7 +628,14 @@ if(ARROW_CPU_FLAG STREQUAL "x86" AND ARROW_HAVE_RUNTIME_SSE4_2) "${ARROW_SSE4_2_FLAG}") endif() +# also provides the RVV128 kernels on riscv64, so it stays in ARROW_UTIL_SRCS +if(ARROW_CPU_FLAG STREQUAL "riscv64" AND ARROW_HAVE_RUNTIME_RVV128) + set_source_files_properties(util/bpacking_simd_128.cc PROPERTIES COMPILE_OPTIONS + "${ARROW_RVV128_FLAGS}") +endif() + append_runtime_sve256_src(ARROW_UTIL_SRCS util/bpacking_simd_256.cc) +append_runtime_rvv256_src(ARROW_UTIL_SRCS util/bpacking_simd_256.cc) if(ARROW_WITH_BROTLI) list(APPEND ARROW_UTIL_SRCS util/compression_brotli.cc) diff --git a/cpp/src/arrow/util/bpacking.cc b/cpp/src/arrow/util/bpacking.cc index b29927345691..729807bd859d 100644 --- a/cpp/src/arrow/util/bpacking.cc +++ b/cpp/src/arrow/util/bpacking.cc @@ -16,10 +16,12 @@ // under the License. #include +#include #include "arrow/util/bpacking_internal.h" #include "arrow/util/bpacking_scalar_internal.h" #include "arrow/util/bpacking_simd_internal.h" +#include "arrow/util/cpu_info.h" #include "arrow/util/dispatch_internal.h" namespace arrow::internal { @@ -32,11 +34,13 @@ struct UnpackDynamicFunction { static constexpr auto targets() { return std::array{ - ARROW_DISPATCH_TARGET_NONE(&bpacking::unpack_scalar) // - ARROW_DISPATCH_TARGET_NEON(&bpacking::unpack_neon) // + ARROW_DISPATCH_TARGET_NONE(&bpacking::unpack_scalar) // + ARROW_DISPATCH_TARGET_NEON(&bpacking::unpack_neon) // + ARROW_DISPATCH_TARGET_RVV128(&bpacking::unpack_rvv128) // // GH-50503: No SVE128 dispatch as it increases code size without // increasing performance vs. Neon, and can produce ODR violations. ARROW_DISPATCH_TARGET_SVE256(&bpacking::unpack_sve256) // + ARROW_DISPATCH_TARGET_RVV256(&bpacking::unpack_rvv256) // ARROW_DISPATCH_TARGET_SSE4_2(&bpacking::unpack_sse4_2) // ARROW_DISPATCH_TARGET_AVX2(&bpacking::unpack_avx2) // ARROW_DISPATCH_TARGET_AVX512(&bpacking::unpack_avx512) // @@ -48,6 +52,46 @@ struct UnpackDynamicFunction { template void unpack(const uint8_t* in, Uint* out, const UnpackOptions& opts) { +#if defined(ARROW_HAVE_RVV128) || defined(ARROW_HAVE_RVV256) || \ + defined(ARROW_HAVE_RUNTIME_RVV128) || \ + defined(ARROW_HAVE_RUNTIME_RVV256) + // On RISC-V RVV, the medium SIMD kernel is slower than the scalar + // implementation (which the compiler auto-vectorizes efficiently) for several + // unpack combinations. Route them directly to the scalar path to avoid both + // the slow kernel and the extra SIMD dispatch indirection. + constexpr bool kIsUint64 = sizeof(Uint) == sizeof(uint64_t); + // Whether the runtime dispatch would target the RVV256 kernel. CpuInfo::RVV256 + // is set only when the hardware VLEN is 256 (see cpu_info.cc), so this is + // reliable on both VLEN=128 and VLEN=256 machines. + static const bool kRvv256 = CpuInfo::GetInstance()->IsSupported(CpuInfo::RVV256); + if (opts.bit_width == 1 && kIsUint64) { + // Uint64/1-bit regresses on all RVV VLENs. + return bpacking::unpack_scalar(in, out, opts); + } + if (kRvv256) { + // The following combinations only regress on VLEN=256 hardware; on VLEN=128 + // they are faster than scalar and must keep using the SIMD kernel. + if (kIsUint64 && opts.bit_width == 2) { + // Uint64/2-bit regresses on VLEN=256 only. + return bpacking::unpack_scalar(in, out, opts); + } + // Large bit widths on small batches have too much fixed medium-kernel + // overhead to beat the scalar path on VLEN=256. + if constexpr (std::is_same_v) { + if (opts.bit_width == 13 && opts.batch_size <= 32) { + return bpacking::unpack_scalar(in, out, opts); + } + } else if constexpr (std::is_same_v) { + if (opts.bit_width == 20 && opts.batch_size <= 32) { + return bpacking::unpack_scalar(in, out, opts); + } + } else if constexpr (std::is_same_v) { + if (opts.bit_width == 20 && opts.batch_size <= 64) { + return bpacking::unpack_scalar(in, out, opts); + } + } + } +#endif static const DynamicDispatch> dispatch; return dispatch(in, out, opts); } diff --git a/cpp/src/arrow/util/bpacking_simd_128.cc b/cpp/src/arrow/util/bpacking_simd_128.cc index 9f35667d2adb..374649a23ace 100644 --- a/cpp/src/arrow/util/bpacking_simd_128.cc +++ b/cpp/src/arrow/util/bpacking_simd_128.cc @@ -18,6 +18,10 @@ #if defined(ARROW_HAVE_NEON) # define UNPACK_PLATFORM unpack_neon # define KERNEL_PLATFORM KernelNeon +#elif defined(ARROW_HAVE_RVV128) || defined(ARROW_HAVE_RUNTIME_RVV128) +# define UNPACK_PLATFORM unpack_rvv128 +# define KERNEL_PLATFORM KernelRvv128 +# define ARROW_RVV_MEDIUM_SCALAR_FALLBACK 1 #elif defined(ARROW_HAVE_SSE4_2) || defined(ARROW_HAVE_RUNTIME_SSE4_2) # define UNPACK_PLATFORM unpack_sse4_2 # define KERNEL_PLATFORM KernelSse42 @@ -26,6 +30,7 @@ #if defined(UNPACK_PLATFORM) # include "arrow/util/bpacking_dispatch_internal.h" +# include "arrow/util/bpacking_scalar_internal.h" # include "arrow/util/bpacking_simd_internal.h" # include "arrow/util/bpacking_simd_kernel_internal.h" @@ -36,6 +41,18 @@ using KERNEL_PLATFORM = Kernel void UNPACK_PLATFORM(const uint8_t* in, Uint* out, const UnpackOptions& opts) { +#if defined(ARROW_RVV_MEDIUM_SCALAR_FALLBACK) + // On RISC-V RVV, unpacking single-bit packed integers into uint64_t is faster + // with the compiler auto-vectorized scalar implementation than with the generic + // medium kernel. The latter relies on byte swizzling plus per-lane variable + // shifts, which do not map efficiently to RVV instructions and cause a + // performance regression (measured on VLEN=128 and VLEN=256 hardware). + if constexpr (sizeof(Uint) == sizeof(uint64_t)) { + if (opts.bit_width == 1) { + return unpack_scalar(in, out, opts); + } + } +#endif return unpack_jump(in, out, opts); } @@ -47,5 +64,6 @@ template void UNPACK_PLATFORM(const uint8_t*, uint64_t*, const UnpackO } // namespace arrow::internal::bpacking +# undef ARROW_RVV_MEDIUM_SCALAR_FALLBACK # undef UNPACK_PLATFORM #endif // UNPACK_PLATFORM diff --git a/cpp/src/arrow/util/bpacking_simd_256.cc b/cpp/src/arrow/util/bpacking_simd_256.cc index 8c5ce4dc7d06..846a04c9622a 100644 --- a/cpp/src/arrow/util/bpacking_simd_256.cc +++ b/cpp/src/arrow/util/bpacking_simd_256.cc @@ -18,6 +18,10 @@ #if defined(ARROW_HAVE_SVE256) || defined(ARROW_HAVE_RUNTIME_SVE256) # define UNPACK_PLATFORM unpack_sve256 # define KERNEL_PLATFORM KernelSve256 +#elif defined(ARROW_HAVE_RVV256) || defined(ARROW_HAVE_RUNTIME_RVV256) +# define UNPACK_PLATFORM unpack_rvv256 +# define KERNEL_PLATFORM KernelRvv256 +# define ARROW_RVV_MEDIUM_SCALAR_FALLBACK 1 #elif defined(ARROW_HAVE_RUNTIME_AVX2) # define UNPACK_PLATFORM unpack_avx2 # define KERNEL_PLATFORM KernelAvx2 @@ -27,8 +31,11 @@ # error "This file must be compiled with a known SIMD micro architecture" #endif +#include + #include "arrow/util/bpacking_dispatch_internal.h" #include "arrow/util/bpacking_internal.h" +#include "arrow/util/bpacking_scalar_internal.h" #include "arrow/util/bpacking_simd_internal.h" #include "arrow/util/bpacking_simd_kernel_internal.h" @@ -39,6 +46,31 @@ using KERNEL_PLATFORM = Kernel void UNPACK_PLATFORM(const uint8_t* in, Uint* out, const UnpackOptions& opts) { +#if defined(ARROW_RVV_MEDIUM_SCALAR_FALLBACK) + // On RISC-V RVV (VLEN=256 here), several unpack combinations are faster with + // the compiler auto-vectorized scalar implementation than with the generic + // medium kernel, which relies on byte swizzling plus per-lane variable shifts + // that do not map efficiently to RVV instructions. Measured on VLEN=256 + // hardware; the VLEN=128 kernel file only falls back for Uint64/1-bit. + constexpr bool kIsUint64 = sizeof(Uint) == sizeof(uint64_t); + if (kIsUint64 && (opts.bit_width == 1 || opts.bit_width == 2)) { + return unpack_scalar(in, out, opts); + } + // Large bit widths on small batches have too much fixed medium-kernel overhead. + if constexpr (std::is_same_v) { + if (opts.bit_width == 13 && opts.batch_size <= 32) { + return unpack_scalar(in, out, opts); + } + } else if constexpr (std::is_same_v) { + if (opts.bit_width == 20 && opts.batch_size <= 32) { + return unpack_scalar(in, out, opts); + } + } else if constexpr (std::is_same_v) { + if (opts.bit_width == 20 && opts.batch_size <= 64) { + return unpack_scalar(in, out, opts); + } + } +#endif return unpack_jump(in, out, opts); } @@ -50,4 +82,5 @@ template void UNPACK_PLATFORM(const uint8_t*, uint64_t*, const UnpackO } // namespace arrow::internal::bpacking +#undef ARROW_RVV_MEDIUM_SCALAR_FALLBACK #undef UNPACK_PLATFORM diff --git a/cpp/src/arrow/util/bpacking_simd_internal.h b/cpp/src/arrow/util/bpacking_simd_internal.h index 88df5f6bb01e..dcd83cc7ceb8 100644 --- a/cpp/src/arrow/util/bpacking_simd_internal.h +++ b/cpp/src/arrow/util/bpacking_simd_internal.h @@ -26,6 +26,8 @@ namespace arrow::internal::bpacking { #if defined(ARROW_HAVE_NEON) # define UNPACK_ARCH128 unpack_neon +#elif defined(ARROW_HAVE_RVV128) || defined(ARROW_HAVE_RUNTIME_RVV128) +# define UNPACK_ARCH128 unpack_rvv128 #elif defined(ARROW_HAVE_SSE4_2) || defined(ARROW_HAVE_RUNTIME_SSE4_2) # define UNPACK_ARCH128 unpack_sse4_2 #endif @@ -55,6 +57,8 @@ extern template ARROW_TEMPLATE_EXPORT void UNPACK_ARCH128( #if defined(ARROW_HAVE_SVE256) || defined(ARROW_HAVE_RUNTIME_SVE256) # define UNPACK_ARCH256 unpack_sve256 +#elif defined(ARROW_HAVE_RVV256) || defined(ARROW_HAVE_RUNTIME_RVV256) +# define UNPACK_ARCH256 unpack_rvv256 #elif defined(UNPACK_ARCH256) || defined(ARROW_HAVE_RUNTIME_AVX2) # define UNPACK_ARCH256 unpack_avx2 #endif diff --git a/cpp/src/arrow/util/cpu_info.cc b/cpp/src/arrow/util/cpu_info.cc index 2f7cd2408df6..a7e9c5fbc446 100644 --- a/cpp/src/arrow/util/cpu_info.cc +++ b/cpp/src/arrow/util/cpu_info.cc @@ -98,6 +98,14 @@ void OsRetrieveCpuInfo(int64_t* hardware_flags, CpuInfo::Vendor* vendor) { *hardware_flags |= (sve && sve_size == 32) ? CpuInfo::SVE256 : 0; *hardware_flags |= (sve && sve_size == 64) ? CpuInfo::SVE512 : 0; + // RVV and length + const bool rvv = cpu.rvv(); + const auto rvv_size = cpu.rvv_size_bytes(); + *hardware_flags |= rvv ? CpuInfo::RVV : 0; + *hardware_flags |= (rvv && rvv_size == 16) ? CpuInfo::RVV128 : 0; + *hardware_flags |= (rvv && rvv_size == 32) ? CpuInfo::RVV256 : 0; + *hardware_flags |= (rvv && rvv_size == 64) ? CpuInfo::RVV512 : 0; + // x86 only switch (cpu.known_manufacturer()) { case (xsimd::x86_manufacturer::intel): @@ -363,6 +371,49 @@ void ArchVerifyCpuRequirements(const CpuInfo* ci) { } } +#elif XSIMD_TARGET_RISCV +//------------------------------ RISCV64 ------------------------------// +bool ArchParseUserSimdLevel(const std::string& simd_level, int64_t* hardware_flags) { + enum { + USER_SIMD_NONE, + USER_SIMD_RVV, + USER_SIMD_RVV128, + USER_SIMD_RVV256, + USER_SIMD_RVV512, + USER_SIMD_MAX, + }; + + int level = USER_SIMD_MAX; + if (simd_level == "RVV") { + level = USER_SIMD_RVV; + } else if (simd_level == "RVV128") { + level = USER_SIMD_RVV128; + } else if (simd_level == "RVV256") { + level = USER_SIMD_RVV256; + } else if (simd_level == "RVV512") { + level = USER_SIMD_RVV512; + } else if (simd_level == "NONE") { + level = USER_SIMD_NONE; + } else { + return false; + } + + if (level < USER_SIMD_RVV512) *hardware_flags &= ~CpuInfo::RVV512; + if (level < USER_SIMD_RVV256) *hardware_flags &= ~CpuInfo::RVV256; + if (level < USER_SIMD_RVV128) *hardware_flags &= ~CpuInfo::RVV128; + if (level < USER_SIMD_RVV) *hardware_flags &= ~CpuInfo::RVV; + return true; +} + +void ArchVerifyCpuRequirements(const CpuInfo* ci) { +# if defined(ARROW_HAVE_RVV128) || defined(ARROW_HAVE_RVV256) || \ + defined(ARROW_HAVE_RVV512) || defined(ARROW_HAVE_RVV_SIZELESS) + if (!ci->IsDetected(CpuInfo::RVV)) { + DCHECK(false) << "CPU does not support the RISC-V Vector instruction set"; + } +# endif +} + #else //------------------------------ PPC, ... ------------------------------// bool ArchParseUserSimdLevel(const std::string& simd_level, int64_t* hardware_flags) { diff --git a/cpp/src/arrow/util/cpu_info.h b/cpp/src/arrow/util/cpu_info.h index 7e4ca4c7f14d..6f451787688b 100644 --- a/cpp/src/arrow/util/cpu_info.h +++ b/cpp/src/arrow/util/cpu_info.h @@ -57,6 +57,12 @@ class ARROW_EXPORT CpuInfo { static constexpr int64_t SVE256 = (1LL << 34); static constexpr int64_t SVE512 = (1LL << 35); + /// RISC-V features + static constexpr int64_t RVV = (1LL << 37); + static constexpr int64_t RVV128 = (1LL << 38); + static constexpr int64_t RVV256 = (1LL << 39); + static constexpr int64_t RVV512 = (1LL << 40); + /// Cache enums for L1 (data), L2 and L3 enum class CacheLevel { L1 = 0, L2, L3, Last = L3 }; diff --git a/cpp/src/arrow/util/dispatch_internal.h b/cpp/src/arrow/util/dispatch_internal.h index 36e5152ee650..a8118ea9a376 100644 --- a/cpp/src/arrow/util/dispatch_internal.h +++ b/cpp/src/arrow/util/dispatch_internal.h @@ -38,6 +38,9 @@ enum class DispatchLevel : int { SVE128, SVE256, SVE512, + RVV128, + RVV256, + RVV512, MAX }; @@ -221,6 +224,36 @@ constexpr DynamicDispatchTarget BestDispatchTarget( # define ARROW_DISPATCH_TARGET_SVE512(func) #endif +#if defined(ARROW_HAVE_RVV128) || defined(ARROW_HAVE_RUNTIME_RVV128) +# define ARROW_DISPATCH_TARGET_RVV128(func) \ + ::arrow::internal::DynamicDispatchTarget{ \ + ::arrow::internal::DispatchLevel::RVV128, \ + (func), \ + }, +#else +# define ARROW_DISPATCH_TARGET_RVV128(func) +#endif + +#if defined(ARROW_HAVE_RVV256) || defined(ARROW_HAVE_RUNTIME_RVV256) +# define ARROW_DISPATCH_TARGET_RVV256(func) \ + ::arrow::internal::DynamicDispatchTarget{ \ + ::arrow::internal::DispatchLevel::RVV256, \ + (func), \ + }, +#else +# define ARROW_DISPATCH_TARGET_RVV256(func) +#endif + +#if defined(ARROW_HAVE_RVV512) || defined(ARROW_HAVE_RUNTIME_RVV512) +# define ARROW_DISPATCH_TARGET_RVV512(func) \ + ::arrow::internal::DynamicDispatchTarget{ \ + ::arrow::internal::DispatchLevel::RVV512, \ + (func), \ + }, +#else +# define ARROW_DISPATCH_TARGET_RVV512(func) +#endif + /// A concept to specify how dynamic dispatch should be handled. /// /// A requirement is that the list of available targets must be compile time @@ -352,6 +385,12 @@ class DynamicDispatch { return cpu_info->IsSupported(CpuInfo::SVE256); case DispatchLevel::SVE512: return cpu_info->IsSupported(CpuInfo::SVE512); + case DispatchLevel::RVV128: + return cpu_info->IsSupported(CpuInfo::RVV128); + case DispatchLevel::RVV256: + return cpu_info->IsSupported(CpuInfo::RVV256); + case DispatchLevel::RVV512: + return cpu_info->IsSupported(CpuInfo::RVV512); default: return false; } diff --git a/cpp/src/arrow/util/io_util_test.cc b/cpp/src/arrow/util/io_util_test.cc index 44188b3f2ee9..2015b6b74a1e 100644 --- a/cpp/src/arrow/util/io_util_test.cc +++ b/cpp/src/arrow/util/io_util_test.cc @@ -1109,6 +1109,14 @@ TEST(CpuInfo, Basic) { ASSERT_EQ(ci->hardware_flags(), 0); ci_rw->EnableFeature(original_hardware_flags, true); ASSERT_EQ(ci->hardware_flags(), original_hardware_flags); + +#if defined(__riscv) && __riscv_xlen == 64 + if (ci->IsDetected(CpuInfo::RVV)) { + EXPECT_NE(ci->hardware_flags() & CpuInfo::RVV, 0); + EXPECT_NE( + ci->hardware_flags() & (CpuInfo::RVV128 | CpuInfo::RVV256 | CpuInfo::RVV512), 0); + } +#endif } TEST(Memory, TotalMemory) {