aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yunxing Dai <yunxing@google.com>2017-10-18 12:16:38 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-10-18 12:20:43 -0700
commitf1603b7893f922dfe64244c6bae9b93d7d594437 (patch)
treeced796e7951fa81e3bef4c900cf4079da1641fa7
parentef060d923acef07cd3a4b1134218abc84fcb3a7b (diff)
[XLA] Deterministically dump an executable.
Previously, dumping a executable is nondeterministic as a map in protobuf is serialized in random order. This CL enables "Deterministic dump" mode of protobuf, which sorts the map first before dumping them. This is helpful in comparing if two dumps are the same in XLA determinism test. PiperOrigin-RevId: 172637100
-rw-r--r--tensorflow/compiler/xla/BUILD1
-rw-r--r--tensorflow/compiler/xla/service/BUILD2
-rw-r--r--tensorflow/compiler/xla/service/executable.cc8
-rw-r--r--tensorflow/compiler/xla/util.h1
4 files changed, 11 insertions, 1 deletions
diff --git a/tensorflow/compiler/xla/BUILD b/tensorflow/compiler/xla/BUILD
index be87506d3c..e51bbffcd0 100644
--- a/tensorflow/compiler/xla/BUILD
+++ b/tensorflow/compiler/xla/BUILD
@@ -171,6 +171,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":status",
+ ":status_macros",
":types",
":xla_data_proto",
"//tensorflow/core:lib",
diff --git a/tensorflow/compiler/xla/service/BUILD b/tensorflow/compiler/xla/service/BUILD
index d1335e20e0..fed7bd01f6 100644
--- a/tensorflow/compiler/xla/service/BUILD
+++ b/tensorflow/compiler/xla/service/BUILD
@@ -581,12 +581,14 @@ cc_library(
":shaped_buffer",
":versioned_computation_handle",
"//tensorflow/compiler/xla:executable_run_options",
+ "//tensorflow/compiler/xla:status",
"//tensorflow/compiler/xla:status_macros",
"//tensorflow/compiler/xla:statusor",
"//tensorflow/compiler/xla:util",
"//tensorflow/compiler/xla:xla_data_proto",
"//tensorflow/compiler/xla/legacy_flags:debug_options_flags",
"//tensorflow/core:lib",
+ "//tensorflow/core:lib_internal",
"//tensorflow/core:stream_executor_no_cuda",
"//tensorflow/stream_executor",
],
diff --git a/tensorflow/compiler/xla/service/executable.cc b/tensorflow/compiler/xla/service/executable.cc
index 62b8fa6a2b..9c96d9eb30 100644
--- a/tensorflow/compiler/xla/service/executable.cc
+++ b/tensorflow/compiler/xla/service/executable.cc
@@ -17,7 +17,9 @@ limitations under the License.
#include "tensorflow/compiler/xla/legacy_flags/debug_options_flags.h"
#include "tensorflow/compiler/xla/service/hlo_graph_dumper.h"
+#include "tensorflow/compiler/xla/status.h"
#include "tensorflow/compiler/xla/status_macros.h"
+#include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/env.h"
@@ -82,7 +84,11 @@ Status Executable::DumpSessionModule() {
}
filename = SanitizeFileName(std::move(filename));
string file_path = tensorflow::io::JoinPath(directory_path, filename);
- return tensorflow::WriteBinaryProto(env, file_path, session_module);
+ string result;
+ TF_RET_CHECK(
+ tensorflow::SerializeToStringDeterministic(session_module, &result));
+ return tensorflow::WriteStringToFile(tensorflow::Env::Default(), file_path,
+ result);
}
} // namespace xla
diff --git a/tensorflow/compiler/xla/util.h b/tensorflow/compiler/xla/util.h
index f6c0bd1563..f58f57b443 100644
--- a/tensorflow/compiler/xla/util.h
+++ b/tensorflow/compiler/xla/util.h
@@ -24,6 +24,7 @@ limitations under the License.
#include <vector>
#include "tensorflow/compiler/xla/status.h"
+#include "tensorflow/compiler/xla/status_macros.h"
#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/compiler/xla/xla_data.pb.h"
#include "tensorflow/core/lib/core/status.h"