From 93da44021d74a65ca0b4dd835f5625912d7eb688 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Mon, 16 Sep 2019 05:32:56 -0700 Subject: [PATCH] Adds new protobuf message HloExecutionProfileData, which describes HloExecutionProfile. PiperOrigin-RevId: 269313040 --- tensorflow/compiler/xla/service/BUILD | 7 +++++ tensorflow/compiler/xla/service/executable.cc | 12 +++++++++ .../xla/service/hlo_execution_profile.cc | 11 ++++++++ .../xla/service/hlo_execution_profile.h | 3 +++ .../service/hlo_execution_profile_data.proto | 27 +++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 tensorflow/compiler/xla/service/hlo_execution_profile_data.proto diff --git a/tensorflow/compiler/xla/service/BUILD b/tensorflow/compiler/xla/service/BUILD index 46d014f48d8..813107abb9b 100755 --- a/tensorflow/compiler/xla/service/BUILD +++ b/tensorflow/compiler/xla/service/BUILD @@ -51,6 +51,12 @@ xla_proto_library( srcs = ["hlo_profile_printer_data.proto"], ) +xla_proto_library( + name = "hlo_execution_profile_data", + srcs = ["hlo_execution_profile_data.proto"], + deps = [":hlo_profile_printer_data"], +) + # Filegroup used to collect source files for dependency checking. filegroup( name = "c_srcs", @@ -2463,6 +2469,7 @@ cc_library( deps = [ ":hlo", ":hlo_cost_analysis", + ":hlo_execution_profile_data", ":hlo_profile_printer", ":human_readable_profile_builder", "//tensorflow/compiler/xla:types", diff --git a/tensorflow/compiler/xla/service/executable.cc b/tensorflow/compiler/xla/service/executable.cc index c45ecc7c2c4..c21721c9339 100644 --- a/tensorflow/compiler/xla/service/executable.cc +++ b/tensorflow/compiler/xla/service/executable.cc @@ -22,6 +22,7 @@ limitations under the License. #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/core/status.h" #include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/strings/proto_serialization.h" @@ -168,6 +169,17 @@ StatusOr Executable::ExecuteAsyncOnStreamWrapper( } } + const auto& dump_path = module_config().debug_options().xla_dump_to(); + if (module_config().debug_options().xla_hlo_profile() && + profile_ptr != nullptr && !dump_path.empty()) { + const std::string full_path = + tensorflow::io::JoinPath(dump_path, "hlo_execution_profile_data"); + TF_CHECK_OK(tensorflow::WriteStringToFile( + tensorflow::Env::Default(), full_path, + profile_ptr->ToProto().SerializeAsString())) + << "Error saving HloExecutionProfileData to " << full_path; + } + if (profile_ptr != nullptr) { const se::DeviceDescription* device_description = &stream->parent()->GetDeviceDescription(); diff --git a/tensorflow/compiler/xla/service/hlo_execution_profile.cc b/tensorflow/compiler/xla/service/hlo_execution_profile.cc index 2df8eb962ae..a7785455cf1 100644 --- a/tensorflow/compiler/xla/service/hlo_execution_profile.cc +++ b/tensorflow/compiler/xla/service/hlo_execution_profile.cc @@ -21,6 +21,7 @@ limitations under the License. #include "absl/algorithm/container.h" #include "absl/memory/memory.h" +#include "tensorflow/compiler/xla/service/hlo_execution_profile_data.pb.h" #include "tensorflow/compiler/xla/service/hlo_instruction.h" #include "tensorflow/compiler/xla/service/hlo_module.h" #include "tensorflow/compiler/xla/service/human_readable_profile_builder.h" @@ -140,4 +141,14 @@ uint64 HloExecutionProfile::GetCyclesTakenBy(const HloInstruction& hlo) const { return profile_counters_[hlo_profile_index_map_.GetProfileIndexFor(hlo)]; } +HloExecutionProfileData HloExecutionProfile::ToProto() const { + HloExecutionProfileData hlo_execution_profile_data; + for (const auto& counter : profile_counters_) { + hlo_execution_profile_data.add_profile_counters(counter); + } + *(hlo_execution_profile_data.mutable_printer_data()) = + hlo_profile_printer_data_; + return hlo_execution_profile_data; +} + } // namespace xla diff --git a/tensorflow/compiler/xla/service/hlo_execution_profile.h b/tensorflow/compiler/xla/service/hlo_execution_profile.h index da30e159083..47de1a25765 100644 --- a/tensorflow/compiler/xla/service/hlo_execution_profile.h +++ b/tensorflow/compiler/xla/service/hlo_execution_profile.h @@ -21,6 +21,7 @@ limitations under the License. #include "tensorflow/compiler/xla/map_util.h" #include "tensorflow/compiler/xla/service/hlo_cost_analysis.h" +#include "tensorflow/compiler/xla/service/hlo_execution_profile_data.pb.h" #include "tensorflow/compiler/xla/service/hlo_profile_printer.h" #include "tensorflow/compiler/xla/types.h" #include "tensorflow/core/platform/stream_executor_no_cuda.h" @@ -151,6 +152,8 @@ class HloExecutionProfile { return profile_counters_; } + HloExecutionProfileData ToProto() const; + private: const HloProfilePrinterData& hlo_profile_printer_data_; const HloProfileIndexMap& hlo_profile_index_map_; diff --git a/tensorflow/compiler/xla/service/hlo_execution_profile_data.proto b/tensorflow/compiler/xla/service/hlo_execution_profile_data.proto new file mode 100644 index 00000000000..c216c4359f1 --- /dev/null +++ b/tensorflow/compiler/xla/service/hlo_execution_profile_data.proto @@ -0,0 +1,27 @@ +/* Copyright 2018 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. +==============================================================================*/ + +syntax = "proto3"; + +package xla; + +import "tensorflow/compiler/xla/service/hlo_profile_printer_data.proto"; + +option cc_enable_arenas = true; + +message HloExecutionProfileData { + HloProfilePrinterData printer_data = 1; + repeated int64 profile_counters = 2; +}