From 516608035f85cec8b126712b0ff8407220206b22 Mon Sep 17 00:00:00 2001 From: Chao Mei Date: Tue, 9 Jun 2020 23:14:16 -0700 Subject: [PATCH] Modified BUILD rules to have a more explicit way to enable XNNPACK delegate by default. PiperOrigin-RevId: 315635582 Change-Id: Ib0e0c2aa02530923b105972397b00b76cd66c35c --- tensorflow/lite/BUILD | 43 ++++++++++++++++++++----- tensorflow/lite/delegates/xnnpack/BUILD | 9 ++++++ tensorflow/lite/model_xnnpack_test.cc | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/tensorflow/lite/BUILD b/tensorflow/lite/BUILD index 06a5fee9739..0eae6ad17c0 100644 --- a/tensorflow/lite/BUILD +++ b/tensorflow/lite/BUILD @@ -332,10 +332,36 @@ cc_library( # Enables applying XNNPACK delegate for float models in TFLite runtime. # WARNING: This build flag is experimental and subject to change. config_setting( - name = "tflite_with_xnnpack_enabled", + name = "tflite_with_xnnpack_explicit_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( name = "tflite_with_xnnpack_optional", srcs = ["tflite_with_xnnpack_optional.cc"], @@ -344,17 +370,18 @@ cc_library( "tflite_with_xnnpack_optional.h", ], copts = tflite_copts() + TFLITE_DEFAULT_COPTS, - defines = select({ - ":tflite_with_xnnpack_enabled": ["TFLITE_BUILD_WITH_XNNPACK_DELEGATE"], - "//conditions:default": [], - }), deps = [ "//tensorflow/lite/c:common", ] + select({ - ":tflite_with_xnnpack_enabled": [ - "//tensorflow/lite/delegates/xnnpack:xnnpack_delegate", + ":tflite_with_xnnpack_explicit_true": [ + "//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": [], }), ) diff --git a/tensorflow/lite/delegates/xnnpack/BUILD b/tensorflow/lite/delegates/xnnpack/BUILD index 455da14e8fe..e2679580e69 100644 --- a/tensorflow/lite/delegates/xnnpack/BUILD +++ b/tensorflow/lite/delegates/xnnpack/BUILD @@ -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( name = "xnnpack_delegate_test_mode", srcs = ["xnnpack_delegate.cc"], diff --git a/tensorflow/lite/model_xnnpack_test.cc b/tensorflow/lite/model_xnnpack_test.cc index 1a7376bfdcf..73860807c00 100644 --- a/tensorflow/lite/model_xnnpack_test.cc +++ b/tensorflow/lite/model_xnnpack_test.cc @@ -36,7 +36,7 @@ TEST(FloatModel, WithXnnpackDelegate) { 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 // following: EXPECT_EQ(1, interpreter->execution_plan().size());