Running rknn model in ROCK 5C lite

I have a radxa rock 5c lite SBC which I am running a yolov5s rknn model. I installed rock-5c_bookworm_cli_b1.output.img OS to the board. I am using the example from the rknn_model_zoo to convert and test my models

from rknnlite.api import RKNNLite as RKNN
import logging
import numpy as np

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

class RKNN_model_container():
    def __init__(self, model_path, target='rk3588', device_id=None) -> None:
        self.rknn = RKNN()  # Create instance of RKNN

        # Direct Load RKNN Model
        ret = self.rknn.load_rknn(path=model_path)  # Added 'path=' keyword argument
        if ret != 0:
            raise RuntimeError(f"Failed to load RKNN model, error code: {ret}")
            
        ret = self.rknn.init_runtime()
        if ret != 0:
            raise RuntimeError(f"Failed to init runtime, error code: {ret}")

The board has been inferencing the model perfectly until recently it has been bring up issue with the rknpu driver.

W rknn-toolkit-lite2 version: 2.3.0
E RKNN: [21:14:26.243] failed to open rknpu module, need to insmod rknpu dirver!
E RKNN: [21:14:26.243] failed to open rknn device!
E Catch exception when init runtime!
E Traceback (most recent call last):
  File "/home/radxa/Yolo_test/rknn/lib/python3.11/site-packages/rknnlite/api/rknn_lite.py", line 157, in init_runtime
    self.rknn_runtime.build_graph(self.rknn_data, self.load_model_in_npu)
  File "rknnlite/api/rknn_runtime.py", line 921, in rknnlite.api.rknn_runtime.RKNNRuntime.build_graph
Exception: RKNN init failed. error code: RKNN_ERR_FAIL

I have been trying to reinstall the OS, updating the kernel 6.1.84-7-rk2410 and even copying librknnrt.so to '/usr/lib/ directory but still the issue is still showing up. How can I fix this issue?

If it was working before and then suddenly doesn’t, then something has been broken. You mention you tried updating the OS, how are you doing that? Doing apt upgrade is not recommended, instead you have to update via rsetup otherwise it maybe installing the wrong kernel which would explain why the rknpu module is not available.

You can test that by checking dmesg for any NPU related errors;

sudo dmesg | grep -i rknpu

Thank you for hour reply. I reinstalled the OS again and did the command

radxa@rock-5c:~$ sudo dmesg | grep -i rknpu
radxa@rock-5c:~$

It was blank but when I did

radxa@rock-5c:~$ sudo dmesg | grep -i npu
[sudo] password for radxa:
[   12.215920] rk_gmac-dwmac fe1c0000.ethernet: clock input or output? (output).
[   12.378092] input: rk805 pwrkey as /devices/platform/feb20000.spi/spi_master/spi2/spi2.0/rk805-pwrkey.5.auto/input/input0
[   12.414278] input: rockchip-hdmi0 rockchip-hdmi0 as /devices/platform/hdmi0-sound/sound/card0/input1
[   12.468064] rockchip-pm-domain fd8d8000.power-management:power-controller: Looking up npu-supply from device tree
[   12.468084] rockchip-pm-domain fd8d8000.power-management:power-controller: Looking up npu-supply property in node /power-management@fd8d8000/power-controller failed
[   15.410189] input: dw_hdmi_qp as /devices/platform/fde80000.hdmi/rc/rc0/input2
[   15.488544] input: headset-keys as /devices/platform/es8316-sound/input/input3
[   27.758541] platform fdab0000.npu: deferred probe pending
``` What might be the issue?

That seems strange for a Radxa OS image for the NPU driver to not be loaded.

The only thing I can think of is to go to rsetup and see if there is an option to turn on the NPU then reboot. I have only had to do that with the Zero 3E, but not with the 5C.

There is also a newer b2 OS image available you could try.

Thank you again for the reply. I installed the rock-5c_bookworm_cli_b2.output.img_.xz from the link you provided for me and retried to check the npu but still it shows the same issue

radxa@rock-5c:~$ uname -r
6.1.84-6-rk2410
radxa@rock-5c:~$ sudo dmesg | grep -i npu
[sudo] password for radxa:
[   12.516151] rk_gmac-dwmac fe1c0000.ethernet: clock input or output? (output).
[   12.679391] input: rk805 pwrkey as /devices/platform/feb20000.spi/spi_master/spi2/spi2.0/rk805-pwrkey.4.auto/input/input0
[   12.808723] rockchip-pm-domain fd8d8000.power-management:power-controller: Looking up npu-supply from device tree
[   12.808743] rockchip-pm-domain fd8d8000.power-management:power-controller: Looking up npu-supply property in node /power-management@fd8d8000/power-controller failed
[   13.221276] input: dw_hdmi_qp as /devices/platform/fde80000.hdmi/rc/rc0/input1
[   17.850096] input: headset-keys as /devices/platform/es8316-sound/input/input2
[   17.887023] input: rockchip-hdmi0 rockchip-hdmi0 as /devices/platform/hdmi0-sound/sound/card0/input3
[   30.346363] platform fdab0000.npu: deferred probe pending

I also checked rsetup overlays list but no npu enable option. Can the hardware malfunction lead to this issue?

Try armbian image instead.

nyanmisaka@rock-5c:~$ uname -r
6.1.115-vendor-rk35xx
nyanmisaka@rock-5c:~$ sudo dmesg | grep -i rknpu
[   11.520579] RKNPU fdab0000.npu: Adding to iommu group 0
[   11.520737] RKNPU fdab0000.npu: RKNPU: rknpu iommu is enabled, using iommu mode
[   11.520834] RKNPU fdab0000.npu: Looking up rknpu-supply from device tree
[   11.521594] RKNPU fdab0000.npu: Looking up mem-supply from device tree
[   11.522115] RKNPU fdab0000.npu: can't request region for resource [mem 0xfdab0000-0xfdabffff]
[   11.522145] RKNPU fdab0000.npu: can't request region for resource [mem 0xfdac0000-0xfdacffff]
[   11.522164] RKNPU fdab0000.npu: can't request region for resource [mem 0xfdad0000-0xfdadffff]
[   11.522899] [drm] Initialized rknpu 0.9.8 20240828 for fdab0000.npu on minor 1
[   11.523880] RKNPU fdab0000.npu: Looking up rknpu-supply from device tree
[   11.525428] RKNPU fdab0000.npu: RKNPU: Failed to get specification_serial_number
[   11.525440] RKNPU fdab0000.npu: Failed to get specification_serial_number
[   11.525459] RKNPU fdab0000.npu: Failed to get leakage
[   11.525483] RKNPU fdab0000.npu: Looking up rknpu-supply from device tree
[   11.525505] debugfs: Directory 'fdab0000.npu-rknpu' with parent 'vdd_npu_s0' already present!
[   11.535814] RKNPU fdab0000.npu: pvtm=918
[   11.544517] RKNPU fdab0000.npu: pvtm-volt-sel=5
[   11.544585] RKNPU fdab0000.npu: Looking up rknpu-supply from device tree
[   11.544615] debugfs: Directory 'fdab0000.npu-rknpu' with parent 'vdd_npu_s0' already present!
[   11.545247] RKNPU fdab0000.npu: Looking up mem-supply from device tree
[   11.546931] RKNPU fdab0000.npu: avs=0
[   11.547042] RKNPU fdab0000.npu: rockchip_pvtpll_set_volt_sel: error cfg clk_id=6 voltsel (-1)
[   11.547220] RKNPU fdab0000.npu: l=15000 h=85000 hyst=5000 l_limit=0 h_limit=800000000 h_table=0
1 Like

Sorry for taking so long to reply but had difficult configuring armbian especially ssh but I noticed the same issue with armbian os. I think is hardware related