Fix linking error of Flex delegate for iOS
This cl fixes three different issues about Flex delegate on iOS: 1. Duplicated symbols of C API exported by TensorFlowLiteC and TensorFlowLiteSelectTfOps. This is fixed by using avoid_deps. 2. Undefined symbol of uprv::getICUData::conversion 3. TensorFlowLiteC do not export the weak symbol AcquireFlexDelegate. This cl replaces the use of weak symbol by LoadLibrary::GetSymbol. PiperOrigin-RevId: 339798211 Change-Id: I2e15c008a48b9638568c1a16b3c3b7bcc61e448f
This commit is contained in:
parent
ec23155aff
commit
4b6c15218b
@ -6448,6 +6448,7 @@ cc_library(
|
|||||||
"//tensorflow/core/platform:strong_hash",
|
"//tensorflow/core/platform:strong_hash",
|
||||||
"//third_party/eigen3",
|
"//third_party/eigen3",
|
||||||
"//third_party/fft2d:fft2d_headers",
|
"//third_party/fft2d:fft2d_headers",
|
||||||
|
"//third_party/icu/data:conversion_data",
|
||||||
"@com_google_absl//absl/base",
|
"@com_google_absl//absl/base",
|
||||||
"@com_google_protobuf//:protobuf",
|
"@com_google_protobuf//:protobuf",
|
||||||
"@fft2d",
|
"@fft2d",
|
||||||
|
@ -20,6 +20,7 @@ load(
|
|||||||
"tflite_jni_linkopts",
|
"tflite_jni_linkopts",
|
||||||
)
|
)
|
||||||
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
|
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
|
||||||
|
load("//tensorflow/lite:special_rules.bzl", "flex_portable_tensorflow_deps")
|
||||||
|
|
||||||
def generate_flex_kernel_header(
|
def generate_flex_kernel_header(
|
||||||
name,
|
name,
|
||||||
@ -130,13 +131,7 @@ def tflite_flex_cc_library(
|
|||||||
clean_dep("//tensorflow/core/kernels:android_all_ops_textual_hdrs"),
|
clean_dep("//tensorflow/core/kernels:android_all_ops_textual_hdrs"),
|
||||||
],
|
],
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
deps = [
|
deps = flex_portable_tensorflow_deps() + [
|
||||||
"@com_google_absl//absl/strings:str_format",
|
|
||||||
"//third_party/fft2d:fft2d_headers",
|
|
||||||
"//third_party/eigen3",
|
|
||||||
"@com_google_absl//absl/types:optional",
|
|
||||||
"@gemmlowp",
|
|
||||||
"@icu//:common",
|
|
||||||
clean_dep("//tensorflow/core:protos_all_cc"),
|
clean_dep("//tensorflow/core:protos_all_cc"),
|
||||||
clean_dep("//tensorflow/core:portable_tensorflow_lib_lite"),
|
clean_dep("//tensorflow/core:portable_tensorflow_lib_lite"),
|
||||||
clean_dep("//tensorflow/core/platform:strong_hash"),
|
clean_dep("//tensorflow/core/platform:strong_hash"),
|
||||||
|
@ -71,6 +71,7 @@ tflite_ios_static_framework(
|
|||||||
# bazel build -c opt --config=ios --ios_multi_cpus=armv7,arm64,x86_64 //tensorflow/lite/experimental/ios:TensorFlowLiteSelectTfOps_framework
|
# bazel build -c opt --config=ios --ios_multi_cpus=armv7,arm64,x86_64 //tensorflow/lite/experimental/ios:TensorFlowLiteSelectTfOps_framework
|
||||||
ios_static_framework(
|
ios_static_framework(
|
||||||
name = "TensorFlowLiteSelectTfOps_framework",
|
name = "TensorFlowLiteSelectTfOps_framework",
|
||||||
|
avoid_deps = ["//tensorflow/lite/c:common"],
|
||||||
bundle_name = "TensorFlowLiteSelectTfOps",
|
bundle_name = "TensorFlowLiteSelectTfOps",
|
||||||
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -47,6 +47,20 @@ limitations under the License.
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// TODO(b/139446230): Move to portable platform header.
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#endif // defined(__ANDROID__)
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#elif TARGET_OS_IPHONE
|
||||||
|
#define TFLITE_IS_MOBILE_PLATFORM
|
||||||
|
#endif
|
||||||
|
#endif // defined(__APPLE__)
|
||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -129,9 +143,16 @@ const char* kEmptyTensorName = "";
|
|||||||
// For flex delegate, see also the strong override in
|
// For flex delegate, see also the strong override in
|
||||||
// lite/delegates/flex/delegate.cc.
|
// lite/delegates/flex/delegate.cc.
|
||||||
TFLITE_ATTRIBUTE_WEAK Interpreter::TfLiteDelegatePtr AcquireFlexDelegate() {
|
TFLITE_ATTRIBUTE_WEAK Interpreter::TfLiteDelegatePtr AcquireFlexDelegate() {
|
||||||
#if !defined(__ANDROID__)
|
auto acquire_flex_delegate_func =
|
||||||
// If _pywrap_tensorflow_internal.so is available, use
|
reinterpret_cast<Interpreter::TfLiteDelegatePtr (*)()>(
|
||||||
// TF_AcquireFlexDelegate() to initialize flex delegate.
|
SharedLibrary::GetSymbol("TF_AcquireFlexDelegate"));
|
||||||
|
if (acquire_flex_delegate_func) {
|
||||||
|
return acquire_flex_delegate_func();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(TFLITE_IS_MOBILE_PLATFORM)
|
||||||
|
// Load TF_AcquireFlexDelegate() from _pywrap_tensorflow_internal.so if it is
|
||||||
|
// available.
|
||||||
const char* filename_pywrap_tensorflow_internal =
|
const char* filename_pywrap_tensorflow_internal =
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
"_pywrap_tensorflow_internal.pyd";
|
"_pywrap_tensorflow_internal.pyd";
|
||||||
@ -143,15 +164,16 @@ TFLITE_ATTRIBUTE_WEAK Interpreter::TfLiteDelegatePtr AcquireFlexDelegate() {
|
|||||||
void* lib_tf_internal =
|
void* lib_tf_internal =
|
||||||
SharedLibrary::LoadLibrary(filename_pywrap_tensorflow_internal);
|
SharedLibrary::LoadLibrary(filename_pywrap_tensorflow_internal);
|
||||||
if (lib_tf_internal) {
|
if (lib_tf_internal) {
|
||||||
auto TF_AcquireFlexDelegate =
|
acquire_flex_delegate_func =
|
||||||
reinterpret_cast<Interpreter::TfLiteDelegatePtr (*)()>(
|
reinterpret_cast<Interpreter::TfLiteDelegatePtr (*)()>(
|
||||||
SharedLibrary::GetLibrarySymbol(lib_tf_internal,
|
SharedLibrary::GetLibrarySymbol(lib_tf_internal,
|
||||||
"TF_AcquireFlexDelegate"));
|
"TF_AcquireFlexDelegate"));
|
||||||
if (TF_AcquireFlexDelegate) {
|
if (acquire_flex_delegate_func) {
|
||||||
return TF_AcquireFlexDelegate();
|
return acquire_flex_delegate_func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // !defined(TFLITE_IS_MOBILE_PLATFORM)
|
||||||
|
|
||||||
return Interpreter::TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
return Interpreter::TfLiteDelegatePtr(nullptr, [](TfLiteDelegate*) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,3 +77,16 @@ def tflite_schema_utils_friends():
|
|||||||
# Its usage should be rare, and is often abused by tools that are doing
|
# Its usage should be rare, and is often abused by tools that are doing
|
||||||
# Flatbuffer creation/manipulation in unofficially supported ways."
|
# Flatbuffer creation/manipulation in unofficially supported ways."
|
||||||
return ["//..."]
|
return ["//..."]
|
||||||
|
|
||||||
|
def flex_portable_tensorflow_deps():
|
||||||
|
"""Returns dependencies for building portable tensorflow in Flex delegate."""
|
||||||
|
|
||||||
|
return [
|
||||||
|
"//third_party/fft2d:fft2d_headers",
|
||||||
|
"//third_party/eigen3",
|
||||||
|
"@com_google_absl//absl/types:optional",
|
||||||
|
"@com_google_absl//absl/strings:str_format",
|
||||||
|
"@gemmlowp",
|
||||||
|
"@icu//:common",
|
||||||
|
"//third_party/icu/data:conversion_data",
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user