| 52 | } |
| 53 | |
| 54 | TEST(FusionUtilsTest, FuseFunctionsByComposition) { |
| 55 | GraphDef graph; |
| 56 | auto *parent_function = graph.mutable_library()->add_function(); |
| 57 | *parent_function = test::function::XTimesTwo(); |
| 58 | auto *function = graph.mutable_library()->add_function(); |
| 59 | *function = test::function::XTimesTwo(); |
| 60 | |
| 61 | auto *fused_function = FuseFunctions( |
| 62 | *parent_function, *function, "fused_maps", fusion_utils::ComposeSignature, |
| 63 | fusion_utils::ComposeInput, fusion_utils::ComposeOutput, |
| 64 | fusion_utils::MergeNodes, graph.mutable_library()); |
| 65 | |
| 66 | EXPECT_EQ(fused_function->signature().name(), "fused_maps"); |
| 67 | EXPECT_EQ(fused_function->signature().input_arg_size(), 1); |
| 68 | EXPECT_EQ(fused_function->signature().output_arg_size(), 1); |
| 69 | EXPECT_EQ(fused_function->ret_size(), 1); |
| 70 | std::cerr << fused_function->DebugString(); |
| 71 | CheckUniqueNames(*fused_function); |
| 72 | |
| 73 | const NodeDef *parent_mul = nullptr, *output_mul = nullptr; |
| 74 | for (const auto &fused_node : fused_function->node_def()) { |
| 75 | if (fused_node.op() == "Mul") { |
| 76 | if (fused_node.name() == "y") |
| 77 | parent_mul = &fused_node; |
| 78 | else |
| 79 | output_mul = &fused_node; |
| 80 | } |
| 81 | } |
| 82 | ASSERT_NE(parent_mul, nullptr); |
| 83 | ASSERT_NE(output_mul, nullptr); |
| 84 | EXPECT_EQ(ParseNodeConnection(output_mul->input(0)), parent_mul->name()); |
| 85 | |
| 86 | auto output_value = fused_function->ret().at( |
| 87 | fused_function->signature().output_arg(0).name()); |
| 88 | |
| 89 | EXPECT_EQ(ParseNodeConnection(output_value), output_mul->name()); |
| 90 | } |
| 91 | |
| 92 | TEST(FusionUtilsTest, FuseFunctionWithPredicate) { |
| 93 | GraphDef graph; |
nothing calls this directly
no test coverage detected