1#include "ggml-backend-impl.h"
2
3#if defined(__riscv) && __riscv_xlen == 64
4#include <asm/hwprobe.h>
5#include <asm/unistd.h>
6#include <unistd.h>
7
8struct riscv64_features {
9 bool has_rvv = false;
10
11 riscv64_features() {
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);
17
18 if (0 == ret) {
19 has_rvv = !!(probe.value & RISCV_HWPROBE_IMA_V);
20 }
21 }
22};
23
24static int ggml_backend_cpu_riscv64_score() {
25 int score = 1;
26 riscv64_features rf;
27
28#ifdef GGML_USE_RVV
29 if (!rf.has_rvv) { return 0; }
30 score += 1 << 1;
31#endif
32
33 return score;
34}
35
36GGML_BACKEND_DL_SCORE_IMPL(ggml_backend_cpu_riscv64_score)
37
38#endif // __riscv && __riscv_xlen == 64