Modified BUILD rules to have a more explicit way to enable XNNPACK delegate by default.

PiperOrigin-RevId: 315635582
Change-Id: Ib0e0c2aa02530923b105972397b00b76cd66c35c
This commit is contained in:
Chao Mei 2020-06-09 23:14:16 -07:00 committed by TensorFlower Gardener
parent 299b1bf0ba
commit 516608035f
3 changed files with 45 additions and 9 deletions

View File

@ -332,10 +332,36 @@ cc_library(
# Enables applying XNNPACK delegate for float models in TFLite runtime. # Enables applying XNNPACK delegate for float models in TFLite runtime.
# WARNING: This build flag is experimental and subject to change. # WARNING: This build flag is experimental and subject to change.
config_setting( config_setting(
name = "tflite_with_xnnpack_enabled", name = "tflite_with_xnnpack_explicit_true",
values = {"define": "tflite_with_xnnpack=true"}, values = {"define": "tflite_with_xnnpack=true"},
) )
config_setting(
name = "tflite_with_xnnpack_explicit_false",
values = {"define": "tflite_with_xnnpack=false"},
)
cc_library(
name = "tflite_with_xnnpack_enabled",
defines = ["TFLITE_BUILD_WITH_XNNPACK_DELEGATE"],
visibility = ["//visibility:private"],
deps = [
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate",
],
)
cc_library(
name = "tflite_with_xnnpack_default",
visibility = ["//visibility:private"],
# TODO(b/151246885): put ":tflite_with_xnnpack_enabled" to macos/windows
# once we have a good testing coverage on these two platforms.
deps = select({
"//tensorflow:macos": [],
"//tensorflow:windows": [],
"//conditions:default": [],
}),
)
cc_library( cc_library(
name = "tflite_with_xnnpack_optional", name = "tflite_with_xnnpack_optional",
srcs = ["tflite_with_xnnpack_optional.cc"], srcs = ["tflite_with_xnnpack_optional.cc"],
@ -344,17 +370,18 @@ cc_library(
"tflite_with_xnnpack_optional.h", "tflite_with_xnnpack_optional.h",
], ],
copts = tflite_copts() + TFLITE_DEFAULT_COPTS, copts = tflite_copts() + TFLITE_DEFAULT_COPTS,
defines = select({
":tflite_with_xnnpack_enabled": ["TFLITE_BUILD_WITH_XNNPACK_DELEGATE"],
"//conditions:default": [],
}),
deps = [ deps = [
"//tensorflow/lite/c:common", "//tensorflow/lite/c:common",
] + select({ ] + select({
":tflite_with_xnnpack_enabled": [ ":tflite_with_xnnpack_explicit_true": [
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate", "//tensorflow/lite/delegates/xnnpack:xnnpack_delegate_hdrs_only",
":tflite_with_xnnpack_enabled",
],
":tflite_with_xnnpack_explicit_false": [],
"//conditions:default": [
"//tensorflow/lite/delegates/xnnpack:xnnpack_delegate_hdrs_only",
":tflite_with_xnnpack_default",
], ],
"//conditions:default": [],
}), }),
) )

View File

@ -29,6 +29,15 @@ cc_library(
], ],
) )
cc_library(
name = "xnnpack_delegate_hdrs_only",
hdrs = ["xnnpack_delegate.h"],
visibility = ["//tensorflow/lite:__subpackages__"],
deps = [
"//tensorflow/lite/c:common",
],
)
cc_library( cc_library(
name = "xnnpack_delegate_test_mode", name = "xnnpack_delegate_test_mode",
srcs = ["xnnpack_delegate.cc"], srcs = ["xnnpack_delegate.cc"],

View File

@ -36,7 +36,7 @@ TEST(FloatModel, WithXnnpackDelegate) {
ASSERT_EQ(interpreter->AllocateTensors(), kTfLiteOk); ASSERT_EQ(interpreter->AllocateTensors(), kTfLiteOk);
#if TFLITE_HAS_ATTRIBUTE_WEAK #if TFLITE_HAS_ATTRIBUTE_WEAK || defined(TFLITE_BUILD_WITH_XNNPACK_DELEGATE)
// As the graph is fully delegated by XNNPACK delegate, we will expect the // As the graph is fully delegated by XNNPACK delegate, we will expect the
// following: // following:
EXPECT_EQ(1, interpreter->execution_plan().size()); EXPECT_EQ(1, interpreter->execution_plan().size());