[XLA] Add option to print out hlo pass hash.

PiperOrigin-RevId: 297693781
Change-Id: I5a804056643f7c97bd51da6a7e14fe2e8bc77153
This commit is contained in:
Yunxing Dai 2020-02-27 14:51:11 -08:00 committed by TensorFlower Gardener
parent dc786329b1
commit fb9f77525b
5 changed files with 21 additions and 3 deletions

View File

@ -1371,6 +1371,7 @@ cc_library(
deps = [ deps = [
":hlo", ":hlo",
":hlo_proto_cc", ":hlo_proto_cc",
"//tensorflow/core:lib",
"@com_google_absl//absl/strings", "@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span", "@com_google_absl//absl/types:span",
], ],

View File

@ -716,9 +716,13 @@ HloComputation* HloModule::GetComputationWithName(absl::string_view name) {
} }
uint64 HloModule::Hash() const { uint64 HloModule::Hash() const {
return tensorflow::Hash64Combine( uint64 result = entry_computation_layout().Hash();
entry_computation_layout().Hash(), for (auto* computation : MakeComputationPostOrder()) {
entry_computation()->root_instruction()->Hash()); for (auto* instruction : computation->MakeInstructionPostOrder()) {
result = tensorflow::Hash64Combine(result, instruction->Hash());
}
}
return result;
} }
/* static */ std::atomic<int> HloModule::next_unique_module_id_(0); /* static */ std::atomic<int> HloModule::next_unique_module_id_(0);

View File

@ -15,6 +15,8 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/hlo_module_group.h" #include "tensorflow/compiler/xla/service/hlo_module_group.h"
#include "tensorflow/core/lib/hash/hash.h"
namespace xla { namespace xla {
HloModuleGroup::HloModuleGroup(std::unique_ptr<HloModule> module) HloModuleGroup::HloModuleGroup(std::unique_ptr<HloModule> module)
@ -65,6 +67,14 @@ HloModuleGroupProto HloModuleGroup::ToProto() const {
return proto; return proto;
} }
uint64 HloModuleGroup::Hash() const {
uint64 result = 0;
for (auto& module : modules_) {
result = tensorflow::Hash64Combine(result, module->Hash());
}
return result;
}
/* static */ StatusOr<HloModuleGroup> HloModuleGroup::CreateFromProto( /* static */ StatusOr<HloModuleGroup> HloModuleGroup::CreateFromProto(
const HloModuleGroupProto& proto, const HloModuleGroupProto& proto,
absl::Span<const HloModuleConfig> module_configs) { absl::Span<const HloModuleConfig> module_configs) {

View File

@ -71,6 +71,8 @@ class HloModuleGroup {
} }
} }
uint64 Hash() const;
// Serialize the module group to/from a proto. // Serialize the module group to/from a proto.
HloModuleGroupProto ToProto() const; HloModuleGroupProto ToProto() const;
static StatusOr<HloModuleGroup> CreateFromProto( static StatusOr<HloModuleGroup> CreateFromProto(

View File

@ -60,6 +60,7 @@ StatusOr<bool> HloPassPipeline::RunPassesInternal(
for (HloPassInterface* pass : passes) { for (HloPassInterface* pass : passes) {
absl::string_view pass_name = pass->name(); absl::string_view pass_name = pass->name();
VLOG(1) << " HLO pass " << pass_name; VLOG(1) << " HLO pass " << pass_name;
VLOG(2) << " Module hash " << hlo->Hash();
MaybeDumpHlo(*hlo, MaybeDumpHlo(*hlo,
/*after_pass_name=*/last_pass_name, /*after_pass_name=*/last_pass_name,
/*before_pass_name=*/pass_name); /*before_pass_name=*/pass_name);