ggml-cpu: add repack GEMM and GEMV for floating-point #17791
+950
−33
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.
Summary
This PR adds repacking and GEMM/GEMV kernels for floating-point (FP16 and FP32) for RVV (with the
zvfhextension).Key Changes
7 x {16, 32, 64, 128}(selected based on VLEN)1 x {16, 32, 64, 128}(selected based on VLEN)ggml_quantize_mat_tis refactored toggml_repack_mat_tto allow for a common interface for both quantization and floating-point repacking.NB_ROWSadded to select the number of rows to interleave for repacking. Previously, this was fixed at4.Tile Sizes
The repack operation interleaves
Nrows ofactivationswith an interleave size ofK, andMcolumns ofweightswith an interleave size ofK.NxKis fixed at7x1. This introduces 7 accumulators withLMUL=4(7 x 4 = 28 registers), each accumulatingMresults.Mis varied based on the available VLEN:Mis the maximum number of values that can be loaded in (LMUL=2 for F16, LMUL=4 for F32).Testing
Kernels were functionally tested on QEMU for VLENs (128-bit, 256-bit, 512-bit and 1024-bit) for a range of input sizes.
Benchmarking Results
End-to-end benchmarking on
BananaPI-BPI F3 (VLEN=256)Prefill / Prompt Processing (GEMM)
Tokens / Second
Result: ~2x-3x speedup over
vec_dotDecode (GEMV)
Tokens / Second
Result: No noticeable improvement, as decode remains memory-bound.
Additional Notes
arch-fallback.has7xMx1is very RVV-specific tiling, and should not be used by other architectures.GEMMreaches peak performance when the prompt is a multiple of 7 (for example,prompt=28). To handle leftovers, it defaults toGEMV, which impacts performance. Ideally, there should be leftoverNx32kernels which handle each leftover case from2-6leftover tokens.