> For the complete documentation index, see [llms.txt](https://zito.gitbook.io/rknn_usermanual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zito.gitbook.io/rknn_usermanual/3.-rknn-toolkit2.md).

# 3. rknn-toolkit2 설치하기

## rknn-toolkit2

rknn-toolkit2는 x86 계열 리눅스 컴퓨터에 설치하는 것을 권장합니다. (arm 계열 지원하지 않음)

<figure><img src="/files/f8oga8ZabVEYouPhgX82" alt="" width="563"><figcaption></figcaption></figure>

```bash
$ mkdir rknn_project 
$ git clone https://github.com/airockchip/rknn-toolkit2.git
$ conda create -n rknn python=3.8
$ conda activate rknn
$ pip3 install -r rknn-toolkit2/packages/requirements_cp38.txt
$ pip3 install rknn-toolkit2/packages/rknn_toolkit2-2.0.0b0+9bab5682-cp38-cp38-linux_x86_64.whl 
```

설치를 완료하면&#x20;

```python
$ python3
>> from rknnlite.api import RKNNLite
```

으로 설치가 정상적으로 되었는지 확인할 수 있습니다.&#x20;

## rknn-toolkit-lite2

rknn-toolkit-lite2는 오렌지 파이에 설치 가능합니다. 마찬가지로 rknn\_toolkit2 깃헙 레포지토리를 clone 하고, 시스템 Python 버전에 맞춰서 whl 파일을 설치합니다.&#x20;

```bash
$ pip3 install rknn-toolkit2/rknn-toolkit-lite2/packages/rknn_toolkit_lite2-2.0.0b0-cp38-cp38-linux_aarch64.whl

$ sudo cp rknn-toolkit2/rknpu2/runtime/Linux/rknn_server/aarch64/usr/bin/rknn_server /usr/bin/
$ sudo chmod 777 /usr/bin/rknn_server
$ sudo cp rknn-toolkit2/rknpu2/runtime/Linux/librknn_api/aarch64/librknnrt.so /usr/lib
$ sudo chmod 777 /usr/lib/librknnrt.so

$ export LD_LIBARY_PATH
```

rknn-toolkit-lite2 설치가 완료되면,&#x20;

<figure><img src="/files/jBYR5eM1WH7ZZvEMG3kZ" alt=""><figcaption></figcaption></figure>

```python
$ python3
>> from rknnlite.api import RKNNLite
```

이와 같이 확인이 가능합니다.&#x20;

### RKNPU2 드라이버가 잘 잡히는지 확인

```bash
dmesg | grep -i rknpu
# or
cat /sys/kernel/debug/rknpu/version
# or
cat /sys/kernel/debug/rknpu/driver_version # or
cat /proc/debug/rknpu/driver_version
```

이와 같이 터미널에 입력했을 때&#x20;

```
RKNPU driver: vX.X.X
```

드라이버 버전이 잘 잡히면 문제가 없는 것입니다.&#x20;

### 예제 컴파일

#### 예제 컴파일 : Please set GCC\_COMPILER for rk3588 에러가 뜰 때

### RKNPU2 드라이버가 안 잡힐 때

정상적으로 드라이버가 잡히는 경우라면 다음과 같은 커맨드를 줬을 때 정보가 출력됩니다.&#x20;

```bash
dmesg | grep -i rknpu
# or
cat /sys/kernel/debug/rknpu/version
```

<figure><img src="/files/VeC0Dq2kZByRZHkvj2HX" alt=""><figcaption></figcaption></figure>

다만 가끔씩 (저의 경우에는 Orange Pi AI pro를 세팅할 때) rknpu 드라이버가 안 잡히는 경우가 있습니다.&#x20;

```basic
fopen /home/HwHiAiUser/libs/grpc/examples/cpp/inference_idmap/model/pidnet_medium_quantized_kl_divergence_intp_argmax.rknn fail!
E RKNN: [14:16:30.934] failed to open rknpu module, need to insmod rknpu dirver!
E RKNN: [14:16:30.935] failed to open rknn device!
```

매뉴얼을 보면 다음과 같이 설명하고 있습니다.&#x20;

***

Rockchip's firmware comes with RKNPU driver pre-installed. If the above commands cannot query the NPU driver version, it may be that the third-party firmware has not installed the RKNPU driver. Open the kernel config file with the "CONFIG\_ROCKCHIP\_RKNPU=y" option, recompile the kernel driver and flash it. It is recommended that the RKNPU driver version is >= 0.9.2.

***

*일단 저도 아직 rknpu 드라이버가 안 잡힐 때 어떻게 해야 하는지 잘 모르겠어서 포기... 혹시 아시는 분 있으면 알려주세요...*
