This patch adds support for RISCV's vector extension RVV1.0.

libeigen/eigen!2030
This commit is contained in:
Chip Kerchner
2025-11-20 11:28:07 -05:00
committed by Charles Schlosser
parent 8eb6551a8a
commit 49623d0c4e
11 changed files with 6642 additions and 5 deletions

View File

@@ -80,6 +80,8 @@
#define EIGEN_IDEAL_MAX_ALIGN_BYTES 32
#elif defined __HVX__ && (__HVX_LENGTH__ == 128)
#define EIGEN_IDEAL_MAX_ALIGN_BYTES 128
#elif defined(EIGEN_RISCV64_USE_RVV10)
#define EIGEN_IDEAL_MAX_ALIGN_BYTES 64
#else
#define EIGEN_IDEAL_MAX_ALIGN_BYTES 16
#endif
@@ -116,7 +118,7 @@
// Only static alignment is really problematic (relies on nonstandard compiler extensions),
// try to keep heap alignment even when we have to disable static alignment.
#if EIGEN_COMP_GNUC && !(EIGEN_ARCH_i386_OR_x86_64 || EIGEN_ARCH_ARM_OR_ARM64 || EIGEN_ARCH_PPC || EIGEN_ARCH_IA64 || \
EIGEN_ARCH_MIPS || EIGEN_ARCH_LOONGARCH64)
EIGEN_ARCH_MIPS || EIGEN_ARCH_LOONGARCH64 || EIGEN_ARCH_RISCV)
#define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
#else
#define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 0
@@ -418,14 +420,55 @@ extern "C" {
#define EIGEN_VECTORIZE_SVE
#include <arm_sve.h>
// Since we depend on knowing SVE vector lengths at compile-time, we need
// to ensure a fixed lengths is set
// Since we depend on knowing SVE vector length at compile-time, we need
// to ensure a fixed length is set
#if defined __ARM_FEATURE_SVE_BITS
#define EIGEN_ARM64_SVE_VL __ARM_FEATURE_SVE_BITS
#else
#error "Eigen requires a fixed SVE lector length but EIGEN_ARM64_SVE_VL is not set."
#endif
#elif defined(EIGEN_ARCH_RISCV)
#if defined(__riscv_zfh)
#define EIGEN_HAS_BUILTIN_FLOAT16
#endif
// We currently require RVV to be enabled explicitly via EIGEN_RISCV64_USE_RVV and
// will not select the backend automatically
#if (defined EIGEN_RISCV64_USE_RVV10)
#define EIGEN_VECTORIZE
#define EIGEN_VECTORIZE_RVV10
#include <riscv_vector.h>
// Since we depend on knowing RVV vector length at compile-time, we need
// to ensure a fixed length is set
#if defined(__riscv_v_fixed_vlen)
#define EIGEN_RISCV64_RVV_VL __riscv_v_fixed_vlen
#if __riscv_v_fixed_vlen >= 256
#undef EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT
#define EIGEN_GCC_AND_ARCH_DOESNT_WANT_STACK_ALIGNMENT 1
#endif
#else
#error "Eigen requires a fixed RVV vector length but -mrvv-vector-bits=zvl is not set."
#endif
#undef EIGEN_STACK_ALLOCATION_LIMIT
#define EIGEN_STACK_ALLOCATION_LIMIT 196608
#if defined(__riscv_zvfh) && defined(__riscv_zfh)
#define EIGEN_VECTORIZE_RVV10FP16
#elif defined(__riscv_zvfh)
#if defined(__GNUC__) || defined(__clang__)
#warning "The Eigen::Half vectorization requires Zfh and Zvfh extensions."
#elif defined(_MSC_VER)
#pragma message("The Eigen::Half vectorization requires Zfh and Zvfh extensions.")
#endif
#endif
#endif // defined(EIGEN_ARCH_RISCV)
#elif (defined __s390x__ && defined __VEC__)
#define EIGEN_VECTORIZE
@@ -510,6 +553,13 @@ extern "C" {
#include <hip/hip_bfloat16.h>
#endif
#if defined(__riscv)
// Defines the default LMUL for RISC-V
#ifndef EIGEN_RISCV64_DEFAULT_LMUL
#define EIGEN_RISCV64_DEFAULT_LMUL 1
#endif
#endif
/** \brief Namespace containing all symbols from the %Eigen library. */
// IWYU pragma: private
#include "../InternalHeaderCheck.h"