| 125 | } |
| 126 | |
| 127 | TEST(PartiallyDeclusterPassTest, ClusteredAndUnclustered) { |
| 128 | std::unique_ptr<Graph> graph(new Graph(OpRegistry::Global())); |
| 129 | { |
| 130 | GraphDefBuilder builder(GraphDefBuilder::kFailImmediately); |
| 131 | Node* input = |
| 132 | ops::SourceOp("FakeNullary", builder.opts().WithName("Input")); |
| 133 | Node* clustered_producer = |
| 134 | ops::BinaryOp("FakeBinary", input, input, |
| 135 | builder.opts().WithName("ClusteredProducer")); |
| 136 | ops::BinaryOp("FakeBinary", clustered_producer, input, |
| 137 | builder.opts().WithName("UnclusteredConsumer")); |
| 138 | Node* clustered_consumer = |
| 139 | ops::BinaryOp("FakeBinary", {clustered_producer, 1}, input, |
| 140 | builder.opts().WithName("ClusteredConsumer")); |
| 141 | clustered_producer->AddAttr(kXlaClusterAttr, "cluster_0"); |
| 142 | clustered_consumer->AddAttr(kXlaClusterAttr, "cluster_0"); |
| 143 | TF_EXPECT_OK(GraphDefBuilderToGraph(builder, graph.get())); |
| 144 | } |
| 145 | |
| 146 | TF_ASSERT_OK(PartiallyDecluster(&graph)); |
| 147 | std::vector<Node*> unclustered_consumer_inputs; |
| 148 | ASSERT_TRUE(GetInputsForNode(*graph, "UnclusteredConsumer", |
| 149 | &unclustered_consumer_inputs)); |
| 150 | ASSERT_EQ(unclustered_consumer_inputs.size(), 2); |
| 151 | EXPECT_EQ(unclustered_consumer_inputs[0]->name(), |
| 152 | "ClusteredProducer/declustered"); |
| 153 | EXPECT_EQ(unclustered_consumer_inputs[1]->name(), "Input"); |
| 154 | |
| 155 | std::vector<Node*> clustered_consumer_inputs; |
| 156 | ASSERT_TRUE(GetInputsForNode(*graph, "ClusteredConsumer", |
| 157 | &clustered_consumer_inputs)); |
| 158 | ASSERT_EQ(clustered_consumer_inputs.size(), 2); |
| 159 | EXPECT_EQ(clustered_consumer_inputs[0]->name(), "ClusteredProducer"); |
| 160 | EXPECT_EQ(clustered_consumer_inputs[1]->name(), "Input"); |
| 161 | } |
| 162 | |
| 163 | TEST(PartiallyDeclusterPassTest, DifferentClusters) { |
| 164 | std::unique_ptr<Graph> graph(new Graph(OpRegistry::Global())); |
nothing calls this directly
no test coverage detected