From 3ce012557bee0c7dafa79180bc57cb784ea038ce Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 13 Mar 2019 10:19:02 -0700 Subject: [PATCH] [XLA] Make ModuleHook return void rather than a Status. We were CHECK_OK'ing these return values anyway, so using Status doesn't buy us much. PiperOrigin-RevId: 238250643 --- tensorflow/compiler/xla/service/cpu/compiler_functor.cc | 7 ++----- tensorflow/compiler/xla/service/cpu/cpu_compiler.cc | 5 ++--- tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc | 4 ++-- tensorflow/compiler/xla/service/llvm_compiler.h | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tensorflow/compiler/xla/service/cpu/compiler_functor.cc b/tensorflow/compiler/xla/service/cpu/compiler_functor.cc index 6f9d0b37735..39926182894 100644 --- a/tensorflow/compiler/xla/service/cpu/compiler_functor.cc +++ b/tensorflow/compiler/xla/service/cpu/compiler_functor.cc @@ -94,7 +94,7 @@ std::unique_ptr CompilerFunctor::operator()( XLA_VLOG_LINES(2, llvm_ir::DumpModuleToString(module)); if (pre_optimization_hook_) { - TF_CHECK_OK(pre_optimization_hook_(module)); + pre_optimization_hook_(module); } // Add the appropriate TargetLibraryInfo and TargetTransformInfo. @@ -138,10 +138,7 @@ std::unique_ptr CompilerFunctor::operator()( XLA_VLOG_LINES(2, llvm_ir::DumpModuleToString(module)); if (post_optimization_hook_) { - // TODO(jlebar): If we're going to CHECK these return values, then we might - // as well make them return void and move the CHECKs into the hooks - // themselves. - TF_CHECK_OK(post_optimization_hook_(module)); + post_optimization_hook_(module); } // Generate code. diff --git a/tensorflow/compiler/xla/service/cpu/cpu_compiler.cc b/tensorflow/compiler/xla/service/cpu/cpu_compiler.cc index 4ebf4e36878..534e35fdb10 100644 --- a/tensorflow/compiler/xla/service/cpu/cpu_compiler.cc +++ b/tensorflow/compiler/xla/service/cpu/cpu_compiler.cc @@ -447,10 +447,9 @@ std::pair GetIRModuleHooks( const auto& user_hook = !optimized ? user_pre_optimization_hook : user_post_optimization_hook; if (user_hook) { - TF_RETURN_IF_ERROR(user_hook(llvm_module)); + user_hook(llvm_module); } llvm_ir::DumpIrIfEnabled(*hlo_module_ptr, llvm_module, optimized); - return Status::OK(); }; return {[hook](const llvm::Module& llvm_module) { return hook(/*optimized=*/false, llvm_module); @@ -886,7 +885,7 @@ CpuCompiler::CompileAheadOfTime(std::unique_ptr module_group, { Status verify_status = VerifyLlvmModule(llvm_module); if (!verify_status.ok() && pre_optimization_ir_hook) { - pre_optimization_ir_hook(llvm_module).IgnoreError(); + pre_optimization_ir_hook(llvm_module); } TF_RETURN_IF_ERROR(verify_status); } diff --git a/tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc b/tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc index 17b7c784396..39cb71c0913 100644 --- a/tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc +++ b/tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc @@ -694,7 +694,7 @@ StatusOr> NVPTXCompiler::RunBackend( } if (user_pre_optimization_hook_) { - TF_CHECK_OK(user_pre_optimization_hook_(llvm_module)); + user_pre_optimization_hook_(llvm_module); } string ir_module_string_before_opt; const bool embed_ir_in_executable = @@ -753,7 +753,7 @@ StatusOr> NVPTXCompiler::RunBackend( llvm_ir::DumpIrIfEnabled(*module, llvm_module, /*optimized=*/true); if (user_post_optimization_hook_) { - TF_CHECK_OK(user_post_optimization_hook_(llvm_module)); + user_post_optimization_hook_(llvm_module); } // Write PTX to IR dump directory, if IR dumping was requested. if (DumpingEnabledForHloModule(*module)) { diff --git a/tensorflow/compiler/xla/service/llvm_compiler.h b/tensorflow/compiler/xla/service/llvm_compiler.h index 182d8edbe30..afd9f370383 100644 --- a/tensorflow/compiler/xla/service/llvm_compiler.h +++ b/tensorflow/compiler/xla/service/llvm_compiler.h @@ -37,7 +37,7 @@ class LLVMCompiler : public Compiler { // A callback of this type can be run before and/or after IR-level // optimization to e.g. dump out the generated IR to disk or gather some // statistics. - using ModuleHook = std::function; + using ModuleHook = std::function; void SetPreOptimizationHook(ModuleHook hook) { CHECK(!user_pre_optimization_hook_)