add support for upstream RKNPU/RKNN/Rocket HW AI accelerator
PATCH v3 1/1 add support for upstream RKNPU/RKNN/Rocket HW AI accelerator
From: Quentin Schulz <[email protected]>
This adds support for the NPU (Neural Processing Unit) found on the RK3588(S).
The NPU is supported by a kernel driver (CONFIG_DRM_ACCEL_ROCKET), Device Tree nodes (so not all RK3588 devices supported upstream necessarily have the NPU declared properly!) and a userspace driver in mesa (teflon delegate with rocket gallium driver).
This adds a config fragment for linux-rockchip kernels such that the disabled-by-default Rocket driver is built and enables the Rocket gallium mesa driver with the teflon delegate, but only when the user requests its support.
This was tested by running the following:
TEFLON_DEBUG=verbose python3 classification.py \ -i /usr/share/label_image/grace_hopper.bmp \ -m /usr/share/label_image/mobilenet_v1_1.0_224_quant.tflite \ -l /usr/share/label_image/labels_mobilenet_quant_v1_224.txt \ -e /usr/lib/libteflon.so
"""
from an image built with meta-tensorflow's tensorflow-lite, mesa's libteflon, meta-openembedded's python3-pillow and OE-Core's python3-numpy packages.
Note that the Aarch64 RK35xx SoCs all have an NPU, but only RK3588's is currently supported in the kernel.
AI-Generated: codex/claude-opus 5.5 (max)
---
changes in v3:
- rebase onto current master; it needed git am --3way against the kernel config fragment list
- gate the fragment and the mesa PACKAGECONFIG with bb.utils.to_boolean(d.getVar(...)) rather than oe.utils.vartrue(). vartrue() passes the variable name as a string literal, which bitbake's code parser does not track, so the do_kernel_configme signature did not change when ENABLE_UPSTREAM_RKNPU was toggled and nothing rebuilt in either direction. This idiom is tracked and matches the other knobs in the layer
- drop the kernel version from the README note, which said v7.0 while the layer builds 7.2
--- README | 20 +++++++++++++++++++ recipes-graphics/mesa/mesa.bbappend | 4 ++++ recipes-kernel/linux/linux-rockchip.inc | 1 + .../bsp/rockchip/rocket-npu.cfg | 2 ++ .../bsp/rockchip/rocket-npu.scc | 1 + 5 files changed, 28 insertions(+) create mode 100644 recipes-kernel/linux/linux-rockchip/rockchip-kmeta/bsp/rockchip/rocket-npu.cfg create mode 100644 recipes-kernel/linux/linux-rockchip/rockchip-kmeta/bsp/rockchip/rocket-npu.scc
README +20 -0
@@ -222,6 +222,26 @@ Notes: NOTE: this variable must be set before any include/require in the machine configuration file + Neural Processing Unit (NPU) + + The Aarch64 RK35xx SoCs have a Neural Processing Unit (NPU) available. + It is typically named by Rockchip as RKNPU/RKNN but upstream has decided + to use Rocket instead. At the time of writing, only RK3588's NPU is + supported upstream. + + This NPU is an AI hardware-accelerator. You can enable its support by + setting: + + ENABLE_UPSTREAM_RKNPU = "1" + + This requires a kernel driver (CONFIG_DRM_ACCEL_ROCKET, v6.18+) and + RKNN Device Tree nodes + (e.g. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=640366d644b1e282771a09c72be37162b6eda438). + The mesa userspace driver (rocket gallium driver) and teflon delegate + are automatically compiled when this option is enabled. You need to add + the libteflon package to your image to be able to use the teflon + delegate. + U-Boot Environment: ------------------ In order to configure U-Boot to be able to store its environment into the
recipes-graphics/mesa/mesa.bbappend +4 -0
@@ -10,5 +10,9 @@ MALI_DRIVER:rk3308 = "" PACKAGECONFIG:append:rockchip = " ${@bb.utils.filter('MALI_DRIVER', 'lima panfrost', d)}" PACKAGECONFIG:append:rockchip = "${@bb.utils.contains('MALI_DRIVER', 'panfrost', ' libclc', '', d)}" +# Enable teflon for upstream RKNPU/rocket support +# Requires CONFIG_DRM_ACCEL_ROCKET in Linux kernel to actually work +PACKAGECONFIG:append:rk3588s = "${@' teflon rocket' if bb.utils.to_boolean(d.getVar('ENABLE_UPSTREAM_RKNPU'), False) else ''}" + # Mali Gen10 (Valhall, supported by Panthor) requires a firmware blob RRECOMMENDS:mesa-megadriver:append:rk3588s = " linux-firmware-mali-csffw-arch108"
recipes-kernel/linux/linux-rockchip.inc +1 -0
@@ -37,3 +37,4 @@ SRC_URI:append:nanopi-r4s = " file://realtek-r8169.cfg" KERNEL_FEATURES:append:rockchip = " bsp/rockchip/lttng.scc" KERNEL_FEATURES:append:rockchip:arm = " bsp/rockchip/remove-non-rockchip-arch-arm.scc" KERNEL_FEATURES:append:rockchip:aarch64 = " bsp/rockchip/remove-non-rockchip-arch-arm64.scc" +KERNEL_FEATURES:append:rockchip = "${@' bsp/rockchip/rocket-npu.scc' if bb.utils.to_boolean(d.getVar('ENABLE_UPSTREAM_RKNPU'), False) else ''}"
recipes-kernel/linux/linux-rockchip/rockchip-kmeta/bsp/rockchip/rocket-npu.cfg new file +2 -0
@@ -0,0 +1,2 @@ +CONFIG_DRM_ACCEL=y +CONFIG_DRM_ACCEL_ROCKET=y
recipes-kernel/linux/linux-rockchip/rockchip-kmeta/bsp/rockchip/rocket-npu.scc new file +1 -0
@@ -0,0 +1 @@ +kconf hardware rocket-npu.cfg
Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
Quoted 37 lines · Trevor Woerner
From: Quentin Schulz <[email protected]>
This adds support for the NPU (Neural Processing Unit) found on the RK3588(S).
The NPU is supported by a kernel driver (
CONFIG_DRM_ACCEL_ROCKET), Device Tree nodes (so not all RK3588 devices supported upstream necessarily have the NPU declared properly!) and a userspace driver in mesa (teflon delegate with rocket gallium driver).This adds a config fragment for linux-rockchip kernels such that the disabled-by-default Rocket driver is built and enables the Rocket gallium mesa driver with the teflon delegate, but only when the user requests its support.
This was tested by running the following:
TEFLON_DEBUG=verbose python3 classification.py \ -i /usr/share/label_image/grace_hopper.bmp \ -m /usr/share/label_image/mobilenet_v1_1.0_224_quant.tflite \ -l /usr/share/label_image/labels_mobilenet_quant_v1_224.txt \ -e /usr/lib/libteflon.so"""
from an image built with meta-tensorflow's tensorflow-lite, mesa's libteflon, meta-openembedded's python3-pillow and OE-Core's python3-numpy packages.
Note that the Aarch64 RK35xx SoCs all have an NPU, but only RK3588's is currently supported in the kernel.
Signed-off-by Quentin Schulz <[email protected]>AI-Generated: codex/claude-opus 5.5 (max)
Signed-off-by Trevor Woerner <[email protected]>
Quoted 13 lines
---
changes in v3:
- rebase onto current master; it needed git am --3way against the kernel config fragment list
- gate the fragment and the mesa PACKAGECONFIG with bb.utils.to_boolean(d.getVar(...)) rather thanoe.utils.vartrue().vartrue()passes the variable name as a string literal, which bitbake's code parser does not track, so thedo_kernel_configmesignature did not change whenENABLE_UPSTREAM_RKNPUwas toggled and nothing rebuilt in either direction. This idiom is tracked and matches the other knobs in the layer
- drop the kernel version from the README note, which said v7.0 while the layer builds 7.2
Why I added the kernel version is because "at the time of writing" means nothing to the user unless they go dig into the git history, then compare the date to the one in openembedded-core, and then check the linux-yocto kernel recipe version at that point in time.
Thanks!
Quentin
Quoted 54 lines · Quentin Schulz
Quoted 37 lines · Trevor Woerner
From: Quentin Schulz <[email protected]>
This adds support for the NPU (Neural Processing Unit) found on the RK3588(S).
The NPU is supported by a kernel driver (
CONFIG_DRM_ACCEL_ROCKET), Device Tree nodes (so not all RK3588 devices supported upstream necessarily have the NPU declared properly!) and a userspace driver in mesa (teflon delegate with rocket gallium driver).This adds a config fragment for linux-rockchip kernels such that the disabled-by-default Rocket driver is built and enables the Rocket gallium mesa driver with the teflon delegate, but only when the user requests its support.
This was tested by running the following:
TEFLON_DEBUG=verbose python3 classification.py \ -i /usr/share/label_image/grace_hopper.bmp \ -m /usr/share/label_image/mobilenet_v1_1.0_224_quant.tflite \ -l /usr/share/label_image/labels_mobilenet_quant_v1_224.txt \ -e /usr/lib/libteflon.so"""
from an image built with meta-tensorflow's tensorflow-lite, mesa's libteflon, meta-openembedded's python3-pillow and OE-Core's python3-numpy packages.
Note that the Aarch64 RK35xx SoCs all have an NPU, but only RK3588's is currently supported in the kernel.
Signed-off-by Quentin Schulz <[email protected]>AI-Generated: codex/claude-opus 5.5 (max)
Signed-off-by Trevor Woerner <[email protected]>Quoted 13 lines
---
changes in v3:
- rebase onto current master; it needed git am --3way against the kernel config fragment list
- gate the fragment and the mesa PACKAGECONFIG with bb.utils.to_boolean(d.getVar(...)) rather thanoe.utils.vartrue().vartrue()passes the variable name as a string literal, which bitbake's code parser does not track, so thedo_kernel_configmesignature did not change whenENABLE_UPSTREAM_RKNPUwas toggled and nothing rebuilt in either direction. This idiom is tracked and matches the other knobs in the layer
- drop the kernel version from the README note, which said v7.0 while the layer builds 7.2
Quoted 6 lines
Why I added the kernel version is because "at the time of writing" means nothing to the user unless they go dig into the git history, then compare the date to the one in openembedded-core, and then check the linux-yocto kernel recipe version at that point in time.
Reviewed-by Quentin Schulz <[email protected]>
I restored your v7.0 parenthetical, added your Reviewed-by tag, and otherwise merged this v3 to meta-rockchip, master branch. Thanks!
Quoted 2 lines
Thanks!
Quentin