Restore with_select_tf_ops build flag.

This remains useful for testing and development. Restore the ability
to inject support for TF ops in TFLite using `--define=with_select_tf_ops=true`.

See also issue .

PiperOrigin-RevId: 313873470
Change-Id: I6b68cd863efc17f5ae0667c0d2c9d68958d6e4ad
This commit is contained in:
Jared Duke 2020-05-29 16:44:16 -07:00 committed by TensorFlower Gardener
parent d99affc72b
commit bacd18849e
3 changed files with 37 additions and 3 deletions
tensorflow/lite

View File

@ -56,6 +56,15 @@ config_setting(
visibility = ["//visibility:public"],
)
# Enables inclusion of select TensorFlow kernels via the TFLite Flex delegate
# when building TFLite shared libraries.
# WARNING: This build flag is experimental and subject to change.
config_setting(
name = "with_select_tf_ops",
define_values = {"with_select_tf_ops": "true"},
visibility = ["//visibility:public"],
)
TFLITE_DEFAULT_COPTS = if_not_windows([
"-Wall",
"-Wno-comment",

View File

@ -110,6 +110,26 @@ def tflite_jni_linkopts():
"""Defines linker flags to reduce size of TFLite binary with JNI."""
return tflite_jni_linkopts_unstripped() + tflite_symbol_opts()
def maybe_flex_deps(deps):
"""Returns necessary flex deps when with_select_tf_ops build flag is used
Args:
deps: The source deps for the target (to avoid deps duplication).
Returns:
A list of additional flex deps required, based on the build flags used.
If with_select_tf_ops is not true, this will be an empty list.
"""
# Filter redundant flex deps if already provided.
flex_dep = clean_dep("//tensorflow/lite/delegates/flex:delegate")
if type(deps) == type([]) and flex_dep in deps:
return []
return select({
clean_dep("//tensorflow/lite:with_select_tf_ops"): [flex_dep],
"//conditions:default": [],
})
def tflite_jni_binary(
name,
copts = tflite_copts(),
@ -139,7 +159,7 @@ def tflite_jni_binary(
copts = copts,
linkshared = linkshared,
linkstatic = linkstatic,
deps = deps + [linkscript, exported_symbols],
deps = deps + [linkscript, exported_symbols] + maybe_flex_deps(deps),
srcs = srcs,
tags = tags,
linkopts = linkopts,
@ -149,6 +169,7 @@ def tflite_jni_binary(
def tflite_cc_shared_object(
name,
copts = tflite_copts(),
deps = [],
linkopts = [],
linkstatic = 1,
per_os_targets = False,
@ -160,6 +181,7 @@ def tflite_cc_shared_object(
linkstatic = linkstatic,
linkopts = linkopts + tflite_jni_linkopts(),
framework_so = [],
deps = deps + maybe_flex_deps(deps),
per_os_targets = per_os_targets,
**kwargs
)

View File

@ -212,8 +212,11 @@ TensorFlow ops library can be included and enabled as follows:
* Enable monolithic builds if necessary by adding the `--config=monolithic`
build flag.
* Add the TensorFlow ops delegate library dependency to the build
dependencies: `tensorflow/lite/delegates/flex:delegate`.
* Do one of the following:
* Include the `--define=with_select_tf_ops=true` build flag in the `bazel
build` invocation when building the TensorFlow Lite binary.
* Add the TensorFlow ops delegate library dependency to the build
dependencies: `tensorflow/lite/delegates/flex:delegate`.
Note that the necessary `TfLiteDelegate` will be installed automatically when
creating the interpreter at runtime as long as the delegate is linked into the