From 5895989a4f331ead9be667d0d7108be49d830920 Mon Sep 17 00:00:00 2001 From: yuyang18 Date: Tue, 15 May 2018 20:14:51 +0800 Subject: [PATCH] Add ref --- paddle/fluid/framework/details/fetch_op_handle.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/details/fetch_op_handle.cc b/paddle/fluid/framework/details/fetch_op_handle.cc index 4a8f20110..c581149a2 100644 --- a/paddle/fluid/framework/details/fetch_op_handle.cc +++ b/paddle/fluid/framework/details/fetch_op_handle.cc @@ -44,6 +44,12 @@ void FetchOpHandle::WaitAndMergeCPUTensors() const { data_->at(offset_).MergeLoDTensor(tensors_ptr, platform::CPUPlace()); } +template +inline T &Ref(T *ptr, ARGS &&... args) { + PADDLE_ENFORCE(ptr != nullptr, args...); + return *ptr; +} + void FetchOpHandle::RunImpl() { WaitInputVarGenerated(platform::CPUPlace()); @@ -56,8 +62,11 @@ void FetchOpHandle::RunImpl() { PADDLE_ENFORCE_EQ(inputs_.size(), scopes.size()); for (size_t i = 0; i < scopes.size(); ++i) { auto &scope = scopes[i]; - auto *var = - scope->FindVar(kLocalExecScopeName)->Get()->FindVar(var_name); + auto *var = Ref(Ref(scope->FindVar(kLocalExecScopeName), "Cannot find %s", + kLocalExecScopeName) + .Get(), + "Cannot get scope") + .FindVar(var_name); PADDLE_ENFORCE_NOT_NULL(var, "Cannot find variable %s in execution scope", var_name); auto &t = var->Get(); -- GitLab