Skip to content

Commit f698a79

Browse files
authored
ggml: replace hwcap with riscv_hwprobe for RVV detection (#17567)
Signed-off-by: Wang Yang <yangwang@iscas.ac.cn>
1 parent 47a268e commit f698a79

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ggml/src/ggml-cpu/arch/riscv/cpu-feats.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
#include "ggml-backend-impl.h"
22

33
#if defined(__riscv) && __riscv_xlen == 64
4-
#include <sys/auxv.h>
5-
6-
//https://github.com/torvalds/linux/blob/master/arch/riscv/include/uapi/asm/hwcap.h#L24
7-
#ifndef COMPAT_HWCAP_ISA_V
8-
#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))
9-
#endif
4+
#include <asm/hwprobe.h>
5+
#include <asm/unistd.h>
6+
#include <unistd.h>
107

118
struct riscv64_features {
129
bool has_rvv = false;
1310

1411
riscv64_features() {
15-
uint32_t hwcap = getauxval(AT_HWCAP);
12+
struct riscv_hwprobe probe;
13+
probe.key = RISCV_HWPROBE_KEY_IMA_EXT_0;
14+
probe.value = 0;
15+
16+
int ret = syscall(__NR_riscv_hwprobe, &probe, 1, 0, NULL, 0);
1617

17-
has_rvv = !!(hwcap & COMPAT_HWCAP_ISA_V);
18+
if (0 == ret) {
19+
has_rvv = !!(probe.value & RISCV_HWPROBE_IMA_V);
20+
}
1821
}
1922
};
2023

0 commit comments

Comments
 (0)