Skip to content

ggml-cpu: add RVV repack GEMM and GEMV for Q3_K, Q6_K#12

Open
taimur-10x wants to merge 13 commits intomasterfrom
10x/riscv-quant-repack-k
Open

ggml-cpu: add RVV repack GEMM and GEMV for Q3_K, Q6_K#12
taimur-10x wants to merge 13 commits intomasterfrom
10x/riscv-quant-repack-k

Conversation

@taimur-10x
Copy link
Copy Markdown
Collaborator

@taimur-10x taimur-10x commented Mar 15, 2026

Summary

This PR extends existing repacking and GEMM/GEMV kernels for Q3_K and Q6_K for RVV (VLEN=128 to 1024).

Key Changes

  • Added repacking RVV GEMM and GEMV kernels for:
    • Q3_K
    • Q6_K

Tile Sizes

VLEN Tiling LHS RHS OUT
128 4, 8, 1 4x1 8x1 4x8
256 4, 16, 1 4x1 16x1 4x16
512 4, 32, 1 4x1 32x1 4x32
1024 4, 64, 1 4x1 64x1 4x64

Testing

Kernels were functionally tested on QEMU for VLENs (128-bit to 1024-bit) for a range of input sizes.

Benchmarking Results

End-to-end benchmarking on BananaPI-BPI F3 (VLEN=256)

Q3_K

Prompt Processing

Model Prompt Size Repack GEMM 4x16x1 (Tok/s) Vec Dot (Tok/ s)
Tinyllama Q3_K 1.1B 32 24.9 11.52
Tinyllama Q3_K 1.1B 64 25.4 11.86
Tinyllama Q3_K 1.1B 128 25.16 10.66
Tinyllama Q3_K 1.1B 256 24.97 10.54
Tinyllama Q3_K 1.1B 512 23.53 10.42

Token Generation

Model Tokens Generated Repack GEMV 1x16x1 (Tok/s) Vec Dot (Tok/s)
Tinyllama Q3_K 1.1B 10 6.04 9.26
Tinyllama Q3_K 1.1B 16 6.26 9.17
Tinyllama Q3_K 1.1B 32 6.05 8.99
Tinyllama Q3_K 1.1B 64 5.98 7.82
Tinyllama Q3_K 1.1B 100 5.91 7.66

Q6_K

Prompt Processing

Model Prompt Size Repack GEMM 4x16x1 (Tok/s) Vec Dot (Tok/s)
Tinyllama Q6_K 1.1B 32 20.34 10.67
Tinyllama Q6_K 1.1B 64 21.11 10.29
Tinyllama Q6_K 1.1B 128 20.29 10.37
Tinyllama Q6_K 1.1B 256 20.73 10.48
Tinyllama Q6_K 1.1B 512 19.92 10.11

Token Generation

Model Tokens Generated Repack GEMV 1x16x1 (Tok/s) Vec Dot (Tok/s)
Tinyllama Q6_K 1.1B 10 5.63 7.08
Tinyllama Q6_K 1.1B 16 5.76 7.05
Tinyllama Q6_K 1.1B 32 5.54 7.06
Tinyllama Q6_K 1.1B 64 5.61 6.67
Tinyllama Q6_K 1.1B 100 5.44 6.75

@taimur-10x taimur-10x self-assigned this Mar 15, 2026
@github-actions github-actions bot added the ggml label Mar 15, 2026
rehan-10xengineer pushed a commit that referenced this pull request Apr 14, 2026
)

* ggml: backend-agnostic tensor parallelism

* support for GPT-OSS, Qwen 3 MoE

* partial Vulkan fix

* add support for 4/8 GPUs

* unconditional peer access

* re-use buffers + ggml contexts

* fix output pattern

* NCCL support

* GGML: HIP: add RCCL support

* Remove shfl and AllReduce from backend interface

* move allocation workaround out of ggml-alloc.c

* 2d tensor set/get support

* Fix the seg fault without NCCL

* Apply suggestion from JohannesGaessler

* support for tensor dims % n_devs != 0

* fix view_offs scaling

* arbitrary num. of GPUs/tensor split

* fix compilation

* better granularity estimate

* Support device-specific host buffer types if all underlying backends expose the same type. This allows using pinned memory instead of pageable memory for CUDA.

Fix compilation errors.

* partial Qwen 3 Next support

* Fix qwen3 30b (#8)

* Fix crash with Qwen-30B-A3B Q4_0

Qwen-30B-A3B Q4_0 has an intermediate dimension of 768. Using a granularity of 256 forces an uneven split between GPUs, which is not supported by the current implementation.

* Decide block size based on tensor quantization type

* Fix crashes due to KV cache serialization (#9)

KV cache serialization requires non-zero offsets on the tensor. Add support in the meta backend to set/get a tensor with a non-zero offset.

* metal : fix build (#7)

* static memory allocations, fix usage count

* fix tensor granularity

* more even memory distribution

* use BF16 for allreduce

* rebase fixup

* better error message for unsupported architectures

* Fix device mismatch during scatter of allReduce. (#11)

There is a mismatch between the dst buffer device and the backend device, causing the use of sync copies

* Enable the previous allreduce implementation. It is better in both perf and stability (#12)

* delay AllReduce for Moe for less I/O

* build : clean-up compile warnings

* backend : move most of the meta backend API to ggml-backend-impl.h

* cont : hide unused public API in the implementation

* llama : use llama_device + remove ggml_backend_dev_is_meta()

* ggml-backend : remove unused alloc include

* minor : remove regex include

* ggml : introduce ggml-ext.h for staging new APIs

* rebase fixup

* fix tests

* llama : more robust logic for determining Meta devices (ggml-org#16)

* llama : more robust logic for determining Meta devices

* cont : fix devs size check

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

* cont : fix log type

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

---------

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

* disable roundtrip for meta backend

* fix arch selection

* Qwen 3.5 support

* fix Gemma 4 MoE

* fix OpenVino, SYCL

* fix test-llama-archs for CPU-only builds

* Fix Qwen 3.5 MoE

* disable meta backend tests for WebGPU

* tests : filter CPU-based devices from the Meta backend tests (ggml-org#17)

* meta : formatting, naming, indentation (ggml-org#18)

* formatting : llama-model.cpp

* formatting : ggml-ext.h

* formatting : ggml-backend-meta.cpp

* meta : add TODO

* add documentation

* better error messages

* fix GPT-OSS

---------

Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz>
Co-authored-by: Gaurav Garg <gaugarg@nvidia.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants