aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/service/executable.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-04-20 15:32:32 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-20 15:35:10 -0700
commitcadbb0b70b9441388a04533433245ac85f2887a9 (patch)
tree267914d9cf43ec849580af0ab92e025f925864e4 /tensorflow/compiler/xla/service/executable.cc
parent6af31f6260161bab02db83d7e9e1d7ba7fd14b2c (diff)
[XLA] Redesign: implement DumpToDirectory for the HloSession.
This is to prepare the migration of tf2xla. PiperOrigin-RevId: 193733029
Diffstat (limited to 'tensorflow/compiler/xla/service/executable.cc')
-rw-r--r--tensorflow/compiler/xla/service/executable.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/service/executable.cc b/tensorflow/compiler/xla/service/executable.cc
index b097ef79cc..8218b5f7c8 100644
--- a/tensorflow/compiler/xla/service/executable.cc
+++ b/tensorflow/compiler/xla/service/executable.cc
@@ -163,4 +163,24 @@ Status Executable::DumpSessionModule() {
result);
}
+/* static */ Status Executable::DumpToDirectory(const string& directory_path,
+ string filename,
+ const HloSession& hlo_session) {
+ tensorflow::Env* env = tensorflow::Env::Default();
+ if (!env->IsDirectory(directory_path).ok()) {
+ // NB! CreateDir does not work reliably with multiple XLA threads -- two
+ // threads can race to observe the absence of the dump directory and
+ // simultaneously try to create it, causing the "losing" thread to get a
+ // "directory already exists" error.
+ TF_RETURN_IF_ERROR(env->RecursivelyCreateDir(directory_path));
+ }
+ filename = SanitizeFileName(std::move(filename));
+ string file_path = tensorflow::io::JoinPath(directory_path, filename);
+ string result;
+ TF_RET_CHECK(
+ tensorflow::SerializeToStringDeterministic(hlo_session, &result));
+ return tensorflow::WriteStringToFile(tensorflow::Env::Default(), file_path,
+ result);
+}
+
} // namespace xla