What per-op profiling caught in 10 seconds
While tuning Qwen4-35B-A3B (UD-Q4_K_XL) on my Snapdragon X2 Elite laptop running Omarchy Linux, a per-op CPU trace exposed two huge ARM64 bottlenecks hiding in plain sight inside ggml-org/llama.cpp.
Neither bottleneck is specific to Snapdragon. Both affect every ARMv8.6-A CPU (Snapdragon X1E/X2E, Apple M2/M3/M4, AWS Graviton 3/4, AmpereOne, and Neoverse V2).
Patch 1: Missing ARMv8.6-A vbfdotq_f32 in ggml_vec_dot_bf16
In the pp206 prefill trace, four small BF16 projection weights (ple_key, ple_value, indexer.q_proj, indexer.k_proj) burned 653.2 ms (33.1% of the entire prefill).
Checking ggml/src/ggml-cpu/vec.cpp showed why: ggml_vec_dot_bf16 had vector paths for AVX-512 BF16, AVX-512F, AVX2, and even RISC-V, but zero ARM64 path. Even though the binary compiled with armv8.6-a+bf16, it fell through to a scalar C loop converting one BF16 element at a time.
Adding a 19-line 4-way unrolled #elif defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) loop using vbfdotq_f32 changed the numbers immediately:
blk.X.ple_key.weight(pp206):319.1 ms -> 10.8 ms(29.6x faster)- End-to-end
pp214prefill:101.5 -> 157.6 tok/s(+55.3%) - Plain
M=1decode:27.5 -> 30.9 tok/s(+12.3%,64/64exact parity on reasoning)
Patch 2: 2x2 i8mm tiles in MUL_MAT_ID and Q5_K
Re-profiling after the BF16 fix showed that MoE experts (MUL_MAT_ID) now took 58.3% of prefill, with ffn_down_exps (359.2 ms) running 1.8x slower than ffn_gate_exps and ffn_up_exps (200 ms each).
Two separate gaps caused it:
ggml_compute_forward_mul_mat_id_one_chunk(ggml-cpu.c): Hardcodednrc = 1for every MoE model, completely bypassing ARMv8.6-Ai8mm(vmmlaq_s32) 2x2 tiles even forQ4_KandQ6_K.ggml_vec_dot_q5_K_q8_K(arch/arm/quants.c): Assertednrc == 1with noi8mm2-row kernel at all.
Pairing two token activations per expert with zero-copy pointer ordering (by >= 0) in MUL_MAT_ID and adding the nrc = 2 vmmlaq_s32 kernel to Q5_K delivered:
- Reasoning
pp39prefill:113.9 -> 140.8 tok/s(+23.6%) - Long
pp214prefill:157.6 -> 166.7 tok/s(64/64exact parity on reasoning) - Numerical check:
Q5_Krelative error0.0068vs F32 reference (identical toQ4_K0.0066andQ6_K0.0070).
Upstream PRs & submission order
ggml-org/llama.cpp limits new contributors to one open PR at a time, so these land sequentially:
- PR #1 (Open now): ggml-org/llama.cpp#33837 (
ggml-cpu : add ARMv8.6-A BFDOT (vbfdotq_f32) path to ggml_vec_dot_bf16) - PR #2 (Queued next):
ggml-cpu : enable ARM i8mm 2x2 tiles in MUL_MAT_ID and Q5_Kon abdelkareemkobo/llama.cpp (arm-i8mm-mul-mat-id-q5k)
Once merged, these improvements flow directly into omacom/omarchy-local-ai for every ARM64 Omarchy Linux user. Full Snapdragon X2 Elite receipts live in Kobo Lab.