Generate separate pod for Core ML delegate
PiperOrigin-RevId: 311651255 Change-Id: I7ba8755d447674fa8d20935b0c9815a5406b879f
This commit is contained in:
parent
93a30c941c
commit
0de7edf8b1
@ -12,7 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
|
||||
package(default_visibility = [
|
||||
"//visibility:public",
|
||||
])
|
||||
@ -46,6 +45,11 @@ objc_library(
|
||||
name = "coreml_delegate",
|
||||
srcs = ["coreml_delegate.mm"],
|
||||
hdrs = ["coreml_delegate.h"],
|
||||
module_name = "TensorFlowLiteCCoreML",
|
||||
# By setting CoreML as weak_framework, the TensorFlow Lite can be built for older iOS versions.
|
||||
weak_sdk_frameworks = [
|
||||
"CoreML",
|
||||
],
|
||||
deps = [
|
||||
":coreml_delegate_kernel",
|
||||
":mlmodel_proto_cc",
|
||||
|
@ -24,7 +24,6 @@ genrule(
|
||||
|
||||
TFL_FRAMEWORK_HDRS = [
|
||||
"//tensorflow/lite/delegates/gpu:metal_delegate.h",
|
||||
":coreml_delegate.h",
|
||||
"//tensorflow/lite/c:c_api.h",
|
||||
"//tensorflow/lite/c:common.h",
|
||||
]
|
||||
@ -58,16 +57,35 @@ ios_static_framework(
|
||||
],
|
||||
)
|
||||
|
||||
# This target builds the Core ML 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.
|
||||
#
|
||||
# bazel build -c opt --config=ios_fat //tensorflow/lite/experimental/ios:TensorFlowLiteCCoreMl_framework
|
||||
ios_static_framework(
|
||||
name = "TensorFlowLiteCCoreML_framework",
|
||||
hdrs = [
|
||||
":coreml_delegate.h",
|
||||
],
|
||||
avoid_deps = [
|
||||
":tensorflow_lite_c",
|
||||
],
|
||||
bundle_name = "TensorFlowLiteCCoreML",
|
||||
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
||||
deps = [
|
||||
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "tensorflow_lite_c",
|
||||
hdrs = [
|
||||
"//tensorflow/lite/c:c_api.h",
|
||||
"//tensorflow/lite/c:common.h",
|
||||
"//tensorflow/lite/delegates/gpu:metal_delegate.h",
|
||||
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate.h",
|
||||
],
|
||||
linkopts = [
|
||||
"-Wl,-weak_framework,CoreML",
|
||||
"-Wl,-weak_framework,Metal",
|
||||
],
|
||||
tags = [
|
||||
@ -77,7 +95,6 @@ cc_library(
|
||||
deps = [
|
||||
"//tensorflow/lite/c:c_api",
|
||||
"//tensorflow/lite/delegates/gpu:metal_delegate",
|
||||
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -19,6 +19,16 @@ Pod::Spec.new do |s|
|
||||
|
||||
s.module_name = 'TensorFlowLiteC'
|
||||
s.library = 'c++'
|
||||
s.vendored_frameworks = 'Frameworks/TensorFlowLiteC.framework'
|
||||
s.weak_frameworks = 'CoreML'
|
||||
|
||||
s.default_subspec = 'Core'
|
||||
|
||||
s.subspec 'Core' do |core|
|
||||
core.vendored_frameworks = 'Frameworks/TensorFlowLiteC.framework'
|
||||
end
|
||||
|
||||
s.subspec 'CoreML' do |coreml|
|
||||
coreml.weak_framework = 'CoreML'
|
||||
coreml.dependency 'TensorFlowLiteC/Core'
|
||||
coreml.vendored_frameworks = 'Frameworks/TensorFlowLiteCCoreML.framework'
|
||||
end
|
||||
end
|
||||
|
@ -10,6 +10,19 @@ package(
|
||||
licenses = ["notice"], # Apache 2.0
|
||||
)
|
||||
|
||||
# TODO(b/153554551): investigate if separate delegate libraries can be made with same module_name
|
||||
# If you don't need delegates and want to reduce size of the app, you can exclude Metal/Core ML
|
||||
# delegate related dependencies from the rule.
|
||||
# For example, if you don't want to use Core ML delegate:
|
||||
# 1. add `exclude = ["Sources/CoreMLDelegate.swift"]` to `glob`, so that `srcs` would look like this:
|
||||
# ```
|
||||
# srcs = glob(
|
||||
# ["Sources/*.swift"],
|
||||
# exclude = ["Sources/CoreMLDelegate.swift"],
|
||||
# ),
|
||||
# 2. remove "-Wl,-weak_framework,CoreML" from `linkopts`
|
||||
# 3. remove "...:coreml_delegate" from `deps`
|
||||
|
||||
swift_library(
|
||||
name = "TensorFlowLite",
|
||||
srcs = glob(["Sources/*.swift"]),
|
||||
@ -21,6 +34,7 @@ swift_library(
|
||||
tags = TFL_DEFAULT_TAGS,
|
||||
visibility = ios_visibility_whitelist(),
|
||||
deps = [
|
||||
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
||||
"//tensorflow/lite/experimental/ios:tensorflow_lite_c",
|
||||
],
|
||||
)
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import TensorFlowLiteC
|
||||
import TensorFlowLiteCCoreML
|
||||
|
||||
/// A delegate that uses the `Core ML` framework for performing TensorFlow Lite graph operations.
|
||||
///
|
||||
|
@ -20,8 +20,20 @@ Pod::Spec.new do |s|
|
||||
|
||||
tfl_dir = 'tensorflow/lite/'
|
||||
swift_dir = tfl_dir + 'experimental/swift/'
|
||||
s.source_files = swift_dir + 'Sources/*.swift'
|
||||
s.dependency 'TensorFlowLiteC', "~> #{s.version}"
|
||||
|
||||
s.default_subspec = 'Core'
|
||||
|
||||
s.subspec 'Core' do |core|
|
||||
core.dependency 'TensorFlowLiteC', "#{s.version}"
|
||||
core.source_files = swift_dir + 'Sources/*.swift'
|
||||
core.exclude_files = swift_dir + 'Sources/CoreMLDelegate.swift'
|
||||
end
|
||||
|
||||
s.subspec 'CoreML' do |coreml|
|
||||
coreml.source_files = swift_dir + 'Sources/CoreMLDelegate.swift'
|
||||
coreml.dependency 'TensorFlowLiteC/CoreML', "#{s.version}"
|
||||
coreml.dependency 'TensorFlowLiteSwift/Core', "#{s.version}"
|
||||
end
|
||||
|
||||
s.test_spec 'Tests' do |ts|
|
||||
ts.source_files = swift_dir + 'Tests/*.swift'
|
||||
|
@ -20,8 +20,20 @@ Pod::Spec.new do |s|
|
||||
|
||||
tfl_dir = 'tensorflow/lite/'
|
||||
swift_dir = tfl_dir + 'experimental/swift/'
|
||||
s.source_files = swift_dir + 'Sources/*.swift'
|
||||
s.dependency 'TensorFlowLiteC', '~> 0.0.1-nightly'
|
||||
|
||||
s.default_subspec = 'Core'
|
||||
|
||||
s.subspec 'Core' do |core|
|
||||
core.dependency 'TensorFlowLiteC', "#{s.version}"
|
||||
core.source_files = swift_dir + 'Sources/*.swift'
|
||||
core.exclude_files = swift_dir + 'Sources/CoreMLDelegate.swift'
|
||||
end
|
||||
|
||||
s.subspec 'CoreML' do |coreml|
|
||||
coreml.source_files = swift_dir + 'Sources/CoreMLDelegate.swift'
|
||||
coreml.dependency 'TensorFlowLiteC/CoreML', "#{s.version}"
|
||||
coreml.dependency 'TensorFlowLiteSwift/Core', "#{s.version}"
|
||||
end
|
||||
|
||||
s.test_spec 'Tests' do |ts|
|
||||
ts.source_files = swift_dir + 'Tests/*.swift'
|
||||
|
Loading…
Reference in New Issue
Block a user