Freeing
the 3.0 TOPS NPU on the Allwinner A733: How an On-Die Neural Accelerator
Works, Mainline Linux etnaviv + Mesa Teflon Bring-Up, and
Zero-Copy Video Processing
By Tim Michals
Featured for Hackster.io — Open-Source Edge AI, Mainline Linux &
Embedded Vision
Introduction: What Does It Actually Take to Accelerate AI at the Edge?
Pick up almost any modern single-board computer and the headline spec jumps right off the box: “Octa-Core CPU + 3.0 TOPS AI NPU!” For robotics, smart cameras, and edge-vision projects, that promise sounds simple—plug in a camera, run a neural network, and detect objects in real time without needing a desktop GPU or sending video to the cloud.
Before diving into Linux drivers or silicon registers, it helps to step back and ask a simpler question: what is an AI accelerator actually doing, and why does a normal CPU struggle with it?
1. Why AI Needs So Much Math (and What “Convolution” Means)
When a computer vision model looks at a camera frame—say, a
1920×1080 image—it doesn’t “see” a person or a stop sign
all at once. Instead, it passes the image through dozens of layers of
convolution (CONV_2D).
A convolution is surprisingly simple: imagine taking
a tiny 3×3 magnifying glass (called a
kernel or filter) and sliding it
across every single pixel of the image. At each stop, the computer
multiplies those 9 pixel values by 9 learned weights
and adds them up into one output number. Early layers look for simple
things like vertical edges or bright spots; deeper layers combine those
patterns into wheels, faces, or text. A single modern vision model might
perform billions of these tiny multiply-and-add steps
on every single frame—30 times a second. A general-purpose CPU is built
for complex logic and branching, not doing billions of repetitive
multiplies per second, so it quickly gets hot, burns power, and drops
frames.
2. Why “8-Bit Quantization” Is the Secret Behind TOPS
Models are usually trained on big server GPUs using 32-bit
floating-point numbers (FP32—high-precision decimals). On a
tiny embedded board, you don’t need 32 bits of decimal precision just to
tell a cat from a coffee mug. Quantization converts
those FP32 weights and pixel values into compact
8-bit whole numbers (INT8 or
UINT8, from -128..127 or
0..255).
Shrinking from 32-bit decimals to 8-bit integers makes each multiply-add circuit roughly 15–20× smaller and more power-efficient, and cuts memory traffic by 4×. When a chip advertises “3.0 TOPS” (Tera Operations Per Second), it means 3 trillion 8-bit integer operations per second—not 32-bit desktop floating point.
3. Fixed-Function NN Cores vs. Programmable Shaders (and Why You Need Both)
An NPU (Neural Processing Unit) isn’t just one giant
calculator. Real AI pipelines do more than convolutions: you also have
to resize/normalize camera pixels before inference, or run custom math,
activations, and image filters afterward. Inside modern NPUs like the
Vivante VIP9000 on Allwinner’s A733, the silicon is split into two
complementary helpers: - NN (Neural Network) Cores:
Fixed-function hardware arrays packed with hundreds of 8-bit
multipliers. They are unbeatable at convolutions, but they
cannot run arbitrary if/else code or general math.
- PPU / Shader Core: A small programmable parallel
processor (like a mini compute GPU) that runs short parallel programs
(shaders) across hundreds of pixels or tensor elements
at once—handling custom math, image pre/post-processing, and ops the
fixed-function NN cores don’t support.
4. Why “Zero-Copy” Memory Matters for Live Video
Even with a fast NPU, copying a 1080p camera frame from the camera
driver into CPU memory, converting it, and copying it back to the NPU
wastes huge amounts of memory bandwidth. On Linux,
dma-buf lets the camera hardware, video
encoder, and NPU share the exact same physical memory
buffer—so frames move from camera to NPU with zero CPU
copies.
Breaking Out of the Vendor BSP Trap
Most SBCs lock this NPU hardware inside an old vendor kernel
(5.15), closed-source userspace libraries
(libVIPlite.so), and proprietary offline .nb
model compilers. On the Radxa Cubie A7A (Allwinner
A733) and Cubie A5E (Allwinner T527), we set
out to unlock this stack on 100% open-source mainline Linux
7.1 using the upstream etnaviv
DRM driver (/dev/dri/renderD128), Mesa 26.1.8
Teflon (libteflon.so, which runs standard
.tflite models directly), and V4L2
dma-buf zero-copy camera pipelines.
Real silicon bring-up is messy, and this article shares the whole
journey—what already works on live Cubie A7A hardware (PPU shader
compute at 0.059–0.396 ms, zero-copy V4L2
/dev/video0 and CMA dma-buf -> NPU PRIME at
0.401–0.487 ms, and ov5647 CSI +
Cedrus H.265 video), as well as the open
HW_V83 NN conv2d DRAM-read investigation still
underway.
Why Edge AI Matters (and CPU vs. GPU vs. NPU at a Glance)
Running AI locally on the board (“at the edge”) instead of in the
cloud delivers sub-millisecond latency (critical for
robotics and drones), privacy (camera feeds never leave
the device), offline reliability, and high
performance per watt: - CPU: Great for
operating systems, networking, and branching logic
(if/else); poor at billions of repetitive matrix
multiplies. - GPU: Built for 32-bit floating-point
graphics and parallel math, but power-hungry and absent or small on many
headless embedded SoCs. - NPU: Purpose-built for
quantized 8-bit neural network math and on-chip SRAM dataflow at a
fraction of the power.
Companion Articles, Guides & How You Can Help
If you want to go deeper—or help crack the remaining open
HW_V83 NN bring-up items—these companion guides cover each
layer of the stack: - Use Cases & Workload Mapping:
Inside
an Edge AI Chip: NN Cores, Shaders, and Why You Need Both —
plain-English guide to matching workloads across NPU, PPU shaders, Arm
NEON, ISP/VE, and the on-die XuanTie E902 RISC-V core. - Silicon
Debugging War Stories: Freeing
the Allwinner A733 NPU on Mainline Linux 7.1: The 8 Real-World Problems
We Solved — deep dive into 0x9003
vs. 0x9202, TP_ENGINE=0, MMUv2 PDMODE, and the
ongoing HW_V83 NN DRAM-read investigation. -
Copy-Pasteable Build, C++, PPU & Video Examples: Allwinner
T527 & A733 Mainline NPU Guide — complete build instructions and
verified npu-ppu-test / npu-v4l2-dmabuf-test
commands. - Camera & Hardware Video Encoding: Camera
/ ISP 602 V4L2 Guide and A733
Cedrus H.264/H.265 Encoder Guide. - Upstream
References: Mesa
Teflon Documentation and Linux kernel
drivers/gpu/drm/etnaviv/. - Want to pitch
in? Community kernel/Mesa hackers are especially welcome to
help test or trace the two remaining open items: the HW_V83
(0x9202) NN conv2d DRAM-read bug and
etnaviv.ko rmmod/insmod
PD_NPU re-probe (GC0 after power-domain
cycle).
๐ 1. Silicon Architecture: How the A733 & T527 NPUs Work Under the Hood
If you have ever deployed a computer vision model (like YOLOv8, MobileNetV2, or PoseNet) on an embedded Linux single-board computer, you have felt the wall that general-purpose CPU cores hit when processing real-time 1080p video.
Even on a modern octa-core processor like the Allwinner A733 (2× Arm Cortex-A76 @ 2.0 GHz + 6× Cortex-A55 @ 1.8 GHz, powering the Radxa Cubie A7A) or the Allwinner T527 (8× Cortex-A55 @ 1.8 GHz, powering the Radxa Cubie A5E), running millions of multiply-accumulate operations per frame on the CPU means: - Burning 3–5 Watts of CPU thermal budget on matrix math instead of application logic. - Saturating the CPU’s L1/L2 caches and external DRAM bus by repeatedly fetching weights and writing intermediate feature maps. - Dropping frames whenever the CPU also has to handle camera capture, H.264/H.265 video encoding, or network streaming.
To solve this, silicon designers place a dedicated Neural
Processing Unit (NPU) right on the SoC die. On the
Allwinner A733 (verified on live Radxa Cubie
A7A silicon), that NPU is a 3.0 TOPS-class VeriSilicon
Vivante VIP9000Nano-DI (npu@3600000,
model 0x9000, rev 0x9202,
HW_V83); on the Allwinner T527,
it is a 2.0 TOPS VeriSilicon Vivante VIP9000Nano-SI+
(npu@7120000, rev 0x9003).
How Does an NPU Work Compared to a CPU or GPU?
Unlike a CPU (which fetches scalar or small SIMD instructions one by one) or a GPU (which runs general-purpose 32-bit floating-point shaders), a neural network accelerator is a spatial dataflow engine purpose-built around four hardware principles:
- 8-Bit Quantized Tensor Math (
INT8/UINT8): Neural networks trained in 32-bit floating point (FP32) are quantized to 8-bit integers (INT8orUINT8) using per-tensor or per-channel scale and zero-point parameters. An 8-bit integer multiply-accumulate (MAC) circuit takes roughly 15–20× less silicon area and switching energy than anFP32fused multiply-add, allowing the A733 NPU to pack 8 parallel NN cores × 64 MADs/core (with ZDP3 spatial reuse, delivering up to 3.0 TOPS marketed peak at high OPP clocks) into a compact silicon footprint. - Spatial Weight & Activation Broadcast Across 8 NN
Cores: In a 2D convolution (3×3 or 1×1), the exact same kernel
weights slide across thousands of
(x, y)pixel locations, while the same input pixel patch is multiplied against dozens of output channels. Instead of reading weights from DRAM over and over, the NPU loads weights and input tiles once into 512 KB of ultra-wide on-chip VIP SRAM (128 bytes / 1024 bits per cycle physical width on the A733) and broadcasts them simultaneously across its 8 Neural Network (NN) cores. - On-the-Fly Hardware Weight Decompression (Huffman + ZRL): Neural network weights contain large runs of zeros and clustered small integer values. When a model is loaded, its weights are compressed using Huffman coding and Zero-Run-Length (ZRL) encoding. Inside the NPU, a dedicated hardware bitstream decoder decompresses weights as DMA streams them from LPDDR5—cutting external memory bandwidth by 2–4× with zero CPU overhead.
- Fused Hardware Pooling, Activation &
Requantization: Before a partial sum ever leaves an NN core,
dedicated inline stages apply 32-bit bias addition, non-linear
activation (
ReLU,ReLU6,Clamp), 2×2 max or average pooling, and 8-bit requantization in a single pass. On SoCs with a dedicated Tensor Processor (TP) (such as the T527), layout transposes and LUT activations run on TP cores; on the A7330x9202(TP_ENGINE = 0), non-NN ops fall to the companion Programmable Shader / PPU core (NumShaderCores = 1) or CPU.
NN Cores vs. PPU Shaders vs. Missing TP Engine: Why Both Paths Matter (and Best Use Cases)
A common misconception is that an “NPU” is one single black-box
circuit. On the Allwinner A733 (VIP9000Nano-DI, rev
0x9202), the block at 0x03600000 is actually a
two-engine heterogeneous compute cluster sharing one
Front-End DMA parser and MMUv2:
- 8× NN Cores (Fixed-Function Convolution Arrays):
Ultra-dense INT8 multiply-accumulate hardware (512 MACs/cycle). Blazing
fast for
CONV_2D,DEPTHWISE_CONV_2D, andFULLY_CONNECTED(90%+ of a YOLO or MobileNet backbone), but unable to run general-purpose code (if/else, float32 math, FFTs, image filters, or bounding-box NMS). - 1× PPU / Shader Core (Programmable Processing Unit, 256 Hardware Threads): A shader is simply a small parallel program (OpenCL / SIMD vector kernel) that executes across hundreds of pixels or tensor elements simultaneously—like a mini compute GPU bolted onto the NPU die. It handles everything fixed-function NN cores cannot: float32/fp16 math, image pre/post-processing, optical flow, custom activations, and tensor layout shuffles.
- No Dedicated TP Engine
(
TP_ENGINE = 0): Older Vivante NPUs (T5270x9003, i.MX8MP0x8002) included a third dedicated Tensor Processor (TP) to transpose tensors (NHWC ↔︎ NCHW) and run LUT activations. On A7330x9202, Vivante removed the TP hardware to save die area—making software support for both the NN engine (Path A) and PPU/CPU ops (Path B) essential.
Real edge-vision and robotics pipelines are never 100% convolutions. Matching each stage to the right silicon block on the A733 is why this dual-path mainline stack matters:
Allwinner
A733 (0x9202) vs. Allwinner T527 / A527
(0x9003): What Live Silicon Revealed
A common pitfall when reading vendor headers is guessing which
gc_feature_database.h row matches an SoC without checking
silicon. Before booting the A7A, it was easy to assume the A733 carried
Allwinner’s 12-core 0x9113 (VIP9000UL-DI+)
block—live hardware readback on the Radxa Cubie A7A
(/sys/kernel/debug/dri/0/gpu) proved the A733 silicon is
actually model 0x9000, revision 0x9202
(product_id 0x05090009,
customer_id 0x1000003b, eco_id 0x08000000,
chip date 2023-05-18) — VeriSilicon
VIP9000Nano-DI (HW_V83,
VIP_VERSION 0x398).
Live silicon register readbacks and VeriSilicon’s hardware feature
database (allwinner/gc_feature_database.h) highlight the
exact architectural differences between the A733 and T527:
๐
2. Breaking Out of the Proprietary Vendor Trap: Why Mainline
etnaviv + Mesa Teflon?
Traditionally, using a Vivante VIP9000 NPU on an Allwinner SoC meant
accepting a locked-down vendor BSP stack: * Kernel
Space: A ~44,000-line out-of-tree kernel module
(vipcore.ko or galcore.ko exposing
/dev/vipcore or /dev/galcore) that breaks on
every minor Linux kernel upgrade (EXTRA_CFLAGS removal,
in_irq() deprecation, MAX_ORDER rename,
platform_driver .remove signature changes). *
Userspace: Precompiled closed-source shared libraries
(libVIPlite.so, libVIPuser.so, or
TIM-VX) tied to a specific glibc/Android ABI. *
Offline Model Lock-In: You cannot load a standard
.tflite model directly. Instead, you must run a proprietary
x86 offline compiler (acuity-toolkit /
pegasus) to convert your model into a locked
.nb (network_binary.nb) blob tailored to a
single chip revision.
To run on mainline Linux 7.1 with zero binary blobs, we replaced the entire vendor stack with upstream open-source components:
Proprietary
ACUITY / libVIPlite / awnn
vs. Mainline etnaviv + Teflon: Honest Trade-Offs
To be fair to the vendor stack, Allwinner and VeriSilicon’s
proprietary tools (ACUITY + .nb +
libVIPlite.so / libNBGlinker.so + Allwinner
awnn) exist for a reason and do offer real
advantages today when running on the vendor 5.15 BSP: *
Ahead-of-Time Whole-Graph Optimization
(.nb): ACUITY compiles ONNX, PyTorch,
or TFLite models offline on an x86 PC into a pre-scheduled
.nb binary—eliminating runtime graph compilation overhead
and fusing Conv + Bias + ReLU + Pool aggressively. *
Hardware Weight Compression & VIP SRAM Tiling:
ACUITY emits Huffman + Zero-Run-Length
(ZRL) compressed weights (2–4× less LPDDR5 traffic) and
statically tiles intermediate feature maps inside the 512 KB
on-chip VIP SRAM across consecutive layers so tensors stay
on-die instead of bouncing through external DRAM. * Broader
Operator & Precision Coverage: Supports INT8,
UINT8, and INT16, custom OpenVX/PPU kernels,
and turnkey Allwinner awnn / vpm_run demos
(YOLOv5, YOLOv8, face/pose) out of the
box.
Can we use libVIPlite.so, ACUITY,
or awnn inside our open-source mainline stack?
No — not directly. libVIPlite.so,
libNBGlinker.so, awnn, and the
ACUITY compiler are closed-source proprietary binaries tied
to the out-of-tree /dev/vipcore ioctl ABI (not Linux DRM
/dev/dri/renderD128), and vipcore.ko cannot be
upstreamed into mainline Linux.
Wait—doesn’t ACUITY need an x86 PC? Can open
source actually match its speed on the board? VeriSilicon ships
ACUITY as an x86-only offline tool largely for convenience
and IP protection, not because the Arm SoC can’t do the
graph compilation. Compressing quantized weights (Huffman/ZRL), planning
512 KB VIP SRAM tiles, and building the command stream take a fraction
of a second once at model-load time on the A733’s Cortex-A76/A55 cores
(and can be cached to disk so subsequent runs load in
milliseconds)—no x86 Docker container required.
Because all of the underlying capabilities
(Huffman/ZRL weight compression, VIP SRAM tiling, multi-layer batching,
and PPU shaders) are hardware features of the VIP9000 die, we are
still resolving the HW_V83 NN DRAM-read issue
first, and our next steps are to bring those
exact optimizations clean-room into MIT-licensed Mesa
etnaviv / Teflon so the open-source stack can
match proprietary .nb performance without binary blobs or
kernel lock-in.
๐ฌ 3. Inside the Chip: How the A733 NPU Works (Clocks, MMUv2, DMA & 8 NN Cores)
To understand what happens inside the silicon at
0x03600000 when an AI inference job runs—and why specific
clock, reset, and MMUv2 registers had to be unlocked for the Allwinner
A733—let’s trace the internal hardware blocks from the power rail down
to the 8 NN cores.
3.1 Power Domain, 4-Clock CCU Hierarchy & Triple Reset Lines
Before a single register at 0x03600000 responds to CPU
reads, three hardware prerequisites must be satisfied in strict
order:
- Power Supply & Silicon Island
(
AXP8191 dcdc2+PCK-600 PD_NPU):- The external
vdd-gpu-npupower rail is driven by the AXP8191 PMICdcdc2buck converter (800 mVat 492–852 MHz boot nominal, scaling up to960–1080 mVat 1008–1120 MHz OPP bins). - Inside the A733 SoC, the PCK-600 Power Controller
(
7060000.power-controller) controls power isolation for the NPU island via domainPD_NPU(id4,pstate=0x8, on). Whenetnavivcallspm_runtime_resume_and_get(), Linuxgenpdpowers onPD_NPUand releases isolation clamps.
- The external
- The 4-Clock Tree in Mainline
ccu-sun60i-a733.c:CLK_NPU(0x0b00,"core"): The high-speed compute clock driving the 8 NN cores and 512 KB VIP SRAM (840 MHzdefault frompll-npu, muxable acrosspll-npu,pll-periph0-800M/600M/480M,pll-ve0,pll-ve1,pll-de-3x) with a 5-bit divider (M) and gateBIT(31).CLK_AHB_NPU(0x05c0bit 6) →CLK_BUS_NPU(0x0b04bit 0,"reg",200 MHz): On the A733, CPU register reads/writes to0x03600000traverse two series AHB clock gates: the top-level NPU AHB master gate (0x05c0bit 6) and the NPU module bus gate (0x0b04bit 0). Indrivers/clk/sunxi-ng/ccu-sun60i-a733.c, we parentedbus_npu_clk(CLK_BUS_NPU) directly toahb_npu_clk(CLK_AHB_NPU). That way, whenetnavivenables its"reg"clock, the Linux Common Clock Framework automatically enables both0x05c0[6]and0x0b04[0].CLK_MBUS_NPU(0x05e0bit 18,"bus",600 MHz): Gates the 128-bit AXI/MBUS DMA master port, parented tombus_clk(600 MHz, synced with Junhui Liu’s upstream A733 CCUv7patch series). IfCLK_MBUS_NPUis left gated, MMIO register reads work fine, but the NPU’s DMA engine stalls forever the moment it tries to fetch its first command buffer from LPDDR5!
- Triple Reset Lines (
0x0b04bits 16, 17, 18):- Unlike the T527 (which has a single
RST_BUS_NPUbit), A733 register0x0b04splits the NPU reset into active-low lines:RST_BUS_NPU_CORE(BIT(16)),RST_BUS_NPU_AXI(BIT(17)),RST_BUS_NPU_AHB(BIT(18)) (plusRST_BUS_NPU_SRAMatBIT(19), read back as0x000F0000deasserted on silicon). - Mainline
etnavivpreviously calleddevm_reset_control_get_optional(), which only supports a single reset line. By switchingetnaviv_gpu_platform_probe()todevm_reset_control_array_get_optional_exclusive(&pdev->dev)(and updatingvivante,gc.yamltomaxItems: 3),etnavivcleanly asserts and deasserts all three reset lines as a unit.
- Unlike the T527 (which has a single
3.2 The Front-End (FE) Wait-Link DMA Command Parser
How does the NPU execute a multi-layer neural network without CPU intervention between layers?
At the front of the NPU sits the Front-End (FE) Command
Parser. It is a dedicated DMA state machine that reads 64-bit
instructions (LOAD_STATE, END,
NOP, WAIT, LINK,
STALL) directly from system memory:
- Wait-Link Ring Buffer: The kernel maintains a small
circular ring buffer in DMA memory ending in a 16-byte
WAIT(200 cycles) →LINK(back toWAIT) loop. While the NPU is idle or finishing a job, the FE parser continuously loops between those two instructions. - Dynamic Job Chaining: When userspace submits an
inference command stream, the kernel writes a
LINKinstruction at the end of the user buffer pointing back to the kernel’s newWAIT -> LINKtail, and then overwrites the previousLINKtarget in the active ring to jump into the user’s command stream. The FE seamlessly follows the new link on its very next cycle without ever stopping. - Why
ETNA_SEC_KERNEL(0x003A4) Is Mandatory: The VIP9000Nano-DI (0x9202) implements Vivante’s Security AHB feature (MINOR_FEATURES7_BIT_SECURITY+MINOR_FEATURES10_SECURITY_AHB). On this hardware, the legacyVIVS_FE_COMMAND_CONTROL(0x00658) kick register is a no-op. By adding the Allwinner0x9000NPU entries (0x8303,0x9003,0x9113,0x9202) to the kernel’setnaviv_hwdb.c,etnavivenablesgpu->sec_mode = ETNA_SEC_KERNEL: it unlocks non-secure register writes at0x003A8, writes the command buffer address toVIVS_FE_COMMAND_ADDR(0x00654), and starts the FE viaVIVS_MMUv2_SEC_COMMAND_CONTROL(0x003A4).
3.3
MMUv2 Virtual Memory & The A733 0x003B4 Page Descriptor
Handshake
Every memory address inside an NPU job—the command buffer, compressed
weights, bias tables, input feature maps, and output tensors—is a
32-bit NPU Virtual Address (NPU_VA).
- Two-Level Page Walk (
PTA→MTLB→STLB):- The NPU’s internal MMUv2 translates every 32-bit
NPU_VAinto a 40-bit LPDDR5 Physical Address (PA) using a Page Table Array (PTAat0x0038C/0x00390), a 1024-entry Master TLB (MTLB, bits[31:22]), and 1024-entry Slave TLB page tables (STLB, bits[21:12], 4 KB pages). - Because the MMU translates scatter-gather physical pages into a contiguous virtual range, large neural network weight buffers do not need physically contiguous CMA memory—standard paged Linux GEM buffers work out of the box.
- The NPU’s internal MMUv2 translates every 32-bit
- The Revision
0x9202MMU_PAGE_DESCRIPTOR(PDMODE) Architecture (0x003B4,0x00388,0x00184):- On older Vivante cores like the T527 (
0x9003),etnaviv_iommuv2_restore_sec()initializes MMUv2 via a Page Table Array (PTAat0x0038C/0x00390/0x00394), runs a physical-mode FE command buffer (load_state(VIVS_MMUv2_PTA_CONFIG)), and writes0x00388 = 0x01. - On the A733 (
0x9202), VeriSilicon enabledMMU_PAGE_DESCRIPTOR = 1(mmu_pd_mode = 1in Allwinner’svip_drv_hardware.c). Instead of PTA indirection, the kernel writes the 4 KB Master TLB physical frame directly to0x003B4 = ((mtlb_dma >> 12) << 4) | MODE4_K(bit 0 =0foretnaviv’s 4 KB MTLB / 4 MB per-MTLB layout, vs1for 1 KB / 16 MBMODE1_K), skipsPTA_CONTROL, configures0x0055C = 0x00FFFFFF(MC_L2_CACHE_CONFIG) and0x00090 |= BIT(6)(bypass_reorder), and enables PDMODE via0x00388 = 0x21(BIT(5) | ENABLE). - Subtle TLB Flush Trap in
etnaviv_buffer.c: Mainlineetnavivflushes the MMUv2 TLB by writing0x00000018(MODE_MASK | FLUSH) toVIVS_MMUv2_CONFIGURATION(0x00184)—which leaves bit 8 (ADDRESS_MASK) as0, zeroing the MTLB base address under PDMODE! Matching Allwinner’svip_drv_mmu.c, PDMODE flushes must write0xffffff7f(ADDRESS_MASK = 1,MODE_MASK = 1,FLUSH_MASK = 0,FLUSH = 1) so dynamic BO mappings flush the TLB without clobbering the page-table base.
- On older Vivante cores like the T527 (
3.4 Inside the Compute Engines: 8 NN Cores, 1 PPU Shader Core & 512 KB VIP SRAM
Once the FE parses a layer kick (VIVS_PS_NN_INST_ADDR at
0x010A0 + VIVS_PS_UNK10A4 at
0x010A4), the actual tensor math runs across the internal
blocks wired to the 512 KB on-chip VIP SRAM:
- 8 Parallel NN Cores (
HW_V83,VIP_VERSION = 0x398): The NN cluster fetches a 128-byte descriptor fromVIVS_PS_NN_INST_ADDR, streams compressed weights from LPDDR5 into the 512 KB VIP SRAM (128-bytephysical width, mapped viaVIVS_GL_OCB_REMAP_START/END), and executes64 MADs/coreacross all 8 NN cores in parallel (32 lanes/output cycle). On0x9202, VeriSilicon enabledHW_V83,NN_SMALL_BATCH_PHASE2 = 1,NN_TENSOR_ADD_FIELD_MOVE_TO_EXT_CMD = 1, andZRL_8BIT = 0. - 1 Programmable Shader / PPU Core (No Dedicated TP
Block): Unlike the T527 (
2 TP cores), the A733’s0x9202silicon setsTP_ENGINE = 0andTPEngine_CoreCount = 0. All non-NN tensor manipulation (such asNHWC ↔︎ NCHWlayout transpose, padding, or custom elementwise activations) must execute on the single USC / PPU Shader core (256 threads,64 temp regs,512 instructions) or the Arm CPU—a key architectural difference that surfaced immediately during our live Mesa Teflon bring-up below.
๐งฉ 4. How It Interfaces: The 4-Layer Open-Source Driver & AI Stack
How does a Python script or C/C++ application loading a standard
.tflite file end up driving 8 NN cores through
/dev/dri/renderD128? The software stack is cleanly split
into four layers.
4.1
Layer 1: Application & TensorFlow Lite Runtime
(libtensorflow-lite.so)
Your application uses the standard TensorFlow Lite C
API (<tensorflow/lite/c/c_api.h>) or Python
tflite_runtime. You do not link against any proprietary NPU
SDK. Instead, you load Mesa’s /usr/lib/libteflon.so as a
standard TFLite external delegate plugin
(tflite_plugin_create_delegate):
#include <dlfcn.h>
#include <tensorflow/lite/c/c_api.h>
typedef TfLiteDelegate* (*create_delegate_fn)(char**, char**, size_t,
void (*)(const char*));
typedef void (*destroy_delegate_fn)(TfLiteDelegate*);
void run_npu_inference(const char *model_path) {
/* 1. Dynamically load Mesa's open-source Teflon TFLite delegate */
void *teflon_so = dlopen("/usr/lib/libteflon.so", RTLD_LAZY);
create_delegate_fn create_delegate =
(create_delegate_fn)dlsym(teflon_so, "tflite_plugin_create_delegate");
destroy_delegate_fn destroy_delegate =
(destroy_delegate_fn)dlsym(teflon_so, "tflite_plugin_destroy_delegate");
TfLiteDelegate *npu_delegate = create_delegate(NULL, NULL, 0, NULL);
/* 2. Attach the NPU delegate to TFLite InterpreterOptions */
TfLiteModel *model = TfLiteModelCreateFromFile(model_path);
TfLiteInterpreterOptions *opts = TfLiteInterpreterOptionsCreate();
TfLiteInterpreterOptionsAddDelegate(opts, npu_delegate);
/* 3. Create interpreter: Teflon partitions supported INT8/UINT8 subgraphs */
TfLiteInterpreter *interp = TfLiteInterpreterCreate(model, opts);
TfLiteInterpreterAllocateTensors(interp);
/* 4. Fill input tensor, run on the 3.0 TOPS NPU, read output tensor */
TfLiteInterpreterInvoke(interp);
TfLiteInterpreterDelete(interp);
TfLiteInterpreterOptionsDelete(opts);
TfLiteModelDelete(model);
destroy_delegate(npu_delegate);
dlclose(teflon_so);
}Or in Python (ctypes or
tflite_runtime):
# Or run our built-in zero-dependency verification & benchmark utility:
# npu-smoke-test /path/to/model_quant.tflite 504.2
Layer 2: Mesa Teflon Delegate Frontend
(src/gallium/frontends/teflon/)
When TfLiteInterpreterCreate() and
TfLiteInterpreterAllocateTensors() execute: 1. DRM
Render Node Discovery: Teflon opens
/dev/dri/renderD128 via
pipe_loader_drm_probe_fd() and instantiates a Gallium
pipe_screen and pipe_context backed by
etnaviv. 2. Automatic Graph Partitioning
(Prepare): Teflon walks every node in the
.tflite flatbuffer graph. Supported quantized
(INT8 / UINT8)
operators—CONV_2D,
DEPTHWISE_CONV_2D,
FULLY_CONNECTED (lowered to 1×1
convolution), ADD,
AVERAGE_POOL_2D,
MAX_POOL_2D,
PAD,
LOGISTIC, and fused
RELU / RELU6—are claimed by
the Teflon delegate and merged into contiguous NPU subgraphs. Any
unsupported operator (such as a final SOFTMAX
dequantization node) automatically remains on the Arm CPU. 3.
Lowering to Gallium ML: Teflon converts the partitioned
TFLite subgraph into an array of hardware-agnostic Gallium
struct pipe_ml_operation descriptors and hands them to
context->ml_subgraph_create().
4.3
Layer 3: Mesa Etnaviv Gallium ML Backend
(src/gallium/drivers/etnaviv/)
Inside Mesa’s etnaviv driver, the neural network
subgraph is compiled directly into VIP9000 hardware descriptors,
compressed weight bitstreams, and FE command buffers:
- Silicon Feature Database Lookup
(
allwinner/gc_feature_database.h):- At screen creation, Mesa queries the kernel via
DRM_IOCTL_ETNAVIV_GET_PARAMforMODEL(0x9000),REVISION(0x9202),PRODUCT_ID(0x05090009),CUSTOMER_ID(0x1000003b), andECO_ID(0x08000000). etna_query_feature_db()insrc/etnaviv/hwdb/etna_hwdb.clooks up the exact silicon row insrc/etnaviv/hwdb/allwinner/gc_feature_database.hand configures the compiler for the A733’snn_core_count = 8,nn_mad_per_core = 64,on_chip_sram_size = 524288(512 KB),physical_vip_sram_width = 128(128 bytes/cycle),nn_zdp3 = true, andnn_lanes_per_out_cycle = 32.- The
TP_ENGINE = 0Discovery on Live0x9202Silicon: Earlier Mesa patches forcedinfo->npu.tp_core_count = db->TPEngine_CoreCount ? db->TPEngine_CoreCount : 1;assuming a single TP unit existed wheneverTPEngine_CoreCountwas0. Live silicon testing on the A7A (0x9202, wheregcFEATURE_BIT_TP_ENGINE = 0andTPEngine_CoreCount = 0) proved that the hardware truly has no TP engine—TPtranspose/detranspose ops become silent no-ops, leaving intermediate and final buffers zeroed unless lowered to the PPU shader core or CPU!
- At screen creation, Mesa queries the kernel via
- One-Time Compilation During
AllocateTensors()(etna_ml_subgraph_create):- Hardware Transpose & Channel Reshuffle Insertion
(
etnaviv_ml_tp.c): Whenever an input or output tensor layout requires realignment between TFLite’sNHWCand the NN engine’sNCHW, Mesa wraps the graph with transpose/detranspose stages (which use hardware TP cores on T5270x9003, and need a PPU shader / CPU fallback on A7330x9202). - V8 Superblock Tiling & Weight Compression
(
etnaviv_ml_nn_v8.c): Filter weights and biases are tiled into V8 superblocks matched to 8 NN cores and the 512 KB VIP SRAM, compressed into a bitstream, and uploaded into a write-combined GEM buffer object (coefficients). - Command Stream Generation
(
etnaviv_ml.c): Mesa records the entire sequence of FE register writes (VIVS_GL_OCB_REMAP_START/END,VIVS_GL_NN_CONFIG,VIVS_PS_NN_INST_ADDR,VIVS_PS_UNK10A4, andVIVS_GL_FLUSH_CACHEbarriers).
- Hardware Transpose & Channel Reshuffle Insertion
(
- Zero-Recompile Inference During
Invoke()(etna_ml_subgraph_invoke):- Every call to
TfLiteInterpreterInvoke()simply updates the input tensor BO, submits the pre-compiled command stream viaDRM_IOCTL_ETNAVIV_GEM_SUBMIT, and waits on the hardware fence viaDRM_IOCTL_ETNAVIV_WAIT_FENCE.
- Every call to
4.4
Layer 4: Mainline Linux 7.1 etnaviv DRM Kernel Driver
(drivers/gpu/drm/etnaviv/)
In kernel space, etnaviv provides: *
Unprivileged Compute Access
(/dev/dri/renderD128): AI applications run as
normal non-root users via the DRM render node. * Per-Process
MMUv2 Isolation & dma-buf PRIME Import: Every
process gets isolated MMUv2 page tables, and camera/video buffers from
V4L2 or G2D can be imported directly into NPU virtual memory via
DRM_IOCTL_PRIME_FD_TO_HANDLE. * DRM GPU Scheduler
(drm_gpu_scheduler) & Runtime PM: Fair job
scheduling, hardware hang detection with automatic triple-reset
recovery, and runtime power gating of PD_NPU when idle.
๐ฅ 5. Zero-Copy Video Processing: Connecting MIPI CSI-2, ISP 602, Hardware H.264/H.265 VE, and the 3.0 TOPS NPU
In a real vision application—an autonomous drone, agricultural sprayer, security camera, or industrial inspection rig—the NPU does not live in isolation. It consumes live video frames from a camera while a video encoder simultaneously records or streams those frames over RTSP/WebRTC.
If the CPU had to copy every 1080p (1920 × 1088)
NV12 frame (3.13 MB/frame, or ~94
MB/s at 30 fps) between the camera driver, the H.265 video
encoder, and the NPU preprocessor, memcpy() and cache
flushes alone would saturate an entire CPU core.
On the Allwinner A733 (Radxa Cubie A7A), we
eliminate CPU frame copies by passing Linux dma-buf
file descriptors allocated in shared LPDDR5 CMA memory directly
across all hardware engines:
5.1
Stage 1: Photon to Shared NV12 dma-buf
(0% CPU Pixel Math)
- MIPI CSI-2 Sensor (
OV5647) & D-PHY (0x05800000): The camera sensor streams 10-bit Raw Bayer (SRGGB10_1X10) at1920 × 1080 @ 30 fpsover a 2-lane MIPI CSI-2 link into the A733 combo D-PHY and CSI0 receiver (0x05811000). - In-Line Hardware ISP 602 (
0x05809400,sun60i-isp): Running in on-the-fly (online) mode directly from the CSI parser FIFO at~148.5 Mpixels/s, the Hardware ISP 602 performs black-level correction, lens shading, 2D noise reduction, Bayer demosaicing, color correction (CCM), gamma, and RGB-to-NV12color space conversion in dedicated silicon (0% CPU). Userspaceaw-isp-2aruns only once per frame (30 Hz) to read compact 3A histogram statistics and update sensor exposure/gain over I²C. - CSI DMA0 (
0x05813000,/dev/video0): Writes stride-aligned1920 × 1088planarNV12frames (Yluma + interleavedUVchroma) directly into contiguous LPDDR5 CMA ring buffers (vb2-dma-contig) and exports each buffer as adma-bufPRIME file descriptor viaVIDIOC_EXPBUF.
5.2 Stage 2: Parallel Zero-Copy Fan-Out to Hardware Video Encoder, 3.0 TOPS NPU & RISC-V
When V4L2 dequeues a completed camera frame
(VIDIOC_DQBUF), userspace hands the
dma-buf FD to three hardware blocks in
parallel without copying the 3.13 MB frame on the
CPU:
- Branch A — Hardware H.264 / H.265 Video Encoding
(
ve@1c10000,< 1.6% CPU):- The V4L2
dma-bufFD is imported directly into the Allwinner A733 Video Engine (ve@1c10000,VE300/V3102_0016) withVE_BUFFER_FLAG_DMA_BUF. - The VE’s internal hardware
CSI/ISPpreprocessor (+0xA00) andAVC(+0xB00) /HEVC(+0xC00) encoder sub-engines read theYandUVplanes directly from the camera CMA buffer over the 128-bit MBUS DMA port (CLK_MBUS_VEat 600 MHz). - Measured Hardware Performance on Radxa Cubie A7A:
- 1080p30 H.264 (AVC) Hardware Encoding: 3.09 ms/frame (323.5 fps max throughput), 0.89% total system CPU usage.
- 1080p30 H.265 (HEVC) Hardware Encoding: 6.34 ms/frame (157.8 fps max throughput), 1.55% total system CPU usage.
- The V4L2
- Branch B — 3.0 TOPS-Class VIP9000Nano-DI NPU Inference
(
npu@3600000):- Simultaneously, the NPU processes the detection tensor
(
e.g. 640 × 640 × 3or320 × 320 × 3UINT8/INT8). - Using Allwinner’s G2D 2D hardware blitter
(
g2d@1480000— hardware YUV-to-RGB color conversion + bilinear downscaler accepting the source V4L2dma-bufFD and writing directly into anetnavivGEMdma-bufBO viadrmPrimeFDToHandle()), or a fast NEON stride-gather into the write-combined Teflon input BO, the input tensor is mapped into the NPU’s MMUv2 (0x00388) page table. - Calling
TfLiteInterpreterInvoke()runs the pre-compiled Teflon command stream across the 8 NN cores and 512 KB VIP SRAM, outputting bounding boxes, class IDs, and confidence scores while the Arm cores remain largely idle.
- Simultaneously, the NPU processes the detection tensor
(
- Branch C — Hard Real-Time Actuation on the On-Die 200 MHz
RISC-V Core (
rproc@7032000):- When the NPU detects a target
(ฮx, ฮy, class, confidence), Linux writes a 16-byte setpoint into System SRAM A2 (0x00044000) and rings the Hardware MSGBOX0 (0x07033000) doorbell. - Within 14.47 ยตs, the on-die 200 MHz XuanTie E902 RISC-V coprocessor updates its bare-metal PID / motor control loop with zero Linux scheduling jitter (see our companion Hackster.io guide on Unlocking the On-Die 200 MHz XuanTie RISC-V Core).
- When the NPU detects a target
๐ ️ 6. Step-by-Step Implementation & Board Verification
Here is the exact Device Tree, Kernel, Buildroot, and verification setup used on the Radxa Cubie A7A (Allwinner A733) in this repository.
6.1 Device Tree Node
(sun60i-a733-cubie-a7a.dts)
In
arch/arm64/boot/dts/allwinner/sun60i-a733-cubie-a7a.dts, we
define the NPU node at 0x03600000 with its 3 clocks
(bus, core, reg), 3 reset lines
(core, axi, ahb), PCK-600 power
domain (PD_NPU), and the AXP8191 dcdc2
(vdd-gpu-npu) regulator:
npu: npu@3600000 {
compatible = "vivante,gc";
reg = <0x03600000 0x1000>;
interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_MBUS_NPU>,
<&ccu CLK_NPU>,
<&ccu CLK_BUS_NPU>;
clock-names = "bus", "core", "reg";
resets = <&ccu RST_BUS_NPU_CORE>,
<&ccu RST_BUS_NPU_AXI>,
<&ccu RST_BUS_NPU_AHB>;
reset-names = "core", "axi", "ahb";
power-domains = <&pck600 PD_NPU>;
#cooling-cells = <2>;
};
6.2
Summary of the 6 Mainline Kernel & Mesa Fixes for Allwinner A733
(0x9202)
6.3 Live Silicon Verification on Radxa Cubie A7A (Two Complementary Compute Paths)
Because the VIP9000Nano-DI (0x9202)
combines a programmable Vivante PPU (OpenCL/Shader)
core with an 8-core HW_V83 Neural Network
(NN) engine, we validate and expose both
compute paths on /dev/dri/renderD128 for different
workloads:
- Path A — Neural Network Inference
(
Mesa 26.1.8 Teflon+ 8× NN Cores): Zero-compile TFLite delegation for quantized CNNs (CONV_2D,DEPTHWISE_CONV_2D,FULLY_CONNECTED). - Path B — General-Purpose Compute (
etnavivDRM + Vivante PPU Shader Core): Low-latency custom kernels (npu_ppu_compute_test.c) for image pre/post-processing, DSP math, or custom non-CNN algorithms.
Booting our mainline Linux 7.1.0 PREEMPT_RT Buildroot
image on the Radxa Cubie A7A confirmed full kernel
bring-up and live PPU + NN execution:
# 1. Verified live kernel boot log on Radxa Cubie A7A:
dmesg | grep -iE "etnaviv|npu"
# [ 0.111755] sunxi-pck-600 7060000.power-controller: domain "NPU" (id 4) pstate=0x8, on
# [ 0.125867] etnaviv etnaviv: bound 3600000.npu (ops gpu_ops)
# [ 0.125975] etnaviv-gpu 3600000.npu: model: GC9000, revision: 9202
# [ 0.125986] etnaviv-gpu 3600000.npu: etnaviv has been instantiated on a NPU, for which the UAPI is still experimental
# [ 0.126585] [drm] Initialized etnaviv 1.4.0 for etnaviv on minor 0
# 2. Verified live silicon identity, clocks, power & thermals:
cat /sys/kernel/debug/dri/0/gpu
# model: 0x9000 | revision: 0x9202 | product_id: 0x5090009
# customer_id: 0x1000003b | eco_id: 0x8000000
# shader_core_count: 1 | nn_core_count: 8 | thread_count: 256
# pll-npu / npu = 840 MHz | mbus-npu = 600 MHz | bus-npu = 200 MHz
# vdd-gpu-npu (AXP8191 dcdc2) = 800 mV (in spec for SID vf0500/vf0501) | NPU temp = 35.9 C✅ Verified Live on A733 Silicon
- Path B — Vivante PPU Compute Shader
(
npu_ppu_compute_test.c): Executing a 28-DWORD cold-boot-deterministic Vivante PPU compute shader (img_load.u8→lshift.s32→rshift.s32→i2f.s32→mov t2, u2→mul→img_store.u8) directly on3600000.npuviaDRM_IOCTL_ETNAVIV_GEM_SUBMITcompleted in0.052–0.950 msper dispatch across 10/10 consecutive runs with 0 MMU faults, 0 hangs, cleanGIC_SPI 65interrupts, and bit-exact IEEE-754 float32 outputs across all tested inputs:fill = 1→0x3d808000(0.062744)fill = 2→0x3e008000(0.125488)fill = 3→0x3e40c000(0.188232)fill = 5→0x3ea0a000(0.313721)fill = 7→0x3ee0e000(0.439209)
- Zero-Copy V4L2 / CMA
dma-bufPRIME → NPU PPU Shader (npu_v4l2_dmabuf_test.c): Exporting a V4L2 capture buffer viaVIDIOC_EXPBUF(/dev/video0,0.206 ms) or allocating a CMAdma-heapbuffer (/dev/dma_heap/default_cma_region,0.220 ms) and importing it intoetnavivviaDRM_IOCTL_PRIME_FD_TO_HANDLEexecuted the PPU compute shader directly on the video buffer with bit-exact IEEE-754 float32 output (0x3ea0a000) and zero CPUmemcpy. - Path A — Live Silicon Reverse-Engineering of
HW_V83(0x9202) NN Descriptors (WIP): Comparing0x9202against every other NPU in Mesa’s HWDB revealed that Allwinner A733 is the first chip in Mesa combining four new VivanteHW_V83features. Live register and descriptor sweeps on the Cubie A7A proved every single bitfield on silicon:FP_INIMAGE_POST_SCALE = 1(NN_INT8_SCALE = 0): On earlier V8 chips (e.g. Amlogic0x8302), Mesa wroteshift = 127 - exp(e.g.8) intopost_shift. On0x9202,HW_V83interpretspost_shift(w2[31:27]+w15[29:28]+w15[30]) as the raw IEEE-754 biased exponent (scale_bits >> 23, e.g.119/120), paired with the 23-bit mantissa inpost_multiplier*(w22[25:18],w17[31:24],w15[27:22],w2[26]) and sign bit inw27[28]. Writing8multiplied every accumulator by2^(8-127) ≈ 0(producing0 + out_zero_point = 128everywhere); switching to the raw IEEE-754 exponent immediately produced real spatially-structured 3×3SAME-padded Conv2D feature maps on silicon (0.11 msper dispatch).NN_CMD_SUPPORT_SLICE = 1:w8[31:16](out_image_y_stride) andw16[31:16](in_image_y_stride) are channel-slice byte strides (x * y), not row counts (y). Programmingout_image_y_stride = 64(8 * 8) immediately wrote all 4 output channels cleanly (256/256bytes,TotalWrites = 0x20).TP_ENGINE = 0(TPEngine_CoreCount = 0): Vivante removed the hardware TP block on0x9202(replacing it with a Stream Processor,SP_VECTOR_DEPTH = 0x400). Our Mesa patch (0002-etnaviv-teflon-add-hw-v83-and-no-tp-support.patch) reportstp_core_count = 0and executes internalNHWC↔︎NCHWlayout transposes and strided reshuffles on CPU with GPU batch synchronization.MMU_PAGE_DESCRIPTOR = 1(mmu_pd_mode = 1) & Current WIP Status: Controlled live probes showed that under legacy PTA mode (0x003B4 = 0x1,0x00388 = 0x01), NN descriptor and output writes hit DRAM while NN input/coefficient DMA streams read0xFF. Cross-checking Allwinner’s vendorvip_drv_hardware.candvip_drv_mmu.cconfirmed0x9202requires nativeMODE4_KMMUv2 PDMODE (0x003B4 = ((mtlb_dma >> 12) << 4) | 0x0,0x00388 = 0x21, skippingPTA_CONTROL, plus0xffffff7fTLB flushes). On live/usr/bin/npu-smoke-test,quantized_add_8x8x3matches CPU192/192(0.002 ms), andquantized_conv2d_8x8x3x4dispatches cleanly (0.105 ms), but still hits an open NN engine DRAM-read issue (max_abs_diff = 31, constant per-channel output[104,104,104,104,92,92,92,92];run_lenet0on officiallenet_v3.nbreturns constant62). Testing vendor#[initial states kernel]+0x038C0=0, 0x038C4=1, 0x03818=1confirmed it does not yet resolve this remaining NN DRAM-read bug.
๐ฌ 7. Community Questions, Common Allwinner A733 NPU Issues & How We Addressed Them
Developers on the Radxa Forums, Armbian
Forums, and GitHub (Cubie A7A / A7Z / A7S,
Orange Pi 4 Pro, Frigate NVR, and YOLOv8/YOLO11 projects) repeatedly run
into the same set of A733 NPU roadblocks. Below is each real-world
issue, its silicon root cause, and how our mainline etnaviv
+ Mesa Teflon stack resolves it:
๐ Related Guides & Source Repositories
- Mainline Linux Kernel Tree: linux-cubie on
GitHub (branch
a7a_remoteproc_camera_usb) - Buildroot, Mesa Patches, Firmware & Tooling: cubie-a5e on GitHub
- NPU Acceleration Subsystem Guide: docs/common/NPU_ACCELERATION_GUIDE.md
- Camera & V4L2 ISP 602 Guide: docs/common/CAMERA_V4L2_GUIDE.md
- A733 Hardware Video Encoder Guide: docs/common/A733_VE_ENCODER_GUIDE.md
- Companion Hackster.io Article (On-Die 200 MHz RISC-V Core): Turning an 8-Core Desktop Processor into a Hard Real-Time Robotics & Industrial Engine