提交 5895989a 编写于 作者: Y yuyang18

Add ref

上级 a77d1bc6
......@@ -44,6 +44,12 @@ void FetchOpHandle::WaitAndMergeCPUTensors() const {
data_->at(offset_).MergeLoDTensor(tensors_ptr, platform::CPUPlace());
}
template <typename T, typename... ARGS>
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<Scope *>()->FindVar(var_name);
auto *var = Ref(Ref(scope->FindVar(kLocalExecScopeName), "Cannot find %s",
kLocalExecScopeName)
.Get<Scope *>(),
"Cannot get scope")
.FindVar(var_name);
PADDLE_ENFORCE_NOT_NULL(var, "Cannot find variable %s in execution scope",
var_name);
auto &t = var->Get<framework::LoDTensor>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册