MobileKernelBench: Can LLMs Write Efficient Kernels for Mobile Devices?

Xingze Zou, Jing Wang, Yuhua Zheng, Xueyi Chen, Haolei Bai, Lingcheng Kong, Syed A.r. Abu-Bakar, Zhaode Wang, chengfei lv, Haoji Hu, Huan Wang

TL;DR

This paper introduces MobileKernelBench, a new benchmark and evaluation framework for assessing LLMs' ability to generate efficient mobile kernels. They found that current LLMs struggle with mobile-specific challenges like engineering complexity and data scarcity, leading to high failure rates. To address this, they propose MoKA, a multi-agent system that significantly improves kernel generation success and performance on mobile devices.

What Problem Does This Paper Address?

The paper tackles the challenge of automatically generating efficient code kernels for mobile devices using Large Language Models (LLMs). While LLMs have shown promise in generating kernels for server-grade GPUs (like CUDA), their application to the mobile domain remains largely unexplored. Mobile kernel development is particularly difficult due to:

  • Compatibility Priority: Mobile frameworks need to support a vast array of operators to ensure broad compatibility across different training frameworks.
  • Engineering Complexity: The mobile ecosystem is fragmented, with diverse backends and architectures that developers must navigate.
  • Data Scarcity: The mobile inference landscape is relatively new, leading to a lack of high-quality reference implementations, which hinders LLMs' ability to learn domain-specific knowledge.

Existing benchmarks often focus on algorithmic complexity rather than operator diversity and don't adequately address the host-device gap for on-device verification, making them ill-suited for evaluating LLM performance in this domain.

Methods

The authors introduce a two-pronged approach:

  1. MobileKernelBench: This is a comprehensive evaluation system comprising:
  2. A Benchmark: It prioritizes operator diversity by curating 190 tasks across 12 categories and 95 primitive operators from the ONNX Opset 20 standard. It also ensures cross-framework interoperability by using (PyTorch, ONNX) pairs.
  3. An Automated Evaluation Pipeline: This pipeline automates the entire lifecycle from operator registration and cross-compilation to on-device verification, bridging the gap between host development and device testing.
  4. MoKA (Mobile Kernel Agent): This is a novel multi-agent system designed to overcome the limitations of standard LLMs. MoKA employs a "plan-and-execute" paradigm with specialized agents:
  5. Coder Agent: Generates C++ kernel code.
  6. Debugger Agent: Identifies and suggests fixes for compilation and functional correctness errors, leveraging repository-aware tools and structured error logs.
  7. Accelerator Agent: Optimizes generated kernels for performance by identifying bottlenecks and proposing specific acceleration strategies.

MoKA uses a shared history mechanism for iterative refinement, allowing agents to learn from past attempts and avoid repetitive mistakes.

Datasets

  • MobileKernelBench: A newly introduced benchmark consisting of 190 tasks derived from 95 primitive ONNX operators. It uses (PyTorch, ONNX) pairs for evaluation.
  • Training Data for Fine-tuning: For supervised fine-tuning (SFT) and reinforcement learning (RL) experiments, they used a subset of MobileKernelBench tasks and data from the Alpaca format.

Key Insights and Ideas

  • Mobile Kernel Generation is Hard for LLMs: Standard LLMs, even fine-tuned ones, struggle significantly with the unique challenges of mobile kernel development, exhibiting high compilation failure rates and minimal performance gains. This highlights a critical gap in their domain-specific knowledge.
  • Data Scarcity is a Major Bottleneck: The lack of extensive, high-quality mobile kernel data prevents LLMs from learning the intricate details of mobile frameworks and optimization heuristics.
  • Agentic Systems Excel: A multi-agent approach like MoKA, which iteratively refines code through specialized agents (Coder, Debugger, Accelerator) and leverages repository-aware reasoning, is far more effective than static fine-tuning for this complex domain.
  • Iterative Refinement is Key: MoKA's iterative process, where feedback from compilation, correctness, and performance evaluation guides subsequent code generation and optimization, is crucial for achieving state-of-the-art results.
  • Diverse Optimization Strategies: MoKA demonstrates the ability to synthesize a range of optimization techniques, from SIMD vectorization and FMA instructions to advanced cache blocking and memory hierarchy management, showcasing its adaptability.

Key Results

  • Baseline LLMs: Standard LLMs (e.g., GPT-5, Claude-Sonnet-4.5) achieved compilation success rates of around 47% but had functional correctness rates as low as 6.3%. Performance speedups over native libraries were negligible. Over 54% of generated kernels failed compilation.
  • SFT and RL: Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL) methods showed marginal improvements, with SFT yielding a compilation success rate of 25.0% and RL (GRPO) improving it to 25.0%, but neither significantly boosted performance speedups.
  • MoKA:
    • Achieved a 93.7% compilation success rate.
  • Reached a 75.3% functional correctness rate.
  • Enabled 27.4% of generated kernels to deliver measurable speedups over native libraries, with a peak speedup of 6.82x observed in a case study.

Limitations and Future Work

  • Limitations:
    • Current LLMs struggle with the engineering complexity and data scarcity inherent to mobile frameworks.
  • The "sparse reward" problem can hinder learning for syntactic correctness.
  • The iterative optimization process in MoKA can exhibit a "sawtooth" pattern due to focusing on single bottlenecks at a time, though this volatility is instrumental for self-correction.
  • Future Work:
    • Extend capabilities to low-level optimizations like multi-threaded NEON and inline assembly.
  • Explore diverse hardware backends and frameworks beyond MNN.
  • Potentially automate the generation of entire deployment frameworks.

Summary updated

BibTeX
@inproceedings{zou2026mobilekernelbench,
  author = {Xingze Zou and Jing Wang and Yuhua Zheng and Xueyi Chen and Haolei Bai and Lingcheng Kong and Syed A.R. Abu-Bakar and Zhaode Wang and chengfei lv and Haoji Hu and Huan Wang},
  title = {{MobileKernelBench: Can LLMs Write Efficient Kernels for Mobile Devices?}},
  booktitle = {DATA-FM @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=bTsMfGz85R},
}
Figure