gregordinary/ggml-rocket
Über uns
Drop-in ggml backend for Rockchip NPUs: offloads llama.cpp/whisper.cpp prefill to the RK3588 NPU
KI und maschinelles LernenGemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +1
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
Originalggml-rocket
AI disclosure
Except for the prior work it builds on, ggml-rocket was developed by AI, primarily Claude. Human involvement was mostly limited to setting project goals and providing hardware access. This is a side project for curiosity's sake, and it comes with no guarantee of quality, accuracy, or update frequency.
About ggml-rocket
ggml-rocket is a drop-in ggml backend for Rockchip NPUs
(validated on the RK3588). It offloads LLM and Whisper prefill to the NPU through the mainline
rocket DRM-accel driver.
It builds as a runtime-loadable libggml-rocket.so for stock llama.cpp, whisper.cpp and other
ggml hosts, such as transcribe.cpp, a multi-model speech-to-text library. Point
GGML_BACKEND_PATH at it, and the NPU appears as a ggml device, as ggml's own BLAS backend does.
It runs the Whisper encoder end to end on the NPU, and the prefill of Gemma-4, Qwen3.5, Qwen3.6,
Llama-3.2, Phi-4, Ministral and more.
Decode stays on the CPU. A decode step is single-row work, bound by the DDR bandwidth the NPU
shares with the CPU. Behind a boot loader that programs SPLL, the NPU's three
cores read weights at 1.0-1.4x the CPU decoder's rate [host-computed]. An offloaded step
adds a dispatch, a weight pack and a de-tile to that read, and an NPU decode is not characterized
end to end. ROCKET_MIN_M (default 24 rows) keeps decode and short prompts on the CPU.
The backend links librocketnpu, which the rocket-userspace project builds and which also runs
on its own. The build expects the checkouts side by side:
.
rocket-userspace/ # the driver library (dependency): git clone https://github.com/gregordinary/rocket-userspace
ggml/ # fresh upstream clone: git clone https://github.com/ggml-org/ggml
ggml-rocket/ # this project
The other documents in this repository are:
- TUNING.md: the configuration for each workload, and what each setting is worth
- MODELS.md: the results and accuracy for each model and precision
- MOE.md: mixture-of-experts models, their placement and their memory budget
- RK3576.md: the backend on the RK3576
- API.md: every
ROCKET_*environment variable, the diagnostic logging, the precision declarations and the implementation notes - MEASUREMENTS.md: how each figure in these documents was measured
Quick start
These commands build llama.cpp and the backend side by side, then run a prompt with the NPU
prefilling it. They need an RK3588 board with the rocket driver loaded, as
Requirements describes.
# 1. latest llama.cpp, shared + DL-capable ggml
cd <workspace> # the dir holding ggml-rocket/
git clone https://github.com/ggml-org/llama.cpp
cmake -S llama.cpp -B llama.cpp/build -DGGML_BACKEND_DL=ON -DBUILD_SHARED_LIBS=ON
cmake --build llama.cpp/build -j
# 2. libggml-rocket.so against llama.cpp's BUNDLED ggml
cd ggml-rocket
cmake -S . -B build-dl -DGGML_ROCKET_DL=ON -DHOST_DIR=$PWD/../llama.cpp
cmake --build build-dl -j # if needed: -DGGML_LIB_DIR=/abs/path
# 3. run with the NPU backend loaded (-ngl 0; ACCEL offload is BLAS-style, scheduler-driven)
GGML_BACKEND_PATH=$PWD/build-dl/libggml-rocket.so \
sudo -E ../llama.cpp/build/bin/llama-cli \
-m /path/to/gemma4/gemma-4-12b-it-F16.gguf \
-p "Explain the RK3588 NPU in two sentences." \
-n 64 -c 4096 -ngl 0 -b 512
Run it under sudo -E: /dev/accel/accel0 needs privilege, and -E keeps GGML_BACKEND_PATH
in the environment. The startup log lists a ROCKET device whose description names the detected
part and driver, such as RK3588 NPU (mainline rocket driver). Cap -c so that the weights and
the KV cache fit in RAM.
An F16 GGUF takes the fp16 route with no conversion. A quantized GGUF (Q8_0, Q4_K,
Q6_K and the rest) also prefills on the NPU, dequantized to fp16 on the fly, with no whole-model
F16 copy. A BF16 GGUF converts to fp16 on every micro-batch, at ~0.55-0.6x the fp16 prefill rate,
so convert it once with llama-quantize in.gguf out.gguf f16.
[!NOTE] A quantized GGUF can prefill 1.4-1.6x as fast if you give it RAM. The setting is off by default:
ROCKET_QUANT_RESIDENT=autouses the free RAM, andROCKET_QUANT_RESIDENT=2600uses at most 2600 MB. RAM for prefill speed gives each model's cost.
[!CAUTION] For a quantized GGUF, turn the host's weight repack off: pass
-nr(--no-repack), or--repack 0tollama-bench. With the repack on, the quantized weights stay on the CPU, and nothing reports it.The CPU backend repacks quantized weights into a non-host
CPU_REPACKbuffer for its own SIMD kernels. ggml's scheduler offloads only an op whose weight is in a host buffer. A host built with-DGGML_CPU_REPACK=OFFalso works, but it removes the repack from CPU-only runs too. At 256 rows on 4 threads, the repack is worth 1.6-1.8x onQ4_K_Mprefill and 2.2x onQ8_0[HW sweep 2026-11-29]. Confirm the offload withROCKET_MM_PROFILE=1.A host that registers each repacked weight's original bytes with the backend can leave the repack on, but llama.cpp and whisper.cpp do not register them. API.md describes the call.
Gemma-4's chat template needs --jinja, or use llama-completion -no-cnv for raw prompt
completion. TUNING.md gives the settings for each workload.
What runs on the NPU
The backend offloads the ops that dominate prefill, and the CPU backend computes every other op:
MUL_MAT: the prefill GEMMs. The backend claims a matmul with an F16, F32 or quantized weight ifM >= ROCKET_MIN_Mand the shape aligns (K%32,N%16,K>=64,N>=64).FLASH_ATTN_EXT: prefill attention and an encoder's self-attention, on the NPU by default atn_kv >= 1024.MUL_MAT_ID: MoE routed experts, on the NPU by default as native-quant experts. The backend claims a quantized expert stack whose per-expert GEMM repays its dispatch. A stack that fits the memory budget is held resident, and the first prefill of eachllama_contextconverts its experts once, which MOE.md times. Any other stack streams its weights on every micro-batch where its experts receive at least 32 rows, and runs whole on the CPU below that.- Opt-in routes: native int8 (
ROCKET_INT8=1), int4 (ROCKET_INT4=1) and bf16 (ROCKET_BF16=1). They fit a model in less RAM or compute an exact fp32 result. Resident int8 prefills at 0.98-1.10x resident fp16 on four models of 3-9 B [HW sweep 2026-11-21], and int4 and bf16 prefill no faster than fp16 (TUNING.md). - Precision declarations: the backend declines a matmul whose model declares a precision the backend cannot meet, such as Mistral-4's F32 routed down-projection activation. API.md has the rules.
- Everything else stays on the CPU: norms, rope, the conv front-end and decode.
Performance
The backend speeds up prefill, a batched GEMM. At pp2048 it prefills a dense F16 model at
4.2-5.8x the 8-thread CPU backend. A dense Q4_K_M model of 2-27 B prefills at pp512 at 3.3-4.8x
the 4-thread CPU backend, and at 4.7-6.9x with ROCKET_QUANT_RESIDENT=auto. At pp2048, a MoE
model prefills at 1.7-3.8x its rate with the experts on the CPU. Decode runs on the CPU, where it
is bound by memory bandwidth and its rate follows the quantization, not the backend.
| Model, F16 | Params | NPU prefill, pp2048, t/s |
Speedup over the CPU, pp2048 |
|---|---|---|---|
| SmolVLM2-2.2B (multimodal) | 1.8B | 117.8 | 4.2x |
| Llama-3.2-3B | 3.2B | 85.1 | 5.0x |
| Ministral-3-3B | 3.4B | 75.0 | 4.7x |
| Phi-4-mini | 3.8B | 76.1 | 5.0x |
| Ministral-3-8B | 8.5B | 39.6 | 5.8x |
| Qwen3.5-9B | 9.0B | 36.1 | 4.9x |
| Gemma-4-12B | 11.9B | 24.6 | 5.2x |
Conditions: RK3588, NPU 928 MHz (the 900 MHz request), SPLL unprogrammed, CPU governor
performance, warm runs. llama.cpp b11539, the default -b and -ub [HW sweep 2026-11-01]. Each
speedup pairs the NPU and the 8-thread CPU backend on the same GGUF.
Not characterized: the F16 table's NPU rates with SPLL programmed. Boot loader
gives what that changes at pp512.
Model, Q4_K_M |
Params | NPU, MHz | CPU, pp512, t/s |
NPU, pp512, t/s |
NPU with auto residency, pp512, t/s |
|---|---|---|---|---|---|
| SmolVLM2-2.2B (multimodal) | 1.8B | 1028 | 48.7 | 159.5 (3.3x) | 228.2 (4.7x) |
| Llama-3.2-3B | 3.2B | 927.5 | 25.8 | 94.1 (3.6x) | 141.6 (5.5x) |
| Ministral-3-3B | 3.4B | 1028 | 26.0 | 91.8 (3.5x) | 134.9 (5.2x) |
| Phi-4-mini | 3.8B | 1028 | 23.1 | 92.6 (4.0x) | 134.1 (5.8x) |
| Ministral-3-8B | 8.5B | 1028 | 10.0 | 44.4 (4.4x) | 69.4 (6.9x) |
| Qwen3.5-9B | 9.0B | 927.5 | 9.7 | 39.9 (4.1x) | 56.3 (5.8x) |
| Gemma-4-12B | 11.9B | 927.5 | 6.2 | 26.4 (4.2x) | 36.0 (5.8x) |
| Phi-4 (14B) | 14.7B | 1028 | 5.4 | 25.7 (4.8x) | 34.8 (6.5x) |
| Qwen3.6-27B (hybrid) | 27.3B | 927.5 | 2.6 | 12.0 (4.6x) | 13.0 (5.0x) |
Conditions: RK3588, SPLL programmed, CPU governor performance, llama.cpp b11539, the default
-b and -ub, taskset 0xf0 -t 4. The CPU column is [HW sweep 2026-11-29/30] and the NPU columns
are [HW sweep 2026-11-30]. The CPU backend runs with llama.cpp's weight repack on, and the NPU
backend with --repack 0.
The auto column is ROCKET_QUANT_RESIDENT=auto. It holds every weight
of the models up to 9 B resident. Of Gemma-4-12B's weights it holds 93-94%, of Phi-4's 70-71% and of
Qwen3.6-27B's 24%. TUNING.md gives the other settings.
RAM for prefill speed
ROCKET_QUANT_RESIDENT is off by default because it costs RAM. A quantized GGUF is then streamed:
each weight is dequantized as it is used, and nothing is held beyond the file. With the setting on,
the backend holds an fp16 copy of each weight in NPU buffers, which is 2.4-2.8x the size of a
Q4_K_M file. The output is the same either way.
Model, Q4_K_M |
GGUF, GiB | fp16 copy under auto, GiB |
pp512 speedup over streamed |
|---|---|---|---|
| SmolVLM2-2.2B | 1.0 | 2.9 | 1.43x |
| Llama-3.2-3B | 1.9 | 5.1 | 1.51x |
| Ministral-3-3B | 2.0 | 5.5 | 1.47x |
| Phi-4-mini | 2.3 | 5.9 | 1.45x |
| Ministral-3-8B | 4.8 | 13.5 | 1.56x |
| Qwen3.5-9B | 5.3 | 12.6 | 1.41x |
A budget in MB holds part of the copy and streams the rest. The speedup follows the RAM. On Llama-3.2-3B:
ROCKET_QUANT_RESIDENT |
fp16 copy, GiB | pp512, t/s |
Speedup |
|---|---|---|---|
| Unset | 0 | 94.1 | 1.00x |
1300 |
1.3 | 104.0 | 1.11x |
2600 |
2.5 | 113.0 | 1.20x |
3900 |
3.8 | 125.2 | 1.33x |
auto |
5.1 | 141.6 | 1.51x |
Choose by what else runs on the board:
- A board dedicated to the model:
auto. It takes the RAM that is free when the model loads, and leaves a reserve of 30% of the board's RAM or more. - A board shared with other processes: a budget in MB, such as
2600. Leave RAM for the whole GGUF too, because decode reads it. - No RAM to spare: leave it unset, and raise the micro-batch with
-b 2048 -ub 2048.
[!CAUTION] The copy stays allocated until the process exits. A process started later competes for what is left, and
autodoes not shrink to make room for it.
Conditions: as the Q4_K_M table. The Llama-3.2-3B figures are three passes [HW sweep 2026-11-30].
A process peaks 0.6-1.0 GiB above the copy on the models of 3-9 B.
| Model, MoE | GGUF | NPU, MHz | pp2048, experts on the CPU, t/s |
pp2048, default, t/s |
Speedup |
|---|---|---|---|---|---|
| gpt-oss-20b | MXFP4 | 1028 | 14.2 | 54.4 | 3.8x |
| DeepSeek-V2-Lite (MoE+MLA) | Q4_K_M | 1028 | 25.6 | 56.6 | 2.2x |
| Qwen3-30B-A3B | Q4_K_M | 927.5 | 17.6 | 29.5 | 1.7x |
Conditions: as the Q4_K_M table, at -b 2048 -ub 2048 [HW sweep 2026-11-29]. Every
configuration is the NPU backend with --repack 0, and the first one leaves the experts on the CPU
with ROCKET_MOE=0. MOE.md gives the other tests and the models' -ub settings.
Decode runs on the CPU backend at -t 4 on the four A76 cores (taskset 0xf0), which decodes
faster than 8 threads (TUNING.md):
| Model | GGUF | GGUF size, GiB | Decode, t/s |
|---|---|---|---|
| SmolVLM2-2.2B | Q4_K_M | 1.0 | 20.7 |
| Llama-3.2-3B | Q4_K_M | 1.9 | 11.1 |
| Ministral-3-3B | Q4_K_M | 2.0 | 10.5 |
| Phi-4-mini | Q4_K_M | 2.3 | 8.8 |
| Ministral-3-8B | Q4_K_M | 4.8 | 4.7 |
| Qwen3.5-9B | Q4_K_M | 5.3 | 4.0 |
| Gemma-4-12B | Q4_K_M | 6.9 | 3.1 |
| Phi-4 (14B) | Q4_K_M | 8.3 | 2.7 |
| DeepSeek-V2-Lite | Q4_K_M | 9.7 | 13.5 |
| gpt-oss-20b | MXFP4 | 11.3 | 9.1 |
| Qwen3.6-27B | Q4_K_M | 15.9 | 1.3 |
Conditions: tg64, the F16 table's board and series [HW sweep 2026-11-01].
NPU prefill's perplexity agrees with the CPU backend's on every dense model in the tables and on DeepSeek-V2-Lite. Wikitext perplexity is not a valid measure for gpt-oss-20b, a reasoning model. Its offloaded expert GEMMs measure a mean cosine of 0.9998 against an fp64 CPU reference instead [HW sweep 2026-08-27]. MODELS.md gives each model's measured difference, and MOE.md the streamed experts'.
Speech models
For a speech model the backend offloads the encoder. The Whisper encoder runs 1.18x-2.14x as fast
as on the CPU backend, from tiny.en to large-v3. Through transcribe.cpp, a whole long-audio
pipeline gains 1.0x-1.9x. It gains most where the encoder is large or the decoder cross-attends
the audio, and least on a small decoder-only model.
Conditions: RK3588, a boot loader that leaves SPLL unprogrammed, warm runs, against the CPU
backend on the same model. Whisper at NPU ~816 MHz (the 600 MHz request), with the encoder's
attention on the CPU. transcribe.cpp at Q8_0.
The encoder's attention also offloads by default. With it offloaded, the multilingual Whisper
encoder runs 1.50-1.52x as fast as on the CPU backend on tiny and 2.90x on small [HW sweep
2026-11-22]. Both figures ran on an RK1 at 927.5 MHz with SPLL programmed, each backend
on 4 threads on the A76 cores.
An interactive turn
On Ministral-3-8B-Instruct, the NPU shortens the wait for the first token, and the quantization sets the decode rate. A 2048-token prompt with a 200-token answer, as in RAG, takes:
| Configuration | Time to first token | Decode, t/s | Total |
|---|---|---|---|
| F16, CPU | 301 s | 1.6 | 426 s |
| F16, NPU | 52 s | 1.6 | 177 s |
Q4_K_M, NPU |
45 s | 4.7 | 88 s |
Conditions: the rates of the F16 table's series, at pp2048 and the default -ub
[host-computed]. The time to first token is the prompt over the prefill rate, and the total adds
200 tokens at the decode rate. Q4_K_M runs under ROCKET_QUANT_RESIDENT=auto.
On this prompt the NPU cuts the time to first token 5.8x and the turn 2.4x. A short chat turn is
mostly decode, so the quantization sets its length: 400 tokens take 250 s at F16 and 85 s at
Q4_K_M.
Run this model as Q4_K_M with the NPU. Under ROCKET_QUANT_RESIDENT=auto it holds an fp16 copy
of its weights, 13.5 GiB, which needs a board with that RAM free. Without it, the 4.83 GB GGUF fits
an 8 GB board and prefills more slowly, as TUNING.md describes.
Hardware support
| Part | Status | Scope |
|---|---|---|
| RK3588 | Supported | Every route. The fully validated target. |
| RK3576 | Supported | The RK3576 route only, with ROCKET_INT8=1. Attention runs on the CPU. |
| Other Rockchip NPUs | Not characterized |
On the RK3576 the backend runs an int8 W8A8 matmul with a per-output-column requant, the only
matmul route on that part. It prefills Qwen2.5-1.5B F16 at 1.31x ggml's Q8_0 CPU kernel, and at
2.37x the same F16 GGUF on the CPU [HW sweep 2026-08-23, pp2048]. RK3576.md
documents the route.
[!CAUTION] On the RK3576, set
ROCKET_INT8=1. Without it the backend declines everyMUL_MAT, and nothing offloads.
Requirements
- An RK3588 or RK3576 board on a mainline kernel with the
rocketDRM-accel driver loaded, so that/dev/accel/accel0exists (lsmod | grep rocket). librocketnpu, from the siblingrocket-userspacecheckout or installed as arocketnpupackage.- A C++20 compiler with
_Float16in C++, which on aarch64 is GCC 13 or later. The build is tested with GCC 13 and GCC 16. - Privilege to open the accel node. Run with
sudo -E, because plainsudodrops theROCKET_*environment variables.
Clock
The NPU boots at 200 MHz, and the backend computes correctly there. Above 200 MHz the RK3588's NPU clock follows the rail voltage, so a requested rate is not the rate the NPU runs at.
Apply the patches/rocket clock and voltage patches, and load the module with
rocket_npu_clk_hz=900000000. On the RK1's 0.80 V rail that request runs the NPU at 928 MHz.
The rate differs between parts: a second RK1 runs the same request at 1028 MHz.
The language-model figures in this README were measured at the 900 MHz request. The speech figures were measured at the 600 MHz request, which runs at ~816 MHz on the same rail, except the encoder figures at the defaults. The boot loader decides how much a faster clock gives. With SPLL programmed, ~70% of one core's fp16 matmul device time scales with the NPU clock at 1028 MHz [HW sweep 2026-11-21]. With SPLL unprogrammed, the 900 MHz request is 1.044x the 600 MHz request on matmul device time [HW sweep 2026-10-19].
[!CAUTION] With the NPU cores pinned on (
power/control=on), anrmmodat the 900 MHz request hard-locks the board, and only a power cycle recovers it. Unload the module only while all three cores are runtime-suspended.
Boot loader
On the RK3588 the NPU reads DDR through the center interconnect, whose clock comes from SPLL. Only the boot loader can program SPLL. Behind a boot loader that leaves it unprogrammed, the NPU reads DDR at half the rate, and Linux reports nothing.
[!NOTE]
clk_summaryreports SPLL at 702 MHz whether or not the boot loader programmed it, so it cannot show the halved read rate.
Mainline U-Boot v2026.07 and v2026.10, built for the RK1's eMMC boot, leave SPLL unprogrammed
[HW sweep 2026-11-21]. The other mainline releases from v2026.01 to v2027.01-rc1 are expected to
as well [expected]. Upstream commit 514663543ecf, first released in v2027.01-rc2, programs it,
and so does Armbian's 2026.07_armbian U-Boot for the RK1.
The read rate moves only the part of a run that waits on the NPU. With SPLL programmed, an LLM
prefill at pp512 runs 1.01-1.11x as fast, and a Whisper encode 0.99-1.03x. A decode-sized weight
read runs 1.98x as fast [HW sweep 2026-11-21]. The F16 and decode figures under
Performance were measured with SPLL unprogrammed.
Build and run
To run a model, build the .so against the host's ggml, so that it links the same
libggml-base.so, and point GGML_BACKEND_PATH at it. Quick start does both for
llama.cpp, and the recipes below do them for whisper.cpp and transcribe.cpp.
Drop into whisper.cpp
Upstream whisper.cpp loads libggml-rocket.so through GGML_BACKEND_PATH, with no source
changes.
# 1. whisper.cpp with a SHARED, DL-capable ggml (single libggml-base.so the host loads)
cd <workspace> # the dir holding ggml-rocket/
git clone https://github.com/ggml-org/whisper.cpp
cmake -S whisper.cpp -B whisper.cpp/build -DGGML_BACKEND_DL=ON -DBUILD_SHARED_LIBS=ON
cmake --build whisper.cpp/build -j
# 2. libggml-rocket.so against whisper's BUNDLED ggml (so it links the same libggml-base.so)
cd ggml-rocket
cmake -S . -B build-dl -DGGML_ROCKET_DL=ON -DWHISPER_DIR=$PWD/../whisper.cpp
cmake --build build-dl -j # if ggml shared libs aren't found, add -DGGML_LIB_DIR=/abs/path
# 3. run stock whisper-cli, pointing GGML_BACKEND_PATH at the .so
GGML_BACKEND_PATH=$PWD/build-dl/libggml-rocket.so \
sudo -E ../whisper.cpp/build/bin/whisper-cli -m /path/ggml-base.en.bin -f /path/audio.wav
A drm_mm "Memory manager not clean" warning at exit comes from a known teardown race and is
harmless. whisper-server loads the .so the same way. For a server fed fixed-length chunks,
TUNING.md gives the three server settings that set its CPU
cost.
Drop into transcribe.cpp
transcribe.cpp, a ggml-based host for several speech-to-text model families, loads
libggml-rocket.so the same way. Through it the backend reaches Granite-Speech, Voxtral, MOSS
diarize, SenseVoice, FunASR and Parakeet. Its runner registers the NPU as an ACCEL device and
logs using accel backend: ROCKET.
# transcribe.cpp shared + DL-capable, CPU backend tuned for the A76 (else the CPU baseline is slow)
cmake -B build -DTRANSCRIBE_BUILD_SHARED=ON -DTRANSCRIBE_GGML_BACKEND_DL=ON \
-DTRANSCRIBE_VULKAN=OFF -DGGML_CPU_ARM_ARCH=armv8.2-a+dotprod+fp16
cmake --build build -j
cp build/bin/libggml-cpu.so build/src/ # the ARM cpu module lands in build/bin; the backend scan globs build/src
GGML_BACKEND_PATH=$PWD/../ggml-rocket/build-dl/libggml-rocket.so \
LD_LIBRARY_PATH=build/ggml/src:build/bin \
sudo -n -E ./build/bin/transcribe-cli -m /path/model.gguf -f audio.wav
Build the .so against transcribe.cpp's ggml
(-DGGML_ROCKET_DL=ON -DHOST_DIR=<...>/transcribe.cpp), as with any host. A
TRANSCRIBE_GGML_BACKEND_DL build forces GGML_NATIVE=OFF, so the -DGGML_CPU_ARM_ARCH=… above
is required for a CPU baseline at full speed.
Build options
The CMake options are:
-DGGML_ROCKET_NATIVE_FP16=ON. Compiles the backend for the RK3588'sarmv8.2-a+fp16baseline. By default the.soruns on any AArch64 core, the RK3576's included, with the same NEON convert kernels. Built ON, it stops withSIGILLon an ARMv8.0 core such as the RK3576's A72.-DGGML_ROCKET_DIAGNOSTICS=ON. Compiles in the per-op recompute and trace diagnostics that API.md lists, which the production.soleaves out.-DGGML_ROCKET_PORTABLE_GLIBC=ON. Lets the.soload on an older glibc and libstdc++, as Troubleshooting describes.-DGGML_ROCKET_STRICT_ABI=ON. Fails the build on a host ggml whoseGGML_BACKEND_API_VERSIONthis backend has not been checked against. By default that build continues with a warning.-DGGML_ROCKET_RK3576_BENCH=ON. Builds the RK3576 GEMM benchmark that Development describes, which needs OpenBLAS.
Development
The standalone build links the source tree's ggml and builds the tests:
# from the workspace root (the dir holding rocket-userspace/, ggml/, ggml-rocket/)
git clone https://github.com/ggml-org/ggml # if not already present
cd ggml-rocket
cmake -S . -B build # or: -DGGML_DIR=/path/to/ggml
cmake --build build -j
sudo ./build/test-rocket-matmul # needs /dev/accel/accel0; each shape prints PASS
The tests below are registered with CTest. Run ctest from the build directory. The NPU tests
report Skipped off the device, and the host-only tests run anywhere. Each NPU test also reads
the route counters ggml-rocket.h declares, so it asserts which route computed its ops instead
of inferring it from the output:
| Test | What it covers |
|---|---|
test-rocket-matmul |
The backend against the CPU backend on real ggml graphs |
test-rocket-moe |
The MoE handler, both the fp16 and the native-quant expert route, against the CPU backend under outlier-channel activations |
test-rocket-int4 |
The int4 route |
test-rocket-bf16 |
The bf16 route |
test-rk3576-w8a8 |
The RK3576 route against the CPU backend. Skipped on any other part |
test-rocket-placement |
The supports_op and offload_op contract |
test-rocket-fa |
FLASH_ATTN_EXT against a double-precision reference, including the logits fp16 cannot hold |
test-rocket-internals |
Host-only: the weight cache's identity, the MoE residency ledger across two live backends, the budget parser, the FA dump's file handling, the device-route circuit breaker, the registered sources of repacked weights |
test-hadamard-neon, test-hadamard-quant |
The Hadamard rotation construction |
test-common.h holds the graph and comparison code the tests share.
test-rk3576-sgemm-ab is a benchmark rather than a test. It times the RK3576's NPU GEMM against
ggml F32, ggml Q8_0 and OpenBLAS on the CPU. It builds only with
-DGGML_ROCKET_RK3576_BENCH=ON.
[!CAUTION] Running
test-rk3576-sgemm-abcan take an RK3576 board down hard enough that only a physical power cycle recovers it.
[!NOTE] If
find_package(rocketnpu)resolves to an installedrocket-userspacepackage (fromcmake --install, for example under/usr/local), the backend links that library, not the sibling source tree. After a change inrocket-userspace/, reinstall it (cd ../rocket-userspace && cmake --build build && sudo cmake --install build) before rebuilding here. Or build against the source tree, whatever is installed, with-DROCKETNPU_DIR=$PWD/../rocket-userspacefrom this directory.
Troubleshooting
ROCKET device not listed at startup
Most often the backend was built against a different ggml from the host's (an ABI mismatch), so
it loads but no NPU device appears. Rebuild the .so against that host checkout's ggml, and
rebuild again after every ggml update in the host:
# HOST_DIR is the host's own checkout: llama.cpp, whisper.cpp or transcribe.cpp
cd ggml-rocket
cmake -S . -B build-dl -DGGML_ROCKET_DL=ON -DHOST_DIR=/abs/path/to/llama.cpp
cmake --build build-dl -j
llama.cpp and whisper.cpp each clone their own ggml, and the host's log names the mismatch:
incompatible API version (backend: N, current: M): the host'sGGML_BACKEND_API_VERSIONdiffers from the one the backend was built against, and ggml's loader refuses the.so.ggml-rocket: op ordinal N is X in this .so and Y in the host's ggml, followed byggml_backend_init returned NULL: ggml's op numbering moved, which the API version does not track. The backend checks the numbering at load and refuses to register.
This backend is checked against GGML_BACKEND_API_VERSION 2 and 3, and another version builds
with a warning. It builds against the ggml of whisper.cpp 1.8.6 through 1.9.5 and of llama.cpp
b10558 through b11539. llama.cpp moved to version 3 at b11351, and b11351 through b11401 label
that ggml 0.25.3. Read a host's API version from its ggml/src/ggml-backend-impl.h, not from
the ggml version.
ggml 1.0.0, the ggml of llama.cpp v1.0.0, keeps API version 3 but removes three ops. That
renumbers the ops after them, MUL_MAT from 29 to 28. A 1.0.0 host refuses a .so built
against an earlier ggml, and an earlier host refuses a 1.0.0 one. Both log the op-ordinal line
above, and the cure is to rebuild against the host. The source needs no change: it compiles
against ggml 1.0.0 with -DGGML_ROCKET_STRICT_ABI=ON. Built against a llama.cpp host on ggml
1.0.0, its ctest suite passes on the RK3588's NPU [HW sweep 2026-11-22, llama.cpp
56eea9e4].
If the device appears but runs zero matmuls, the backend was built without a working
offload_op. See Implementation notes.
version 'GLIBC_2.38' not found at load
libggml-rocket.so was built on a host with a newer glibc (2.38 or later, such as Debian trixie
or forky) than the runtime it is deployed to (such as a Debian 12 bookworm container, glibc
2.36). The message names GLIBC_2.43 instead when the build host has glibc 2.43, and
GLIBCXX_3.4.31 when the target's libstdc++ is older than the build host's. Rebuild it with
-DGGML_ROCKET_PORTABLE_GLIBC=ON:
cd ggml-rocket
cmake -S . -B build-dl -DGGML_ROCKET_DL=ON -DGGML_ROCKET_PORTABLE_GLIBC=ON \
-DHOST_DIR=/abs/path/to/llama.cpp
cmake --build build-dl -j
The option links forwarders for glibc 2.38's __isoc23_* symbols and glibc 2.43's sqrtf into
the .so, so it needs only glibc 2.34. It also holds the .so to the libstdc++ of GCC 12
(GLIBCXX_3.4.30), which Debian 12 provides. If the linked .so still needs a newer glibc or
libstdc++, the build fails and names the symbol. The option takes effect in DL mode only, and a
same-host build is byte-unchanged.
A Debian 12 host cannot build the backend for the board itself, because GCC 12 accepts _Float16
in C++ only on x86 (the GCC 12 manual, "Floating Types"). Build on a newer host with the option.
Terms
The terms these documents use that ggml's and llama.cpp's documentation does not define:
| Term | Definition | Source | Nearest standard term |
|---|---|---|---|
| CBUF | Convolution buffer. The on-chip buffer of an NPU core that holds the feature data and weights the core computes on. Matmul tiles are sized to fit it. | NVDLA | |
| Claim | The backend's acceptance of a ggml op, made by supports_op returning true. ggml's scheduler can then run a claimed op on the NPU. Its opposite is decline. |
Coined | supports_op returning true |
| Decline | The backend's refusal of a ggml op, made by supports_op returning false. The CPU backend then computes the op. Its opposite is claim. |
Coined | supports_op returning false |
| Expert stack | One layer's [K, N, n_expert] weight tensor of routed experts: its ffn_gate_exps, ffn_up_exps or ffn_down_exps. The backend places a stack whole: resident on the NPU, streamed to it, or on the CPU. |
Coined | |
| Ingest | The one-time conversion of a quantized expert to int8 codes in NPU buffers, done inside the first prefill of each llama_context. |
Coined | Weight preparation |
| IOVA window | The range of I/O virtual addresses (IOVA) through which the NPU reaches the buffers of one open device file. Each NPU worker of the backend opens its own device file. | Coined | IOMMU address space |
| K-accumulation | The summing of a matmul's partial results over successive tiles of its inner dimension, K. ROCKET_KACC selects the form that sums the partials in fp16 on the NPU. |
Coined | Split-K reduction |
| Native-quant experts | The route for MoE experts that converts each quantized GGUF expert once into int8 codes, held as resident weights. Each call then quantizes only the activation (ROCKET_MOE_NATIVE). |
Coined | |
| Pre-flight | The check in supports_op that reserves the RAM and IOVA window a resident expert stack needs, before the backend claims its MUL_MAT_ID op. |
Coined | Admission control |
| Resident weight | A weight converted to the NPU's tile layout and written to NPU buffers once, then reused by every later call. Its opposite is a streamed weight. | Coined | Prepacked weight |
| Route | The way the backend computes one op, named by its precision and by whether its weights are resident: for example the fp16 route, the native-quant route or the RK3576 route. ggml_backend_rocket_route_ops counts ops per route. |
Coined | Code path |
| SPLL | Not expanded. A PLL of the RK3588 that clocks the center interconnect, through which the NPU reads DDR. Only the boot loader can program it. | RK3588 TRM | |
| Streamed weight | A weight converted and written to NPU buffers on every call that uses it. Its opposite is a resident weight. | Coined | |
| The RK3576 route | The int8 route for MUL_MAT on an RK3576, with int8 weights and activations (W8A8) and the result requantized per output column on the NPU. |
Coined | W8A8 quantized matmul |
| Work per dispatch | The multiply-accumulates one expert GEMM does, M_e · K · N, where M_e is the rows routed to the expert. The backend offloads an expert stack only above a minimum. |
Coined |
The rocket NPU stack
This backend is one frontend of an open source stack for Rockchip NPUs. The stack is a driver library, three frontends, a submit provider for the vendor kernel, and a set of optional kernel patches:
rocket-userspace(librocketnpu): the userspace driver, matmul, and on-NPU op library. It is the dependency, and usable on its own.ggml-rocket: this backend, a ggml.soforllama.cppandwhisper.cpp.tflite-rocket: a TFLite external delegate for detection models, linking the same library.ort-rocket: an ONNX Runtime execution provider for transformer encoders and per-layer convolutions, linking the same library.rknpu-submit: a submit provider that runslibrocketnpuon the vendorrknpuBSP kernel driver instead of mainlinerocket.patches(rocket/scope): optional out-of-tree kernel-module patches for clock, voltage and IOMMU. They raise the NPU clock above its 200 MHz boot default.
License and credits
ggml-rocket is MIT-licensed. See LICENSE. It builds on
ggml (MIT) as an out-of-tree, runtime-loadable backend, modeled
on ggml's own BLAS backend, and on the rocket-userspace driver for NPU access.
THIRD_PARTY_NOTICES carries ggml's license notice.
Ähnliche Projekte entdecken
Wird geladen…