KernelShift: Benchmarking Kernel Optimization Across Evolving Hardware
Organizations: Carnegie Mellon University · Arm Ltd.
Abstract
Efficient AI computation depends on hardware that evolves over time, shifting the strategies needed to implement performant code. For CPU kernels, a key evolving factor is the set of available architectural extensions, which expose specialized hardware instructions that change the techniques used to optimize kernels. We study how effectively coding agents use these new, potentially unfamiliar extensions to write fast code. We introduce KernelShift, a benchmarking pipeline and a set of environments for evaluating coding agents in kernel optimization across evolving CPU architectures. Its agent-assisted, human-verified pipeline turns code repositories into benchmark instances, and its environments let agents optimize code with feedback from the target hardware. Using this pipeline, we construct 99 kernels from real-world, actively developed repositories (ncnn, llama.cpp, Arm SIMD Loops, and KleidiAI), including inference workloads derived from real model executions. KernelShift supports incorporating new kernels and hardware configurations as libraries and processors evolve. We evaluate agents with proprietary and open-weight models across progressively newer architectural extensions (Arm Neon, SVE, SVE2, and SME2), examining how performance changes as hardware evolves. On established extensions, agents beat the auto-vectorized compiler everywhere (2.4-19.8x) and exceed general-purpose libraries such as ncnn (getting up to 2.74x over its Neon kernels), but fall behind Arm's hand-tuned KleidiAI kernels (0.70x). In end-to-end inference of two LLMs, agent-written kernels achieve a 1.3-1.6x prefill speedup over llama.cpp's fast path. However, current agents do not yet reliably adapt to new extensions that require unfamiliar programming models, such as SME2's matrix tiles.
Figures & tables
| Source | Op types | Precisions | Expert reference | #Kernels |
|---|---|---|---|---|
| ncnn | conv, dwconv, pool | FP32, INT8 (w8a8ch) | ncnn Neon | 23 |
| llama.cpp | gemm, moe, attn, rmsnorm | FP32, BF16, q8_0, q4_K_M | ggml | 26 |
| SIMD Loops | loops (reduction, string, search, …) | fp/int/uint | Arm SVE | 24 |
| KleidiAI | gemm, conv, dwconv (NHWC) | FP32, FP16, BF16, INT8, INT4, INT2 | KleidiAI | 26 (6 SVE, 20 SME2) |
| Total | 99 |
| Harness | Model | Geomean Speedup@40 (beat-ref %) vs. expert reference | |||
|---|---|---|---|---|---|
| ncnn (23) | llama.cpp (26) | SIMD Loops (24) | KleidiAI (6) | ||
| Claude Code | Claude Opus 4.8 | 2.574 (96%) | 1.779 (73%) | 1.555 (96%) | 0.701 (33%) |
| Claude Code | Claude Sonnet 4.6 | 1.934 (83%) | 1.243 (46%) | 1.516 (100%) | 0.386 (33%) |
| Codex | GPT-5.6-sol | 1.815 (78%) | 1.297 (62%) | 1.487 (96%) | 0.431 (17%) |
| Codex | GPT-5.6-luna | 0.674 (35%) | 0.627 (27%) | 1.127 (79%) | 0.147 (0%) |
| nanobot | Claude Opus 4.8 | 2.597 (91%) | 1.708 (73%) | 1.521 (96%) | 0.453 (17%) |
| Setting | Speedup@40 |
|---|---|
| SVE | |
| Control | 1.074 |
| Arm docs | 0.997 |
| cross-kernel notepad | 0.974 |
| disassemble tool | 0.999 |
| No intrinsics | 0.300 |
| Qwen3.5-4B | Llama-3.1-8B-Instruct | |||
|---|---|---|---|---|
| Threads | Prefill | Decode | Prefill | Decode |
| 1 | 1.395 | 1.045 | 1.568 | 1.099 |
| 4 | 1.348 | 1.059 | 1.454 | 1.069 |
| 16 | 1.298 | 1.048 | 1.391 | 1.102 |
Appendix figures & tables20 assets
Supplementary material from the paper’s appendix.
Appendix
| Source | Kernels | Precisions | Workload shapes | Expert reference | # |
|---|---|---|---|---|---|
| ncnn | conv2d (10), depthwise conv2d (8), pooling (5) | FP32, INT8 (w8a8ch) | 6 vision models: ResNet50, MobileNetV3-Large, VGG16, GoogLeNet, AlexNet, SqueezeNet1.1 | ncnn Arm (Neon) layers | 23 |
| llama.cpp | GEMM (15), MoE (6), attention: MHA, GQA, MLA prefill, MLA decode (4), RMSNorm (1) | BF16, q8_0, q4_K_M, FP32 | 5 LLMs on ShareGPT prompts: Qwen1.5-MoE-A2.7B, OLMoE-1B-7B, DeepSeek-V3, Llama-3.1-8B, Mistral-7B | ggml CPU kernels | 26 |
| Arm SIMD Loops | reductions and dot products (9), element-wise arithmetic (4), complex arithmetic (4), convolution and correlation (2), string and pixel processing (2), search and conditional update (2), INT8 matrix–vector product (1) | FP16–FP64, INT8–INT64 | edge-case and performance sizes | Arm’s hand-written SVE version of each loop | 24 |
| KleidiAI | SVE: GEMM (5; FP32, INT8, INT4), conv2d (1). SME2: GEMM (16; FP32, FP16, BF16, INT8, INT4, INT2), conv2d (2), depthwise conv2d (2) | FP32, FP16, BF16, INT8, INT4, INT2 | edge-case and performance sizes | KleidiAI SVE and SME2 micro-kernels | 6 + 20 |
| Total | 99 |
| Experiment | Where | Machine | Harness, model | Kernels | Reference |
| Main comparison | Tab. 2 | G3 | all 14 pairs | 23 / 26 / 24 / 6 (79) | expert |
| ISA ladder L1–L3 | Tab. 4 | G4 | nanobot, GPT-5.6-luna | 32-subset: 10 / 9 / 12 / 1 | expert, same in every arm |
| ISA ladder L4–L6 | Tab. 4 | M4 | nanobot, GPT-5.6-luna | KleidiAI SME2: 20 | expert, same in every arm |
| KleidiAI SVE SME2 | Tab. 4 | G3 M4 | nanobot, 5 models | KleidiAI: 6 6 | KleidiAI SVE SME2 |
| SIMD Loops SVE SVE2 | Tab. 4 | G3 G4 | nanobot, 4 models | SIMD Loops: 8 | Arm SVE SVE2 versions |
| Ablations, SVE | Tab. 5 | G3 | nanobot, GPT-5.6-luna | 32-subset: 10 / 9 / 12 / 1 | expert |
| Source | Family | Variants | # |
| ncnn | conv2d | {FP32, w8a8ch} { s1, s2, s1, s2, s2} | 10 |
| depthwise conv2d | {FP32, w8a8ch} { , } {s1, s2} | 8 | |
| pooling (FP32) | global average; max s2; max s1; max s2 with and without padding | 5 | |
| llama.cpp | GEMM | {BF16, q8_0, q4_K_M} {(1024, 2048), (1408, 2048), (2048, 1024), (2048, 1408), (2048, 2048)}; q4_K_M uses in place of 1408 | 15 |
| MoE | {BF16, q8_0, q4_K_M} {Qwen: 60 experts, top-4; OLMoE: 64 experts, top-8} | 6 | |
| attention (BF16) | MHA (Qwen); GQA, 32 query and 8 KV heads (Llama-3.1-8B, Mistral-7B); MLA prefill and MLA decode (DeepSeek-V3) | 4 |
| Kernels | Absolute tol. | Relative tol. | Match ratio |
| Default (convolution, pooling, RMSNorm, SIMD Loops) | 1.00 | ||
| GEMM | 0.98 | ||
| MoE | 0.95 | ||
| MHA | 0.98 | ||
| GQA, MLA prefill | 0.98 | ||
| MLA decode | 0.98 |
| Step | Agent | Human |
|---|---|---|
| Scope and definitions | Writes one definition per shape and quantization format | Chooses the models and formats; corrects two shapes the agent got wrong |
| Workloads ( collect , add ) | Runs each model, records the shapes every GEMM sees, selects and registers workloads | — |
| Inputs ( capture ) | Stores the activations reaching each GEMM as workload inputs | — |
| Calibration ( calibrate ) | Measures the SQNR of ggml’s own arithmetic on every workload | — |
| Machines | Provisions instances, sets them up, reruns failed steps | Chooses the instance type and approves each launch |
| Gen. | Machine | Core, vector width | OS / compiler | Target flag | CPU pinning | Counter feedback |
|---|---|---|---|---|---|---|
| SVE | Graviton3, AWS c7g.xlarge | Neoverse V1, 256-bit SVE | Ubuntu 22.04, clang-18 | -march=armv8.2-a+sve | CPU 0 | cycles, instructions, cache misses |
| SVE2 | Graviton4, AWS c8g.xlarge | Neoverse V2, 128-bit SVE2 | Ubuntu 22.04, clang-18 | -march=armv9-a+sve2 | CPU 0 | cycles, instructions, cache misses |
| SME2 | Apple M4, AWS mac-m4.metal | 512-bit, streaming SVE only | macOS, Apple clang | -mcpu=apple-m4 | none | none |
| Arm | Machine | Compile target | Additionally rejected |
|---|---|---|---|
| L1: Neon only | Graviton4 | -march=armv8-a | — (SVE intrinsics do not compile) |
| L2: SVE | Graviton4 | -march=armv8.2-a+sve | — (SVE2 intrinsics do not compile) |
| L3: SVE2 | Graviton4 | -march=armv9-a+sve2 | — |
| L4: Neon only | Apple M4 | -mcpu=apple-m4+nosme | Source: SVE and SME headers and types, streaming attributes, smstart . Binary: smstart , SVE and ZA/ZT0 registers. |
| L5: streaming SVE | Apple M4 | -mcpu=apple-m4 | Source: ZA/ZT0 attributes and intrinsics, smstart za . Binary: smstart without sm , outer products ( MOPA / MOPS ), ZA/ZT0 registers. |
| L6: ZA (full SME2) | Apple M4 | -mcpu=apple-m4 | — |
| Tool | Arguments | What it does | Returns |
|---|---|---|---|
| check_progress | definition | Looks up the best result so far on this definition. | Its version, metrics, and code. |
| compile | definition , code | Compiles the agent’s kernel.cpp ; the harness and binding files are added automatically. | A version number, or the compiler error. |
| evaluate | definition , version | Checks correctness on all workloads, stopping at the first failure; if correct, times the kernel. A new best result is saved immediately. | Errors, speedups, and counters; or the failing workload’s ID and a log. |
| disassemble | definition , version , optional fn | Disassembles the kernel entry symbol, or fn . | Up to 300 lines of AArch64 assembly. |
| Harness | Model | ncnn (23) | llama.cpp (26) | SIMD Loops (24) | KleidiAI (6) |
|---|---|---|---|---|---|
| Claude Code | Claude Opus 4.8 | 2.574 [1.96, 3.40] | 1.779 [1.26, 2.61] | 1.555 [1.24, 2.09] | 0.701 [0.45, 0.98] |
| Claude Code | Claude Sonnet 4.6 | 1.934 [1.50, 2.55] | 1.243 [0.88, 1.82] | 1.516 [1.20, 2.06] | 0.386 [0.20, 0.75] |
| Codex | GPT-5.6-sol | 1.815 [1.37, 2.39] | 1.297 [0.94, 1.82] | 1.487 [1.19, 1.96] | 0.431 [0.23, 0.74] |
| Codex | GPT-5.6-luna | 0.674 [0.47, 0.97] | 0.627 [0.38, 1.02] | 1.127 [0.89, 1.45] | 0.147 [0.06, 0.36] |
| nanobot | Claude Opus 4.8 | 2.597 [2.01, 3.38] | 1.708 [1.22, 2.48] | 1.521 [1.21, 2.02] | 0.453 [0.24, 0.83] |
| nanobot | Claude Sonnet 4.6 | 2.046 [1.53, 2.78] | 1.449 [1.01, 2.12] | 1.503 [1.21, 1.97] | 0.231 [0.12, 0.48] |
| Harness | Model | ncnn (23) | llama.cpp (26) | SIMD Loops (24) | KleidiAI (6) |
|---|---|---|---|---|---|
| Claude Code | Claude Opus 4.8 | 11.24 (100%) | 14.18 (100%) | 3.32 (92%) | 19.77 (100%) |
| Claude Code | Claude Sonnet 4.6 | 8.44 (100%) | 9.91 (100%) | 3.24 (92%) | 10.88 (100%) |
| Codex | GPT-5.6-sol | 7.92 (100%) | 10.34 (100%) | 3.18 (88%) | 12.14 (100%) |
| Codex | GPT-5.6-luna | 2.94 (100%) | 5.00 (100%) | 2.41 (79%) | 4.15 (100%) |
| nanobot | Claude Opus 4.8 | 11.34 (100%) | 13.62 (100%) | 3.25 (88%) | 12.77 (100%) |
| nanobot | Claude Sonnet 4.6 | 8.93 (100%) | 11.55 (100%) | 3.21 (92%) | 6.52 (100%) |
| Harness | Model | ncnn (23) | llama.cpp (26) | SIMD Loops (21) | KleidiAI (6) |
|---|---|---|---|---|---|
| Claude Code | Claude Opus 4.8 | 17.4% | 14.2% | 50.0% | 30.1% |
| Claude Code | Claude Sonnet 4.6 | 13.1% | 9.9% | 48.9% | 16.5% |
| Codex | GPT-5.6-sol | 12.3% | 10.4% | 48.2% | 18.5% |
| Codex | GPT-5.6-luna | 4.6% | 5.0% | 38.4% | 6.3% |
| nanobot | Claude Opus 4.8 | 17.6% | 13.7% | 49.0% | 19.4% |
| nanobot | Claude Sonnet 4.6 | 13.9% | 11.6% | 48.6% | 9.9% |
| Calls | What the agent does | Result |
|---|---|---|
| 1–2 | compile and evaluate the given scalar code | 0.004 |
| 3 | first BFMOPA kernel, operands gathered inside streaming mode | compile error |
| 4–7 | pack operands to BF16 outside streaming mode; one ZA tile; fix load predicates | incorrect (twice) |
| 8–9 | 16-bit governing predicates for BFMOPA | 0.370 |
| 10–11 | blocking over all four FP32 ZA tiles | 0.799 |
| 12–20 | Neon packing of , disassembly, alternative packing of , unrolling | 1 compile error; 0.507–0.799 |
| Target | Claude Opus 4.8 | Claude Sonnet 4.6 | DeepSeek-V4-Pro | GLM-5.3 |
|---|---|---|---|---|
| SVE | 79/79 (100%) | 75/79 (95%) | 71/79 (90%) | 78/79 (99%) |
| SVE2 | 6/8 (75%) | 8/8 (100%) | 4/8 (50%) | 3/8 (38%) |
| SME2 | 15/18 (83%) | 5/18 (28%) | 1/18 (6%) | 5/18 (28%) |
| Tier | SIMD class of final kernel | # final kernels (of 60) | Relative to Neon only |
| Neon only | Neon | 59 | 0.99 |
| plain C | 1 | 0.16 | |
| Streaming SVE | streaming SVE | 25 | 0.37 |
| plain C | 34 | 0.42 | |
| Neon | 1 | 0.76 | |
| Full SME2 | Neon | 23 | 0.75 |