Freeing the Allwinner A733 3.0 TOPS NPU on Mainline Linux 7.1: 203 FPS MobileNetV1 & the 10 Driver and Software Bugs We Solved
By Tim Michals
Embedded Linux, Edge AI & Robotics Engineering Blog
Spend ten minutes browsing the Radxa Forums, Armbian Forums, or GitHub issues for the Allwinner A733 (Radxa Cubie A7A / A7Z / A7S, Orange Pi 4 Pro), and you will see developers hitting the exact same brick walls:
- "Why does
vpm_runcrash with*_t527.nbmodels?" - "Why did
vip_initbreak after updating my OS image (2.0.3.4vs2.0.3.2)?" - "Why are my Frigate NVR / YOLOv8 bounding boxes completely scrambled?"
- "Why won't
aw_nna_vipcompile on Linux 6.6 / 6.18 / 7.1?" - "Why does Mesa Teflon output all
128(0x80), ignore input DRAM reads, or hang on1×1pointwise layers on0x9202?"
We brought up the Allwinner A733 NPU from scratch on mainline Linux 7.1.0 PREEMPT_RT (drivers/gpu/drm/etnaviv) + Mesa 26.1.7 Teflon on live Radxa Cubie A7A silicon — with zero proprietary VIPLite/Acuity blobs and zero GPU hangs.
Headline Live Silicon Results (Linux 7.1.0, 1008 MHz, Zero Vendor Blobs)
| Workload | Mainline NPU (Teflon / etnaviv) | Throughput | Accuracy vs. TFLite CPU |
|---|---|---|---|
All 6 /usr/bin/npu-smoke-test models | 0.099–0.141 ms | — | 100% bit-exact (max_diff = 0, Cosine = 1.000000) |
All 65 MobileNetV2 single layers (000..064) | 1.42–21.9 ms | — | 65/65 PASS (CONV: max_diff = 0; DWCONV: max_diff = 1, Cosine ≥ 0.999994) |
Full MobileNetV1 (224×224, 4.1 MB) | 4.92 ms | 203 FPS | 994 / 1001 exact, Cosine = 0.999958 (~4× faster than Cortex-A76 CPU) |
Full MobileNetV2 (224×224, 3.5 MB) | 5.37 ms | 186 FPS | 3.3× faster than Cortex-A76 CPU (17.9 ms), zero hangs |
Full InceptionV1 (224×224, 6.5 MB) | 18.66 ms | 53.6 FPS | 2× faster than Cortex-A76 CPU (36.5 ms), Cosine = 0.999624 |
Vivante PPU Compute Shader (npu-ppu-test) | 0.073 ms | 13,700/s | 5/5 bit-exact IEEE-754 float32 |
Zero-Copy V4L2 /dev/video0 → PRIME → NPU | 0.803 ms | 1,245/s | Bit-exact, zero CPU frame copies |
Here are the 10 concrete driver, bring-up, and Mesa software bugs we hunted down and solved, how each interacts with the A733 hardware, and where to grab every patch.
Problem 1: Marketing Specs vs. Live Silicon Identity (Why T527 .nb Files Crash A733)
The Problem: Early community notes assumed the A733 used Allwinner's 12-core 0x9113 NPU, and developers routinely tried running T527 (*_t527.nb) models on A733 boards—hitting immediate vpm_run crashes.
What Live Silicon Proved: Reading /sys/kernel/debug/dri/0/gpu on the Cubie A7A proved the A733 silicon is model 0x9000, revision 0x9202, product_id 0x05090009, customer_id 0x1000003b (VeriSilicon VIP9000Nano-DI, HW_V83, chip date 2023-05-18).
Comparing it to T527 (0x9003, cid 0x10000016) explains why .nb binaries can never cross between them:
- T527 (
0x9003): 6 NN cores, 2 TP cores,NN_CMD_SUPPORT_SLICE = 0,FP_INIMAGE_POST_SCALE = 0,MMU_PAGE_DESCRIPTOR = 0. - A733 (
0x9202): 8 NN cores, 0 TP cores (TP_ENGINE = 0),HW_V83 = 1,NN_CMD_SUPPORT_SLICE = 1,FP_INIMAGE_POST_SCALE = 1,MMU_PAGE_DESCRIPTOR = 1.
The Fix: Added exact 0x9202 HWDB entries to both mainline kernel etnaviv_hwdb.c and Mesa (0001-etnaviv-hwdb-add-allwinner-npu-feature-database.patch). Because Mesa Teflon compiles standard .tflite flatbuffers on-device at runtime, the exact same .tflite file runs across A733, T527, i.MX8MP, and Amlogic—no Acuity Docker container and no per-SoC .nb exports.
Problem 2: Vendor aw_nna_vip Build Failures & VIPLite Version Hell
The Problem: Vendor BSP users constantly hit vip_init failures from kernel/userspace version drift (2.0.3.4-AW vs 2.0.3.2) and missing aw_nna_vip headers (sunxi-autogen.h) on Linux 6.6–7.1.
The Fix: Dropped the 44,000-line out-of-tree aw_nna_vip module entirely and bound npu@3600000 directly to in-tree mainline drivers/gpu/drm/etnaviv (/dev/dri/renderD128) paired with Buildroot-compiled Mesa 26.1.7 libteflon.so. Zero proprietary blobs, zero ABI drift.
Problem 3: 0x03600000 Bus Hangs (4 Clocks, 4 Resets, PD_NPU & 1008 MHz)
The Problem: Reading 0x03600000 hangs the A733 bus unless every piece of its power/clock/reset hierarchy is active:
- PCK-600 power domain
PD_NPU(domain 4) and AXP8191dcdc2(800 mV) must be on. - Register access traverses two series AHB gates:
CLK_AHB_NPU(0x05c0bit 6) andCLK_BUS_NPU(0x0b04bit 0). - DMA stalls silently if
CLK_MBUS_NPU(0x05e0bit 18,600 MHz) isn't enabled. - A733 splits NPU resets across 4 separate bits in
0x0b04(COREbit 16,AXIbit 17,AHBbit 18,SRAMbit 19), whereas mainlineetnavivonly fetched one reset line.
The Fix: Parented bus_npu_clk to ahb_npu_clk in ccu-sun60i-a733.c, switched etnaviv_gpu_platform_probe() to devm_reset_control_array_get_optional_exclusive(), and configured npu@3600000 at 1008 MHz (PLL_NPU, matching stock Radxa Bullseye 5.15, verified stable at 800 mV / 42.5 °C with GIC_SPI 65 firing cleanly).
Problem 4: Cracking MMUv2 PDMODE (MODE1_K, 0x00184, MTLB[0] VIP SRAM & initcmd)
The Problem: On 0x9000 rev >= 0x9100, legacy PTA mode (0x003B4 = 1, 0x00388 = 1) failed to feed NN input/weight DMA streams, and mainline etnaviv's SZ_4K IOVA allocator placed NN buffers at VA 0x00041000..0x00045000—colliding directly with the default 512 KB on-chip VIP SRAM window (0x00000000..0x0007ffff).
The Fix (verified against live Radxa 5.15 MMUv2 page tables):
- Programmed true
MODE1_KPDMODE (256MTLB entries ×16 MB,SZ_16K4 KB STLBs,0x003B4 = ((mtlb_dma >> 12) << 4) | 1,0x00388 = 0x21,0x0055C = 0x00FFFFFF,0x00090 |= BIT(6)). - Reserved
MTLB[0](0x00000000..0x00ffffff) in 1 MB page mode (stlb0_dma | 0x9) withSTLB[0][0..5] = 0x5for VIP SRAM remapped to0x00400000, and started DRAM IOVAs atSZ_16M(0x01000000). - Fixed the
VIVS_MMUv2_CONFIGURATION(0x00184) TLB flush trap: writing0xffffff7finstead of0x00000018preserves the page-table base on every dynamic BO flush. - Emitted the 36-word VIP9000
initcmd(0x3954 = 0x03010000..7× 8 NN cores,0x3938 = 0x00400000,0x0a28,0x3848,0x384c,0x3884,0x08b0) and fixed0x00100 = 0x00140021,0x00104 = 0,0x0010C = (val & ~BIT(16)) | BIT(17).
Problem 5: The Final Boss — SYSCTRL 0x03000008 Bit 1 (512 KB Shared VIP SRAM Ownership)
The Problem: Even after matching vipcore.ko's MODE1_K page tables, initcmd, and power registers—and even in an MMU-OFF (0x0388 = 0) bisection on 32-bit physical dma_alloc_wc buffers—the NN Top Controller read config headers and wrote output bytes cleanly, yet the 8 NN Core streamers still ignored DRAM input/weight changes (while PPU shaders passed 10/10!).
The Breakthrough (Live Radxa Bullseye 5.15 Oracle): Running v3/lenet.nb natively on Radxa's stock Bullseye 5.15 image (/dev/vipcore) worked 100% (orig, 0x00, 0xff all produced valid distinct outputs), and every single NPU MMIO register (0x03600000..0x0664) and NSI M18 register matched Linux 7.1 identically. Only one SoC register differed:
SYSCTRL 0x03000008: Bullseye 5.15 =0x00000000, Linux 7.1 =0x00000002!- Bit 1 of
SYSCTRL+0x08switches the A733's 512 KB shared VIP SRAM between CPU/E902 (1, hardware reset default) and the NPU (0). - Live bidirectional proof: Writing
0x03000008 = 0x2on working Bullseye 5.15 immediately broke/hunglenet.nb(VIPDRV_WAIT_TASKtimeout); restoring0x0immediately fixed it. (And E902 is completely unaffected—our E902 firmware runs in its DRAM carveout + SRAM A2.)
The Fix: Added allwinner,sun60i-a733-system-control (sun60i_a733_sramc_variant) in drivers/soc/sunxi/sunxi_sram.c + sun60i-a733-cubie-a7a.dts to clear SYSCTRL+0x08 bit 1 at boot. Immediately, all 6 /usr/bin/npu-smoke-test models passed 100% bit-exact (max_diff = 0, Cosine = 1.000000) on clean cold boot!
Problem 6: HW_V83 NN Descriptors (FP_INIMAGE_POST_SCALE & NN_CMD_SUPPORT_SLICE)
The Problem: A733 0x9202 is the first chip in Mesa with FP_INIMAGE_POST_SCALE = 1 (NN_INT8_SCALE = 0) and one of only three with NN_CMD_SUPPORT_SLICE = 1. Unmodified Mesa output 128 (0x80) everywhere and only wrote 1 of 4 channels.
The Fix (0002-etnaviv-teflon-add-hw-v83-and-no-tp-support.patch):
FP_INIMAGE_POST_SCALE = 1: Pass the raw IEEE-754 biased exponent (scale_bits >> 23, including bit 7 inw15[30]) directly alongside the 23-bit mantissa.NN_CMD_SUPPORT_SLICE = 1: Programin_image_y_strideandout_image_y_strideas channel-slice byte strides (x * y), not row counts (y).NN_TENSOR_ADD_FIELD_MOVE_TO_EXT_CMD = 1: Decline legacy v8ADD/SUBTRACTcleanly so TFLite runs them on CPU until extended-commandADDlowering is added.
Problem 7: Large-Tile 1×1 & Stride-2 Hangs (0x3930, 0x3968, 192-Byte Extended Descriptor)
The Problem: Even after npu-smoke-test passed 6/6, real MobileNetV2 layers with h ≥ 36 (002.tflite, 004.tflite, 010.tflite) hung the NN engine after ~1,442 cycles (IDLE = 0x7FFBFFF6, zero MMU/AXI faults).
The Fix (0003-etnaviv-teflon-hw-v83-ext-cmd-and-nn-config.patch): Matched the exact HW_V83 dispatch state captured from v3/lenet.nb:
- Extended
struct etna_nn_paramsto 192 bytes (w27 = 0x00015000,w28 = 0,w31 = 4,w35 = 0x07ffffff). - Emitted
VIVS_GL_NN_CONFIG (0x3930) = 0x0493e040,0x3968 = 0x00451440, andVIVS_PS_NN_INST_ADDR (0x10a0) = va_nn | 1.
That eliminated 100% of GPU hangs across all 65 MobileNetV2 layers (000..064), full MobileNetV1, full MobileNetV2, full InceptionV1, and YOLOX-Nano.
Problem 8: TP_ENGINE = 0 & the 6.3× Uncached ETNA_BO_WC Transpose Speedup
The Problem: Upstream Mesa forced tp_core_count = 1 even when db->TP_ENGINE == 0, turning TRANSPOSE/DETRANSPOSE into silent no-ops that zeroed output tensors. Once we added a scalar CPU fallback (0002), MobileNetV2 ran in 17.3 ms and InceptionV1 took 118.4 ms because strided 1-byte reads/writes directly on uncached write-combining (ETNA_BO_WC) GPU buffers stalled the memory bus on every byte!
The Fix (0004-etnaviv-teflon-fast-cached-neon-tp-cpu.patch): Stage ETNA_BO_WC buffers with linear memcpy bursts through cached L1/L2 RAM and run an AArch64 NEON 8×8 vtrn transpose before writing back linearly:
MobileNetV1:10.26 ms→4.92 ms(203 FPS)MobileNetV2:17.33 ms→5.37 ms(186 FPS)InceptionV1:118.38 ms→18.66 ms(53.6 FPS— 6.3× speedup!)mobilenetv2/010:11.12 ms→1.65 ms(451,584/451,584exact)
Problem 9: Post-Processing Accuracy (NMS, TopK, Softmax)
The Problem: Forcing NMS, TopK, or Softmax through INT8 quantization inside a monolithic .nb binary destroys bounding-box precision.
The Fix: Because Mesa Teflon plugs in as a standard TFLite external delegate, heavy quantized convolutions run on the 8× NN cores while precision-sensitive float32 post-processing stays seamlessly on the Arm Cortex-A76/A55 CPU—zero manual model surgery.
Problem 10: Unlocking General-Purpose Vivante PPU Compute Shaders & Zero-Copy V4L2 PRIME
The Problem: Proprietary VIPLite .nb blobs hide the NPU's programmable Vivante PPU shader core completely.
The Fix: Built and verified npu_ppu_compute_test.c (28-DWORD deterministic PPU compute shader with explicit u2 uniform, 0.073 ms, 5/5 bit-exact IEEE-754 float32) and npu_v4l2_dmabuf_test.c (0.803 ms, zero-copy /dev/video0 VIDIOC_EXPBUF → DRM_IOCTL_PRIME_FD_TO_HANDLE → etnaviv PPU shader).
Where to Grab the Code & Patches
- Mainline Linux 7.1 Kernel (
sunxi_sram+etnavivPDMODE + A733 CCU/DT/ISP/VE/RemoteProc): linux-cubie (a7a_remoteproc_camera_usb) - Mesa 26.1.7 Teflon Patches & Tools (cubie-a5e):
- Companion Guides:
No comments:
Post a Comment