# 3. rknn-toolkit2 설치하기

## rknn-toolkit2

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

<figure><img src="https://2142194689-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF7wWHEk0b5r5goRGl7JY%2Fuploads%2Fzkdydr1elMp6hTyRhWim%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202024-08-08%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%203.52.24.png?alt=media&#x26;token=0f2cf495-a047-4615-995f-61c2904ae5d7" 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="https://2142194689-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF7wWHEk0b5r5goRGl7JY%2Fuploads%2FucCz5wJFvrUlccSBRrXV%2Fimage.png?alt=media&#x26;token=9e088291-d5b8-4d63-81e9-abc636901062" 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="https://2142194689-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FF7wWHEk0b5r5goRGl7JY%2Fuploads%2FosXzraMfBoafGoxZGZIq%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202024-08-13%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.34.07.png?alt=media&#x26;token=3aec043d-54ba-44ec-a332-13e2d033980b" 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 드라이버가 안 잡힐 때 어떻게 해야 하는지 잘 모르겠어서 포기... 혹시 아시는 분 있으면 알려주세요...*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zito.gitbook.io/rknn_usermanual/3.-rknn-toolkit2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
