[tflite] Support tflite v2.7.0 for tizen and deian
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Tue, 9 Nov 2021 05:50:03 +0000 (14:50 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 28 Feb 2022 05:29:45 +0000 (14:29 +0900)
- Remove unnecessary gles dependency
- Support newly introduced xnnpack delegate
- Remove unnecessary build options

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
ext/nnstreamer/tensor_filter/meson.build
ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc
meson_options.txt
packaging/nnstreamer.spec

index 077f91e..39eaec2 100644 (file)
@@ -223,25 +223,12 @@ if tflite2_support_is_available
     tflite2_compile_args += '-DUSE_TENSORFLOW2_HEADER_PATH=1'
   endif
 
-  if get_option('tflite2-gpu-delegate-support')
-    # GLES dependency for tflite GPU delegate
-    gles_dep = dependency('gles20', required: true)
-    nnstreamer_filter_tflite2_deps += gles_dep
-    tflite2_compile_args += '-DTFLITE_GPU_DELEGATE_SUPPORTED'
-  endif
-
-  if get_option('tflite2-nnapi-delegate-support')
-    tflite2_compile_args += '-DTFLITE_NNAPI_DELEGATE_SUPPORTED'
-  endif
-
+  # TODO: tflite v2.8.0+ supports build option for external delegate
+  # remove below option after that.
   if get_option('tflite2-external-delegate-support')
     tflite2_compile_args += '-DTFLITE_EXTERNAL_DELEGATE_SUPPORTED'
   endif
 
-  if get_option('tflite2-xnnpack-delegate-support')
-    tflite2_compile_args += '-DTFLITE_XNNPACK_DELEGATE_SUPPORTED'
-  endif
-
   tflite2_extra_dep = declare_dependency(
     compile_args : tflite2_compile_args
   )
index 97da893..c3c7929 100644 (file)
 #  include <tensorflow/contrib/lite/model.h>
 #endif
 
-#ifdef TFLITE_XNNPACK_DELEGATE_SUPPORTED
+#if TFLITE_VERSION_MAJOR >= 2
 #  if USE_TENSORFLOW2_HEADER_PATH
 #    include <tensorflow2/lite/delegates/xnnpack/xnnpack_delegate.h>
-#  else
-#    include <tensorflow/lite/delegates/xnnpack/xnnpack_delegate.h>
-#  endif
-#endif
-
-#ifdef TFLITE_NNAPI_DELEGATE_SUPPORTED
-#  if USE_TENSORFLOW2_HEADER_PATH
-#    include <tensorflow2/lite/delegates/nnapi/nnapi_delegate.h>
-#  else
-#    include <tensorflow/lite/delegates/nnapi/nnapi_delegate.h>
-#  endif
-#endif
-
-#ifdef TFLITE_GPU_DELEGATE_SUPPORTED
-#  if USE_TENSORFLOW2_HEADER_PATH
 #    include <tensorflow2/lite/delegates/gpu/delegate.h>
+#    include <tensorflow2/lite/delegates/nnapi/nnapi_delegate.h>
 #  else
+#    include <tensorflow/lite/delegates/xnnpack/xnnpack_delegate.h>
 #    include <tensorflow/lite/delegates/gpu/delegate.h>
+#    include <tensorflow/lite/delegates/nnapi/nnapi_delegate.h>
 #  endif
 #endif
 
@@ -96,7 +84,6 @@
 #define TFLITE_RESOLVER_WITHOUT_DEFAULT_DELEGATES
 #endif
 
-
 /**
  * @brief Macro for debug mode.
  */
@@ -441,14 +428,14 @@ TFLiteInterpreter::loadModel (int num_threads, tflite_delegate_e delegate_e)
   switch (delegate_e) {
     case TFLITE_DELEGATE_XNNPACK:
     {
-#ifdef TFLITE_XNNPACK_DELEGATE_SUPPORTED
+#if TFLITE_VERSION_MAJOR >= 2
       /* set xnnpack delegate */
       TfLiteXNNPackDelegateOptions xnnpack_options =
           TfLiteXNNPackDelegateOptionsDefault();
       xnnpack_options.num_threads = (num_threads > 1) ? num_threads : 0;
 
       is_xnnpack_delegated = true;
-      ml_logw ("Input/output tensors should be memcpy-ed rather than explictly assigning its ptr when XNNPACK Delegate is used.");
+      ml_logw ("Input/output tensors should be memcpy-ed rather than explicitly assigning its ptr when XNNPACK Delegate is used.");
       ml_logw ("This could cause performance degradation if sizes of input/output tensors are large");
 
       delegate = TfLiteXNNPackDelegateCreate (&xnnpack_options);
@@ -459,13 +446,13 @@ TFLiteInterpreter::loadModel (int num_threads, tflite_delegate_e delegate_e)
 
       setDelegate (delegate, deleter);
 #else
-      ml_logw ("XNNPACK delegate support is available only in Android with tflite v2.3.0 or higher and XNNPACK support should be enabled for tf-lite subplugin build.");
+      ml_logw ("NNStreamer was built without XNNPACK delegate. Given delegate option XNNPACK is ignored.");
 #endif
       break;
     }
     case TFLITE_DELEGATE_GPU:
     {
-#ifdef TFLITE_GPU_DELEGATE_SUPPORTED
+#if TFLITE_VERSION_MAJOR >= 2
       /* set gpu delegate when accelerator set to GPU */
       TfLiteGpuDelegateOptionsV2 options = TfLiteGpuDelegateOptionsV2Default ();
       options.experimental_flags = TFLITE_GPU_EXPERIMENTAL_FLAGS_NONE;
@@ -489,13 +476,13 @@ TFLiteInterpreter::loadModel (int num_threads, tflite_delegate_e delegate_e)
 
       setDelegate (delegate, deleter);
 #else
-      ml_logw ("GPU delegate support is available with tflite v2.3.0 or higher");
+      ml_logw ("NNStreamer was built without GPU delegate. Given delegate option GPU is ignored.");
 #endif
       break;
     }
     case TFLITE_DELEGATE_NNAPI:
     {
-#ifdef TFLITE_NNAPI_DELEGATE_SUPPORTED
+#if TFLITE_VERSION_MAJOR >= 2
       /* set nnapi delegate when accelerator set to auto (cpu.neon in Android) or NPU */
       delegate = new tflite::StatefulNnApiDelegate ();
       void (* deleter) (TfLiteDelegate *) =
@@ -505,7 +492,7 @@ TFLiteInterpreter::loadModel (int num_threads, tflite_delegate_e delegate_e)
 
       setDelegate (delegate, deleter);
 #else
-      ml_logw ("NNAPI delegate support is available only in Android with tflite v1.14.0 or higher");
+      ml_logw ("NNStreamer was built without NNAPI delegate. Given delegate option NNAPI is ignored.");
 #endif
       break;
     }
@@ -535,7 +522,7 @@ TFLiteInterpreter::loadModel (int num_threads, tflite_delegate_e delegate_e)
 
       setDelegate (delegate, deleter);
 #else
-      ml_logw ("External delegate support is available with tflite v2.4.0 or higher");
+      ml_logw ("NNStreamer was built without external delegate. Given delegate option external is ignored.");
 #endif
       break;
     }
index 9968f1b..322dcd9 100644 (file)
@@ -27,10 +27,7 @@ option('trix-engine-support', type: 'feature', value: 'auto')
 option('enable-test', type: 'boolean', value: true)
 option('install-test', type: 'boolean', value: false)
 option('enable-pytorch-use-gpu', type: 'boolean', value: false) # default value, can be specified at run time
-option('tflite2-gpu-delegate-support', type: 'boolean', value: 'false')
-option('tflite2-nnapi-delegate-support', type: 'boolean', value: 'false')
 option('tflite2-external-delegate-support', type: 'boolean', value: 'false')
-option('tflite2-xnnpack-delegate-support', type: 'boolean', value: 'false')
 option('enable-mediapipe', type: 'boolean', value: false)
 option('enable-env-var', type: 'boolean', value: true)
 option('enable-symbolic-link', type: 'boolean', value: true)
index c00b0d7..d551a2f 100644 (file)
@@ -22,7 +22,6 @@
 %define                tensorflow_support 0
 %define                tensorflow_lite_support 1
 %define                tensorflow2_lite_support 1
-%define                tensorflow2_gpu_delegate_support 1
 %define                armnn_support 1
 %define                vivante_support 0
 %define                flatbuf_support 1
@@ -196,9 +195,6 @@ BuildRequires: tensorflow-lite-devel
 %if 0%{?tensorflow2_lite_support}
 # for tensorflow2-lite
 BuildRequires: tensorflow2-lite-devel
-%if 0%{?tensorflow2_gpu_delegate_support}
-BuildRequires: pkgconfig(gles20)
-%endif
 %endif
 # custom_example_opencv filter requires opencv-devel
 BuildRequires: opencv-devel
@@ -685,11 +681,7 @@ Provides additional gstreamer plugins for nnstreamer pipelines
 
 # Support tensorflow2-lite
 %if 0%{?tensorflow2_lite_support}
-%if 0%{?tensorflow2_gpu_delegate_support}
-%define enable_tf2_lite -Dtflite2-support=enabled -Dtflite2-gpu-delegate-support=true
-%else
-%define enable_tf2_lite -Dtflite2-support=enabled -Dtflite2-gpu-delegate-support=false
-%endif
+%define enable_tf2_lite -Dtflite2-support=enabled
 %else
 %define enable_tf2_lite -Dtflite2-support=disabled
 %endif