🛠 Exploiter le NPU 5 TOPS de l'A311D pour l'inférence embarquée
Objectives
The Amlogic A311D features a NPU advertised at 5 TOPS — the BPI-CM4's selling point against a Broadcom CM4: the vendor emphasizes the absence of an external accelerator like the Google Coral. However, the NPU stack resides in Amlogic/BSP binaries, not in the mainline kernel: the recommended path according to the wiki is to boot a Khadas VIM3 rootfs image (same A311D SoC), which provides the complete NPU demo chain. You will verify NPU visibility depending on the image, boot the VIM3 rootfs from microSD, run a classification inference, and then compare CPU (6 cores) versus NPU performance.
Hardware
- BPI-CM4 + carrier board, 5 V / 3 A power supply
- Blank microSD card dedicated to the VIM3 rootfs (the eMMC must be erased to boot from SD, see first boot tutorial)
- Khadas VIM3 rootfs image (linked from the third-party section of the BPI-CM4 wiki) + HDMI display
- Optional: USB camera for live detection
Full Code
# 1) Sur l'image vendor (BSP 4.9) : vérifier la présence de la pile Amlogic
dmesg | grep -i -e npu -e mali
ls /dev/ | grep -i -e npu -e vpu
# 2) Amorcer le rootfs VIM3 sur la microSD (même famille meson-g12b)
sudo dd if=vim3-ubuntu-rootfs.img of=/dev/sdX bs=8M status=progress conv=fsync
# 3) Sur le système VIM3 booté : récupérer la suite de démo NPU Khadas
sudo apt update && sudo apt install -y git build-essential
git clone https://github.com/khadas/khadas-fptl && cd khadas-fptl
./install_dependencies.sh && make
# Exécuter une classification MobileNet sur une image
./demo/demo_classification_mobilenet ./model/mobilenet_v1/fp_np/ ./res/cat.jpg
Expected Verification
The demo prints ImageNet classes with scores and inference time per image; repeating the same workload using TFLite on the 6 CPU cores highlights the difference in latency and power consumption. On a mainline kernel (Armbian), no usable NPU interface is expected: this is a documented limitation, not a failure.
Common Errors
- Expecting an NPU device under mainline Armbian: the Amlogic stack is not present there; the on-chip alternative remains the Mali-G52 GPU (Panfrost).
- Confusing NPU and GPU: Panfrost (OpenGL ES/Vulkan) does not run Amlogic NPU demos.
- Forgetting that the VIM3 rootfs is designed for the VIM3: some peripherals on the BPI carrier (mini-PCIe, ADC button) may lack support.
- Leaving a bootable eMMC that hides the SD boot of the demo rootfs.
- Running demos without a heatsink: throttling at 70 °C skews any latency measurement.
Other tutorials for this board
- Monter le module BPI-CM4 sur son carrier et réussir le premier boot
- Apprivoiser les LED et la touche ADC du carrier CM4IO
- Mesurer le stockage du BPI-CM4 : eMMC, microSD et le palier NVMe
- Activer I2C, SPI et UART sur le BPI-CM4 : env.txt ou armbianEnv.txt
- Brancher un capteur BME280 sur l'I2C1 du carrier (GPIOX_17/18)
- Déplacer le rootfs sur un SSD NVMe via le port mini-PCIe
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash