ggml-cpu/riscv: gate cpu-riscv64 backend on Zv* sub-extensions#1475
Open
mikey wants to merge 1 commit into
Open
ggml-cpu/riscv: gate cpu-riscv64 backend on Zv* sub-extensions#1475mikey wants to merge 1 commit into
mikey wants to merge 1 commit into
Conversation
The existing runtime hwprobe check only looks at base RVV. When the build emits Zvbb / Zvbc / Zvkb / Zvkn* / Zvfh instructions and the runtime CPU supports RVV but not these addition extensions, the kernels SIGILL rather than falling back to scalar. This can happen if ggml is compiled for a fully featured RVA23 CPU, but then run on only a baseline RVA23 CPU (like qemu -cpu rva23s64). Probe each sub-extension via RISCV_HWPROBE_KEY_IMA_EXT_0 and, in the backend score function, refuse to register as cpu-riscv64 (return 0) whenever the binary was compiled __riscv_zvX but the runtime CPU lacks zvX. Bits 17..31 of IMA_EXT_0 may be missing from older asm/hwprobe.h headers, so the patch ships fallback definitions; on kernels >= 6.5 the values match the upstream definitions. Claude Opus was used to find this issue and write the initial version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The existing runtime hwprobe check only looks at base RVV. When the build emits Zvbb / Zvbc / Zvkb / Zvkn* / Zvfh instructions and the runtime CPU supports RVV but not these addition extensions, the kernels SIGILL rather than falling back to scalar.
This can happen if ggml is compiled for a fully featured RVA23 CPU, but then run on only a baseline RVA23 CPU (like qemu -cpu rva23s64).
Probe each sub-extension via RISCV_HWPROBE_KEY_IMA_EXT_0 and, in the backend score function, refuse to register as cpu-riscv64 (return 0) whenever the binary was compiled __riscv_zvX but the runtime CPU lacks zvX.
Bits 17..31 of IMA_EXT_0 may be missing from older asm/hwprobe.h headers, so the patch ships fallback definitions; on kernels >= 6.5 the values match the upstream definitions.
Claude Opus was used to find this issue and write the initial version.
For changes to the core
ggmllibrary (including to the CMake build system), please open a PR in https://github.com/ggml-org/llama.cpp. Doing so will make your PR more visible, better tested and more likely to be reviewed.