Fix _riscv_supports_rvv_vlen128() to detect RVV on hardware without zvl flags (#43179)

Signed-off-by: liuyudong <liuyudong@iscas.ac.cn>
Co-authored-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>
This commit is contained in:
lyd1992
2026-06-18 21:22:35 +08:00
committed by GitHub
co-authored by YuanSheng
parent 4cb5e746b6
commit 021cdf72bc
3 changed files with 30 additions and 3 deletions
+16 -3
View File
@@ -438,9 +438,22 @@ def _riscv_supports_rvv() -> bool:
cpuinfo = f.read()
except OSError:
return False
return any(f"zvl{n}b" in cpuinfo for n in (128, 256)) and all(
f"zvl{n}b" not in cpuinfo for n in (512, 1024)
)
# If VLEN >= 512 is detected, the RVV kernel was not compiled.
if any(f"zvl{n}b" in cpuinfo for n in (512, 1024)):
return False
# zvl128b or zvl256b explicitly advertised -> RVV kernel available.
if any(f"zvl{n}b" in cpuinfo for n in (128, 256)):
return True
# No zvl<N>b flag at all (e.g. some hardware reports zve* without
# a VLEN hint). Delegate to the C++ compile-time check instead.
try:
import torch
return torch.ops._C.cpu_attn_has_isa("rvv")
except Exception:
return False
def _get_attn_isa(