aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--tensorflow/compiler/xla/BUILD15
-rw-r--r--tensorflow/compiler/xla/client/lib/BUILD1
-rw-r--r--tensorflow/compiler/xla/client/lib/testing.cc3
-rw-r--r--tensorflow/compiler/xla/execution_options_util.cc27
-rw-r--r--tensorflow/compiler/xla/execution_options_util.h29
-rw-r--r--tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc3
-rw-r--r--tensorflow/compiler/xla/tests/BUILD2
-rw-r--r--tensorflow/compiler/xla/tests/client_library_test_base.cc22
-rw-r--r--tensorflow/compiler/xla/tests/client_library_test_base.h8
-rw-r--r--tensorflow/compiler/xla/tests/deallocation_test.cc3
-rw-r--r--tensorflow/compiler/xla/tests/prng_test.cc6
11 files changed, 104 insertions, 15 deletions
diff --git a/tensorflow/compiler/xla/BUILD b/tensorflow/compiler/xla/BUILD
index cde790c0ae..c508071f8c 100644
--- a/tensorflow/compiler/xla/BUILD
+++ b/tensorflow/compiler/xla/BUILD
@@ -47,6 +47,21 @@ xla_proto_library(
)
cc_library(
+ name = "execution_options_util",
+ srcs = [
+ "execution_options_util.cc",
+ ],
+ hdrs = [
+ "execution_options_util.h",
+ ],
+ visibility = [":friends"],
+ deps = [
+ ":xla_proto",
+ "//tensorflow/compiler/xla/legacy_flags:debug_options_flags",
+ ],
+)
+
+cc_library(
name = "test",
testonly = 1,
hdrs = ["test.h"],
diff --git a/tensorflow/compiler/xla/client/lib/BUILD b/tensorflow/compiler/xla/client/lib/BUILD
index 86b16be62f..edd971e114 100644
--- a/tensorflow/compiler/xla/client/lib/BUILD
+++ b/tensorflow/compiler/xla/client/lib/BUILD
@@ -32,6 +32,7 @@ cc_library(
srcs = ["testing.cc"],
hdrs = ["testing.h"],
deps = [
+ "//tensorflow/compiler/xla:execution_options_util",
"//tensorflow/compiler/xla:literal_util",
"//tensorflow/compiler/xla:shape_util",
"//tensorflow/compiler/xla:statusor",
diff --git a/tensorflow/compiler/xla/client/lib/testing.cc b/tensorflow/compiler/xla/client/lib/testing.cc
index ffdc7dd943..d8bfc94580 100644
--- a/tensorflow/compiler/xla/client/lib/testing.cc
+++ b/tensorflow/compiler/xla/client/lib/testing.cc
@@ -17,6 +17,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/client/computation.h"
#include "tensorflow/compiler/xla/client/computation_builder.h"
+#include "tensorflow/compiler/xla/execution_options_util.h"
#include "tensorflow/compiler/xla/literal_util.h"
#include "tensorflow/compiler/xla/shape_util.h"
#include "tensorflow/compiler/xla/statusor.h"
@@ -38,7 +39,7 @@ std::unique_ptr<GlobalData> MakeFakeDataOrDie(const Shape& shape,
AsInt64Slice(shape.dimensions()));
Computation computation = b.Build().ConsumeValueOrDie();
- ExecutionOptions execution_options;
+ auto execution_options = CreateDefaultExecutionOptions();
*execution_options.mutable_shape_with_output_layout() = shape;
return client->Execute(computation, /*arguments=*/{}, &execution_options)
.ConsumeValueOrDie();
diff --git a/tensorflow/compiler/xla/execution_options_util.cc b/tensorflow/compiler/xla/execution_options_util.cc
new file mode 100644
index 0000000000..e83ff7cddd
--- /dev/null
+++ b/tensorflow/compiler/xla/execution_options_util.cc
@@ -0,0 +1,27 @@
+/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+#include "tensorflow/compiler/xla/execution_options_util.h"
+#include "tensorflow/compiler/xla/legacy_flags/debug_options_flags.h"
+
+namespace xla {
+
+ExecutionOptions CreateDefaultExecutionOptions() {
+ ExecutionOptions execution_options;
+ *(execution_options.mutable_debug_options()) =
+ legacy_flags::GetDebugOptionsFromFlags();
+ return execution_options;
+}
+
+} // namespace xla
diff --git a/tensorflow/compiler/xla/execution_options_util.h b/tensorflow/compiler/xla/execution_options_util.h
new file mode 100644
index 0000000000..562da78e83
--- /dev/null
+++ b/tensorflow/compiler/xla/execution_options_util.h
@@ -0,0 +1,29 @@
+/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#ifndef THIRD_PARTY_TENSORFLOW_COMPILER_XLA_EXECUTION_OPTIONS_UTIL_H_
+#define THIRD_PARTY_TENSORFLOW_COMPILER_XLA_EXECUTION_OPTIONS_UTIL_H_
+
+#include "tensorflow/compiler/xla/xla.pb.h"
+
+namespace xla {
+
+// Create a default ExecutionOptions proto; this proto has its debug options
+// popupated to the default values taken from flags.
+ExecutionOptions CreateDefaultExecutionOptions();
+
+} // namespace xla
+
+#endif // THIRD_PARTY_TENSORFLOW_COMPILER_XLA_EXECUTION_OPTIONS_UTIL_H_
diff --git a/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc b/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc
index 16fe4455db..881522a029 100644
--- a/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc
+++ b/tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc
@@ -380,6 +380,9 @@ StatusOr<string> CompileModuleToPtx(llvm::Module* module,
int32 opt_level =
hlo_module_config.debug_options().xla_backend_optimization_level();
+ CHECK_GE(opt_level, 2)
+ << "The XLA GPU backend doesn't support unoptimized code generation";
+
AddOptimizationPasses(opt_level,
/*size_level=*/0, target_machine.get(), &module_passes,
&function_passes);
diff --git a/tensorflow/compiler/xla/tests/BUILD b/tensorflow/compiler/xla/tests/BUILD
index bf7c106832..a11ac0bec6 100644
--- a/tensorflow/compiler/xla/tests/BUILD
+++ b/tensorflow/compiler/xla/tests/BUILD
@@ -144,6 +144,7 @@ cc_library(
"//tensorflow/compiler/xla:array2d",
"//tensorflow/compiler/xla:array3d",
"//tensorflow/compiler/xla:array4d",
+ "//tensorflow/compiler/xla:execution_options_util",
"//tensorflow/compiler/xla:literal_util",
"//tensorflow/compiler/xla:shape_util",
"//tensorflow/compiler/xla:status_macros",
@@ -156,7 +157,6 @@ cc_library(
"//tensorflow/compiler/xla/client:computation_builder",
"//tensorflow/compiler/xla/client:global_data",
"//tensorflow/compiler/xla/client:local_client",
- "//tensorflow/compiler/xla/legacy_flags:debug_options_flags",
"//tensorflow/compiler/xla/tests:literal_test_util",
"//tensorflow/compiler/xla/tests:test_utils",
"//tensorflow/core:lib",
diff --git a/tensorflow/compiler/xla/tests/client_library_test_base.cc b/tensorflow/compiler/xla/tests/client_library_test_base.cc
index 6094a31231..4e2e0c7776 100644
--- a/tensorflow/compiler/xla/tests/client_library_test_base.cc
+++ b/tensorflow/compiler/xla/tests/client_library_test_base.cc
@@ -20,7 +20,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/client/client_library.h"
#include "tensorflow/compiler/xla/client/computation.h"
#include "tensorflow/compiler/xla/client/local_client.h"
-#include "tensorflow/compiler/xla/legacy_flags/debug_options_flags.h"
+#include "tensorflow/compiler/xla/execution_options_util.h"
#include "tensorflow/compiler/xla/literal_util.h"
#include "tensorflow/compiler/xla/ptr_util.h"
#include "tensorflow/compiler/xla/shape_util.h"
@@ -45,10 +45,8 @@ Client* GetOrCreateLocalClientOrDie(se::Platform* platform) {
} // namespace
ClientLibraryTestBase::ClientLibraryTestBase(se::Platform* platform)
- : client_(GetOrCreateLocalClientOrDie(platform)) {
- *(execution_options_.mutable_debug_options()) =
- legacy_flags::GetDebugOptionsFromFlags();
-
+ : client_(GetOrCreateLocalClientOrDie(platform)),
+ execution_options_(CreateDefaultExecutionOptions()) {
// Disabling constant_folding so that tests (usually written using Constants)
// will exercise the intended code paths, instead of being constant folded.
//
@@ -72,12 +70,9 @@ StatusOr<std::unique_ptr<GlobalData>> ClientLibraryTestBase::Execute(
}
StatusOr<std::unique_ptr<Literal>> ClientLibraryTestBase::ExecuteAndTransfer(
- ComputationBuilder* builder,
+ const Computation& computation,
tensorflow::gtl::ArraySlice<GlobalData*> arguments,
const Shape* shape_with_output_layout) {
- // Build the computation, as a convenience.
- TF_ASSIGN_OR_RETURN(auto computation, builder->Build());
-
ExecutionOptions execution_options = execution_options_;
if (shape_with_output_layout != nullptr) {
*execution_options.mutable_shape_with_output_layout() =
@@ -87,6 +82,15 @@ StatusOr<std::unique_ptr<Literal>> ClientLibraryTestBase::ExecuteAndTransfer(
&execution_options);
}
+StatusOr<std::unique_ptr<Literal>> ClientLibraryTestBase::ExecuteAndTransfer(
+ ComputationBuilder* builder,
+ tensorflow::gtl::ArraySlice<GlobalData*> arguments,
+ const Shape* shape_with_output_layout) {
+ // Build the computation, as a convenience.
+ TF_ASSIGN_OR_RETURN(auto computation, builder->Build());
+ return ExecuteAndTransfer(computation, arguments, shape_with_output_layout);
+}
+
std::unique_ptr<GlobalData> ClientLibraryTestBase::ExecuteOrDie(
ComputationBuilder* builder,
tensorflow::gtl::ArraySlice<GlobalData*> arguments) {
diff --git a/tensorflow/compiler/xla/tests/client_library_test_base.h b/tensorflow/compiler/xla/tests/client_library_test_base.h
index a5cb74bdfa..763ff09965 100644
--- a/tensorflow/compiler/xla/tests/client_library_test_base.h
+++ b/tensorflow/compiler/xla/tests/client_library_test_base.h
@@ -66,7 +66,9 @@ class ClientLibraryTestBase : public ::testing::Test {
// TODO(b/25566808): Add helper that populates a literal from a testdata file.
- // Convenience methods for building and running a computation from a builder.
+ // Convenience methods for building and running a computation with the member
+ // execution options. Modify execution_options_ in your test if you want to
+ // customize the options.
StatusOr<std::unique_ptr<GlobalData>> Execute(
ComputationBuilder* builder,
tensorflow::gtl::ArraySlice<GlobalData*> arguments);
@@ -74,6 +76,10 @@ class ClientLibraryTestBase : public ::testing::Test {
ComputationBuilder* builder,
tensorflow::gtl::ArraySlice<GlobalData*> arguments,
const Shape* shape_with_output_layout = nullptr);
+ StatusOr<std::unique_ptr<Literal>> ExecuteAndTransfer(
+ const Computation& computation,
+ tensorflow::gtl::ArraySlice<GlobalData*> arguments,
+ const Shape* shape_with_output_layout = nullptr);
// Convenience OrDie variants of above methods.
std::unique_ptr<GlobalData> ExecuteOrDie(
diff --git a/tensorflow/compiler/xla/tests/deallocation_test.cc b/tensorflow/compiler/xla/tests/deallocation_test.cc
index 9952ff3186..0c7c3a8ff6 100644
--- a/tensorflow/compiler/xla/tests/deallocation_test.cc
+++ b/tensorflow/compiler/xla/tests/deallocation_test.cc
@@ -41,7 +41,8 @@ class DeallocationTest : public ClientLibraryTestBase {
tensorflow::gtl::ArraySlice<GlobalData*> arguments) {
Computation computation = builder->Build().ConsumeValueOrDie();
auto global_data =
- client_->Execute(computation, arguments).ConsumeValueOrDie();
+ client_->Execute(computation, arguments, &execution_options_)
+ .ConsumeValueOrDie();
TF_CHECK_OK(client_->Transfer(*global_data).status());
return global_data;
}
diff --git a/tensorflow/compiler/xla/tests/prng_test.cc b/tensorflow/compiler/xla/tests/prng_test.cc
index 57e390bff9..ed994fda45 100644
--- a/tensorflow/compiler/xla/tests/prng_test.cc
+++ b/tensorflow/compiler/xla/tests/prng_test.cc
@@ -243,9 +243,11 @@ XLA_TEST_F(PrngTest, PassInGlobalRngSeed) {
client_->ExecuteAndTransfer(computation, /*arguments=*/{},
&execution_options2));
TF_ASSIGN_OR_ASSERT_OK(
- result5, client_->ExecuteAndTransfer(computation, /*arguments=*/{}));
+ result5, client_->ExecuteAndTransfer(computation, /*arguments=*/{},
+ &execution_options_));
TF_ASSIGN_OR_ASSERT_OK(
- result6, client_->ExecuteAndTransfer(computation, /*arguments=*/{}));
+ result6, client_->ExecuteAndTransfer(computation, /*arguments=*/{},
+ &execution_options_));
}
LiteralTestUtil::ExpectEqual(*result1, *result2);