当我尝试在riscv开发板上编译支持RVV的llama.cpp时,我遇到了一些编译器问题,想求助一下大家。
- gcc遇到的问题
首先是我尝试用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’
看起来似乎与https://forum.spacemit.com/t/topic/419的情况一致,可以通过使用高版本的gcc解决。我想问如何不通过源码编译的方式安装高版本的gcc安装包呢?
- clang遇到的问题
当我用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的case时,会通过内联汇编的形式支持。我的板子的VLEN是256,所以不会走这个分支,我将其注释之后可以通过编译。
我的问题是,这个问题是由于编译器版本不足还是编译器配置问题呢,我该如何解决这类问题?
期待回复。