Introducing FastRPC/mempool‑based ggml‑hexagon backend #84
zhouwg
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
FastRPC/mempool‑based ggml‑hexagon backend
Overview
Qualcomm Hexagon SDK exposes two distinct RPC transport mechanisms: native FastRPC and dspqueue.
Project ggml‑hexagon introduces FastRPC/mempool‑based ggml‑hexagon backend, which co‑exists alongside the existing dspqueue‑based ggml‑hexagon implementation and demonstrates that the FastRPC/mempool-based ggml-hexagon greatly outperforms Qualcomm's official ggml-hexagon on some modern models.
This dual‑backend pattern mirrors existing patterns inside llama.cpp:
Both backends share the same Hexagon/HTP kernel source tree; users select transport layer via build‑time CMake option, zero breaking changes to upstream default dspqueue workflow. The real performance difference does not lie in the Hexagon/HTP kernels themselves, but in the scheduling framework, cache policy and offloading strategy
(See details at The mempool/FastRPC and dspqueue ggml-hexagon variants: Architecture Analysis).
FastRPC‑based ggml‑hexagon originated from upstream PR #12326, with follow‑up upstream PRs: PR #26373, PR #27642.
Key Features
PP and TG offer some advantages over Qualcomm's dspqueue‑based ggml‑hexagon for certain modern models.
Single shared mempool + Native FastRPC transport, no complex dspqueue
Enables effective lm‑head offloading, which is the primary source of PP / TG throughput improvements observed in benchmarks. The optimization depends directly on the shared mempool architecture.
NPU‑side role‑aware cache coherency
Distinguishes long‑lived resident weights from short‑lived per‑batch activations. Cache invalidation for resident weights runs only once, eliminating redundant coherency traffic.
Low‑footprint co‑existing backend
Reuses 100 % of existing Hexagon/HTP kernels; both backends share the htp/ operator source tree. Selection is purely a compile‑time option, zero breaking changes for existing dspqueue users.
Compatible with Qualcomm's dspqueue-based ggml-hexagon
Design & Trade‑offs
Re‑use existing Hexagon kernels
Build‑time variant selection, no ABI difference
Single shared mempool + NPU‑side role‑aware cache coherency
Minimal incremental code footprint
Build option mapping
-DGGML_HEXAGON=ON(default)-DGGML_HEXAGON=ON -DGGML_HEXAGON_USE_MEMPOOL=ONChanged / New source files
New files:
Modified files:
Optional utility script (for local verification & CI):
Benchmark results
Test device
Snapdragon 8 Elite (aka 8 Gen 4), QCOM_HTP_V79, VTCM=8MB, HVX+HMX
PP&TG in dspqueue-based ggml-hexagon(aka Qualcomm's official ggml-hexagon)
PP&TG in FastRPC-based ggml-hexagon
Eight-Model AB Test Results (fastrpc vs dspqueue)
Device: Qualcomm Snapdragon 8 Elite (aka 8 Gen 4)
Date: All AB tests complete 2026-09-15 11:49:13
llama.cpp version:
version: 0.4.1-dev (build 11594, commit 57364ab5b)
built with Clang 21.0.0 for Android aarch64
Updated eight-model A/B test results can be found at #83
How to reproduce the benchmark results
The build script (
scripts/build-run-ggmlhexagon-android.sh) automatically downloads and sets up dependencies(8 models and dependent SDKs) on first run.usage of ./scripts/build-run-ggmlhexagon-android.sh
PP & TG Performance Comparison: dspqueue-based ggml-hexagon vs FastRPC-based ggml-hexagon
Pls refer to: #83
Verified SoCs
Known Limitations
4 GiB DSP virtual‑address‑space limit (HTP‑v75 / v79) due to limitations in the Qualcomm Hexagon SDK.
When model weight footprint exceeds 4 GiB (example: Qwen3.5‑9B ~5.1 GiB), the FastRPC backend cannot fit everything inside the shared mempool. It falls back to heap‑allocation with mirror‑buffer memcpy for overflow weights, which introduces substantial token‑generation overhead. This explains the large performance regression observed for Qwen3.5‑9B/Spark-X2.5-4B in benchmark.
FastRPC async is currently disabled due to limitations in the Qualcomm Hexagon SDK.
There are two large PRs from Qualcomm: PR #26501 (commit 192067b, "hexagon: support for multi-NPU devices (IQ9, IQ10) and fully asynchronous backend") and PR #28589 (commit eafe15a, "hexagon: support for multi-device model split (aka row-split)"). The FastRPC-based ggml-hexagon has no real multi-NPU implementation due to the lack of suitable hardware for development and testing(implementation based on PR-26501 and PR-28589 will be done in less than 24 hours once suitable hardware is available).
There is a tricky issue in QKV/FFN NX fusion that gets triggered with
nanbeige-3b-q80(Nanbeige_Nanbeige4.2-3B-Q8_0.gguf), workaround: add a mempool-pressure gate in Phase 3.Contribution Notes
Follows CONTRIBUTING.md.
Disclosure on AI Use
Per project llama.cpp's policies, I am disclosing that significant portions of this work have been developed with AI assistance. All code has been meticulously reviewed, revised and tested by me to ensure the implementation aligns with the rest of the project.
The core ideas originate from my fully‑original, hand‑written PR‑12326. Starting in June 2026, I have used AI coding agents to assist with brainstorming, drafting code snippets, composing technical documentation (with questions and scope defined by me), and generating test reports.
I have inspected, tested, and fully understand all code within ggml-hexagon-fastrpc.cpp and htp/entry.c, excluding quantization-type conversion routines. Most importantly, all technical decisions, design directions and code adjustments are made solely by me.
Acknowledgement
[07/01/2026, July 1 2026] Thanks to Trae and GLM‑5.2 for their great assistance. Qualcomm’s ggml‑hexagon implementation also provided valuable reference. GLM‑5.2 and I co‑designed the mempool‑based op‑batch solution after many hours of iteration. I intentionally avoid Qualcomm’s dspqueue within JZ's ggml‑hexagon, as this dspqueue‑free, mempool‑based op‑batch mechanism is one of the key highlights of this backend. GLM‑5.2 has acted as a co‑contributor to JZ's ggml‑hexagon starting June, 2026.
[07/06/2026, July 6 2026] Thanks for Trae + DeepSeek-V4-Pro's great help. DeepSeek-V4-Pro did a good job in performance optimization.
[07/09/2026, July 9 2026] Thanks for Trae + MiniMax-M3's breakthrough help and profound insights, the PP performance has been boosted from around 180 to over 300 based on Qualcomm's new operators/kernels.
[07/09/2026, July 9 2026] GLM-5.2, DeepSeek-V4-Pro, MiniMax-M3 are both China's top AI Coding Models, sincerely thanks for the original authors of them.
[07/14/2026, July 14 2026] Kimi-K2.7 also made solid contribution on 07/13/2026 although Kimi-K2.7-Code joined this project on late evening 07-13-2026.
[07/14/2026, July 14 2026] There would be no 100% upstream compatible FastRPC-based ggml-hexagon without the excellent operators/kernels implementation provided by Qualcomm, because the FastRPC-based ggml-hexagon can directly 100% re-use the highly-excellent hexagon kernels.
[07/17/2026, July 17 2026] Kimi-K3 joined this project on late evening 07-17-2026, Kimi-K3 did a breakthrough optimization(offload lm-head) in this backend.
[08, 2026] Xiaomi Mimo V2.5 joined this project.
Language Policy
Both English and Chinese posts are accepted for discussions and issues in this project.
All reactions