From: Jaeyun Date: Fri, 3 Jul 2020 07:18:40 +0000 (+0900) Subject: [Android] enable nnfw X-Git-Tag: accepted/tizen/unified/20200708.125346^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62af9a02d0b732302f5faffd7bf82a1ad619cf8d;p=platform%2Fupstream%2Fnnstreamer.git [Android] enable nnfw Change default option to enable NNFW in android-api build, and clean up build script. When building android library, download nnfw libs from ONE repo and start to build library. Signed-off-by: Jaeyun --- diff --git a/api/android/README.md b/api/android/README.md index 9a3943d..bc04707 100644 --- a/api/android/README.md +++ b/api/android/README.md @@ -152,7 +152,7 @@ Run the build script in NNStreamer. - `--build_type=all` to include all features. - `--build_type=single` to enable SingleShot API only. - `--build_type=lite` to get the minimized library with GStreamer core elements. - 3. Including sub-plugins: Default TensorFlow-Lite enabled. + 3. Including sub-plugins: Default TensorFlow-Lite and NNFW enabled. To enable each neural network frameworks, you should download and set-up proper environment. - `--enable_tflite=yes` to build with TensorFlow-Lite. - `--enable_snpe=yes` to build with SNPE (Qualcomm Snapdragon Neural Processing Engine). diff --git a/api/android/api/src/main/jni/Android-nnfw-prebuilt.mk b/api/android/api/src/main/jni/Android-nnfw-prebuilt.mk new file mode 100644 index 0000000..bdbce17 --- /dev/null +++ b/api/android/api/src/main/jni/Android-nnfw-prebuilt.mk @@ -0,0 +1,66 @@ +#------------------------------------------------------ +# NNFW (On-device neural network inference framework, which is developed by Samsung Research.) +# https://github.com/Samsung/ONE +# +# This mk file defines prebuilt libraries for nnfw module. +# (nnfw core libraries, arm64-v8a only) +# You can download specific version of nnfw libraries from https://github.com/Samsung/ONE/releases. +#------------------------------------------------------ +LOCAL_PATH := $(call my-dir) + +ifndef NNFW_LIB_PATH +$(error NNFW_LIB_PATH is not defined!) +endif + +NNFW_PREBUILT_LIBS := + +#------------------------------------------------------ +# nnfw prebuilt shared libraries +#------------------------------------------------------ +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libbackend_cpu +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libbackend_cpu.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libbackend_cpu + +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libcircle_loader +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libcircle_loader.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libcircle_loader + +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libneuralnetworks +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libneuralnetworks.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libneuralnetworks + +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libnnfw-dev +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libnnfw-dev.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libnnfw-dev + +#include $(CLEAR_VARS) +#LOCAL_MODULE := nnfw-libnnfw_lib_benchmark +#LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libnnfw_lib_benchmark.so +#include $(PREBUILT_SHARED_LIBRARY) +#NNFW_PREBUILT_LIBS += nnfw-libnnfw_lib_benchmark + +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libonert_core +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libonert_core.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libonert_core + +#include $(CLEAR_VARS) +#LOCAL_MODULE := nnfw-libtensorflowlite_jni +#LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libtensorflowlite_jni.so +#include $(PREBUILT_SHARED_LIBRARY) +#NNFW_PREBUILT_LIBS += nnfw-libtensorflowlite_jni + +include $(CLEAR_VARS) +LOCAL_MODULE := nnfw-libtflite_loader +LOCAL_SRC_FILES := $(NNFW_LIB_PATH)/libtflite_loader.so +include $(PREBUILT_SHARED_LIBRARY) +NNFW_PREBUILT_LIBS += nnfw-libtflite_loader diff --git a/api/android/api/src/main/jni/Android-nnfw.mk b/api/android/api/src/main/jni/Android-nnfw.mk new file mode 100644 index 0000000..1fe9c4a --- /dev/null +++ b/api/android/api/src/main/jni/Android-nnfw.mk @@ -0,0 +1,41 @@ +#------------------------------------------------------ +# NNFW (On-device neural network inference framework, which is developed by Samsung Research.) +# https://github.com/Samsung/ONE +# +# This mk file defines nnfw module with prebuilt shared library. +# (nnfw core libraries, arm64-v8a only) +#------------------------------------------------------ +LOCAL_PATH := $(call my-dir) + +ifndef NNSTREAMER_ROOT +$(error NNSTREAMER_ROOT is not defined!) +endif + +include $(NNSTREAMER_ROOT)/jni/nnstreamer.mk + +NNFW_DIR := $(LOCAL_PATH)/nnfw +NNFW_INCLUDES := $(NNFW_DIR)/include $(NNFW_DIR)/include/nnfw + +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) +NNFW_LIB_PATH := $(NNFW_DIR)/lib +else +$(error Target arch ABI not supported: $(TARGET_ARCH_ABI)) +endif + +#------------------------------------------------------ +# nnfw prebuilt shared libraries +#------------------------------------------------------ +include $(LOCAL_PATH)/Android-nnfw-prebuilt.mk + +#------------------------------------------------------ +# tensor-filter sub-plugin for nnfw +#------------------------------------------------------ +include $(CLEAR_VARS) + +LOCAL_MODULE := nnfw-subplugin +LOCAL_SRC_FILES := $(NNSTREAMER_FILTER_NNFW_SRCS) +LOCAL_CFLAGS := -O3 -fPIC +LOCAL_C_INCLUDES := $(NNFW_INCLUDES) $(NNSTREAMER_INCLUDES) $(GST_HEADERS_COMMON) +LOCAL_SHARED_LIBRARIES := $(NNFW_PREBUILT_LIBS) + +include $(BUILD_STATIC_LIBRARY) diff --git a/api/android/api/src/main/jni/Android-nnstreamer-prebuilt.mk b/api/android/api/src/main/jni/Android-nnstreamer-prebuilt.mk new file mode 100644 index 0000000..565a4e1 --- /dev/null +++ b/api/android/api/src/main/jni/Android-nnstreamer-prebuilt.mk @@ -0,0 +1,79 @@ +#------------------------------------------------------ +# nnstreamer +# +# This mk file defines nnstreamer module with prebuilt shared libraries. +# ABI: armeabi-v7a, arm64-v8a +#------------------------------------------------------ +LOCAL_PATH := $(call my-dir) + +NNSTREAMER_DIR := $(LOCAL_PATH)/nnstreamer + +NNSTREAMER_INCLUDES := $(NNSTREAMER_DIR)/include +NNSTREAMER_LIB_PATH := $(NNSTREAMER_DIR)/lib/$(TARGET_ARCH_ABI) + +ENABLE_TF_LITE := false +ENABLE_SNAP := false +ENABLE_NNFW := false +ENABLE_SNPE := false + +#------------------------------------------------------ +# define required libraries for nnstreamer +#------------------------------------------------------ +NNSTREAMER_LIBS := nnstreamer-native gst-android cpp-shared + +#------------------------------------------------------ +# nnstreamer-native +#------------------------------------------------------ +include $(CLEAR_VARS) +LOCAL_MODULE := nnstreamer-native +LOCAL_SRC_FILES := $(NNSTREAMER_LIB_PATH)/libnnstreamer-native.so +include $(PREBUILT_SHARED_LIBRARY) + +#------------------------------------------------------ +# gstreamer android +#------------------------------------------------------ +include $(CLEAR_VARS) +LOCAL_MODULE := gst-android +LOCAL_SRC_FILES := $(NNSTREAMER_LIB_PATH)/libgstreamer_android.so +include $(PREBUILT_SHARED_LIBRARY) + +#------------------------------------------------------ +# c++ shared +#------------------------------------------------------ +include $(CLEAR_VARS) +LOCAL_MODULE := cpp-shared +LOCAL_SRC_FILES := $(NNSTREAMER_LIB_PATH)/libc++_shared.so +include $(PREBUILT_SHARED_LIBRARY) + +#------------------------------------------------------ +# SNAP (arm64-v8a only) +#------------------------------------------------------ +ifeq ($(ENABLE_SNAP),true) +SNAP_LIB_PATH := $(NNSTREAMER_LIB_PATH) +include $(LOCAL_PATH)/Android-snap-prebuilt.mk + +NNSTREAMER_LIBS += $(SNAP_PREBUILT_LIBS) +endif + +#------------------------------------------------------ +# NNFW (arm64-v8a only) +#------------------------------------------------------ +ifeq ($(ENABLE_NNFW),true) +NNFW_LIB_PATH := $(NNSTREAMER_LIB_PATH) +include $(LOCAL_PATH)/Android-nnfw-prebuilt.mk + +NNSTREAMER_LIBS += $(NNFW_PREBUILT_LIBS) +endif + +#------------------------------------------------------ +# SNPE +#------------------------------------------------------ +ifeq ($(ENABLE_SNPE),true) +SNPE_LIB_PATH := $(NNSTREAMER_LIB_PATH) +include $(LOCAL_PATH)/Android-snpe-prebuilt.mk + +NNSTREAMER_LIBS += $(SNPE_PREBUILT_LIBS) +endif + +# Remove any duplicates. +NNSTREAMER_LIBS := $(sort $(NNSTREAMER_LIBS)) diff --git a/api/android/api/src/main/jni/Android-tensorflow-lite.mk b/api/android/api/src/main/jni/Android-tensorflow-lite.mk index 27d07b4..401f4d0 100644 --- a/api/android/api/src/main/jni/Android-tensorflow-lite.mk +++ b/api/android/api/src/main/jni/Android-tensorflow-lite.mk @@ -3,11 +3,9 @@ # # This mk file defines tensorflow-lite module with prebuilt static library. # To build and run the example with gstreamer binaries, we built a static library (e.g., libtensorflow-lite.a) -# for Android/Tensorflow-lite from the Tensorflow repository of the Tizen software platform with version 1.9 using the Android-tensorflow-lite.mk. +# for Android/Tensorflow-lite from the Tensorflow repository of the Tizen software platform. # - [Tizen] Tensorflow git repository: # * Repository: https://review.tizen.org/gerrit/p/platform/upstream/tensorflow -# * Branch name: sandbox/sangjung/launchpad_bugfix -# * Commit: 5c3399d [Debian] add dependency on python 2.7, provides of tensorflow #------------------------------------------------------ LOCAL_PATH := $(call my-dir) @@ -24,10 +22,6 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) TF_LITE_LIB_PATH := $(TF_LITE_DIR)/lib/armv7 else ifeq ($(TARGET_ARCH_ABI),arm64-v8a) TF_LITE_LIB_PATH := $(TF_LITE_DIR)/lib/arm64 -else ifeq ($(TARGET_ARCH_ABI),x86) -TF_LITE_LIB_PATH := $(TF_LITE_DIR)/lib/x86 -else ifeq ($(TARGET_ARCH_ABI),x86_64) -TF_LITE_LIB_PATH := $(TF_LITE_DIR)/lib/x86_64 else $(error Target arch ABI not supported: $(TARGET_ARCH_ABI)) endif diff --git a/api/android/build-android-lib.sh b/api/android/build-android-lib.sh index f486e07..86d374d 100644 --- a/api/android/build-android-lib.sh +++ b/api/android/build-android-lib.sh @@ -20,7 +20,7 @@ # --target_abi (default 'arm64-v8a', 'armeabi-v7a' available) # --run_test (default 'no', 'yes' to run the instrumentation test) # --enable_snap (default 'no', 'yes' to build with sub-plugin for SNAP) -# --enable_nnfw (default 'no', 'yes' to build with sub-plugin for NNFW) +# --enable_nnfw (default 'yes' to build with sub-plugin for NNFW) # --enable_snpe (default 'no', 'yes' to build with sub-plugin for SNPE) # --enable_tflite (default 'yes' to build with sub-plugin for tensorflow-lite) # @@ -33,7 +33,7 @@ set -e # 'all' : default # 'lite' : with GStreamer core plugins # 'single' : no plugins, single-shot only -# 'internal' : no plugins, single-shot only, disable SNAP and tf-lite +# 'internal' : no plugins, single-shot only, enable NNFW only build_type="all" nnstreamer_api_option="all" @@ -52,7 +52,7 @@ release_bintray="no" enable_snap="no" # Enable NNFW -enable_nnfw="no" +enable_nnfw="yes" # Enable SNPE enable_snpe="no" @@ -61,7 +61,10 @@ enable_snpe="no" enable_tflite="yes" # Set tensorflow-lite version (available: 1.9.0/1.13.1/1.15.2) -nnstreamer_tf_lite_ver="1.13.1" +tf_lite_ver="1.13.1" + +# Set NNFW version (https://github.com/Samsung/ONE/releases) +nnfw_ver="1.6.0" # Parse args for arg in "$@"; do @@ -129,7 +132,7 @@ elif [[ $build_type == "internal" ]]; then nnstreamer_api_option="single" enable_snap="no" - enable_nnfw="no" + enable_nnfw="yes" enable_snpe="no" enable_tflite="no" @@ -146,10 +149,9 @@ if [[ $enable_snap == "yes" ]]; then fi if [[ $enable_nnfw == "yes" ]]; then - [ -z "$NNFW_DIRECTORY" ] && echo "Need to set NNFW_DIRECTORY, to build sub-plugin for NNFW." && exit 1 [ $target_abi != "arm64-v8a" ] && echo "Set target ABI arm64-v8a to build sub-plugin for NNFW." && exit 1 - echo "Build with NNFW: $NNFW_DIRECTORY" + echo "Build with NNFW $nnfw_ver" fi if [[ $enable_snpe == "yes" ]]; then @@ -228,8 +230,14 @@ cp -r ./api/android/* ./$build_dir mkdir -p $build_dir/external svn --force export https://github.com/nnstreamer/nnstreamer-android-resource/trunk/android_api ./$build_dir -svn --force export https://github.com/nnstreamer/nnstreamer-android-resource/trunk/external/tensorflow-lite-$nnstreamer_tf_lite_ver.tar.xz ./$build_dir/external -svn --force export https://github.com/nnstreamer/nnstreamer-android-resource/trunk/external/jni/Android-nnstreamer-prebuilt.mk ./$build_dir/external + +if [[ $enable_tflite == "yes" ]]; then + wget --directory-prefix=./$build_dir/external https://raw.githubusercontent.com/nnstreamer/nnstreamer-android-resource/master/external/tensorflow-lite-$tf_lite_ver.tar.xz +fi + +if [[ $enable_nnfw == "yes" ]]; then + wget --directory-prefix=./$build_dir/external https://github.com/Samsung/ONE/releases/download/$nnfw_ver/nnfw-$nnfw_ver-android-aarch64.tar.gz +fi pushd ./$build_dir @@ -252,21 +260,22 @@ sed -i "s|sdk.dir=sdk-path|sdk.dir=$android_sdk_dir|" local.properties # Update SNAP option if [[ $enable_snap == "yes" ]]; then - sed -i "s|ENABLE_SNAP := false|ENABLE_SNAP := true|" external/Android-nnstreamer-prebuilt.mk + sed -i "s|ENABLE_SNAP := false|ENABLE_SNAP := true|" api/src/main/jni/Android-nnstreamer-prebuilt.mk sed -i "s|ENABLE_SNAP := false|ENABLE_SNAP := true|" api/src/main/jni/Android.mk cp -r $SNAP_DIRECTORY/* api/src/main/jni fi # Update NNFW option if [[ $enable_nnfw == "yes" ]]; then - sed -i "s|ENABLE_NNFW := false|ENABLE_NNFW := true|" external/Android-nnstreamer-prebuilt.mk + sed -i "s|ENABLE_NNFW := false|ENABLE_NNFW := true|" api/src/main/jni/Android-nnstreamer-prebuilt.mk sed -i "s|ENABLE_NNFW := false|ENABLE_NNFW := true|" api/src/main/jni/Android.mk - cp -r $NNFW_DIRECTORY/* api/src/main/jni + mkdir -p api/src/main/jni/nnfw + tar -zxf ./external/nnfw-$nnfw_ver-android-aarch64.tar.gz -C ./api/src/main/jni/nnfw fi # Update SNPE option if [[ $enable_snpe == "yes" ]]; then - sed -i "s|ENABLE_SNPE := false|ENABLE_SNPE := true|" external/Android-nnstreamer-prebuilt.mk + sed -i "s|ENABLE_SNPE := false|ENABLE_SNPE := true|" api/src/main/jni/Android-nnstreamer-prebuilt.mk sed -i "s|ENABLE_SNPE := false|ENABLE_SNPE := true|" api/src/main/jni/Android.mk sed -i "$ a SNPE_DSP_LIBRARY_PATH=src/main/jni/snpe/lib/dsp" gradle.properties mkdir -p api/src/main/jni/snpe/lib/dsp/arm64-v8a @@ -277,9 +286,9 @@ fi # Update tf-lite option if [[ $enable_tflite == "yes" ]]; then - sed -i "s|ENABLE_TF_LITE := false|ENABLE_TF_LITE := true|" external/Android-nnstreamer-prebuilt.mk + sed -i "s|ENABLE_TF_LITE := false|ENABLE_TF_LITE := true|" api/src/main/jni/Android-nnstreamer-prebuilt.mk sed -i "s|ENABLE_TF_LITE := false|ENABLE_TF_LITE := true|" api/src/main/jni/Android.mk - tar xJf ./external/tensorflow-lite-$nnstreamer_tf_lite_ver.tar.xz -C ./api/src/main/jni + tar -xJf ./external/tensorflow-lite-$tf_lite_ver.tar.xz -C ./api/src/main/jni fi # Add dependency for release @@ -327,7 +336,6 @@ if [[ -e "$nnstreamer_android_api_lib" ]]; then unzip $nnstreamer_android_api_lib -d aar_extracted mkdir -p main/java/org/freedesktop - mkdir -p main/java/org/nnsuite/nnstreamer mkdir -p main/jni/nnstreamer/lib mkdir -p main/jni/nnstreamer/include @@ -341,7 +349,6 @@ if [[ -e "$nnstreamer_android_api_lib" ]]; then cp -r api/src/main/java/org/freedesktop/* main/java/org/freedesktop cp -r aar_extracted/jni/* main/jni/nnstreamer/lib cp api/src/main/jni/*-prebuilt.mk main/jni - cp external/Android-nnstreamer-prebuilt.mk main/jni # header for C-API cp $nnstreamer_dir/api/capi/include/nnstreamer.h main/jni/nnstreamer/include