diff --git a/paddle/framework/lod_tensor.cc b/paddle/framework/lod_tensor.cc index beb2edee23d5586ef19155ac59a172f23a9794d9..dcde3705d6a6d2d7aa69d43dcd7cfc8bd1c1a49b 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 fae36892f00132c5fb2d9bc017d9b4f24e78b6ea..7e44ffca3b81da990cdef6871ca4d1ac85ce109b 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 b15d171b9b6e6debf53c34050b718bf3e3fa851c..fd48c1b54cb9cc45416d2fd8e9b1426d488e5d2d 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;