| 67 | } |
| 68 | |
| 69 | TEST(ConvertGraphDefToXla, Sum) { |
| 70 | GraphDef graph_def = SumGraph(); |
| 71 | tf2xla::Config config = SumConfig(); |
| 72 | |
| 73 | xla::LocalClient* client = xla::ClientLibrary::LocalClientOrDie(); |
| 74 | xla::XlaComputation computation; |
| 75 | TF_EXPECT_OK(ConvertGraphDefToXla(graph_def, config, client, &computation)); |
| 76 | |
| 77 | // Set up arguments. |
| 78 | auto x_literal = xla::LiteralUtil::CreateR0<int32>(10); |
| 79 | auto y_literal = xla::LiteralUtil::CreateR0<int32>(32); |
| 80 | auto x_global_or = client->TransferToServer(x_literal); |
| 81 | auto y_global_or = client->TransferToServer(y_literal); |
| 82 | TF_EXPECT_OK(x_global_or.status()); |
| 83 | TF_EXPECT_OK(y_global_or.status()); |
| 84 | std::unique_ptr<xla::GlobalData> x_global = |
| 85 | std::move(x_global_or.ValueOrDie()); |
| 86 | std::unique_ptr<xla::GlobalData> y_global = |
| 87 | std::move(y_global_or.ValueOrDie()); |
| 88 | |
| 89 | // Execute and check result. |
| 90 | auto result_or = |
| 91 | client->ExecuteAndTransfer(computation, {x_global.get(), y_global.get()}); |
| 92 | TF_EXPECT_OK(result_or.status()); |
| 93 | xla::Literal result = std::move(result_or.ValueOrDie()); |
| 94 | EXPECT_EQ("(\ns32[] 42\n)", result.ToString()); |
| 95 | |
| 96 | config.mutable_feed(0)->mutable_id()->set_output_index( |
| 97 | 123); /* invalid output_index */ |
| 98 | EXPECT_TRUE(errors::IsInvalidArgument( |
| 99 | ConvertGraphDefToXla(graph_def, config, client, &computation))); |
| 100 | } |
| 101 | |
| 102 | } // namespace |
| 103 | } // namespace tensorflow |
nothing calls this directly
no test coverage detected