NPU kernel module not available on Debian 11

Hello,

I’m running Debian 11 on my Rock5 B with the following kernel:

Linux rock-5b 5.10.110-37-rockchip-g74457be0716d #rockchip SMP Mon Feb 6 09:18:21 UTC 2023 aarch64 GNU/Linux

The system is running fine and running some critical workloads for me. However, I would like to start using the NPU and I’m currently stuck because the kernel I’m currently running has no rknpu module available.

How can I build this kernel module? I would like to load this kernel module without having to start from a new image given the existing workload running on my rock5.

Thx,

Thibault

1 Like

Maybe it’s a built-in module, so you don’t see the module.

CONFIG_ROCKCHIP_RKNPU=y

Thank you @avaf! Could be indeed.
Where should I add this configuration line? I could not find a single page on the internet referencing this.
Here is the error I get when trying to run the yolov5 demo:

thibault@rock-5b:~/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux$ ./rknn_yolov5_demo ../../model/RK3588/yolov5s-640-640.rknn ../../model/bus.jpg
post process config: box_conf_threshold = 0.25, nms_threshold = 0.45
Read ../../model/bus.jpg ...
img width = 640, img height = 640
Loading mode...
E RKNN: [20:42:36.283] failed to open rknpu module, need to insmod rknpu dirver!
E RKNN: [20:42:36.284] failed to open rknn device!
rknn_init error ret=-1

export LD_LIBRARY_PATH=./lib
./rknn_yolov5_demo ./model/RK3588/yolov5s-640-640.rknn ./model/bus.jpg

Based on latest RKNN:

export LD_LIBRARY_PATH=./lib should point to runtime lib in your project:
./runtime/RK3588/Linux/librknn_api/aarch64/librknnrt.so

I already did that step, here is the error if the lib is not found:

./rknn_yolov5_demo: error while loading shared libraries: librknnrt.so: cannot open shared object file: No such file or directory

My problem is due to the missing rknn module and device:

E RKNN: [20:42:36.283] failed to open rknpu module, need to insmod rknpu dirver!
E RKNN: [20:42:36.284] failed to open rknn device!

Try with sudo.

Or check if your running kernel configuration has CONFIG_ROCKCHIP_RKNPU

1 Like

Thank you! It worked with sudo :slight_smile:
I’m glad to know my NPU is working, however not so much that sudo is needed to use it…
Is it only for those compiled programs or will I need it too when calling from Python?

I can’t remember if i did something to run without sudo.

Try something like this:
move librknnrt.so to /usr/lib/
and then sudo ldconfig

Or you need to add a udev rule.

1 Like

Looks like I need the udev rule, thank you for the stellar support!

1 Like

hello, i’m getting this error with ubuntu server on rockpi5:

  1. libEGL warning: MESA-LOADER: failed to open rknpu: /usr/lib/dri/rknpu_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/aarch64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)

my goal is to do headless opengl rendering. any hint how to fix this?

I Have the same problem with radxa-zero3_debian_bullseye_xfce_b6.
I checked with

zcat /proc/config.gz | grep NPU

, it showed that checked

  # RKNPU
    CONFIG_ROCKCHIP_RKNPU=y
    CONFIG_ROCKCHIP_RKNPU_DEBUG_FS=y
    # CONFIG_ROCKCHIP_RKNPU_PROC_FS is not set
    # CONFIG_ROCKCHIP_RKNPU_FENCE is not set
    # CONFIG_ROCKCHIP_RKNPU_SRAM is not set
    CONFIG_ROCKCHIP_RKNPU_DRM_GEM=y
    # end of RKNPU

but dmesg show nothing

Is ther a way to compile the kernel again?

I didn’t need to recompile the kernel to get the NPU running, my method is as follows;

Flashed Debian CLI B39 image from here

Updated APT repository

apt update

Download the RKNN libraries built here

wget https://github.com/radxa-pkg/rknn2/releases/download/1.6.0-2/rknpu2-rk3588_1.6.0-2_arm64.deb
wget https://github.com/radxa-pkg/rknn2/releases/download/1.6.0-2/python3-rknnlite2_1.6.0-2_arm64.deb
wget https://github.com/radxa-pkg/rknn2/releases/download/1.6.0-2/python3-rknnlite2-example_1.6.0-2_all.deb

Install the packages downloaded

apt install ./rknpu2-rk3588_1.6.0-2_arm64.deb ./python3-rknnlite2_1.6.0-2_arm64.deb ./python3-rknnlite2-example_1.6.0-2_all.deb

Rebooted.

Then ran the inference test script;

cd /usr/share/python3-rknnlite2/resnet18/
python test.py 

Which gives the output;

--> Load RKNN model
done
--> Init runtime environment
I RKNN: [02:31:33.412] RKNN Runtime Information, librknnrt version: 1.6.0 (9a7b5d24c@2023-12-13T17:31:11)
I RKNN: [02:31:33.413] RKNN Driver Information, version: 0.8.2
W RKNN: [02:31:33.413] Current driver version: 0.8.2, recommend to upgrade the driver to the new version: >= 0.8.8
I RKNN: [02:31:33.417] RKNN Model Information, version: 6, toolkit version: 1.6.0+81f21f4d(compiler version: 1.6.0 (585b3edcf@2023-12-11T07:42:56)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_shape
W RKNN: [02:31:33.447] query RKNN_QUERY_INPUT_DYNAMIC_RANGE error, rknn model is static shape type, please export rknn with dynamic_shapes
W Query dynamic range failed. Ret code: RKNN_ERR_MODEL_INVALID. (If it is a static shape RKNN model, please ignore the above warning message.)
done
--> Running model
resnet18
-----TOP 5-----
[812] score:0.999676 class:"space shuttle"
[404] score:0.000249 class:"airliner"
[657] score:0.000014 class:"missile"
[833] score:0.000009 class:"submarine, pigboat, sub, U-boat"
[466] score:0.000009 class:"bullet train, bullet"

done