riscv64开启llama.cpp的RVV
首先,不开RVV的编译命令如下:
cmake -B build -DGGML_RVV=OFF -DCMAKE_BUILD_TYPE=Debug
cmake --build build --config Debug -j 8
指令字符串的配置
可以看到,通过-DGGML_RVV=OFF 开关可以打开RVV的选项,但在实操中发现,开启RVV之后会报错_v指令找不到,但我的开发板支持v扩展,查询之后发现支持的指令集是rv64gcv而不是rv64gc_v之类的。
通过修改ggml/src/ggml-cpu/CMakeLists.txt中的构造字符串的方式,例如将_v变成如下方式:
if(GGML_RVV)string(APPEND MARCH_STR "v")endif()
但是我还没弄明白_v和v的区别,有明白的也可以评论区发言哦。
内联汇编的格式报错
在9b17d74ab7d31cb7d15ee7eec1616c3d825a84c0上做测试时发现,
用clang version 18.1.3进行编译时,会报错
error: operand must be e[8|16|32|64|128|256|512|1024],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu]585 | "vsetivli zero, 16, e8, m1\n\t"
之类的,报错文件在ggml/src/ggml-cpu/arch/riscv/quants.c。
而这个文件是PLCT的小伙伴修改的,且用内联汇编写算子的情况只发生在VLEN是128时,因此我这里暂时将其注释。
当我用gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0时发现,报错如下:
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c: In function ‘ggml_cpu_fp32_to_fp16’:
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3270:9: error: unknown type name ‘vfloat16m1_t’; did you mean ‘vfloat64m1_t’?3270 | vfloat16m1_t vy = __riscv_vfncvt_f_f_w_f16m1(vx, vl);| ^~~~~~~~~~~~| vfloat64m1_t
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3270:27: error: implicit declaration of function ‘__riscv_vfncvt_f_f_w_f16m1’; did you mean ‘__riscv_vfncvt_f_f_w_f32m1’? [-Werror=implicit-function-declaration]3270 | vfloat16m1_t vy = __riscv_vfncvt_f_f_w_f16m1(vx, vl);| ^~~~~~~~~~~~~~~~~~~~~~~~~~| __riscv_vfncvt_f_f_w_f32m1
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3271:9: error: implicit declaration of function ‘__riscv_vse16_v_f16m1’; did you mean ‘__riscv_vse16_v_u16m1’? [-Werror=implicit-function-declaration]3271 | __riscv_vse16_v_f16m1((_Float16 *)&y[i], vy, vl);| ^~~~~~~~~~~~~~~~~~~~~| __riscv_vse16_v_u16m1
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3271:32: warning: ISO C does not support the ‘_Float16’ type [-Wpedantic]3271 | __riscv_vse16_v_f16m1((_Float16 *)&y[i], vy, vl);| ^~~~~~~~
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c: In function ‘ggml_cpu_fp16_to_fp32’:
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3302:9: error: unknown type name ‘vfloat16m1_t’; did you mean ‘vfloat64m1_t’?3302 | vfloat16m1_t vx = __riscv_vle16_v_f16m1((_Float16 *)&x[i], vl);| ^~~~~~~~~~~~| vfloat64m1_t
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3302:27: error: implicit declaration of function ‘__riscv_vle16_v_f16m1’; did you mean ‘__riscv_vle16_v_u16m1’? [-Werror=implicit-function-declaration]3302 | vfloat16m1_t vx = __riscv_vle16_v_f16m1((_Float16 *)&x[i], vl);| ^~~~~~~~~~~~~~~~~~~~~| __riscv_vle16_v_u16m1
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3302:50: warning: ISO C does not support the ‘_Float16’ type [-Wpedantic]3302 | vfloat16m1_t vx = __riscv_vle16_v_f16m1((_Float16 *)&x[i], vl);| ^~~~~~~~
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3302:49: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]3302 | vfloat16m1_t vx = __riscv_vle16_v_f16m1((_Float16 *)&x[i], vl);| ^
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3303:27: error: implicit declaration of function ‘__riscv_vfwcvt_f_f_v_f32m2’; did you mean ‘__riscv_vfwcvt_f_x_v_f32m2’? [-Werror=implicit-function-declaration]3303 | vfloat32m2_t vy = __riscv_vfwcvt_f_f_v_f32m2(vx, vl);| ^~~~~~~~~~~~~~~~~~~~~~~~~~| __riscv_vfwcvt_f_x_v_f32m2
/home/orangepi/chenyk/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c:3303:27: error: incompatible types when initializing type ‘vfloat32m2_t’ using type ‘int’
看起来似乎是编译器不支持这些intrinsics。
这点和https://forum.spacemit.com/t/topic/419的判断一致。
