4. RKNN API

Rockchip provides a set of RKNN API SDK, which is a set of acceleration scheme for NPU hardware of neural network based on RK3399Pro Linux/Android, and can provide general acceleration support for AI-related applications developed with RKNN API.

RKNN API SDK related API introduction refer to the documentation《RK3399Pro_Linux&Android_RKNN_API_V*.pdf》,The following is an introduction to the configuration and use of the RKNN API. Refer to the example in the RKNN API for details.

4.1. 1. Linux

The application only needs to include the header file and the dynamic library to write the relevant AI application.

4.1.1. Fedora

4.1.1.1. 1)Installing rknn-api development kit through dnf

sudo dnf install –y rknn-api

The method as follows:

a. Include header file in your code:

#include <rockchip/rknn_api.h>

b. Add the following statement link library file in Makefile:

LDFLAGS += -lrknn_api

4.1.1.2. 2)download from netdisk

RKNN API:LINK

The method as follows:

a. Copy the rknn_api/ directory to the root directory

b. Include header file in your code

#include "rknn_api.h"

c. Add the following statement in Makefile to set the link library path and header file path

CFLAGS += -Lrknn_api/lib64 -Irknn_api/include

d. Add the following statement link library file in Makefile

LDFLAGS += -lrknn_api

The structure as follows:

...
├── Makefile
└── rknn_api
    ├── include
    │   └── rknn_api.h
    └── lib64
        └── librknn_api.so
 ...

4.1.2. Ubuntu

Please refer to 2)download from netdiskto configuration

4.2. 2. Android

The RKNN API supports Android 8.1 and Android9.0 systems released by Firefly (or systems compiled from published source code)

Download from Netdisk RKNN API:LINK

The dynamic library path of RKNN API is lib64/librknn_api.so and lib/librknn_api.so。The application only needs to include the header file and the dynamic library to write the JNI Library of the relevant AI application. Currently, only JNI is supported on Android.

The specific configuration of Android Studio is as follows

a.Copy lib64/librknn_api.so to Project jniLibs/arm64-v8a and lib/librknn_api.so to jniLibs/armeabi-v7a. The results of the catalogue are as follows

├── jniLibs
│   └── arm64-v8a
│       └── librknn_api.so
│   └── armeabi-v7a
│       └── librknn_api.so

b. Copy rknn_api.h to the JNI source directory for reference:

├── jni
│   ├── direct_texture.cc
│   ├── direct_texture.h
│   ├── rknn_api.h
│   ├── ssd_image.cc
│   ├── ssd_image.h
│   ├── ssd_native_c_api.cc
│   └── ssd_native_c_api.h

c. Configure CMakeLists.txt,link librknn_api.so

...
set(link_libs ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/librknn_api.so
               ...
              ${log-lib}
)
target_link_libraries( rkssd4j
                       ${link_libs} )
...

d. Configure build.gradle and complie the JNI library of arm64-v8a and armeabi-v7a

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        ...
        ndk {
            abiFilters "arm64-v8a", "armeabi-v7a"
        }
    }
    ...
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

The structure as follow:

# pwd: $(project_root)/app
.
├── app.iml
├── build
...
├── build.gradle
├── CMakeLists.txt
└── src
    └── main
        ├── AndroidManifest.xml
        ...
        ├── jni
        │   ├── direct_texture.cc
        │   ├── direct_texture.h
        │   ├── rknn_api.h
        │   ├── ssd_image.cc
        │   ├── ssd_image.h
        │   ├── ssd_native_c_api.cc
        │   └── ssd_native_c_api.h
        ├── jniLibs
        │   └── arm64-v8a
        │       └── librknn_api.so
        │   └── armeabi-v7a
        │       └── librknn_api.so
        ...