Check tflite version in build time (#4371)
author대인기/On-Device Lab(SR)/Staff Engineer/삼성전자 <inki.dae@samsung.com>
Fri, 8 Feb 2019 06:46:27 +0000 (15:46 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Fri, 8 Feb 2019 06:46:27 +0000 (15:46 +0900)
* Check tflite version in build time

This patch seperates what OBS_BUILD flag means into.
- OBS_BUILD flag decides where external packages should be
  installed from - if OBS_BUILD == 1 then from tizen package server
  otherwise from upstream.
- TFLITE_VER means what tensorflow-lite version nnfw uses - if
  TFLITE_VER == 190 then nnfw uses tensorflow-lite v1.9.0 for Tizen
  otherwise tensorflow-lite v1.12.0. In default TFLITE_VER is 1120.

For this, I added a TFLITE_VER flag, which will pass proper version
information - 190 for gbs build or 1120 in default - to code side.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
* Seperated TFLITE_VER into TFLITE_MAJOR_VER and TFLITE_MINOR_VER

Signed-off-by: Inki Dae <inki.dae@samsung.com>
* Updated nnapi_delegate.h I missed.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
* Updated and cleaned up

- Cleaned up CMakeLists.txt file
- Added TFLITE_MAJOR_VER and TFLITE_MINOR_VER flags when coverage_build == 1

Signed-off-by: Inki Dae <inki.dae@samsung.com>
* Updated description

Signed-off-by: Inki Dae <inki.dae@samsung.com>
* Fix typo

Signed-off-by: Inki Dae <inki.dae@samsung.com>
CMakeLists.txt
Makefile
libs/tflite/include/tflite/ext/nnapi_delegate.h
libs/tflite/src/ext/kernels/register.cpp
libs/tflite/src/ext/nnapi_delegate.cpp
libs/tflite/src/ext/nnapi_delegate_ex_AddOpsAndParams_lambda.inc
packaging/nnfw.spec

index 0979a4a..3b558f4 100644 (file)
@@ -58,10 +58,13 @@ option(DOWNLOAD_NONIUS "Download nonius source" ON)
 option(BUILD_GTEST "Download and build Google Test" ON)
 nnfw_find_package(GTest QUIET)
 
-# NOTE Workaround to avoid build fail by tensorflow (or acl) package version mismatch on obs build
-if(OBS_BUILD)
-  add_definitions(-DOBS_BUILD)
-endif(OBS_BUILD)
+# NOTE For now NNFW supports two TFLITE versions - v1.12 for Unbuntu and v1.9 for Tizen.
+#      So TFLITE version should mandatorily be specified to distinguish the version.
+if(NOT TFLITE_MAJOR_VER OR NOT TFLITE_MINOR_VER)
+  message(FATAL_ERROR "TFLITE_MAJOR_VER and TFLITE_MINOR_VER should be defined")
+endif(NOT TFLITE_MAJOR_VER OR NOT TFLITE_MINOR_VER)
+
+add_definitions(-DTFLITE_MAJOR_VER=${TFLITE_MAJOR_VER} -DTFLITE_MINOR_VER=${TFLITE_MINOR_VER})
 
 nnfw_include(ExtendCMakeFunction)
 
index 990e56e..e9cfd91 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,8 @@ COVERAGE_BUILD?=0
 BENCHMARK_ACL_BUILD?=0
 OPTIONS?=
 GENERATE_NNAPI_TESTS?=1
+TFLITE_MAJOR_VER?=1
+TFLITE_MINOR_VER?=12
 
 # make TARGET and TYPE to lowercase
 TARGET_ARCH_LC=$(shell echo $(TARGET_ARCH) | tr A-Z a-z)
@@ -155,6 +157,8 @@ endif
                -DHOST_OS=$(HOST_OS) \
                -DTARGET_OS=$(TARGET_OS) \
                -DOBS_BUILD=$(OBS_BUILD) \
+               -DTFLITE_MAJOR_VER=$(TFLITE_MAJOR_VER) \
+               -DTFLITE_MINOR_VER=$(TFLITE_MINOR_VER) \
                $(OPTION_TOOLCHAIN) \
                $(OPTIONS)
        touch $(TIMESTAMP_CONFIGURE)
index 3aac01a..d10ad84 100644 (file)
@@ -23,7 +23,7 @@ limitations under the License.
 #define __NNFW_TFLITE_EXT_NNAPI_DELEGATE_H__
 
 #include "tensorflow/contrib/lite/allocation.h"
-#ifdef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 9
 #include "tensorflow/contrib/lite/context.h"
 #include "tensorflow/contrib/lite/error_reporter.h"
 #else
index b822bd6..e354bbf 100644 (file)
@@ -90,7 +90,7 @@ TfLiteRegistration *Register_SLICE();
 TfLiteRegistration *Register_SIN();
 TfLiteRegistration *Register_TRANSPOSE_CONV();
 TfLiteRegistration *Register_SPARSE_TO_DENSE();
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
 TfLiteRegistration *Register_SUM();
 TfLiteRegistration *Register_REDUCE_MAX();
 TfLiteRegistration *Register_REDUCE_MIN();
@@ -110,7 +110,7 @@ TfLiteRegistration *Register_UNPACK();
 TfLiteRegistration *Register_FLOOR_DIV();
 TfLiteRegistration *Register_SQUARE();
 TfLiteRegistration *Register_ZEROS_LIKE();
-#endif // OBS_BUILD
+#endif // TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
 
 }  // namespace builtin
 }  // namespace ops
@@ -187,7 +187,7 @@ BuiltinOpResolver::BuiltinOpResolver()
   AddBuiltin(BuiltinOperator_SELECT, Register_SELECT());
   AddBuiltin(BuiltinOperator_SLICE, Register_SLICE());
   AddBuiltin(BuiltinOperator_SIN, Register_SIN());
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
   AddBuiltin(BuiltinOperator_SUM, Register_SUM());
   AddBuiltin(BuiltinOperator_REDUCE_MAX, Register_REDUCE_MAX());
   AddBuiltin(BuiltinOperator_REDUCE_MIN, Register_REDUCE_MIN());
@@ -209,7 +209,7 @@ BuiltinOpResolver::BuiltinOpResolver()
   AddBuiltin(BuiltinOperator_FLOOR_DIV, Register_FLOOR_DIV());
   AddBuiltin(BuiltinOperator_SQUARE, Register_SQUARE());
   AddBuiltin(BuiltinOperator_ZEROS_LIKE, Register_ZEROS_LIKE());
-#endif // OBS_BUILD
+#endif // TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
 
   AddCustom("TensorFlowMax", nnfw::tflite::custom::Register_TensorFlowMax());
   AddCustom("SquaredDifference", nnfw::tflite::custom::Register_SquaredDifference());
index 472b3fb..02abe3f 100644 (file)
@@ -24,7 +24,7 @@ limitations under the License.
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#ifdef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 9
 #include "tensorflow/contrib/lite/builtin_op_data.h"
 #include "tensorflow/contrib/lite/error_reporter.h"
 #else
@@ -449,7 +449,7 @@ TfLiteStatus AddOpsAndParams(
     };
 
     auto add_mean_params = [&add_scalar_int32](void* data) {
-#ifdef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 9
       auto builtin = reinterpret_cast<TfLiteMeanParams*>(data);
 #else
       auto builtin = reinterpret_cast<TfLiteReducerParams*>(data);
@@ -763,7 +763,7 @@ TfLiteStatus AddOpsAndParams(
             augmented_inputs.data(), static_cast<uint32_t>(node.outputs->size),
             reinterpret_cast<uint32_t*>(node.outputs->data)));
         continue;
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
       case tflite::BuiltinOperator_PACK:
         add_pack_ex_params(node.builtin_data);
         CHECK_NN(ANeuralNetworksModel_addOperationEx(
@@ -886,7 +886,7 @@ TfLiteStatus AddOpsAndParams(
       //case tflite::BuiltinOperator_PRELU:
       case tflite::BuiltinOperator_MAXIMUM:
       case tflite::BuiltinOperator_MINIMUM:
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
       case tflite::BuiltinOperator_ARG_MIN:
 #endif
       case tflite::BuiltinOperator_GREATER:
@@ -897,11 +897,11 @@ TfLiteStatus AddOpsAndParams(
       case tflite::BuiltinOperator_SELECT:
       case tflite::BuiltinOperator_SLICE:
       case tflite::BuiltinOperator_SIN:
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
       case tflite::BuiltinOperator_LOG:
 #endif
       //case tflite::BuiltinOperator_TRANSPOSE_CONV:
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
       case tflite::BuiltinOperator_TILE:
       case tflite::BuiltinOperator_EXPAND_DIMS:
       case tflite::BuiltinOperator_SPARSE_TO_DENSE:
@@ -973,12 +973,10 @@ TfLiteStatus AddOpsAndParams(
         return kTfLiteError;
         break;
       }
-#ifdef OBS_BUILD
       default:
         logError("Op code %d is currently not delegated to NNAPI", builtin);
         return kTfLiteError;
         break;
-#endif
     }
 
     if (nnapi_version == 11 && GetAndroidSdkVersionCached() < 28) {
index 8c539d6..31170a8 100644 (file)
@@ -56,7 +56,7 @@
       }
     };
 
-#ifndef OBS_BUILD
+#if TFLITE_MAJOR_VER == 1 && TFLITE_MINOR_VER == 12
     auto add_pack_ex_params = [&add_scalar_int32](void* data) {
       auto builtin = reinterpret_cast<TfLitePackParams*>(data);
       add_scalar_int32(builtin->values_count);
index 3649e8e..9acbe70 100644 (file)
@@ -48,9 +48,9 @@ NNFW test rpm. It does not depends on nnfw rpm since it contains nnfw runtime.
 
 %{!?coverage_build: %define coverage_build 0}
 %if %{coverage_build} == 1
-%define build_options COVERAGE_BUILD=1 OBS_BUILD=1 BUILD_TYPE=Debug TARGET_ARCH=%{target_arch} TARGET_OS=tizen
+%define build_options COVERAGE_BUILD=1 OBS_BUILD=1 BUILD_TYPE=Debug TARGET_ARCH=%{target_arch} TARGET_OS=tizen TFLITE_MAJOR_VER=1 TFLITE_MINOR_VER=9
 %else
-%define build_options OBS_BUILD=1 BUILD_TYPE=%{build_type} INSTALL_PATH=%{buildroot}%{_prefix} TARGET_ARCH=%{target_arch} TARGET_OS=tizen
+%define build_options OBS_BUILD=1 BUILD_TYPE=%{build_type} INSTALL_PATH=%{buildroot}%{_prefix} TARGET_ARCH=%{target_arch} TARGET_OS=tizen TFLITE_MAJOR_VER=1 TFLITE_MINOR_VER=9
 %endif
 
 %prep