tensorflow/core/common_runtime/graph_runner_test.cc
// If not using DeepCopy, and the allocator is deleted with the cpu-device,
// this test will seg-fault.
If not using DeepCopy, and the allocator is deleted with the cpu-device,
this test will seg-fault.
If not using DeepCopy and the allocator is deleted with the cpu - device this test will seg - fault .
TEST(GraphRunnerTest, DeepCopy) {
  Scope root = Scope::NewRootScope();
  auto p1 = ops::Placeholder(root.WithOpName("p1"), DT_FLOAT);
  auto p2 = ops::Placeholder(root.WithOpName("p2"), DT_FLOAT);
  auto add = ops::Add(root.WithOpName("add"), p1, p2);
  Tensor p1_data(DT_FLOAT, TensorShape({}));
  Tensor p2_data(DT_FLOAT, TensorShape({}));
  p1_data.scalar<float>()() = 1.0f;
  p2_data.scalar<float>()() = 2.0f;
  std::vector<std::pair<string, Tensor>> inputs = {{"p1:0", p1_data},
                                                   {"p2:0", p2_data}};
  std::vector<Tensor> outputs;
  {
    GraphRunner graph_runner(Env::Default());
    Status s =
        graph_runner.Run(root.graph(), nullptr, inputs, {"add:0"}, &outputs);
    TF_ASSERT_OK(s);
  }
  test::ExpectEqual(test::AsScalar(3.0f), outputs[0]);
}
TEST ( GraphRunnerTest , DeepCopy ) { Scope root = Scope :: NewRootScope ( ) ; auto p1 = ops :: Placeholder ( root . WithOpName ( " " ) , DT_FLOAT ) ; auto p2 = ops :: Placeholder ( root . WithOpName ( " " ) , DT_FLOAT ) ; auto add = ops :: Add ( root . WithOpName ( " " ) , p1 , p2 ) ; Tensor p1_data ( DT_FLOAT , TensorShape ( { } ) ) ; Tensor p2_data ( DT_FLOAT , TensorShape ( { } ) ) ; p1_data . scalar < float > ( ) ( ) = 1.0f ; p2_data . scalar < float > ( ) ( ) = 2.0f ; std :: vector < std :: pair < string , Tensor > > inputs = { { " " , p1_data } , { " " , p2_data } } ; std :: vector < Tensor > outputs ; { GraphRunner graph_runner ( Env :: Default ( ) ) ; Status s = graph_runner . Run ( root . graph ( ) , nullptr , inputs , { " " } , & outputs ) ; TF_ASSERT_OK ( s ) ; } test :: ExpectEqual ( test :: AsScalar ( 3.0f ) , outputs [ 0 ] ) ; }
If not using DeepCopy, and the allocator is deleted with the cpu-device,
this test will seg-fault.
If not using DeepCopy and the allocator is deleted with the cpu - device this test will seg - fault .
// Create and destroy the GraphRunner, and ensure that the outputs are // consumable beyond the lifetime of GraphRunner.