blob: fcdf62ebcc6e79b406f6e802d8e5adf1f9d79eb7 [file] [edit]
From c4d6512d82b6399bc111ba3c67d25b8221e11c53 Mon Sep 17 00:00:00 2001
From: TFLite Patcher <tflite@localhost>
Date: Fri, 18 Oct 2024 17:59:37 +0800
Subject: [PATCH] Enable Gpu Delegate for ChromeOS.
PATCH_NAME=gpu-delegate
---
tensorflow/lite/BUILD | 1 +
.../acceleration/configuration/gpu_plugin.h | 2 +-
tensorflow/lite/core/kernels/BUILD | 17 +++--------------
tensorflow/lite/delegates/gpu/BUILD | 6 ++++++
tensorflow/lite/delegates/gpu/build_defs.bzl | 2 +-
tensorflow/lite/delegates/gpu/cl/BUILD | 2 +-
tensorflow/lite/tools/evaluation/utils.h | 2 +-
7 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/tensorflow/lite/BUILD b/tensorflow/lite/BUILD
index 5bf1aaae..1d702413 100644
--- a/tensorflow/lite/BUILD
+++ b/tensorflow/lite/BUILD
@@ -1422,6 +1422,7 @@ tflite_cc_shared_object(
":tflite_exported_symbols.lds",
":tflite_version_script.lds",
"//tensorflow/lite/kernels:builtin_ops_all_linked",
+ "//tensorflow/lite/delegates/gpu:delegate",
],
)
diff --git a/tensorflow/lite/acceleration/configuration/gpu_plugin.h b/tensorflow/lite/acceleration/configuration/gpu_plugin.h
index a45c44d8..048795ea 100644
--- a/tensorflow/lite/acceleration/configuration/gpu_plugin.h
+++ b/tensorflow/lite/acceleration/configuration/gpu_plugin.h
@@ -18,7 +18,7 @@ limitations under the License.
// This file provides the GpuPlugin class, which implements the
// TFLite Delegate Plugin for the GPU Delegate.
-#if defined(__ANDROID__) || defined(CL_DELEGATE_NO_GL)
+#if defined(__ANDROID__) || defined(CL_DELEGATE_NO_GL) || defined(FORCE_ENABLE_GPU_DELEGATE)
#define TFLITE_SUPPORTS_GPU_DELEGATE 1
#endif
diff --git a/tensorflow/lite/core/kernels/BUILD b/tensorflow/lite/core/kernels/BUILD
index e253f294..8471cb9f 100644
--- a/tensorflow/lite/core/kernels/BUILD
+++ b/tensorflow/lite/core/kernels/BUILD
@@ -30,25 +30,14 @@ cc_test(
],
)
-cc_library(
+# Make this an alias to avoid ODR violation with GPU delegate.
+alias(
name = "builtin_ops",
- srcs = ["register.cc"],
- hdrs = [
- "builtin_op_kernels.h",
- "register.h",
- ],
+ actual = "builtin_ops_all_linked",
compatible_with = get_compatible_with_portable(),
visibility = [
"//tensorflow/lite:__subpackages__",
] + builtin_ops_visibility_allowlist(),
- deps = [
- "//tensorflow/lite:mutable_op_resolver",
- "//tensorflow/lite:tflite_with_xnnpack_optional",
- "//tensorflow/lite/core:cc_api_stable",
- "//tensorflow/lite/core/c:common",
- "//tensorflow/lite/kernels:builtin_op_kernels",
- "//tensorflow/lite/schema:schema_fbs",
- ],
)
# For internal usage by shared libraries only.
diff --git a/tensorflow/lite/delegates/gpu/BUILD b/tensorflow/lite/delegates/gpu/BUILD
index d66d66b5..adfff1fd 100644
--- a/tensorflow/lite/delegates/gpu/BUILD
+++ b/tensorflow/lite/delegates/gpu/BUILD
@@ -75,6 +75,11 @@ config_setting(
},
)
+config_setting(
+ name = "force_enable_gpu_delegate",
+ values = {"copt": "-DFORCE_ENABLE_GPU_DELEGATE"},
+)
+
cc_library(
name = "gl_delegate",
srcs = ["gl_delegate.cc"],
@@ -264,6 +269,7 @@ selects.config_setting_group(
name = "supports_gpu_delegate",
match_any = [
"//tensorflow:android",
+ "//tensorflow/lite/delegates/gpu:force_enable_gpu_delegate",
"//tensorflow/lite/delegates/gpu/cl:opencl_delegate_no_gl",
],
)
diff --git a/tensorflow/lite/delegates/gpu/build_defs.bzl b/tensorflow/lite/delegates/gpu/build_defs.bzl
index cdea91ae..58b8386e 100644
--- a/tensorflow/lite/delegates/gpu/build_defs.bzl
+++ b/tensorflow/lite/delegates/gpu/build_defs.bzl
@@ -3,7 +3,7 @@
def gpu_delegate_linkopts():
"""Additional link options needed when linking in the GPU Delegate."""
return select({
- "//tensorflow:android": [
+ "//tensorflow/lite/delegates/gpu:force_enable_gpu_delegate": [
"-lEGL",
# We don't need to link libGLESv3, because if it exists,
# it is a symlink to libGLESv2.
diff --git a/tensorflow/lite/delegates/gpu/cl/BUILD b/tensorflow/lite/delegates/gpu/cl/BUILD
index ecc22a1f..1b315ab8 100644
--- a/tensorflow/lite/delegates/gpu/cl/BUILD
+++ b/tensorflow/lite/delegates/gpu/cl/BUILD
@@ -411,7 +411,7 @@ cc_library(
srcs = ["gpu_api_delegate.cc"],
hdrs = ["gpu_api_delegate.h"],
linkopts = select({
- "//tensorflow:android": [
+ "//tensorflow/lite/delegates/gpu:force_enable_gpu_delegate": [
"-lEGL",
"-lGLESv3",
],
diff --git a/tensorflow/lite/tools/evaluation/utils.h b/tensorflow/lite/tools/evaluation/utils.h
index 638d9e7e..63c9eb08 100644
--- a/tensorflow/lite/tools/evaluation/utils.h
+++ b/tensorflow/lite/tools/evaluation/utils.h
@@ -23,7 +23,7 @@ limitations under the License.
#if !TFLITE_WITH_STABLE_ABI
// TODO(b/240438534): enable nnapi.
-#if defined(__ANDROID__)
+#if defined(__ANDROID__) || defined(FORCE_ENABLE_GPU_DELEGATE)
#define TFLITE_SUPPORTS_NNAPI_DELEGATE 1
#define TFLITE_SUPPORTS_GPU_DELEGATE 1
#elif defined(CL_DELEGATE_NO_GL)