tensorflow/core/grappler/optimizers/data/use_private_thread_pool_test.cc
// Test the autotune case with ModelDataset in the pipeline. We will insert
// PrivateThreadPoolDataset before ModelDataset.
Test the autotune case with ModelDataset in the pipeline.
Test the autotune case with ModelDataset in the pipeline .
TEST(AutotuneWithModelTest, PrivateThreadPool) {
  GrapplerItem item;
  item.graph = test::function::GDef(
      {NDef("start", "Const", {}, {{"value", 0}, {"dtype", DT_INT32}}),
       NDef("stop", "Const", {}, {{"value", 10}, {"dtype", DT_INT32}}),
       NDef("step", "Const", {}, {{"value", 1}, {"dtype", DT_INT32}}),
       NDef("range", "RangeDataset", {"start", "stop", "step"},
            {{"output_shapes", gtl::ArraySlice<TensorShape>{}},
             {"output_types", gtl::ArraySlice<DataType>{}}}),
       NDef("model", "ModelDataset", {"range"}, {}),
       NDef("Sink", "Identity", {"model"}, {})});
  EXPECT_FALSE(
      graph_utils::ContainsNodeWithOp("PrivateThreadPoolDataset", item.graph));
  EXPECT_EQ(item.graph.node_size(), 6);
  item.fetch.push_back("Sink");
  UsePrivateThreadPool optimizer;
  GraphDef output;
  TF_ASSERT_OK(optimizer.Optimize(nullptr, item, &output));
  EXPECT_EQ(output.node_size(), 8);
  EXPECT_TRUE(
      graph_utils::ContainsNodeWithOp("PrivateThreadPoolDataset", output));
  NodeDef sink_node =
      output.node(graph_utils::FindGraphNodeWithName("Sink", output));
  EXPECT_EQ(sink_node.input_size(), 1);
  NodeDef model_node = output.node(
      graph_utils::FindGraphNodeWithName(sink_node.input(0), output));
  EXPECT_EQ(model_node.op(), "ModelDataset");
  EXPECT_EQ(model_node.input_size(), 1);
  NodeDef private_threads_node = output.node(
      graph_utils::FindGraphNodeWithName(model_node.input(0), output));
  EXPECT_EQ(private_threads_node.op(), "PrivateThreadPoolDataset");
  EXPECT_EQ(private_threads_node.input_size(), 2);
  NodeDef range_node = output.node(graph_utils::FindGraphNodeWithName(
      private_threads_node.input(0), output));
  EXPECT_EQ(range_node.name(), "range");
  NodeDef num_of_threads_val = output.node(graph_utils::FindGraphNodeWithName(
      private_threads_node.input(1), output));
  EXPECT_EQ(num_of_threads_val.attr().at("value").tensor().int64_val(0), 0);
}
TEST ( AutotuneWithModelTest , PrivateThreadPool ) { GrapplerItem item ; item . graph = test :: function :: GDef ( { NDef ( " " , " " , { } , { { " " , 0 } , { " " , DT_INT32 } } ) , NDef ( " " , " " , { } , { { " " , 10 } , { " " , DT_INT32 } } ) , NDef ( " " , " " , { } , { { " " , 1 } , { " " , DT_INT32 } } ) , NDef ( " " , " " , { " " , " " , " " } , { { " " , gtl :: ArraySlice < TensorShape > { } } , { " " , gtl :: ArraySlice < DataType > { } } } ) , NDef ( " " , " " , { " " } , { } ) , NDef ( " " , " " , { " " } , { } ) } ) ; EXPECT_FALSE ( graph_utils :: ContainsNodeWithOp ( " " , item . graph ) ) ; EXPECT_EQ ( item . graph . node_size ( ) , 6 ) ; item . fetch . push_back ( " " ) ; UsePrivateThreadPool optimizer ; GraphDef output ; TF_ASSERT_OK ( optimizer . Optimize ( nullptr , item , & output ) ) ; EXPECT_EQ ( output . node_size ( ) , 8 ) ; EXPECT_TRUE ( graph_utils :: ContainsNodeWithOp ( " " , output ) ) ; NodeDef sink_node = output . node ( graph_utils :: FindGraphNodeWithName ( " " , output ) ) ; EXPECT_EQ ( sink_node . input_size ( ) , 1 ) ; NodeDef model_node = output . node ( graph_utils :: FindGraphNodeWithName ( sink_node . input ( 0 ) , output ) ) ; EXPECT_EQ ( model_node . op ( ) , " " ) ; EXPECT_EQ ( model_node . input_size ( ) , 1 ) ; NodeDef private_threads_node = output . node ( graph_utils :: FindGraphNodeWithName ( model_node . input ( 0 ) , output ) ) ; EXPECT_EQ ( private_threads_node . op ( ) , " " ) ; EXPECT_EQ ( private_threads_node . input_size ( ) , 2 ) ; NodeDef range_node = output . node ( graph_utils :: FindGraphNodeWithName ( private_threads_node . input ( 0 ) , output ) ) ; EXPECT_EQ ( range_node . name ( ) , " " ) ; NodeDef num_of_threads_val = output . node ( graph_utils :: FindGraphNodeWithName ( private_threads_node . input ( 1 ) , output ) ) ; EXPECT_EQ ( num_of_threads_val . attr ( ) . at ( " " ) . tensor ( ) . int64_val ( 0 ) , 0 ) ; }
Test the autotune case with ModelDataset in the pipeline.
Test the autotune case with ModelDataset in the pipeline .