From a84f64b3c19bd45f1e491c4dfa85c0e73d19824f Mon Sep 17 00:00:00 2001 From: Ariel Xiong Date: Wed, 17 Apr 2024 08:25:03 +0800 Subject: [PATCH] TST: Add CPU Dispatch test for RISC-V Vector Extenson. --- numpy/_core/meson.build | 2 +- numpy/_core/tests/test_cpu_dispatcher.py | 2 +- numpy/_core/tests/test_cpu_features.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/numpy/_core/meson.build b/numpy/_core/meson.build index 5a343340d315..d249c1ec2745 100644 --- a/numpy/_core/meson.build +++ b/numpy/_core/meson.build @@ -729,7 +729,7 @@ _umath_tests_mtargets = mod_features.multi_targets( AVX2, SSE41, SSE2, ASIMDHP, ASIMD, NEON, VSX3, VSX2, VSX, - VXE, VX, + VXE, VX, RVV, ], baseline: CPU_BASELINE, prefix: 'NPY_', diff --git a/numpy/_core/tests/test_cpu_dispatcher.py b/numpy/_core/tests/test_cpu_dispatcher.py index 959725ea7bc8..5a60147e0ece 100644 --- a/numpy/_core/tests/test_cpu_dispatcher.py +++ b/numpy/_core/tests/test_cpu_dispatcher.py @@ -12,7 +12,7 @@ def test_dispatcher(): "SSE2", "SSE41", "AVX2", "VSX", "VSX2", "VSX3", "NEON", "ASIMD", "ASIMDHP", - "VX", "VXE" + "VX", "VXE", "RVV" ) highest_sfx = "" # no suffix for the baseline all_sfx = [] diff --git a/numpy/_core/tests/test_cpu_features.py b/numpy/_core/tests/test_cpu_features.py index f4a85c54ca6a..075a55d1bb33 100644 --- a/numpy/_core/tests/test_cpu_features.py +++ b/numpy/_core/tests/test_cpu_features.py @@ -415,3 +415,21 @@ def load_flags(self): # if the kernel reports any one of the following ARM8 features. ASIMD=("AES", "SHA1", "SHA2", "PMULL", "CRC32") ) + + +is_riscv = re.match("^riscv(64|32)", machine, re.IGNORECASE) +@pytest.mark.skipif(not is_linux or not is_riscv, reason="Only for Linux and RISC-V") +class Test_RISCV_Features(AbstractTest): + features = ["RVV"] + + def load_flags(self): + isa = self.get_cpuinfo_item("isa") + rv_flags = [s.strip() for s in list(isa)[0][4:].split('_')] + values = values.union([ch for ch in rv_flags[0].upper()]) + for s in rv_flags[1:]: + values = values.union([s.upper()]) + self.features_flags = values + if 'V' in values: + self.features_map = dict( + RVV="V" + )