From 05ed82f0f4c00982cd274a2ebc5d0aeb759eebcb Mon Sep 17 00:00:00 2001 From: YoungSeok Yoon Date: Mon, 2 Dec 2019 20:43:51 -0800 Subject: [PATCH] Make the TFLite with select TF ops for iOS composable PiperOrigin-RevId: 283472625 Change-Id: I59b4c378465043c5dfbb61e454073afadade2ac1 --- .bazelrc | 3 +- tensorflow/lite/experimental/ios/BUILD.apple | 32 +++++++++++-------- .../ios/TensorFlowLiteSelectTfOps.md | 19 +++++++++++ ...TensorFlowLiteSelectTfOps.podspec.template | 21 ++++++++++++ 4 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.md create mode 100644 tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.podspec.template diff --git a/.bazelrc b/.bazelrc index 5fd28e867c0..451cc60fdd1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -100,9 +100,9 @@ build --apple_platform_type=macos # iOS configs for each architecture and the fat binary builds. build:ios --apple_platform_type=ios build:ios --apple_bitcode=embedded --copt=-fembed-bitcode +build:ios --copt=-Wno-c++11-narrowing build:ios_armv7 --config=ios build:ios_armv7 --cpu=ios_armv7 -build:ios_armv7 --copt -Wno-c++11-narrowing build:ios_arm64 --config=ios build:ios_arm64 --cpu=ios_arm64 build:ios_i386 --config=ios @@ -111,7 +111,6 @@ build:ios_x86_64 --config=ios build:ios_x86_64 --cpu=ios_x86_64 build:ios_fat --config=ios build:ios_fat --ios_multi_cpus=armv7,arm64,i386,x86_64 -build:ios_fat --copt -Wno-c++11-narrowing # Config to use a mostly-static build and disable modular op registration # support (this will revert to loading TensorFlow with RTLD_GLOBAL in Python). diff --git a/tensorflow/lite/experimental/ios/BUILD.apple b/tensorflow/lite/experimental/ios/BUILD.apple index 6ecd3d589ea..cf81057b167 100644 --- a/tensorflow/lite/experimental/ios/BUILD.apple +++ b/tensorflow/lite/experimental/ios/BUILD.apple @@ -26,18 +26,6 @@ ios_static_framework( ], ) -# bazel build -c opt --config=ios --ios_multi_cpus=armv7,arm64,x86_64 //tensorflow/lite/experimental/ios:TensorFlowLiteCWithSelectTfOps_framework -ios_static_framework( - name = "TensorFlowLiteCWithSelectTfOps_framework", - hdrs = TFL_LIBRARY_HDRS, - bundle_name = "TensorFlowLiteC", - minimum_os_version = TFL_MINIMUM_OS_VERSION, - deps = [ - ":TensorFlowLiteC", - "//tensorflow/lite/delegates/flex:delegate", - ], -) - objc_library( name = "TensorFlowLiteC", hdrs = TFL_LIBRARY_HDRS, @@ -50,6 +38,24 @@ objc_library( ], ) +# This target builds the flex delegate as a separate static framework, which +# does not include the TensorFlow Lite runtime. As this target does not contain +# TensorFlow Lite runtime, it is intended to be linked along with the +# TensorFlowLiteC framework above in a composable way. +# +# The flex delegate cannot be built for i386, so it can't be built with ios_fat +# config. +# +# bazel build -c opt --config=ios --ios_multi_cpus=armv7,arm64,x86_64 //tensorflow/lite/experimental/ios:TensorFlowLiteSelectTfOps_framework +ios_static_framework( + name = "TensorFlowLiteSelectTfOps_framework", + bundle_name = "TensorFlowLiteSelectTfOps", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + "//tensorflow/lite/delegates/flex:delegate", + ], +) + # Using this intermediate target is a workaround for a bug in bazel build rules # involving mixed objc_library & cc_library deps mentioned in (b/74809458). # When these dependencies are declared directly under the "TensorFlowLiteC" @@ -79,6 +85,6 @@ build_test( ], targets = [ ":TensorFlowLiteC_framework", - ":TensorFlowLiteCWithSelectTfOps_framework", + ":TensorFlowLiteSelectTfOps_framework", ], ) diff --git a/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.md b/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.md new file mode 100644 index 00000000000..525049db2b7 --- /dev/null +++ b/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.md @@ -0,0 +1,19 @@ +# TensorFlow Lite with Select TensorFlow ops + +For enabling the Select TensorFlow ops for your TensorFlow Lite app, please add +the `TensorFlowLiteSelectTfOps` pod to your Podfile, in addition to +`TensorFlowLiteSwift` or `TensorFlowLiteObjC` pod, depending on your primary +language. + +After that, you should also force load the framework from your project. Add the +following line to the `Other Linker Flags` under your project's Build Settings +page. + +``` +-force_load "$(PROJECT_DIR)/Pods/TensorFlowLiteSelectTfOps/Frameworks/TensorFlowLiteSelectTfOps.framework/TensorFlowLiteSelectTfOps" +``` + +Please refer to the [Select operators from TensorFlow][ops-select] guide for +more details. + +[ops-select]: https://www.tensorflow.org/lite/guide/ops_select#ios diff --git a/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.podspec.template b/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.podspec.template new file mode 100644 index 00000000000..7a91e4a08ce --- /dev/null +++ b/tensorflow/lite/experimental/ios/TensorFlowLiteSelectTfOps.podspec.template @@ -0,0 +1,21 @@ +Pod::Spec.new do |s| + s.name = 'TensorFlowLiteSelectTfOps' + s.version = '${TFL_BUILD_VERSION}' + s.authors = 'Google Inc.' + s.license = { :type => 'Apache' } + s.homepage = 'https://github.com/tensorflow/tensorflow' + s.source = { :http => "${TFL_DOWNLOAD_URL}" } + s.summary = 'TensorFlow Lite' + s.description = <<-DESC + + This pod can be used in addition to `TensorFlowLiteSwift` or + `TensorFlowLiteObjC` pod, in order to enable Select TensorFlow ops. The + resulting binary should also be force-loaded to the final app binary. + DESC + + s.ios.deployment_target = '9.0' + + s.module_name = 'TensorFlowLiteSelectTfOps' + s.library = 'c++' + s.vendored_frameworks = 'Frameworks/TensorFlowLiteSelectTfOps.framework' +end