From 47d10c55d5028f43d8986923508c430870a90a60 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 30 Dec 2020 13:04:01 +0800 Subject: [PATCH] Enhance debugging (#30001) * add debug code * add place info * fix compile problem * add place for output --- paddle/fluid/framework/operator.cc | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index b3658bacf9..9c29c938af 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -34,6 +34,7 @@ limitations under the License. */ #include "paddle/fluid/framework/transfer_scope_cache.h" #include "paddle/fluid/framework/unused_var_check.h" #include "paddle/fluid/framework/var_type.h" +#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/profiler.h" #ifdef PADDLE_WITH_XPU #include "paddle/fluid/platform/xpu_info.h" @@ -112,6 +113,35 @@ static std::string GetDtype(const Scope& scope, const std::string& name) { } } +static std::string GetPlace(const Scope& scope, const std::string& name) { + Variable* var = scope.FindVar(name); + if (var == nullptr) { + return ""; + } + auto to_string = [](const platform::Place& p) { + std::stringstream sstream; + sstream << p; + return sstream.str(); + }; + + if (var->IsType()) { + const LoDTensor& tensor = var->Get(); + if (UNLIKELY(!tensor.IsInitialized())) { + return ""; + } + return to_string(tensor.place()); + } else if (var->IsType()) { + auto tensor = var->Get().value(); + if (UNLIKELY(!tensor.IsInitialized())) { + return "uninited"; + } else { + return to_string(tensor.place()); + } + } else { + return ""; + } +} + static int GetRowSize(const Scope& scope, const std::string& name) { Variable* var = scope.FindVar(name); if (var == nullptr) { @@ -297,6 +327,7 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const { ss << ":" << dtype; ss << "[" << GetDimsDebug(*scope, var_name, true) << "]"; ss << "(" << GetLoDDebug(*scope, var_name) << ")"; + ss << "(" << GetPlace(*scope, var_name) << ")"; } } if (i != input.second.size() - 1) { @@ -328,6 +359,7 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const { ss << ":" << dtype; ss << "[" << GetDimsDebug(*scope, var_name, true) << "]"; ss << "(" << GetLoDDebug(*scope, var_name) << ")"; + ss << "(" << GetPlace(*scope, var_name) << ")"; } } if (i != output.second.size() - 1) { @@ -1130,6 +1162,10 @@ void OperatorWithKernel::RunImpl(const Scope& scope, /*For profiling/benchmark only*/ if (FLAGS_benchmark) { dev_ctx->Wait(); +#if defined(PADDLE_WITH_CUDA) + PADDLE_ENFORCE_CUDA_SUCCESS(cudaGetLastError()); + VLOG(4) << "Operator(" << Type() << "): context wait and get last error"; +#endif } if (FLAGS_fast_check_nan_inf) { -- GitLab