Skip to content

Commit 89735ae

Browse files
committed
[Build/Android] option for ml-service
Add new option to build native code for ml-service and mlops-agent. Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
1 parent 7b39b87 commit 89735ae

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

java/android/nnstreamer/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ android {
4343
if (nnsEdgeRoot == null)
4444
throw new GradleException('NNSTREAMER_EDGE_ROOT must be set, or "nnstreamerEdgeRoot" must be defined in your gradle.properties')
4545

46+
def mlopsAgentRoot
47+
48+
if (project.hasProperty('mlopsAgentRoot'))
49+
mlopsAgentRoot = project.mlopsAgentRoot
50+
else
51+
mlopsAgentRoot = System.env.MLOPS_AGENT_ROOT
52+
53+
if (mlopsAgentRoot == null)
54+
throw new GradleException('MLOPS_AGENT_ROOT must be set, or "mlopsAgentRoot" must be defined in your gradle.properties')
55+
4656
def mlApiRoot
4757

4858
if (project.hasProperty('mlApiRoot'))
@@ -60,6 +70,7 @@ android {
6070
"GSTREAMER_ASSETS_DIR=src/main/assets",
6171
"NNSTREAMER_ROOT=$nnsRoot",
6272
"NNSTREAMER_EDGE_ROOT=$nnsEdgeRoot",
73+
"MLOPS_AGENT_ROOT=$mlopsAgentRoot",
6374
"ML_API_ROOT=$mlApiRoot"
6475

6576
targets "nnstreamer-native"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
CURL_DIR := $(LOCAL_PATH)/curl
4+
CURL_INCLUDE := $(CURL_DIR)/include
5+
6+
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
7+
CURL_LIB_PATH := $(CURL_DIR)/lib/armeabi-v7a
8+
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
9+
CURL_LIB_PATH := $(CURL_DIR)/lib/arm64-v8a
10+
else ifeq ($(TARGET_ARCH_ABI),x86)
11+
CURL_LIB_PATH := $(CURL_DIR)/lib/x86
12+
else ifeq ($(TARGET_ARCH_ABI),x86_64)
13+
CURL_LIB_PATH := $(CURL_DIR)/lib/x86_64
14+
else
15+
$(error For curl, target arch ABI is not supported: $(TARGET_ARCH_ABI))
16+
endif
17+
18+
#------------------------------------------------------
19+
# curl prebuilt library
20+
#------------------------------------------------------
21+
include $(CLEAR_VARS)
22+
LOCAL_MODULE := libcurl
23+
LOCAL_SRC_FILES := $(CURL_LIB_PATH)/libcurl.a
24+
LOCAL_EXPORT_C_INCLUDES := $(CURL_INCLUDE)
25+
include $(PREBUILT_STATIC_LIBRARY)

java/android/nnstreamer/src/main/jni/Android-nnstreamer.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ endif
7373
NNSTREAMER_CAPI_INCLUDES += $(NNSTREAMER_EDGE_INCLUDES)
7474
endif
7575

76+
ifeq ($(ENABLE_ML_SERVICE), true)
77+
NNSTREAMER_SRC_FILES += \
78+
$(ML_API_ROOT)/c/src/ml-api-service.c \
79+
$(ML_API_ROOT)/c/src/ml-api-service-agent-client.c \
80+
$(ML_API_ROOT)/c/src/ml-api-service-extension.c \
81+
$(NNSTREAMER_AGENT_SRCS) \
82+
$(MLOPS_AGENT_SRCS)
83+
84+
ifeq ($(ENABLE_ML_OFFLOADING), true)
85+
NNSTREAMER_SRC_FILES += \
86+
$(ML_API_ROOT)/c/src/ml-api-service-query-client.c \
87+
$(ML_API_ROOT)/c/src/ml-api-service-offloading.c
88+
89+
NNSTREAMER_EXTERNAL_LIBS += libcurl
90+
endif
91+
92+
NNSTREAMER_CAPI_INCLUDES += $(MLOPS_AGENT_INCLUDE)
93+
endif
7694
endif # ifneq ($(NNSTREAMER_API_OPTION),single)
7795

7896
include $(CLEAR_VARS)

java/android/nnstreamer/src/main/jni/Android.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ NNSTREAMER_API_OPTION := all
3838
# support tensor-query and offloading
3939
ENABLE_ML_OFFLOADING := false
4040

41+
# enable service api and mlops-agent
42+
ENABLE_ML_SERVICE := false
43+
4144
ENABLE_TF_LITE ?= false
4245
# TensorFlow Lite (nnstreamer tf-lite sub-plugin)
4346
ifeq ($(ENABLE_TF_LITE),true)
@@ -119,6 +122,20 @@ NNS_API_FLAGS += -DENABLE_NNSTREAMER_EDGE=1
119122
include $(NNSTREAMER_EDGE_ROOT)/jni/nnstreamer-edge.mk
120123
endif
121124

125+
ifeq ($(ENABLE_ML_SERVICE), true)
126+
ifndef MLOPS_AGENT_ROOT
127+
$(error MLOPS_AGENT_ROOT is not defined!)
128+
endif
129+
130+
NNS_API_FLAGS += -DENABLE_ML_AGENT=1
131+
include $(MLOPS_AGENT_ROOT)/jni/mlops-agent.mk
132+
133+
ifeq ($(ENABLE_ML_OFFLOADING), true)
134+
NNS_API_FLAGS += -DENABLE_SERVICE_OFFLOADING=1
135+
include $(LOCAL_PATH)/Android-curl.mk
136+
endif
137+
endif
138+
122139
ifeq ($(ENABLE_MQTT), true)
123140
NNS_API_FLAGS += -DENABLE_MQTT=1
124141
include $(LOCAL_PATH)/Android-paho-mqtt-c.mk

java/build-nnstreamer-android.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
##@@ This option overrides the NNSTREAMER_EDGE_ROOT variable
3939
##@@ --nnstreamer_android_resource_dir=(the_source_root_of_nnstreamer_android_resource)
4040
##@@ This option overrides the NNSTREAMER_ANDROID_RESOURCE variable
41+
##@@ --mlops_agent_dir=(the_source_root_of_mlops_agent)
42+
##@@ This option overrides the MLOPS_AGENT_ROOT variable
4143
##@@ --ml_api_dir=(the_source_root_of_ml_api)
4244
##@@ This option overrides the ML_API_ROOT variable
4345
##@@ --result_dir=(path_to_build_result)
@@ -88,6 +90,11 @@
8890
##@@ 'yes' : build with tensor_query elements.
8991
##@@ 'no' : [default] build without the tensor_query elements.
9092
##@@
93+
##@@ options for ml-service
94+
##@@ --enable_ml_service=(yes|no)
95+
##@@ 'yes' : build with ml-service api.
96+
##@@ 'no' : [default]
97+
##@@
9198
##@@ options for mqtt:
9299
##@@ --enable_mqtt=(yes|no)
93100
##@@ 'yes' : [default] build with paho.mqtt.c prebuilt libs. This option supports the mqtt plugin
@@ -155,6 +162,12 @@ paho_mqtt_c_ver="1.3.7"
155162
# Enable option for tensor_query and offloading
156163
enable_ml_offloading="no"
157164

165+
# Enable option for service api and ml-agent
166+
enable_ml_service="no"
167+
168+
# curl for ml-service offloading
169+
curl_ver="7.60.0"
170+
158171
# Set tensorflow-lite version (available: 2.8.1 / 2.16.1)
159172
tf_lite_ver="2.16.1"
160173
tf_lite_vers_support="2.8.1 2.16.1"
@@ -192,6 +205,9 @@ for arg in "$@"; do
192205
--nnstreamer_android_resource_dir=*)
193206
nnstreamer_android_resource_dir=${arg#*=}
194207
;;
208+
--mlops_agent_dir=*)
209+
mlops_agent_dir=${arg#*=}
210+
;;
195211
--ml_api_dir=*)
196212
ml_api_dir=${arg#*=}
197213
;;
@@ -279,6 +295,9 @@ for arg in "$@"; do
279295
--enable_ml_offloading=*)
280296
enable_ml_offloading=${arg#*=}
281297
;;
298+
--enable_ml_service=*)
299+
enable_ml_service=${arg#*=}
300+
;;
282301
--enable_mqtt=*)
283302
enable_mqtt=${arg#*=}
284303
;;
@@ -311,6 +330,7 @@ if [[ $nnstreamer_api_option == "single" ]]; then
311330
enable_flatbuf="no"
312331
enable_mqtt="no"
313332
enable_ml_offloading="no"
333+
enable_ml_service="no"
314334
fi
315335

316336
# Check target abi and set dir name prefix for each abi
@@ -443,6 +463,15 @@ if [[ $enable_ml_offloading == "yes" ]]; then
443463
echo "nnstreamer-edge root directory: $nnstreamer_edge_dir"
444464
fi
445465

466+
# MLOps Agent root directory
467+
if [[ $enable_ml_service == "yes" ]]; then
468+
if [[ -z "$mlops_agent_dir" ]]; then
469+
[ -z "$MLOPS_AGENT_ROOT" ] && echo "Need to set MLOPS_AGENT_ROOT." && exit 1
470+
mlops_agent_dir=$MLOPS_AGENT_ROOT
471+
fi
472+
echo "MLOps Agent root directory: $mlops_agent_dir"
473+
fi
474+
446475
# ML API root directory
447476
if [[ -z "$ml_api_dir" ]]; then
448477
[ -z "$ML_API_ROOT" ] && echo "Need to set ML_API_ROOT." && exit 1
@@ -532,6 +561,10 @@ if [[ $enable_mqtt == "yes" ]]; then
532561
cp $nnstreamer_android_resource_dir/external/paho-mqtt-c-${paho_mqtt_c_ver}.tar.xz ./$build_dir/external
533562
fi
534563

564+
if [[ $enable_ml_service == "yes" ]]; then
565+
cp $nnstreamer_android_resource_dir/external/curl-${curl_ver}.tar.xz ./$build_dir/external
566+
fi
567+
535568
pushd ./$build_dir
536569

537570
# Update target ABI
@@ -547,6 +580,7 @@ fi
547580

548581
# Update ML_API, nnstreamer-edge, NNStreamer, GStreamer and Android SDK
549582
sed -i "s|mlApiRoot=ml-api-path|mlApiRoot=$ml_api_dir|" gradle.properties
583+
sed -i "s|mlopsAgentRoot=mlops-agent-path|mlopsAgentRoot=$mlops_agent_dir|" gradle.properties
550584
sed -i "s|nnstreamerEdgeRoot=nnstreamer-edge-path|nnstreamerEdgeRoot=$nnstreamer_edge_dir|" gradle.properties
551585
sed -i "s|nnstreamerRoot=nnstreamer-path|nnstreamerRoot=$nnstreamer_dir|" gradle.properties
552586
sed -i "s|gstAndroidRoot=gstreamer-path|gstAndroidRoot=$gstreamer_dir|" gradle.properties
@@ -691,6 +725,11 @@ if [[ $enable_ml_offloading == "yes" ]]; then
691725
sed -i "s|ENABLE_ML_OFFLOADING := false|ENABLE_ML_OFFLOADING := true|" nnstreamer/src/main/jni/Android.mk
692726
fi
693727

728+
if [[ $enable_ml_service == "yes" ]]; then
729+
sed -i "s|ENABLE_ML_SERVICE := false|ENABLE_ML_SERVICE := true|" nnstreamer/src/main/jni/Android.mk
730+
tar -xJf ./external/curl-${curl_ver}.tar.xz -C ./nnstreamer/src/main/jni
731+
fi
732+
694733
if [[ $enable_mqtt == "yes" ]]; then
695734
sed -i "s|ENABLE_MQTT := false|ENABLE_MQTT := true|" nnstreamer/src/main/jni/Android.mk
696735
tar -xJf ./external/paho-mqtt-c-${paho_mqtt_c_ver}.tar.xz -C ./nnstreamer/src/main/jni
@@ -742,6 +781,9 @@ if [[ $android_lib_build_res -eq 0 ]]; then
742781
cp $ml_api_dir/c/include/nnstreamer-single.h main/jni/nnstreamer/include
743782
cp $ml_api_dir/c/include/ml-api-common.h main/jni/nnstreamer/include
744783
cp $ml_api_dir/c/include/platform/tizen_error.h main/jni/nnstreamer/include
784+
if [[ $enable_ml_service == "yes" ]]; then
785+
cp $ml_api_dir/c/include/ml-api-service.h main/jni/nnstreamer/include
786+
fi
745787

746788
# header for plugin (copy if necessary)
747789
##if [[ $nnstreamer_api_option != "single" ]]; then

0 commit comments

Comments
 (0)