Enable building TFLite Micro runtime for embedded systems under Bazel.

PiperOrigin-RevId: 305537308
Change-Id: Ia2a35cc06872709b27ca551316567edd4b241baa
This commit is contained in:
A. Unique TensorFlower 2020-04-08 12:59:45 -07:00 committed by TensorFlower Gardener
parent 5fb9558424
commit 0dfd23a641
7 changed files with 75 additions and 39 deletions

View File

@ -83,6 +83,7 @@ FRAMEWORK_LIB_HDRS = [
cc_library(
name = "version",
hdrs = ["version.h"],
build_for_embedded = True,
copts = TFLITE_DEFAULT_COPTS,
# Note that we only use the header defines from :version_lib.
deps = ["//tensorflow/core:version_lib"],
@ -135,6 +136,7 @@ cc_library(
name = "external_cpu_backend_context",
srcs = ["external_cpu_backend_context.cc"],
hdrs = ["external_cpu_backend_context.h"],
build_for_embedded = True,
copts = TFLITE_DEFAULT_COPTS,
deps = [
"//tensorflow/lite/c:common",

View File

@ -230,14 +230,15 @@ cc_test(
cc_library(
name = "tflite_with_ruy_enabled",
build_for_embedded = True,
defines = ["TFLITE_WITH_RUY"],
visibility = ["//visibility:private"],
)
cc_library(
name = "tflite_with_ruy_default",
visibility = ["//visibility:private"],
deps = select({
build_for_embedded = True,
select_deps = {
":chromiumos_arm64": [":tflite_with_ruy_enabled"],
":cpu_aarch64": [":tflite_with_ruy_enabled"],
":cpu_arm64": [":tflite_with_ruy_enabled"],
@ -247,16 +248,18 @@ cc_library(
":cpu_arm64_v8a": [":tflite_with_ruy_enabled"],
"//tensorflow:android_arm": ["tflite_with_ruy_enabled"],
"//conditions:default": [],
}),
},
visibility = ["//visibility:private"],
)
cc_library(
name = "tflite_with_ruy",
deps = select({
build_for_embedded = True,
select_deps = {
":tflite_with_ruy_explicit_true": [":tflite_with_ruy_enabled"],
":tflite_with_ruy_explicit_false": [],
"//conditions:default": [":tflite_with_ruy_default"],
}),
},
)
cc_library(
@ -267,6 +270,7 @@ cc_library(
hdrs = [
"cpu_backend_context.h",
],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":tflite_with_ruy",
@ -376,6 +380,7 @@ cc_library(
hdrs = [
"kernel_util.h",
],
build_for_embedded = True,
copts = tflite_copts() + micro_copts(),
deps = [
"//tensorflow/lite/c:common",
@ -411,6 +416,7 @@ cc_library(
name = "padding",
srcs = [],
hdrs = ["padding.h"],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
"//tensorflow/lite/c:common",

View File

@ -62,6 +62,7 @@ cc_library(
cc_library(
name = "legacy_types",
hdrs = ["legacy_types.h"],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":types",
@ -201,6 +202,7 @@ cc_library(
name = "common",
srcs = [],
hdrs = ["common.h"],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":cpu_check",
@ -357,6 +359,7 @@ cc_library(
name = "quantization_util",
srcs = ["quantization_util.cc"],
hdrs = ["quantization_util.h"],
build_for_embedded = True,
copts = tflite_copts() + micro_copts(),
deps = [
":compatibility",
@ -384,6 +387,7 @@ cc_library(
hdrs = [
"transpose_utils.h",
],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":types",
@ -405,6 +409,7 @@ cc_library(
hdrs = [
"strided_slice_logic.h",
],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":compatibility",
@ -463,23 +468,9 @@ cc_library(
"reference/sub.h",
"reference/svdf.h",
],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
":common",
":compatibility",
":quantization_util",
":cppmath",
":strided_slice_logic",
":tensor",
":tensor_utils",
":types",
"@gemmlowp//:fixedpoint",
"//third_party/eigen3",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:op_macros",
"@ruy//ruy/profiler:instrumentation",
"//tensorflow/lite/tools/optimize/sparsity:format_converter",
] + select({
select_deps = {
":haswell": tflite_deps_intel,
":ios_x86_64": tflite_deps_intel,
":k8": tflite_deps_intel,
@ -490,7 +481,23 @@ cc_library(
":freebsd": tflite_deps_intel,
":windows": tflite_deps_intel,
"//conditions:default": [],
}),
},
deps = [
":common",
":compatibility",
":cppmath",
":quantization_util",
":strided_slice_logic",
":tensor",
":tensor_utils",
":types",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:op_macros",
"//tensorflow/lite/tools/optimize/sparsity:format_converter",
"//third_party/eigen3",
"@gemmlowp//:fixedpoint",
"@ruy//ruy/profiler:instrumentation",
],
)
cc_library(
@ -658,6 +665,7 @@ cc_library(
name = "kernel_utils",
srcs = ["kernel_utils.cc"],
hdrs = ["kernel_utils.h"],
build_for_embedded = True,
copts = tflite_copts() + micro_copts(),
deps = [
":tensor_utils",
@ -695,13 +703,9 @@ cc_library(
hdrs = [
"tensor_utils.h",
],
build_for_embedded = True,
copts = tflite_copts() + NEON_FLAGS_IF_APPLICABLE,
deps = [
":cpu_check",
"//third_party/eigen3",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:cpu_backend_context",
] + select({
select_deps = {
":aarch64": [
":neon_tensor_utils",
],
@ -757,7 +761,13 @@ cc_library(
"//conditions:default": [
":portable_tensor_utils",
],
}),
},
deps = [
":cpu_check",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels:cpu_backend_context",
"//third_party/eigen3",
],
)
cc_library(
@ -995,10 +1005,9 @@ cc_library(
"optimized/neon_check.h",
"optimized/sse_check.h",
],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
"//tensorflow/lite/kernels:cpu_backend_context",
] + select({
select_deps = {
":haswell": tflite_deps_intel,
":ios_x86_64": tflite_deps_intel,
":k8": tflite_deps_intel,
@ -1009,7 +1018,10 @@ cc_library(
":freebsd": tflite_deps_intel,
":windows": tflite_deps_intel,
"//conditions:default": [],
}),
},
deps = [
"//tensorflow/lite/kernels:cpu_backend_context",
],
)
cc_test(

View File

@ -12,6 +12,12 @@ def micro_copts():
def cc_library(**kwargs):
kwargs.pop("build_for_embedded", False)
if "select_deps" in kwargs.keys():
select_deps = kwargs.pop("select_deps", {})
if "deps" in kwargs.keys():
kwargs["deps"] += select(select_deps)
else:
kwargs["deps"] = select(select_deps)
_cc_library(**kwargs)
def flatbuffer_cc_library(**kwargs):

View File

@ -7,6 +7,7 @@ load(
)
load(
"//tensorflow/lite/micro:build_def.bzl",
"cc_library",
"micro_copts",
)
@ -22,6 +23,7 @@ cc_library(
hdrs = [
"sine_model_data.h",
],
build_for_embedded = True,
copts = micro_copts(),
)

View File

@ -4,6 +4,7 @@ load(
)
load(
"//tensorflow/lite/micro:build_def.bzl",
"cc_library",
"micro_copts",
)
@ -70,7 +71,14 @@ cc_library(
],
}),
hdrs = ["micro_ops.h"],
build_for_embedded = True,
copts = micro_copts(),
select_deps = {
"//conditions:default": [],
":xtensa_hifimini": [
#"//third_party/xtensa:hifi_mini_cstub64",
],
},
deps = [
":activation_utils",
":micro_utils",
@ -85,12 +93,7 @@ cc_library(
"//tensorflow/lite/kernels/internal:tensor",
"//tensorflow/lite/kernels/internal:types",
"//tensorflow/lite/micro:micro_utils",
] + select({
"//conditions:default": [],
":xtensa_hifimini": [
#"//third_party/xtensa:hifi_mini_cstub64",
],
}),
],
)
# LINT.ThenChange(//tensorflow/lite/micro/kernels/BUILD:portable_optimized_micro_ops)
@ -102,6 +105,7 @@ cc_library(
hdrs = [
"all_ops_resolver.h",
],
build_for_embedded = True,
copts = micro_copts(),
deps = [
":micro_ops",
@ -529,6 +533,7 @@ tflite_micro_cc_test(
cc_library(
name = "activation_utils",
hdrs = ["activation_utils.h"],
build_for_embedded = True,
deps = [
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels/internal:cppmath",
@ -566,6 +571,7 @@ tflite_micro_cc_test(
cc_library(
name = "micro_utils",
hdrs = ["micro_utils.h"],
build_for_embedded = True,
)
tflite_micro_cc_test(

View File

@ -1,4 +1,5 @@
load("//tensorflow/lite:build_def.bzl", "tflite_copts")
load("//tensorflow/lite/micro:build_def.bzl", "cc_library")
package(
default_visibility = [
@ -11,6 +12,7 @@ cc_library(
name = "format_converter",
srcs = ["format_converter.cc"],
hdrs = ["format_converter.h"],
build_for_embedded = True,
copts = tflite_copts(),
deps = [
"//tensorflow/lite/c:common",