Skip to content

ggml-cpu: add Q4_0 8x8 gemv/gemm for riscv vlenb=16 case - #28642

Open
hongyang-7 wants to merge 1 commit into
ggml-org:masterfrom
hongyang-7:dev_rvv_8x8
Open

ggml-cpu: add Q4_0 8x8 gemv/gemm for riscv vlenb=16 case#28642
hongyang-7 wants to merge 1 commit into
ggml-org:masterfrom
hongyang-7:dev_rvv_8x8

Conversation

@hongyang-7

@hongyang-7 hongyang-7 commented Sep 9, 2026

Copy link
Copy Markdown

Summary

This PR extends existing riscv gemv/gemm kernels for q4_0_q8_0 in 8x8 layout for vlenb=16.

Key Changes

  • Enable rvv gemv/gemm kernel for q4_0_q8_0 in 8x8 layout, which is not in real use in master branch, despite the 8x8 kernel implementation (vlenb>=32) already provided.
  • Make the 8x8 kernel support vlenb=16 case, which is the choice of current mainstream high-performance hardware like SOPHGO2044.

Perplexity Test

./bin/llama-perplexity -m models/Qwen3.5-0.8B-Q4_0.gguf -f path/to/test_prompt.txt
model master PPL opt PPL
Qwen3.5-0.8B-Q4_0 17.8834 +/- 0.83491 17.8859 +/- 0.83492

Performance Test

Performance is tested on a real high-performance RISC-V server.

Env Value
CPU SG2044 64core riscv processor 2.6GHz
OS openEuler 24.03 (LTS)
kernel Linux 6.12
gcc gcc-15.3.0
bench tool numactl -C 0-15 -m 0 llama-batched-bench

Llama-3.2-1B-Instruct-Q4_0.gguf (738M)

Batch size PP t/s
(master)
PP t/s
(opt)
PP boost
(opt/master)
TG t/s
(master)
TG t/s
(opt)
TG boost
(opt/master)
1 21.00 90.46 431% 15.54 20.04 129%
2 21.07 91.38 434% 16.81 29.70 177%
4 21.10 91.41 433% 17.37 48.91 282%
8 21.13 92.05 436% 17.69 53.80 304%

PP: 4.3x speedup
TG: 1.2x~3.0x speedup

Meta-Llama-3-8B-Instruct.Q4_0.gguf (4.4G)

Batch size PP t/s
(master)
PP t/s
(opt)
PP boost
(opt/master)
TG t/s
(master)
TG t/s
(opt)
TG boost
(opt/master)
1 2.89 13.63 472% 2.40 3.50 146%
2 2.90 13.67 471% 2.64 5.23 198%
4 2.90 13.65 471% 2.68 10.16 379%
8 2.90 13.65 471% 2.71 10.93 403%

PP: 4.7x speedup
TG: 1.4x~4.0x speedup

Future Work

  • Optimize other layout for more quantization types.
  • Try to remove #if defined __riscv_zvfh path from top ggml-cpu/repack.cpp

Requirements

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Sep 9, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

Hi @hongyang-7, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Sep 9, 2026
@github-actions
github-actions Bot marked this pull request as draft September 9, 2026 09:52
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Sep 9, 2026
@hongyang-7
hongyang-7 marked this pull request as ready for review September 9, 2026 11:21
@hongyang-7

Copy link
Copy Markdown
Author

Add Requirements section to respect PR Template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant