From: Sangjung Woo Date: Tue, 24 Nov 2020 02:32:30 +0000 (+0900) Subject: [Filter/tflite] Support GPU Delegate on Tizen X-Git-Tag: submit/tizen/20201201.095355^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=502159c9d72759c19d080cac29ca50789d31bf6b;p=platform%2Fupstream%2Fnnstreamer.git [Filter/tflite] Support GPU Delegate on Tizen This patch supports the GPU Delegate functionality on Tizen platform. NNStreamer filter for TFLite2 GPU delegate only supports OpenCL backend since GLES v3.1 backend has a constraint that Invoke() must be called from the same EGLContext. If both tensorflow2_lite_support and tensorflow2_gpu_delegate_support are set as 1 in nnstreamer.spec, GPU Delegate functionality is enabled. If tensorflow2_gpu_delegate_support is set but tensorflow2_lite_support is 0, then tensorflow2_gpu_delegate_support option is ignored. Since Tensorflow2 GPU delegate is ready, tensorflow2_gpu_delegate_support is set as 1 in this patch. Signed-off-by: Sangjung Woo --- diff --git a/ext/nnstreamer/tensor_filter/meson.build b/ext/nnstreamer/tensor_filter/meson.build index 865a1b8..d4f1b33 100644 --- a/ext/nnstreamer/tensor_filter/meson.build +++ b/ext/nnstreamer/tensor_filter/meson.build @@ -187,6 +187,13 @@ if tflite2_support_is_available tflite2_compile_args += '-DTFLITE_FLOAT16=1' tflite2_compile_args += '-DTFLITE_COMPLEX64=1' + 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 + tflite2_extra_dep = declare_dependency( compile_args : tflite2_compile_args ) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc index 7ca3fc5..303a6bf 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc @@ -355,6 +355,14 @@ TFLiteInterpreter::loadModel (int num_threads, accl_hw accelerator) options.experimental_flags = TFLITE_GPU_EXPERIMENTAL_FLAGS_NONE; options.experimental_flags |= TFLITE_GPU_EXPERIMENTAL_FLAGS_ENABLE_QUANT; + /** NNStreamer filter for TFLite2 GPU delegate only supports OpenCL backend + * since GLES v3.1 backend has a constraint that + * Invoke() must be called from the same EGLContext. */ + options.experimental_flags |= TFLITE_GPU_EXPERIMENTAL_FLAGS_CL_ONLY; + options.inference_priority1 = TFLITE_GPU_INFERENCE_PRIORITY_MIN_LATENCY; + options.inference_priority2 = TFLITE_GPU_INFERENCE_PRIORITY_MIN_MEMORY_USAGE; + options.inference_priority3 = TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION; + gpu_delegate.reset (TfLiteGpuDelegateV2Create (&options)); setDelegate (gpu_delegate.get ()); #else diff --git a/meson_options.txt b/meson_options.txt index d409535..7f62905 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -23,6 +23,7 @@ option('grpc-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('enable-mediapipe', type: 'boolean', value: false) option('enable-env-var', type: 'boolean', value: true) option('enable-symbolic-link', type: 'boolean', value: true) diff --git a/packaging/nnstreamer.spec b/packaging/nnstreamer.spec index 5db34c1..57c7bb0 100644 --- a/packaging/nnstreamer.spec +++ b/packaging/nnstreamer.spec @@ -22,6 +22,7 @@ %define tensorflow_support 0 %define tensorflow_lite_support 1 %define tensorflow2_lite_support 1 +%define tensorflow2_gpu_delegate_support 1 %define armnn_support 0 %define vivante_support 0 %define flatbuf_support 1 @@ -162,6 +163,9 @@ 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 @@ -562,7 +566,11 @@ Provides additional gstreamer plugins for nnstreamer pipelines # Support tensorflow2-lite %if 0%{?tensorflow2_lite_support} -%define enable_tf2_lite -Dtflite2-support=enabled +%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 %else %define enable_tf2_lite -Dtflite2-support=disabled %endif