From cb0b81f97b5791a29aab73797abfa2820b89f8a3 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Wed, 3 Jan 2018 07:21:40 +0000 Subject: [PATCH] add << lodtensor --- paddle/framework/lod_tensor.cc | 16 ++++++++++++++++ paddle/framework/lod_tensor.h | 1 + paddle/operators/parallel_do_op.cc | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/paddle/framework/lod_tensor.cc b/paddle/framework/lod_tensor.cc index beb2edee23..dcde3705d6 100644 --- a/paddle/framework/lod_tensor.cc +++ b/paddle/framework/lod_tensor.cc @@ -43,6 +43,22 @@ std::ostream &operator<<(std::ostream &os, const LoD &lod) { return os; } +std::ostream &operator<<(std::ostream &os, const LoDTensor &t) { + PADDLE_ENFORCE(platform::is_cpu_place(t.place())); + PADDLE_ENFORCE(t.type().hash_code() == typeid(float).hash_code()); + + os << "dim: " << t.dims() << "\n"; + os << "lod: " << t.lod() << "\n"; + + // only print first ten elements + int64_t size = t.numel() < 10 ? t.numel() : 10; + for (int64_t i = 0; i < size; ++i) { + os << t.data()[i] << " "; + } + + return os; +} + LoD SliceLevels(const LoD &in, size_t level_begin, size_t level_end) { LoD new_lod; new_lod.reserve(level_end - level_begin); diff --git a/paddle/framework/lod_tensor.h b/paddle/framework/lod_tensor.h index fae36892f0..7e44ffca3b 100644 --- a/paddle/framework/lod_tensor.h +++ b/paddle/framework/lod_tensor.h @@ -58,6 +58,7 @@ using Vector = thrust::host_vector< using LoD = std::vector>; std::ostream& operator<<(std::ostream& os, const LoD& lod); +std::ostream& operator<<(std::ostream& os, const LoDTensor& t); /* * Slice levels from a LoD. diff --git a/paddle/operators/parallel_do_op.cc b/paddle/operators/parallel_do_op.cc index b15d171b9b..fd48c1b54c 100644 --- a/paddle/operators/parallel_do_op.cc +++ b/paddle/operators/parallel_do_op.cc @@ -156,11 +156,12 @@ class ParallelDoGradOp : public OperatorBase { for (auto &s : Inputs(framework::GradVarName(kOutputs))) { LOG(INFO) << s; - LOG(INFO) << scope.FindVar(s)->Get().dims(); + LOG(INFO) << scope.FindVar(s)->Get(); for (auto *sub_scope : sub_scopes) { - LOG(INFO) << sub_scope->FindVar(s)->Get().dims(); + LOG(INFO) << sub_scope->FindVar(s)->Get(); } } + // exe run for (int place_idx = 0; place_idx < places.size(); ++place_idx) { VLOG(3) << "Run " << place_idx; -- GitLab