Fix build failure of list_flex_ops_main in OSS

The cc_binary required --config=monolithic which can't be passed
into a native.genrule. Using tf_cc_binary solves the build failure.

PiperOrigin-RevId: 316631689
Change-Id: Ia706d532578ccbf5bc8f172f6344f166d05531fb
This commit is contained in:
Thai Nguyen 2020-06-16 00:47:28 -07:00 committed by TensorFlower Gardener
parent e887f933e4
commit ec0e105c6f
2 changed files with 16 additions and 14 deletions
tensorflow/lite/tools

View File

@ -1,5 +1,6 @@
load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite")
load("//tensorflow/lite:build_def.bzl", "tflite_copts") load("//tensorflow/lite:build_def.bzl", "tflite_copts")
load("//tensorflow:tensorflow.bzl", "tf_cc_binary", "tf_cc_test")
package( package(
default_visibility = [ default_visibility = [
@ -271,7 +272,7 @@ cc_library(
# This tool list flex ops and kernels inside a TFLite file. # This tool list flex ops and kernels inside a TFLite file.
# It is used to generate header file for selective registration. # It is used to generate header file for selective registration.
cc_binary( tf_cc_binary(
name = "list_flex_ops_main", name = "list_flex_ops_main",
srcs = ["list_flex_ops_main.cc"], srcs = ["list_flex_ops_main.cc"],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
@ -282,7 +283,7 @@ cc_binary(
], ],
) )
cc_test( tf_cc_test(
name = "list_flex_ops_test", name = "list_flex_ops_test",
srcs = ["list_flex_ops_test.cc"], srcs = ["list_flex_ops_test.cc"],
data = [ data = [
@ -293,7 +294,6 @@ cc_test(
"//tensorflow/lite:testdata/test_model_broken.bin", "//tensorflow/lite:testdata/test_model_broken.bin",
], ],
tags = [ tags = [
"no_oss", # Currently requires --config=monolithic, b/118895218.
"tflite_not_portable_android", "tflite_not_portable_android",
"tflite_not_portable_ios", "tflite_not_portable_ios",
], ],
@ -301,6 +301,7 @@ cc_test(
":list_flex_ops", ":list_flex_ops",
"//tensorflow/core:protos_all_cc", "//tensorflow/core:protos_all_cc",
"//tensorflow/core/platform:protobuf", "//tensorflow/core/platform:protobuf",
"//tensorflow/core/platform:resource_loader",
"//tensorflow/lite/kernels:test_util", "//tensorflow/lite/kernels:test_util",
"@com_google_googletest//:gtest", "@com_google_googletest//:gtest",
"@flatbuffers", "@flatbuffers",

View File

@ -22,6 +22,7 @@ limitations under the License.
#include "flatbuffers/flexbuffers.h" // from @flatbuffers #include "flatbuffers/flexbuffers.h" // from @flatbuffers
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/resource_loader.h"
#include "tensorflow/lite/kernels/test_util.h" #include "tensorflow/lite/kernels/test_util.h"
namespace tflite { namespace tflite {
@ -31,8 +32,9 @@ class FlexOpsListTest : public ::testing::Test {
protected: protected:
FlexOpsListTest() {} FlexOpsListTest() {}
void ReadOps(const string& model_path) { void ReadOps(const string& path) {
auto model = FlatBufferModel::BuildFromFile(model_path.data()); std::string full_path = tensorflow::GetDataDependencyFilepath(path);
auto model = FlatBufferModel::BuildFromFile(full_path.data());
AddFlexOpsFromModel(model->GetModel(), &flex_ops_); AddFlexOpsFromModel(model->GetModel(), &flex_ops_);
output_text_ = OpListToJSONString(flex_ops_); output_text_ = OpListToJSONString(flex_ops_);
} }
@ -84,30 +86,29 @@ class FlexOpModel : public SingleOpModel {
}; };
TEST_F(FlexOpsListTest, TestModelsNoFlex) { TEST_F(FlexOpsListTest, TestModelsNoFlex) {
ReadOps("third_party/tensorflow/lite/testdata/test_model.bin"); ReadOps("tensorflow/lite/testdata/test_model.bin");
EXPECT_EQ(output_text_, "[]"); EXPECT_EQ(output_text_, "[]");
} }
TEST_F(FlexOpsListTest, TestBrokenModel) { TEST_F(FlexOpsListTest, TestBrokenModel) {
EXPECT_DEATH_IF_SUPPORTED( EXPECT_DEATH_IF_SUPPORTED(
ReadOps("third_party/tensorflow/lite/testdata/test_model_broken.bin"), ReadOps("tensorflow/lite/testdata/test_model_broken.bin"), "");
"");
} }
TEST_F(FlexOpsListTest, TestZeroSubgraphs) { TEST_F(FlexOpsListTest, TestZeroSubgraphs) {
ReadOps("third_party/tensorflow/lite/testdata/0_subgraphs.bin"); ReadOps("tensorflow/lite/testdata/0_subgraphs.bin");
EXPECT_EQ(output_text_, "[]"); EXPECT_EQ(output_text_, "[]");
} }
TEST_F(FlexOpsListTest, TestFlexAdd) { TEST_F(FlexOpsListTest, TestFlexAdd) {
ReadOps("third_party/tensorflow/lite/testdata/multi_add_flex.bin"); ReadOps("tensorflow/lite/testdata/multi_add_flex.bin");
EXPECT_EQ(output_text_, EXPECT_EQ(output_text_,
"[[\"Add\", \"BinaryOp<CPUDevice, functor::add<float>>\"]]"); "[[\"Add\", \"BinaryOp<CPUDevice, functor::add<float>>\"]]");
} }
TEST_F(FlexOpsListTest, TestTwoModel) { TEST_F(FlexOpsListTest, TestTwoModel) {
ReadOps("third_party/tensorflow/lite/testdata/multi_add_flex.bin"); ReadOps("tensorflow/lite/testdata/multi_add_flex.bin");
ReadOps("third_party/tensorflow/lite/testdata/softplus_flex.bin"); ReadOps("tensorflow/lite/testdata/softplus_flex.bin");
EXPECT_EQ(output_text_, EXPECT_EQ(output_text_,
"[[\"Add\", \"BinaryOp<CPUDevice, " "[[\"Add\", \"BinaryOp<CPUDevice, "
"functor::add<float>>\"],\n[\"Softplus\", \"SoftplusOp<CPUDevice, " "functor::add<float>>\"],\n[\"Softplus\", \"SoftplusOp<CPUDevice, "
@ -115,8 +116,8 @@ TEST_F(FlexOpsListTest, TestTwoModel) {
} }
TEST_F(FlexOpsListTest, TestDuplicatedOp) { TEST_F(FlexOpsListTest, TestDuplicatedOp) {
ReadOps("third_party/tensorflow/lite/testdata/multi_add_flex.bin"); ReadOps("tensorflow/lite/testdata/multi_add_flex.bin");
ReadOps("third_party/tensorflow/lite/testdata/multi_add_flex.bin"); ReadOps("tensorflow/lite/testdata/multi_add_flex.bin");
EXPECT_EQ(output_text_, EXPECT_EQ(output_text_,
"[[\"Add\", \"BinaryOp<CPUDevice, functor::add<float>>\"]]"); "[[\"Add\", \"BinaryOp<CPUDevice, functor::add<float>>\"]]");
} }