aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Justin Lebar <jlebar@google.com>2018-02-05 17:45:26 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-05 17:50:17 -0800
commitf92d4e8bc878245379ed2c04123b20758a261af0 (patch)
tree9845b1e9f7aa19e58410f0718f5e027c1215799b
parent78af5c7e2cf9e7a09acfceb368d6bd3818405353 (diff)
[XLA] Add HloBindings::ToString().
PiperOrigin-RevId: 184615306
-rw-r--r--tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.cc54
-rw-r--r--tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.h2
-rw-r--r--tensorflow/compiler/xla/service/gpu/ir_emitter_unnested.cc2
3 files changed, 58 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.cc b/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.cc
index dd4426ca7b..061210352c 100644
--- a/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.cc
+++ b/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.cc
@@ -22,12 +22,17 @@ limitations under the License.
#include "tensorflow/compiler/xla/service/hlo_opcode.h"
#include "tensorflow/compiler/xla/service/llvm_ir/llvm_util.h"
#include "tensorflow/compiler/xla/service/llvm_ir/tuple_ops.h"
+#include "tensorflow/core/lib/strings/str_util.h"
+#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/types.h"
namespace xla {
namespace gpu {
+using tensorflow::strings::StrAppend;
+using tensorflow::strings::StrCat;
+
void HloToIrBindings::EmitBasePointersForHlos(
tensorflow::gtl::ArraySlice<const HloInstruction*> io_hlos,
tensorflow::gtl::ArraySlice<const HloInstruction*> non_io_hlos) {
@@ -227,5 +232,54 @@ void HloToIrBindings::UnbindAllLocalIrValues() {
}
}
+string HloToIrBindings::ToString() const {
+ string s = StrCat("** HloToIrBindings **\n");
+ StrAppend(&s, " is_nested_=", is_nested_, "\n");
+ StrAppend(&s,
+ " temp_buffer_base_=", llvm_ir::DumpToString(*temp_buffer_base_),
+ "\n");
+
+ if (base_ptrs_.empty()) {
+ return s;
+ }
+
+ // Iterate over all computations in the module in topological order, and print
+ // out the base pointers we have in each computation in topological order.
+ for (const HloComputation* computation :
+ base_ptrs_.begin()->first->GetModule()->MakeComputationPostOrder()) {
+ bool is_first = true;
+ for (const HloInstruction* instr :
+ computation->MakeInstructionPostOrder()) {
+ auto it = base_ptrs_.find(instr);
+ if (it == base_ptrs_.end()) {
+ continue;
+ }
+ if (is_first) {
+ StrAppend(&s, " Base pointers for computation ", computation->name(),
+ ":\n");
+ is_first = false;
+ }
+ StrAppend(&s, " ", instr->ToString());
+
+ const ShapeTree<llvm::Value*>& shape_tree = it->second;
+ if (!ShapeUtil::IsTuple(instr->shape())) {
+ const llvm::Value* val = shape_tree.begin()->second;
+ StrAppend(&s, " -> ", llvm_ir::DumpToString(*val), "\n");
+ continue;
+ }
+
+ StrAppend(&s, "\n");
+ for (auto shape_it = shape_tree.begin(); shape_it != shape_tree.end();
+ ++shape_it) {
+ llvm::Value* val = shape_it->second;
+ StrAppend(&s, " ", shape_it->first.ToString(), " -> ",
+ (val != nullptr ? llvm_ir::DumpToString(*val) : "null"),
+ "\n");
+ }
+ }
+ }
+ return s;
+}
+
} // namespace gpu
} // namespace xla
diff --git a/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.h b/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.h
index 62ae1769a1..1fe7970e7d 100644
--- a/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.h
+++ b/tensorflow/compiler/xla/service/gpu/hlo_to_ir_bindings.h
@@ -87,6 +87,8 @@ class HloToIrBindings {
const HloInstruction& consumer,
const ShapeIndex& shape_index = {});
+ string ToString() const;
+
private:
// Emits IR to resolve (possibly) recursive GetTupleElement instructions.
llvm::Value* EmitGetTupleElement(const HloInstruction* gte,
diff --git a/tensorflow/compiler/xla/service/gpu/ir_emitter_unnested.cc b/tensorflow/compiler/xla/service/gpu/ir_emitter_unnested.cc
index 08fea34a70..c81dfbf6c2 100644
--- a/tensorflow/compiler/xla/service/gpu/ir_emitter_unnested.cc
+++ b/tensorflow/compiler/xla/service/gpu/ir_emitter_unnested.cc
@@ -2271,6 +2271,8 @@ std::unique_ptr<Thunk> IrEmitterUnnested::BuildConditionalThunk(
Status IrEmitterUnnested::EmitTargetElementLoopInThunk(
const HloInstruction& hlo,
const llvm_ir::ElementGenerator& element_generator, KernelThunk* thunk) {
+ VLOG(3) << bindings_.ToString();
+
const Shape& element_shape = hlo.IsMultiOutputFusion()
? ShapeUtil::GetSubshape(hlo.shape(), {0})
: hlo.shape();