This adds new experimental flags to the interpreter options of TFLite Obj-C and Swift APIs, which can be used for opting in to a set of highly optimized floating point kernels provided via the XNNPACK delegate. The flags can be used as follows. Obj-C: TFLInterpreterOptions *options = [[TFLInterpreterOptions alloc] init]; options.useXNNPACK = YES; NSError *error; TFLInterpreter *interpreter = [[TFLInterpreter alloc] initWithModelPath:@"model/path" options:options error:&error]; Swift: var options = InterpreterOptions() options.isXNNPackEnabled = true var interpreter = try Interpreter(modelPath: "model/path", options: options) PiperOrigin-RevId: 317270012 Change-Id: I82aae43c3de13ab08af3c70513e2a458e807b0f1
149 lines
4.9 KiB
Plaintext
149 lines
4.9 KiB
Plaintext
# TensorFlow Lite for iOS
|
|
|
|
load("@bazel_skylib//rules:build_test.bzl", "build_test")
|
|
load("//tensorflow/lite/experimental/ios:ios.bzl", "TFL_MINIMUM_OS_VERSION", "tflite_ios_static_framework")
|
|
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_static_framework")
|
|
|
|
package(
|
|
default_visibility = [
|
|
"//tensorflow/lite:__subpackages__",
|
|
],
|
|
licenses = ["notice"], # Apache 2.0
|
|
)
|
|
|
|
sh_binary(
|
|
name = "hide_symbols_with_whitelist",
|
|
srcs = [
|
|
"hide_symbols_with_whitelist.sh",
|
|
],
|
|
)
|
|
|
|
# When the static framework is built with bazel, the all header files are moved
|
|
# to the "Headers" directory with no header path prefixes. This auxiliary rule
|
|
# is used for stripping the path prefix to the "common.h" file included by the
|
|
# "xnnpack_delegate.h" header.
|
|
genrule(
|
|
name = "strip_xnnpack_include_hdr",
|
|
srcs = ["//tensorflow/lite/delegates/xnnpack:xnnpack_delegate.h"],
|
|
outs = ["xnnpack_delegate.h"],
|
|
cmd = """
|
|
sed 's|#include ".*common.h"|#include "common.h"|'\
|
|
"$(location //tensorflow/lite/delegates/xnnpack:xnnpack_delegate.h)"\
|
|
> "$@"
|
|
""",
|
|
)
|
|
|
|
# bazel build -c opt --config=ios_fat //tensorflow/lite/experimental/ios:TensorFlowLiteC_framework
|
|
tflite_ios_static_framework(
|
|
name = "TensorFlowLiteC_framework",
|
|
hdrs = [
|
|
":xnnpack_delegate.h",
|
|
"//tensorflow/lite/c:c_api.h",
|
|
"//tensorflow/lite/c:common.h",
|
|
],
|
|
bundle_name = "TensorFlowLiteC",
|
|
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
|
whitelist_symbols_file = ":whitelist_TensorFlowLiteC.txt",
|
|
deps = [
|
|
":tensorflow_lite_c",
|
|
],
|
|
)
|
|
|
|
# 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",
|
|
],
|
|
)
|
|
|
|
genrule(
|
|
name = "strip_coreml_include_hdr",
|
|
srcs = ["//tensorflow/lite/experimental/delegates/coreml:coreml_delegate.h"],
|
|
outs = ["coreml_delegate.h"],
|
|
cmd = """
|
|
sed 's|#include ".*common.h"|#include "TensorFlowLiteC/common.h"|'\
|
|
"$(location //tensorflow/lite/experimental/delegates/coreml:coreml_delegate.h)"\
|
|
> "$@"
|
|
""",
|
|
)
|
|
|
|
# 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
|
|
tflite_ios_static_framework(
|
|
name = "TensorFlowLiteCCoreML_framework",
|
|
hdrs = [
|
|
":coreml_delegate.h",
|
|
],
|
|
bundle_name = "TensorFlowLiteCCoreML",
|
|
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
|
whitelist_symbols_file = ":whitelist_TensorFlowLiteCCoreML.txt",
|
|
deps = [
|
|
"//tensorflow/lite/experimental/delegates/coreml:coreml_delegate",
|
|
],
|
|
)
|
|
|
|
# This target builds the Metal 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:TensorFlowLiteCMetal_framework
|
|
tflite_ios_static_framework(
|
|
name = "TensorFlowLiteCMetal_framework",
|
|
hdrs = [
|
|
"//tensorflow/lite/delegates/gpu:metal_delegate.h",
|
|
],
|
|
bundle_name = "TensorFlowLiteCMetal",
|
|
minimum_os_version = TFL_MINIMUM_OS_VERSION,
|
|
whitelist_symbols_file = ":whitelist_TensorFlowLiteCMetal.txt",
|
|
deps = [
|
|
"//tensorflow/lite/delegates/gpu:metal_delegate",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "tensorflow_lite_c",
|
|
hdrs = [
|
|
"//tensorflow/lite/c:c_api.h",
|
|
"//tensorflow/lite/c:common.h",
|
|
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate.h",
|
|
],
|
|
tags = [
|
|
"nobuilder",
|
|
"swift_module=TensorFlowLiteC",
|
|
],
|
|
deps = [
|
|
"//tensorflow/lite/c:c_api",
|
|
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
|
|
],
|
|
)
|
|
|
|
# Used for building TensorFlowLiteC framework.
|
|
build_test(
|
|
name = "framework_build_test",
|
|
tags = [
|
|
"noasan", # b/147230742
|
|
"nomsan", # b/145205324
|
|
"notsan", # b/145205324
|
|
],
|
|
targets = [
|
|
":TensorFlowLiteC_framework",
|
|
":TensorFlowLiteSelectTfOps_framework",
|
|
],
|
|
)
|