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 pp214 prefill: 101.5 -> 157.6 tok/s (+55.3%)
  • Plain M=1 decode: 27.5 -> 30.9 tok/s (+12.3%, 64/64 exact 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): Hardcoded nrc = 1 for every MoE model, completely bypassing ARMv8.6-A i8mm (vmmlaq_s32) 2x2 tiles even for Q4_K and Q6_K.
  • ggml_vec_dot_q5_K_q8_K (arch/arm/quants.c): Asserted nrc == 1 with no i8mm 2-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 pp39 prefill: 113.9 -> 140.8 tok/s (+23.6%)
  • Long pp214 prefill: 157.6 -> 166.7 tok/s (64/64 exact parity on reasoning)
  • Numerical check: Q5_K relative error 0.0068 vs F32 reference (identical to Q4_K 0.0066 and Q6_K 0.0070).

Upstream PRs & submission order

ggml-org/llama.cpp limits new contributors to one open PR at a time, so these land sequentially:

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.