← Back to projects

exploration · ongoing

How I Made Offline AI Run 7× Faster on a Classroom Panel

Getting language, image and speech AI to run on a classroom panel with no internet: which chip to use, how to stop an AI crash taking the app down, and the measurements that changed the plan.

AI / Edge · Embedded SystemsKotlin & JNI · Rockchip RKLLM / RKNN (NPU) · llama.cpp (Vulkan / CPU) · LiteRT / MediaPipe LLM Inference · Quantization (w4a16, Q4 / Q8)

Role
On-device AI lead
Duration
May – Sep 2026
Type
exploration
Status
ongoing

Key results

  • ~7×Faster on the panel's graphics chip than its processor (3.07 vs 0.45 tokens per second)
  • 38 s →5 sTime for the AI model to start, after switching to a smaller model
  • 14–52 s →0.3–1.2 sWait for speech to appear as text, after fixing a threading bug

Overview

Teachmint’s classroom panels run on Rockchip RK3576 boards: four Cortex-A72 and four Cortex-A53 cores, a Mali-G52 GPU and a 6-TOPS NPU, with 8 GB of RAM on the models I tested. From May to September 2026 I worked out what AI could run on that hardware with no network: language models, vision-language models and speech recognition.

The question wasn’t “can a model run”. It was which accelerator, which model size, and what breaks when it shares the panel with a teacher’s apps.

The problem

Three things make a classroom panel harder than a phone for this:

  • Three accelerators, three toolchains. The NPU runs Rockchip’s own formats through RKLLM/RKNN, the GPU runs Vulkan or vendor runtimes, and the CPU runs everything slowly. Each has its own model conversion and failure modes.
  • Production builds are locked. The panels run user builds. There’s no root to read or lock NPU and memory clocks, which is how vendor benchmarks are usually produced.
  • Native inference crashes. A segfault inside a vendor library would take the whole whiteboard down with it.

My approach

A separate process for inference

The design I wrote for the whiteboard puts inference in its own :ai process behind AIDL, with two backends in one APK:

  • NPU, through Rockchip’s RKLLM runtime, for Qwen3 and InternVL .rkllm models
  • GPU, through Google’s LiteRT / MediaPipe LLM Inference, for Gemma models

A native crash in the vendor library kills only :ai. The app sees the service disconnect and rebinds for the next request. Images cross the process boundary as content URIs, not bitmaps, because a bitmap blows past Binder’s 1 MB transaction limit. Feature code depends only on a tiny API module with no native libraries.

A benchmark lab instead of assumptions

I built a test app that runs the same prompts through three engines: RKLLM on the NPU, llama.cpp with Vulkan on the Mali GPU, and llama.cpp on the CPU. It records tokens per second and time-to-first-token for text, vision and long-context recall suites.

Important decisions

The GPU beat the CPU, and the reason was the instruction set

The common advice is that llama.cpp on a Mali GPU through Vulkan is slower than the CPU. On the RK3576 it was the other way round. TinyLlama at Q4 ran at 3.07 tok/s on the GPU against 0.45 tok/s on all eight CPU cores, about 7×. The RK3576’s A72 and A53 cores are ARMv8.0 and lack the dotprod and i8mm instructions that make quantized CPU inference fast elsewhere, while the Mali-G52 exposes Vulkan integer dot products. So the lab ships all three modes, with the GPU as the default for llama.cpp.

A smaller model, chosen for startup

For a hackathon assistant, Gemma 3n E2B (3.4 GB) took about 38 seconds to initialise on the panel’s GPU and about 2 GB of RAM. Gemma 3 1B (530 MB) took about 5 seconds and about 500 MB. The task only needed text, so the smaller model won. Rockchip’s NPU wasn’t an option there, because LiteRT-LM doesn’t support RKNN.

Speech on the NPU: find where the quality goes

Qwen3-ASR ran on the NPU as an RKNN fp16 encoder plus an RKLLM w4a16 decoder:

  • Speed: real-time factor about 0.8, decode about 8.6 tok/s.
  • Memory: peak about 1.24 GB.
  • Startup: about 8.5 s to load.

The transcripts were poor. Swapping halves against the official fp32 model isolated it: the device’s fp16 encoder was fine, and the w4a16 decoder was the loss. Running the official decoder at Q8 on the CPU became the default where it’s available. It improves quality, at the cost of speed and some lag when streaming live. Two inherited defaults were also wrong: a repetition penalty of 1.15 and a non-standard prompt template.

What went wrong: a thread pin we didn’t set

A second speech model, Moonshine, ran fine on one panel and collapsed on another. Its final transcript arrived 14–52 seconds after the audio.

The cause wasn’t Moonshine. RKLLM’s OpenMP runtime pins the thread that calls it to a single core. When the app switched from the NPU model to Moonshine on the same engine thread, ONNX Runtime’s worker threads inherited that pin. All of them were running on CPU 4.

Creating a fresh engine thread on each model switch fixed it. Moonshine’s threads spread across all eight cores again, and its final transcript arrived in 0.3–1.2 seconds.

Result

  • A crash-isolated AI service design for the whiteboard, with NPU and GPU backends behind one AIDL contract.
  • A three-engine benchmark lab, with measurements that reversed the expected GPU-vs-CPU answer on this SoC.
  • On-device speech recognition on the NPU, with its quality bottleneck isolated to the quantized decoder.

What these numbers aren’t: vendor-grade benchmarks. NPU clocks can’t be locked or even read on user builds, and upstream reports the same models running 2–3× faster with locked clocks. Every figure here is what a production panel gets as shipped.

What I learned

  1. Measure on the target SoC. The instruction set, not the model, decided GPU vs CPU here.
  2. Isolate quality loss by swapping components. Half-official, half-device pipelines found the bad stage in one run.
  3. Native runtimes change thread state you don’t own. An inherited CPU pin cost a 50× slowdown.
  4. Pick models for startup and memory, not just quality. On a shared panel, 5 seconds and 500 MB beat a better model nobody waits for.
  5. Keep native inference in its own process. A vendor segfault should cost one request, not the app.