blob: f78a3e75b7f664e8093fe4dfbd7588406113e194 [file]
From 16cf01380c78fd469d0912e99ea10cdfd8ee84e8 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 d4993082..a603bb69 100644
--- a/tensorflow/lite/BUILD
+++ b/tensorflow/lite/BUILD
@@ -1435,6 +1435,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 71f9980f..0e69dee4 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 5eeb1764..e8a55c56 100644
--- a/tensorflow/lite/delegates/gpu/BUILD
+++ b/tensorflow/lite/delegates/gpu/BUILD
@@ -33,6 +33,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"],
@@ -216,6 +221,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 cc593ef4..3291e3a9 100644
--- a/tensorflow/lite/delegates/gpu/cl/BUILD
+++ b/tensorflow/lite/delegates/gpu/cl/BUILD
@@ -364,7 +364,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 201564cd..46fa87c1 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)