Skip to content

ggml-cpu: repack kernels for targets without dotprod (ARMv8.0 64-bit) for Q4_0/Q8_0 - #32142

Merged
chaxu01 merged 3 commits into
ggml-org:masterfrom
rjtokenring:cpu-arm-repack-no-dotprod
Nov 24, 2026
Merged

chaxu01 merged 3 commits into
ggml-org:masterfrom
rjtokenring:cpu-arm-repack-no-dotprod

Conversation

@rjtokenring

Copy link
Copy Markdown
Contributor

Overview

ggml-cpu: repack kernels for targets without dotprod (ARMv8.0 64bit) for Q4_0/Q8_0
Tested on Arduino UNOQ with Qwen3.5 0.8B Q4_0 pure and Q8_0

Measured a max throughput increase by x2.6 on prefill, x1.6 in token generation.

llama-bench, tokens/s

model test master PR
Gemma-3-1b-it Q4_0 (Unsloth) pp128 10.30 25.89
pp512 10.17 24.84
tg128 5.85 8.93
Qwen3.5-0.8B Q4_0 pp128 12.96 31.79
pp512 12.84 31.05
tg128 6.56 9.45

llama-server, chat request with a 584-token prompt, tokens/s

model phase master PR
Qwen3.5-0.8B Q8_0 (Unsloth) prompt 11.84 23.98
generation 5.38 6.85

@rjtokenring
rjtokenring marked this pull request as ready for review November 12, 2026 14:31
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Nov 12, 2026
@rjtokenring
rjtokenring force-pushed the cpu-arm-repack-no-dotprod branch from dfd5157 to 1fcbf43 Compare November 13, 2026 10:36
@rjtokenring

Copy link
Copy Markdown
Contributor Author

@ServeurpersoCom please verify. Thanks.

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on a Cortex-A53 emulated with qemu in my rootless container. This uses qemu user mode, so it needs no KVM, no binfmt and no privileges: qemu translates the aarch64 binary process by process, and with -cpu cortex-a53 any dotprod instruction would crash with SIGILL.

cmake -B build -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DGGML_NATIVE=OFF -DGGML_CPU_ARM_ARCH=armv8-a
qemu-aarch64 -L /usr/aarch64-linux-gnu -cpu cortex-a53 build/bin/llama-perplexity -m Qwen3-0.6B-Q4_0.gguf ...

Correctness looks good: the new kernels give the same results as the generic ones, and the int16 sums don't overflow even with every value at its max. A full mul_mat through the repack buffer also matches the plain CPU path, row tails included.

With this PR, Qwen3-0.6B Q4_0 on the emulated A53 gets the same perplexity (9.8626) as the existing dotprod repack on an emulated A76.

Emulation says nothing about speed, so for the performance numbers I trust your measurements on the real board.

@rjtokenring Nit: the ggml_hsum_4x_s16 comment says lanes must stay below 8192, but the pairwise add only needs below 16384.

@rjtokenring
rjtokenring force-pushed the cpu-arm-repack-no-dotprod branch from 11e1b5e to 2d677c3 Compare November 16, 2026 11:42
@rjtokenring

Copy link
Copy Markdown
Contributor Author

@ServeurpersoCom for completeness, here is a bech performed on a Raspberry Pi 4.
Performance increase is evident and reproducible also on this platform.

Raspberry Pi 4 Model B (4x Cortex-A72 @ 1.5 GHz, no dotprod), gcc 14.2 -mcpu=cortex-a72, llama-bench -fa 1 -ub 512, master 2d8a32502 vs this PR, mean of 2 interleaved runs.

4 threads

model test master t/s PR t/s speedup
Qwen3.5-0.8B Q4_0 (all tensors Q4_0) pp128 16.57 34.02 2.05x
Qwen3.5-0.8B Q4_0 (all tensors Q4_0) pp512 16.29* 33.79 2.07x*
Qwen3.5-0.8B Q4_0 (all tensors Q4_0) tg128 5.29 5.36 1.01x
Qwen3.5-0.8B Q4_0 (unsloth) pp128 16.32 30.38 1.86x
Qwen3.5-0.8B Q4_0 (unsloth) pp512 16.10* 30.29 1.88x*
Qwen3.5-0.8B Q4_0 (unsloth) tg128 4.82 4.95 1.03x
Qwen3.5-0.8B Q8_0 (unsloth) pp128 17.41 27.62 1.59x
Qwen3.5-0.8B Q8_0 (unsloth) pp512 17.26* 27.92 1.62x*
Qwen3.5-0.8B Q8_0 (unsloth) tg128 3.29 3.54 1.08x
gemma-3-1b-it Q4_0 (unsloth) pp128 13.53 30.27 2.24x
gemma-3-1b-it Q4_0 (unsloth) pp512 12.96* 29.70 2.29x*
gemma-3-1b-it Q4_0 (unsloth) tg128 4.55 4.62 1.01x

1 thread

model test master t/s PR t/s speedup
Qwen3.5-0.8B Q4_0 (all tensors Q4_0) pp128 4.54 10.51 2.32x
Qwen3.5-0.8B Q4_0 (all tensors Q4_0) tg128 2.65 3.98 1.50x

@rjtokenring

Copy link
Copy Markdown
Contributor Author

Tested on a Cortex-A53 emulated with qemu in my rootless container. This uses qemu user mode, so it needs no KVM, no binfmt and no privileges: qemu translates the aarch64 binary process by process, and with -cpu cortex-a53 any dotprod instruction would crash with SIGILL.

cmake -B build -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DGGML_NATIVE=OFF -DGGML_CPU_ARM_ARCH=armv8-a
qemu-aarch64 -L /usr/aarch64-linux-gnu -cpu cortex-a53 build/bin/llama-perplexity -m Qwen3-0.6B-Q4_0.gguf ...

Correctness looks good: the new kernels give the same results as the generic ones, and the int16 sums don't overflow even with every value at its max. A full mul_mat through the repack buffer also matches the plain CPU path, row tails included.

With this PR, Qwen3-0.6B Q4_0 on the emulated A53 gets the same perplexity (9.8626) as the existing dotprod repack on an emulated A76.

Emulation says nothing about speed, so for the performance numbers I trust your measurements on the real board.

@rjtokenring Nit: the ggml_hsum_4x_s16 comment says lanes must stay below 8192, but the pairwise add only needs below 16384.

@ServeurpersoCom comment fixed, thanks!

@rjtokenring

Copy link
Copy Markdown
Contributor Author

@max-krasnyansky please review

@gatewaytofredom

Copy link
Copy Markdown

If you build this, #32142, without dotprod the repack might be making prompt processing slower for cpu inference because repacked weights can't use Accelerate BLAS. The BLAS backend can only accept host buffers and repacked weights are not host buffers.

Tested on my macmini m4 with -mcpu=apple-a7 to simulate a build for iOS and visionOS builds which don't have dotproduct. Prompt processing slowed down, but token generation speed is up.

Cmake command:
cmake -B build -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=OFF -DGGML_METAL=OFF -DCMAKE_C_FLAGS=-mcpu=apple-a7 -DCMAKE_CXX_FLAGS=-mcpu=apple-a7

Model tested: SmolLM2-360M-Instruct

Q4_0:

model size params backend threads rpk test t/s
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 pp128 1015.60 ± 11.06
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 pp512 984.45 ± 3.92
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 tg128 79.63 ± 0.12
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 pp128 1129.34 ± 4.94
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 pp512 1451.15 ± 9.78
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 tg128 219.27 ± 0.44
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 pp128 217.10 ± 0.29
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 pp512 204.70 ± 0.15
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 tg128 114.52 ± 0.17
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 pp128 785.95 ± 16.95
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 pp512 750.36 ± 1.43
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 tg128 253.78 ± 0.94

build: 2d677c3 (20)

Q8_0:

model size params backend threads rpk test t/s
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 pp128 1184.81 ± 4.42
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 pp512 1015.73 ± 5.52
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 tg128 98.24 ± 0.13
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 pp128 1209.68 ± 25.02
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 pp512 1469.27 ± 15.83
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 tg128 169.30 ± 0.19
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 pp128 192.51 ± 0.15
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 pp512 182.27 ± 0.17
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 tg128 128.98 ± 0.35
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 pp128 717.36 ± 0.31
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 pp512 676.76 ± 0.95
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 tg128 171.65 ± 0.17

build: 2d677c3 (20)

@rjtokenring

Copy link
Copy Markdown
Contributor Author

If you build this, #32142, without dotprod the repack might be making prompt processing slower for cpu inference because repacked weights can't use Accelerate BLAS. The BLAS backend can only accept host buffers and repacked weights are not host buffers.

Tested on my macmini m4 with -mcpu=apple-a7 to simulate a build for iOS and visionOS builds which don't have dotproduct. Prompt processing slowed down, but token generation speed is up.

Cmake command: cmake -B build -DCMAKE_BUILD_TYPE=Release -DGGML_NATIVE=OFF -DGGML_METAL=OFF -DCMAKE_C_FLAGS=-mcpu=apple-a7 -DCMAKE_CXX_FLAGS=-mcpu=apple-a7

Model tested: SmolLM2-360M-Instruct

Q4_0:

model size params backend threads rpk test t/s
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 pp128 1015.60 ± 11.06
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 pp512 984.45 ± 3.92
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 0 tg128 79.63 ± 0.12
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 pp128 1129.34 ± 4.94
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 pp512 1451.15 ± 9.78
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 0 tg128 219.27 ± 0.44
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 pp128 217.10 ± 0.29
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 pp512 204.70 ± 0.15
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 1 1 tg128 114.52 ± 0.17
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 pp128 785.95 ± 16.95
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 pp512 750.36 ± 1.43
llama 3B Q4_0 217.39 MiB 361.82 M BLAS 4 1 tg128 253.78 ± 0.94
build: 2d677c3 (20)

Q8_0:

model size params backend threads rpk test t/s
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 pp128 1184.81 ± 4.42
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 pp512 1015.73 ± 5.52
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 0 tg128 98.24 ± 0.13
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 pp128 1209.68 ± 25.02
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 pp512 1469.27 ± 15.83
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 0 tg128 169.30 ± 0.19
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 pp128 192.51 ± 0.15
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 pp512 182.27 ± 0.17
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 1 1 tg128 128.98 ± 0.35
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 pp128 717.36 ± 0.31
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 pp512 676.76 ± 0.95
llama 3B Q8_0 366.80 MiB 361.82 M BLAS 4 1 tg128 171.65 ± 0.17
build: 2d677c3 (20)

The CPU buffer order is ACCEL, GPU host, CPU extra (repack), CPU, and BLAS uses the plain CPU buffer type, so it is skipped.
Master already applies the same precedence for Q4_0/Q8_0 with dotprod and the default macOS target has dotprod, so standard macOS builds already skip Accelerate for these types.
Also -mcpu=apple-a7 does not limit Accelerate, which still uses the M4 matrix unit at runtime.
On Cortex-A53, OpenBLAS gave +3% pp vs about 2x from repack.
The "--no-repack" restores the old behavior.

@max-krasnyansky max-krasnyansky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get a chance to try it on my setups but the repack/ukernel changes look good to me.

@max-krasnyansky

Copy link
Copy Markdown
Member

@rjtokenring take a look at the CI failures. EditorConfig, etc.
I'll kick it again one you push the updates.

@rjtokenring
rjtokenring force-pushed the cpu-arm-repack-no-dotprod branch from 2d677c3 to 28f6159 Compare November 18, 2026 21:01
@rjtokenring

Copy link
Copy Markdown
Contributor Author

Thanks @max-krasnyansky! Failures (EditorConfig) were in master and has been fixed after my rebase.
I rebased now with master again: please kick CI jobs.

@max-krasnyansky

Copy link
Copy Markdown
Member

@chaxu01 please review/ack when you get the chance

@chaxu01

chaxu01 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

I have one comment:

The new default repack selection for Q4/Q8 appears to prevent Accelerate/BLAS from handling these weights, since BLAS cannot consume the repacked buffers. This seems consistent with the reported Q8 pp128 regression.

While existing dotprod builds may have the same limitation, this introduces a regression for previously unaffected ARM builds. --no-repack provides a workaround, but the default behavior is still concerning.

@rjtokenring

Copy link
Copy Markdown
Contributor Author

I have one comment:

The new default repack selection for Q4/Q8 appears to prevent Accelerate/BLAS from handling these weights, since BLAS cannot consume the repacked buffers. This seems consistent with the reported Q8 pp128 regression.

While existing dotprod builds may have the same limitation, this introduces a regression for previously unaffected ARM builds. --no-repack provides a workaround, but the default behavior is still concerning.

@chaxu01 thanks for the review.
Since the problematic case could be Apple target compiled without dot-prod, I'm reducing the scope of this change by removing them from selection.
This changes is addressing the concern and the possible regression.

For a53 CPU, BLAS is slower wrt new repack approack.
Here are some numbers.

Arduino UNO Q (4x Cortex-A53 @ 2.0 GHz, no dotprod), PR head 28f6159, gcc 14.2 -mcpu=cortex-a53,
-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS (OpenBLAS 0.3.29 pthread), SmolLM2-360M-Instruct Q4_0,
llama-bench -t 1,4 --repack 0,1 -p 128,512 -n 128 -r 1, 1 run per cell.

threads test --repack 0 (OpenBLAS) t/s --repack 1 (this PR) t/s ratio
1 pp128 7.66 17.12 2.23x
1 pp512 8.11 15.33 1.89x
1 tg128 4.29 6.51 1.52x
4 pp128 23.35 64.13 2.75x
4 pp512 26.65 56.57 2.12x
4 tg128 15.83 22.81 1.44x

@rjtokenring

Copy link
Copy Markdown
Contributor Author

@chaxu01 do you have any comment? Thanks!

@chaxu01

chaxu01 commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

The changes look good to me, and I don't have any further code review concerns.

I noticed there are still failing CI checks. They don't appear to be related to this patch.

Could you please take a look and clarify the failures before merging.

@rjtokenring
rjtokenring force-pushed the cpu-arm-repack-no-dotprod branch from 9838345 to 47b41ce Compare November 23, 2026 10:18
@rjtokenring

Copy link
Copy Markdown
Contributor Author

The changes look good to me, and I don't have any further code review concerns.

I noticed there are still failing CI checks. They don't appear to be related to this patch.

Could you please take a look and clarify the failures before merging.

Thanks!

I rebased now with master, but I see those jobs failing on master as well.
Failures are not related to changes on this PR.

@rjtokenring
rjtokenring force-pushed the cpu-arm-repack-no-dotprod branch from 47b41ce to e361196 Compare November 24, 2026 09:44
@rjtokenring

Copy link
Copy Markdown
Contributor Author

@chaxu01 checked again the CI failures. For OpenVino, fix is in master ("ggml-openvino: CI fixes" (#32861)). other failures are not related to these changes and can be seen also on master.

@chaxu01
chaxu01 merged commit f20c590 into ggml-org:master Nov 24, 2026
39 of 42 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
… for Q4_0/Q8_0 (ggml-org#32142)

* ggml-cpu: optimized kernels for ARM v8.0 (without dotprod)

* ggml-cpu: fix comment and align to implementation

* ggml-cpu: exclude new kernels for apple arch
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