[Bugfix][CPU][RISC-V] Fix VLEN detection for RVV attention path (#47532)
Signed-off-by: liutong <liutong@iscas.ac.cn> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -437,27 +437,24 @@ def _riscv_supports_rvv() -> bool:
|
||||
The RVV path is compiled whenever __riscv_v_min_vlen is defined, so
|
||||
we check that at least one supported zvl<N>b is advertised.
|
||||
"""
|
||||
# The C++ compile-time check is the ground truth: it knows which
|
||||
# VLEN the binary was actually compiled for. The cpuinfo check
|
||||
# below is only a fast-path shortcut.
|
||||
try:
|
||||
import torch
|
||||
|
||||
if torch.ops._C.cpu_attn_has_isa("rvv"):
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Fallback: check /proc/cpuinfo for zvl128b/zvl256b.
|
||||
try:
|
||||
with open("/proc/cpuinfo") as f:
|
||||
cpuinfo = f.read()
|
||||
except OSError:
|
||||
return False
|
||||
# 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
|
||||
return any(f"zvl{n}b" in cpuinfo for n in (128, 256))
|
||||
|
||||
|
||||
def _get_attn_isa(
|
||||
|
||||
Reference in New Issue
Block a user