Skip to content

ggml-cpu: add SVE-optimized q5_0 and q5_1 dot-product kernels - #30867

Merged
taronaeo merged 15 commits into
ggml-org:masterfrom
FujitsuResearch:perf/q5sve
Nov 24, 2026
Merged

taronaeo merged 15 commits into
ggml-org:masterfrom
FujitsuResearch:perf/q5sve

Conversation

@t-kusanagi

Copy link
Copy Markdown
Contributor

Overview

  • Add SVE-optimized implementations for the q5_0 x q8_0 and q5_1 x q8_1 dot-product kernels.
  • Keep the existing NEON implementations as the fallback for CPUs without SVE support.
  • Use vector-length-specific code paths to efficiently unpack the upper quantization bits (qh), as the required unpacking differs depending on the SVE vector length.

Additional information

Environment

  • CPU: FX700
  • Compiler: gcc 15.2.0
  • Build Options:
    cmake -B build -S . \
      -DGGML_CUDA=OFF \
      -DGGML_CPU_KLEIDIAI=ON \
      -DBUILD_SHARED_LIBS=OFF \
      -DGGML_NATIVE=ON \
      -DGGML_LTO=ON \
      -DLLAMA_BUILD_UI=OFF \
      -DLLAMA_USE_PREBUILT_UI=OFF \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Performance Results

Results from the optimized q5sve build and gcc baseline

Type Build IPC Elapsed time Improvement vs baseline
q5_0 baseline 0.67 12.549 +- 0.149 s -
q5_0 q5sve 1.68 10.802 +- 0.105 s 13.9% faster
q5_1 baseline 0.66 16.03 +- 1.18 s -
q5_1 q5sve 1.49 13.92196 +- 0.00852 s 13.1% faster

Commands used to collect the performance results:

numactl -C 0-47 perf stat -r 3 -e cycles,instructions,task-clock -- <build-dir>/bin/test-backend-ops perf -b CPU -o MUL_MAT -p '^type_a=<q5_0|q5_1>,type_b=f32,.*$'

Perplexity

Non-regression check

Result: No significant regression

Command:

llama-perplexity --model /models/gpt-oss-20b-Q4_K_M.gguf --parallel 2 --predict 128 --seed 0 --threads 72 -f /datasets/wikitext-2-raw/wiki.test.raw
# Baseline
(...snip)
19.12.657.583 I Final estimate: PPL = 168.6365 +/- 1.42695
# This PR
(...snip)
18.43.108.886 I Final estimate: PPL = 168.8142 +/- 1.42959

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES
    • Help write code that complies with compiler rules and requirements.

@t-kusanagi
t-kusanagi requested a review from ggerganov as a code owner October 20, 2026 10:09
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Oct 20, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

Hi @t-kusanagi, thanks for your contribution!

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

  • Maintainers cannot push to this PR: Please enable Allow edits by maintainers. If this PR comes from an organization-owned fork, that option is not available on GitHub; please re-open the PR from a fork owned by your personal account.

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 Oct 20, 2026
@github-actions
github-actions Bot marked this pull request as draft October 20, 2026 10:16
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Oct 20, 2026
@t-kusanagi
t-kusanagi marked this pull request as ready for review October 20, 2026 10:16
@t-kusanagi

Copy link
Copy Markdown
Contributor Author

@chaxu01 @taronaeo
Kindly support to review the PR

@chaxu01

chaxu01 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Some comments:

  1. The benchmark filter in the PR description appears incorrect:
    ^type_a=<q5_0|q5_1>,type_b=f32,.$
    With std::regex_search, the ungrouped | splits this into two alternatives, and the angle brackets are treated literally. As a result, it won't match the intended q5_0 or q5_1 test labels.
    Could the benchmarks be rerun using the corrected filter?
    -p '^type_a=(q5_0|q5_1),type_b=f32,.
    $'

  2. The predicate-load helper calls ggml_cpu_get_sve_cnt() repeatedly inside the kernel loops (once for VL below 512 bits and twice at VL512). In my Clang cross-compilation without LTO, these calls remain and cause SVE register spills around them, potentially adding overhead to the hot path.

  3. Both the Q5_0 and Q5_1 SVE paths assert in the default switch branch for unsupported vector lengths. With assertions enabled, this terminates execution instead of falling back to the existing scalar implementation.
    Since the scalar path already handles these cases when assertions are disabled (NDEBUG), could the assertions be removed to allow unsupported SVE vector lengths to fall back?

@t-kusanagi

Copy link
Copy Markdown
Contributor Author

@chaxu01

Thank you for the review and the detailed feedback.

It seems I caused confusion by combining two separate commands into one in the PR description. The commands I actually ran were:

numactl -C 0-47 perf stat -r 3 -e cycles,instructions,task-clock -- <build-dir>/bin/test-backend-ops perf -b CPU -o MUL_MAT -p '^type_a=q5_0,type_b=f32,.*$'


numactl -C 0-47 perf stat -r 3 -e cycles,instructions,task-clock -- <build-dir>/bin/test-backend-ops perf -b CPU -o MUL_MAT -p '^type_a=q5_1,type_b=f32,.*$'

I apologize for the confusion and for not making this clear in the PR description.

Therefore, the performance results I initially posted were obtained by running the Q5_0 and Q5_1 benchmarks separately.

I changed the code to pass the result of ggml_cpu_get_sve_cnt() from the caller. This also eliminated the spills. I verified this with Clang 22.1.8.

I rebuilt the code with LTO disabled using the following configuration, then extracted only the relevant functions from the generated assembly to confirm that the spills were eliminated without relying on link-time optimization.

cmake -B ${CMAKE_BUILD_DIR} -S . \
   -DGGML_CUDA=OFF \
    -DGGML_CPU_KLEIDIAI=$KLEIDI \
   -DBUILD_SHARED_LIBS=OFF \
   -DGGML_NATIVE=$NATIVE \
   -DLLAMA_BUILD_UI=OFF \
   -DLLAMA_USE_PREBUILT_UI=OFF \
   -DLLAMA_BUILD_TESTS=$TESTS \
   -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

before

$ grep ggml_cpu_get_sve_cnt build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_{q5_0_q8_0,q5_1_q8_1}.s
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      bl      ggml_cpu_get_sve_cnt
$ grep -e str -e ldr build-perf_q5sve_971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_{q5_0_q8_0,q5_1_q8_1}.s | grep -i spill | grep z
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z1, [x29, #-1, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z0, [x29, #-2, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z4, [x29, #-3, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z2, [x29, #-4, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z0, [x29, #-4, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z4, [x29, #-3, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-2, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-1, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-2, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-1, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-2, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-1, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-2, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-1, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z0, [x29, #-4, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z1, [x29, #-3, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-4, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-3, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z2, [x29, #-1, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z2, [x29, #-2, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z0, [x29, #-2, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      str     z4, [x29, #-1, mul vl]          // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-4, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:      ldr     z1, [x29, #-3, mul vl]          // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z1, [x8, #-1, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z0, [x8, #-2, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z4, [x8, #-3, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z2, [x8, #-4, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z0, [x8, #-4, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z4, [x8, #-3, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-2, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-1, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-2, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-1, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-2, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-1, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-2, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-1, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z0, [x8, #-4, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z1, [x8, #-3, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-4, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-3, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z2, [x8, #-1, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z2, [x8, #-2, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z0, [x8, #-2, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      str     z4, [x8, #-1, mul vl]           // 16-byte Folded Spill
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-4, mul vl]           // 16-byte Folded Reload
build-perf_q5sve_prev-971b03b0a-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:      ldr     z1, [x8, #-3, mul vl]           // 16-byte Folded Reload

after

grep -e str -e ldr build-perf_q5sve-04ea271a5-modified-clang/q5-sve-spill-check/ggml_vec_dot_{q5_0_q8_0,q5_1_q8_1}.s | grep -i spill | grep z
$ grep ggml_cpu_get_sve_cnt build-perf_q5sve-04ea271a5-modified-clang/q5-sve-spill-check/ggml_vec_dot_{q5_0_q8_0,q5_1_q8_1}.s
build-perf_q5sve-04ea271a5-modified-clang/q5-sve-spill-check/ggml_vec_dot_q5_0_q8_0.s:  bl      ggml_cpu_get_sve_cnt
build-perf_q5sve-04ea271a5-modified-clang/q5-sve-spill-check/ggml_vec_dot_q5_1_q8_1.s:  bl      ggml_cpu_get_sve_cnt

I removed the assertions triggered by unsupported SVE vector lengths in the Q5_0 and Q5_1 paths. For unsupported lengths, SVE processing is skipped, and all blocks are computed using the existing scalar loop.

Comment thread ggml/src/ggml-cpu/arch/arm/quants.c Resolved
@t-kusanagi

Copy link
Copy Markdown
Contributor Author

Thank you for the review, @chaxu01 !

@taronaeo, could you also take a look when you have a chance?

@taronaeo

Copy link
Copy Markdown
Member

@t-kusanagi There are CI failures. Can you fix them and maybe rebase against upstream/master again?

https://github.com/ggml-org/llama.cpp/actions/runs/42609421256/job/131275543369?pr=30867#step:4:466

@t-kusanagi
t-kusanagi force-pushed the perf/q5sve branch 3 times, most recently from 5e99d73 to 77c0006 Compare November 24, 2026 00:11
msy-kato and others added 12 commits November 24, 2026 18:14
…q5_1_q8_1

SVE suooprt for ggml_vec_dot_q5_0_q8_0, ggml_vec_dot_q5_1_q8_1
- Load high-bit masks directly from quantized blocks
- Replace lookup-table expansion with predicated SVE duplication
- Reduce scalar high-bit unpacking overhead
- Add a helper to load mask data as svbool_t with ldr
- Replace direct svbool_t pointer casts in the q5 dot-product path
- Fix qh bit inversion in the SVE q5_0/q8_0 dot-product path
- Use the proper predicate-aware svnot_b_z mask logic for bit extraction
- Restore correct quantized compute behavior on ARM SVE targets
- replace manual qh extraction with vector bitmask loads in the ARM SVE path
- remove temporary unpack buffers used during q5_1 dot-product assembly
- preserve the qh bit pattern while keeping the quantized dot-product logic intact
- Add the existing GNU/Clang inline assembly path for SVE bool loading
- Provide a portable fallback for other compilers using SVE intrinsics
- Preserve current behavior on supported toolchains while improving compatibility
- fix SVE byte load by casting the uint32_t pointer to uint8_t*
- preserve correct mask generation in load_as_svbool on Arm SVE
- prevent undefined pointer aliasing in the SIMD vector path
- Limit q5 dot-product paths to 256-bit and 512-bit SVE vectors
- Assert when encountering unsupported vector lengths
- Localize the SVE predicate loader to the ARM quantization kernels
- Add an intrinsic predicate loader for SVE VL128 qh halves
- Replace table-based qh expansion in q5_0 and q5_1 paths
- Remove temporary qh expansion buffers
- Preserve direct predicate loads for wider SVE vector lengths
- Unify predicate loading for q5 quantization paths
- Prevent out-of-bounds reads from 8-bit high-bit storage
- Remove unsupported VL512 q5 dot-product cases
- Bound qh predicate loads for SVE vectors at or above 512 bits
- Use the shared SVE vector-length helper
- Extend q5_0 and q5_1 dot products to VL512
- Document that values beyond the first 32 bits of qh are undefined
- Warn that the loader may cause a SEGV for vector lengths above 1024
- Pass the cached vector length to SVE predicate loading
- Remove repeated SVE vector length queries
- Allow unsupported vector lengths to exit without assertions
- Remove obsolete VL > 1024 SEGV warning from load_as_svbool
@t-kusanagi

Copy link
Copy Markdown
Contributor Author

@taronaeo

Thank you for your review.

I've fixed the compilation errors and pushed the updated commits. I've confirmed that the compilation errors observed in the previous CI runs no longer occur.

However, some CI jobs failed for reasons that appear to be unrelated to the changes in this PR. I've rebased onto the latest master and pushed the updated commits several times, but encountered different CI failures each time. Therefore, it may be necessary to rerun only the failed jobs rather than rebase and push again.

It appears that the CI workflows require approval from someone with write access to the repository. Since I don't have write access, could you please approve and trigger the CI workflows for the latest commit?

If any unrelated CI failures occur again, I may ask for your help in rerunning the failed jobs.

Thank you for your help and patience!

@taronaeo

Copy link
Copy Markdown
Member

CI failures unrelated to PR. Merging.

@taronaeo
taronaeo merged commit 5fddd0b into ggml-org:master Nov 24, 2026
37 of 41 checks passed
abeloin added a commit to abeloin/llama.cpp-mix that referenced this pull request Nov 25, 2026
…owner 2026-11-25)

Base b12723 (merge a940ab9), pin ggml-org#401 removed (80211b4), RoPE
multi-section fusion from upstream ggml-org#32500 (owner's decision), MIX.md
(3563400). Build gate: test-backend-ops ROCm 21878/21878, bench r17
(llama-mix-notes, mesures/2026.md): Inkling tg +4.5 % [bon], Qwen3.6 and
Gemma 4 without regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QBjnvFCJ83vkmygsLNv5cu

* mix/wip-b12723: (55 commits)
  mix: MIX.md — base b12723 (branche wip), retrait du pin ggml-org#401, conflit RoPE tranché (amont ggml-org#32500)
  revert: pin: CUDA: fuse the row L2 clip chain (unslothai#401, commit 6c0e84d)
  model : inkling2 graph with fewer ops in mix() and control() (ggml-org#32948)
  opencl: add clc coopmat moe kernel for q4_0/q4_1/q4_k/q5_0/q5_1/q5_k/q6_k/mxfp4 (ggml-org#32971)
  tests : fix MSVC static build of test-batch-alloc and test-server-component (ggml-org#32870)
  feat: Inkling 2 DSpark support (ggml-org#32218)
  cuda : fix int overflow of the MMVF matrix offsets (ggml-org#32965)
  docs : describe SpacemiT runtime environment variables (ggml-org#32452)
  ggml : fix SpacemiT flash attention null mask, ALiBi and softcap (ggml-org#32182)
  cmake : include the llguidance header from the source tree (ggml-org#32928)
  ci : move some jobs to gb10 runners (ggml-org#32968)
  ui: run Llama Chat apart from llama-server, named in config.json or npx --server (ggml-org#32945)
  ui: fix prebuilt UI download in shallow clones (ggml-org#32952)
  convert : fix qwen3-omni conversion (ggml-org#32941)
  ggml-cpu: repack kernels for targets without dotprod (ARMv8.0 64-bit) for Q4_0/Q8_0 (ggml-org#32142)
  ui: expect the Llama Chat name in the PWA manifest e2e test (ggml-org#32959)
  ggml-cpu: add SVE-optimized q5_0 and q5_1 dot-product kernels (ggml-org#30867)
  server : include MCP image and audio data in tool results (ggml-org#32064)
  context : prevent excessive CPU polling without OpenMP (ggml-org#32378)
  metal : reserve the top-k scratch only for short rows (ggml-org#32942)
  ...
Mr-J-369 pushed a commit to Mr-J-369/llama.cpp-Android that referenced this pull request Nov 26, 2026
…rg#30867)

* Merged PR 5925: SVE suooprt for ggml_vec_dot_q5_0_q8_0, ggml_vec_dot_q5_1_q8_1

SVE suooprt for ggml_vec_dot_q5_0_q8_0, ggml_vec_dot_q5_1_q8_1

* perf(arm): optimize q5_0 q8_0 dot products with SVE

- Load high-bit masks directly from quantized blocks
- Replace lookup-table expansion with predicated SVE duplication
- Reduce scalar high-bit unpacking overhead

* fix(arm): load SVE masks through inline assembly

- Add a helper to load mask data as svbool_t with ldr
- Replace direct svbool_t pointer casts in the q5 dot-product path

* fix(arm): correct q5/q8 SVE bitmask handling

- Fix qh bit inversion in the SVE q5_0/q8_0 dot-product path
- Use the proper predicate-aware svnot_b_z mask logic for bit extraction
- Restore correct quantized compute behavior on ARM SVE targets

* fix(arm): simplify q5_1/q8_1 bitpack handling

- replace manual qh extraction with vector bitmask loads in the ARM SVE path
- remove temporary unpack buffers used during q5_1 dot-product assembly
- preserve the qh bit pattern while keeping the quantized dot-product logic intact

* fix(ggml-cpu): support SVE load on non-GNU compilers

- Add the existing GNU/Clang inline assembly path for SVE bool loading
- Provide a portable fallback for other compilers using SVE intrinsics
- Preserve current behavior on supported toolchains while improving compatibility

* fix(cpu): cast SVE input pointer before byte load

- fix SVE byte load by casting the uint32_t pointer to uint8_t*
- preserve correct mask generation in load_as_svbool on Arm SVE
- prevent undefined pointer aliasing in the SIMD vector path

* fix(arm): restrict q5 SVE kernels to supported vector lengths

- Limit q5 dot-product paths to 256-bit and 512-bit SVE vectors
- Assert when encountering unsupported vector lengths
- Localize the SVE predicate loader to the ARM quantization kernels

* perf(arm): optimize SVE q5 dot products for VL128

- Add an intrinsic predicate loader for SVE VL128 qh halves
- Replace table-based qh expansion in q5_0 and q5_1 paths
- Remove temporary qh expansion buffers
- Preserve direct predicate loads for wider SVE vector lengths

* fix(arm): correct SVE q5 predicate loading

- Unify predicate loading for q5 quantization paths
- Prevent out-of-bounds reads from 8-bit high-bit storage
- Remove unsupported VL512 q5 dot-product cases

* fix(arm): support SVE VL512 q5 dot products

- Bound qh predicate loads for SVE vectors at or above 512 bits
- Use the shared SVE vector-length helper
- Extend q5_0 and q5_1 dot products to VL512

* docs(arm): clarify SVE predicate loader limit

- Document that values beyond the first 32 bits of qh are undefined
- Warn that the loader may cause a SEGV for vector lengths above 1024

* perf(arm): reuse SVE vector length in quantized dot products

- Pass the cached vector length to SVE predicate loading
- Remove repeated SVE vector length queries
- Allow unsupported vector lengths to exit without assertions

* docs(arm): remove outdated SVE loader warning

- Remove obsolete VL > 1024 SEGV warning from load_as_svbool

* fix compilation errors

---------

Co-authored-by: Kato, Masaya 加藤 雅也 <[email protected]>
Co-authored-by: Masaru Ito <[email protected]>
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.

5 participants