Skip to content

Commit

Permalink
[XLA] Redesign: delete SessionModule.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 199361402
  • Loading branch information
tensorflower-gardener committed Jun 5, 2018
1 parent d935dd9 commit f023073
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 202 deletions.
1 change: 0 additions & 1 deletion tensorflow/compiler/xla/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ xla_proto_library(
deps = [
":xla_data_proto",
"//tensorflow/compiler/xla/service:hlo_proto",
"//tensorflow/compiler/xla/service:session_proto",
],
)

Expand Down
1 change: 1 addition & 0 deletions tensorflow/compiler/xla/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ cc_library(
"//tensorflow/compiler/xla/service:compiler",
"//tensorflow/compiler/xla/service:device_memory_allocator",
"//tensorflow/compiler/xla/service:executable",
"//tensorflow/compiler/xla/service:hlo_proto",
"//tensorflow/compiler/xla/service:local_service",
"//tensorflow/compiler/xla/service:shaped_buffer",
"//tensorflow/compiler/xla/service:source_map_util",
Expand Down
22 changes: 11 additions & 11 deletions tensorflow/compiler/xla/client/local_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ StatusOr<ScopedShapedBuffer> LocalExecutable::Run(
run_options, backend_->StreamBorrower(),
backend_->eigen_intra_op_thread_pool());

if (executable_->dumping()) {
if (executable_->dumping_snapshot()) {
return ExecuteAndDump(&service_options, arguments);
}
return executable_->ExecuteOnStreamWrapper(
Expand All @@ -195,36 +195,36 @@ StatusOr<ScopedShapedBuffer> LocalExecutable::Run(
StatusOr<ScopedShapedBuffer> LocalExecutable::ExecuteAndDump(
const ServiceExecutableRunOptions* run_options,
const tensorflow::gtl::ArraySlice<const ShapedBuffer*> arguments) {
executable_->session_module()->set_execution_platform(
executable_->hlo_snapshot()->set_execution_platform(
backend_->platform()->Name());
TF_RETURN_IF_ERROR(RecordArguments(arguments, executable_->session_module()));
TF_RETURN_IF_ERROR(RecordArguments(arguments, executable_->hlo_snapshot()));
TF_ASSIGN_OR_RETURN(
ScopedShapedBuffer result,
executable_->ExecuteOnStream(run_options, arguments,
/*hlo_execution_profile=*/nullptr));
TF_RETURN_IF_ERROR(RecordResult(&result, executable_->session_module()));
TF_RETURN_IF_ERROR(executable_->DumpSessionModule());
TF_RETURN_IF_ERROR(RecordResult(&result, executable_->hlo_snapshot()));
TF_RETURN_IF_ERROR(executable_->DumpHloSnapshot());
return std::move(result);
}

Status LocalExecutable::RecordArguments(
const tensorflow::gtl::ArraySlice<const ShapedBuffer*> arguments,
SessionModule* session_module) {
session_module->clear_arguments();
HloSnapshot* hlo_snapshot) {
hlo_snapshot->clear_arguments();
for (const ShapedBuffer* argument : arguments) {
TF_ASSIGN_OR_RETURN(std::unique_ptr<Literal> literal,
LiteralFromShapedBuffer(*argument));
*session_module->add_arguments() = literal->ToProto();
*hlo_snapshot->add_arguments() = literal->ToProto();
}
return Status::OK();
}

Status LocalExecutable::RecordResult(const ShapedBuffer* result,
SessionModule* session_module) {
session_module->clear_result();
HloSnapshot* hlo_snapshot) {
hlo_snapshot->clear_result();
TF_ASSIGN_OR_RETURN(std::unique_ptr<Literal> literal,
LiteralFromShapedBuffer(*result));
*session_module->mutable_result() = literal->ToProto();
*hlo_snapshot->mutable_result() = literal->ToProto();
return Status::OK();
}

Expand Down
6 changes: 3 additions & 3 deletions tensorflow/compiler/xla/client/local_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/compiler.h"
#include "tensorflow/compiler/xla/service/device_memory_allocator.h"
#include "tensorflow/compiler/xla/service/executable.h"
#include "tensorflow/compiler/xla/service/hlo.pb.h"
#include "tensorflow/compiler/xla/service/local_service.h"
#include "tensorflow/compiler/xla/service/shaped_buffer.h"
#include "tensorflow/compiler/xla/statusor.h"
Expand Down Expand Up @@ -78,11 +79,10 @@ class LocalExecutable {
// proto.
Status RecordArguments(
const tensorflow::gtl::ArraySlice<const ShapedBuffer*> arguments,
SessionModule* session_module);
HloSnapshot* hlo_snapshot);

// Records the result of the computation in a SessionModule proto.
Status RecordResult(const ShapedBuffer* result,
SessionModule* session_module);
Status RecordResult(const ShapedBuffer* result, HloSnapshot* hlo_snapshot);

// Returns a literal containing the contents of the given ShapedBuffer.
StatusOr<std::unique_ptr<Literal>> LiteralFromShapedBuffer(
Expand Down
10 changes: 0 additions & 10 deletions tensorflow/compiler/xla/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ load(
"tf_proto_library_py",
)

xla_proto_library(
name = "session_proto",
srcs = ["session.proto"],
visibility = ["//visibility:public"],
deps = ["//tensorflow/compiler/xla:xla_data_proto"],
)

xla_proto_library(
name = "hlo_proto",
srcs = ["hlo.proto"],
Expand Down Expand Up @@ -608,7 +601,6 @@ cc_library(
":hlo_module_config",
":hlo_proto_util",
":platform_util",
":session_proto",
":source_map_util",
":transfer_manager",
":versioned_computation_handle",
Expand Down Expand Up @@ -766,7 +758,6 @@ cc_library(
":hlo_graph_dumper",
":hlo_proto",
":pool",
":session_proto",
":shaped_buffer",
":versioned_computation_handle",
"//tensorflow/compiler/xla:executable_run_options",
Expand Down Expand Up @@ -870,7 +861,6 @@ cc_library(
hdrs = ["channel_tracker.h"],
deps = [
":hlo",
":session_proto",
":versioned_computation_handle",
"//tensorflow/compiler/xla:status",
"//tensorflow/compiler/xla:status_macros",
Expand Down
1 change: 0 additions & 1 deletion tensorflow/compiler/xla/service/channel_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
#include <map>

#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/session.pb.h"
#include "tensorflow/compiler/xla/service/versioned_computation_handle.h"
#include "tensorflow/compiler/xla/status.h"
#include "tensorflow/compiler/xla/statusor.h"
Expand Down
34 changes: 0 additions & 34 deletions tensorflow/compiler/xla/service/executable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,6 @@ StatusOr<ScopedShapedBuffer> Executable::ExecuteOnStreamWrapper(
return return_value;
}

Status Executable::DumpSessionModule() {
TF_RET_CHECK(dumping());
const string& directory_path =
module_config().debug_options().xla_dump_executions_to();
VersionedComputationHandle versioned_handle = entry_computation_handle();
// This filename does not include the version number because the computation
// is only ever executed at one version.
string filename = tensorflow::strings::Printf(
"computation_%lld__%s__execution_%lld", versioned_handle.handle.handle(),
session_module_->entry().name().c_str(), ++execution_count_);
return Executable::DumpToDirectory(directory_path, filename,
*session_module_);
}

Status Executable::DumpHloSnapshot() {
TF_RET_CHECK(dumping_snapshot());
TF_RET_CHECK(hlo_snapshot_->has_hlo() &&
Expand All @@ -156,26 +142,6 @@ Status Executable::DumpHloSnapshot() {
return Executable::DumpToDirectory(directory_path, filename, *hlo_snapshot_);
}

/* static */ Status Executable::DumpToDirectory(
const string& directory_path, string filename,
const SessionModule& session_module) {
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(session_module, &result));
return tensorflow::WriteStringToFile(tensorflow::Env::Default(), file_path,
result);
}

/* static */ Status Executable::DumpToDirectory(
const string& directory_path, string filename,
const HloSnapshot& hlo_session) {
Expand Down
16 changes: 0 additions & 16 deletions tensorflow/compiler/xla/service/executable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/hlo_graph_dumper.h"
#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/service_executable_run_options.h"
#include "tensorflow/compiler/xla/service/session.pb.h"
#include "tensorflow/compiler/xla/service/shaped_buffer.h"
#include "tensorflow/compiler/xla/service/versioned_computation_handle.h"
#include "tensorflow/compiler/xla/statusor.h"
Expand Down Expand Up @@ -144,14 +143,6 @@ class Executable {
return hlo_module_->config().host_entry_computation_layout().result_shape();
}

// TODO(b/74197823): Delete the session module dumping helpers.
void set_session_module(std::unique_ptr<xla::SessionModule> session_module) {
session_module_ = std::move(session_module);
}
bool dumping() const { return session_module_ != nullptr; }
SessionModule* session_module() const { return session_module_.get(); }
Status DumpSessionModule();

// Dumping helpers.
void set_hlo_snapshot(std::unique_ptr<xla::HloSnapshot> hlo_snapshot) {
hlo_snapshot_ = std::move(hlo_snapshot);
Expand All @@ -160,10 +151,6 @@ class Executable {
HloSnapshot* hlo_snapshot() const { return hlo_snapshot_.get(); }
Status DumpHloSnapshot();

// Dump session_module to directory_path/filename.
static Status DumpToDirectory(const string& directory_path, string filename,
const SessionModule& session_module);

// Dump hlo snapshot to directory_path/filename.
static Status DumpToDirectory(const string& directory_path, string filename,
const HloSnapshot& hlo_session);
Expand All @@ -179,9 +166,6 @@ class Executable {
// around.
const std::unique_ptr<const HloModule> hlo_module_;

// SessionModule this was compiled from. Null if not dumping executions.
std::unique_ptr<SessionModule> session_module_;

// HloSnapshot this was compiled from. Null if not dumping executions.
std::unique_ptr<HloSnapshot> hlo_snapshot_;

Expand Down
28 changes: 0 additions & 28 deletions tensorflow/compiler/xla/service/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/hlo_module_config.h"
#include "tensorflow/compiler/xla/service/hlo_proto_util.h"
#include "tensorflow/compiler/xla/service/platform_util.h"
#include "tensorflow/compiler/xla/service/session.pb.h"
#include "tensorflow/compiler/xla/service/source_map_util.h"
#include "tensorflow/compiler/xla/service/transfer_manager.h"
#include "tensorflow/compiler/xla/shape_layout.h"
Expand All @@ -62,33 +61,6 @@ namespace xla {

namespace {

// Records the arguments used to invoke a computation in a SessionModule
// proto.
Status RecordArguments(
const tensorflow::gtl::ArraySlice<const ShapedBuffer*> arguments,
se::StreamExecutor* executor, TransferManager* transfer_manager,
SessionModule* module) {
module->clear_arguments();
for (const ShapedBuffer* argument : arguments) {
TF_ASSIGN_OR_RETURN(
std::unique_ptr<Literal> literal,
transfer_manager->TransferLiteralFromDevice(executor, *argument));
*module->add_arguments() = literal->ToProto();
}
return Status::OK();
}

// Records the result of a computation in a SessionModule proto.
Status RecordResult(const ShapedBuffer& result, se::StreamExecutor* executor,
TransferManager* transfer_manager, SessionModule* module) {
module->clear_result();
TF_ASSIGN_OR_RETURN(
std::unique_ptr<Literal> literal,
transfer_manager->TransferLiteralFromDevice(executor, result));
*module->mutable_result() = literal->ToProto();
return Status::OK();
}

// Records the arguments used to invoke a computation in an HloSnapshot proto.
Status RecordArguments(
const tensorflow::gtl::ArraySlice<const ShapedBuffer*> arguments,
Expand Down
1 change: 0 additions & 1 deletion tensorflow/compiler/xla/service/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/hlo_execution_profile.h"
#include "tensorflow/compiler/xla/service/hlo_module.h"
#include "tensorflow/compiler/xla/service/hlo_module_config.h"
#include "tensorflow/compiler/xla/service/session.pb.h"
#include "tensorflow/compiler/xla/service/versioned_computation_handle.h"
#include "tensorflow/compiler/xla/service_interface.h"
#include "tensorflow/compiler/xla/statusor.h"
Expand Down
85 changes: 0 additions & 85 deletions tensorflow/compiler/xla/service/session.proto

This file was deleted.

2 changes: 1 addition & 1 deletion tensorflow/compiler/xla/tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ tf_cc_binary(
deps = [
"//tensorflow/compiler/xla:statusor",
"//tensorflow/compiler/xla:types",
"//tensorflow/compiler/xla/service:session_proto",
"//tensorflow/compiler/xla/service:hlo_proto",
"//tensorflow/core:lib",
],
)
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/compiler/xla/tools/convert_computation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ limitations under the License.
#include <unistd.h>
#include <string>

#include "tensorflow/compiler/xla/service/session.pb.h"
#include "tensorflow/compiler/xla/service/hlo.pb.h"
#include "tensorflow/compiler/xla/statusor.h"
#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/core/platform/env.h"
Expand All @@ -33,7 +33,7 @@ namespace xla {
namespace tools {

void RealMain(const string& mode, const string& path) {
SessionModule module;
HloSnapshot module;
tensorflow::Env* env = tensorflow::Env::Default();
if (mode == "txt2bin") {
TF_CHECK_OK(tensorflow::ReadTextProto(env, path, &module));
Expand Down
Loading

0 comments on commit f023073

Please sign in to comment.