提交 c0b240aa 编写于 作者: L luotao1

try to fix distributed unit-test

test=develop
上级 784826a4
......@@ -919,15 +919,16 @@ std::vector<KernelConfig>* OperatorWithKernel::GetKernelConfig(
void OperatorWithKernel::RunImpl(const Scope& scope,
const platform::Place& place) const {
const Scope* cur_scope = &scope;
if (!runtime_ctx_ || pre_scope_ != cur_scope ||
scope.FindVar(details::kLocalExecScopeName)) {
// RuntimeContext is used to relate input/output names of Operator with
// the corresponding variables in Scope.
// In a same Scope, since the input/output names of Operator do not change
// in the execution, RuntimeContext could be created only at the first
// iteration of the execution to save the elapsed time.
// Note that the Scope should not be the local scope, since local scope
// would be cleaned regularly.
// RuntimeContext is used to relate input/output names of Operator with
// the corresponding variables in Scope.
// In a same Scope, since the input/output names of Operator do not change
// in the execution, RuntimeContext could be created only at the first
// iteration of the execution to save the elapsed time.
// Note that the Scope should not be the local scope, since local scope
// would be cleaned regularly.
if (scope.FindVar(details::kLocalExecScopeName)) {
runtime_ctx_.reset(new RuntimeContext(Inputs(), Outputs(), scope));
} else if (!runtime_ctx_ || pre_scope_ != cur_scope) {
runtime_ctx_.reset(new RuntimeContext(Inputs(), Outputs(), scope));
pre_scope_ = cur_scope;
}
......
......@@ -107,6 +107,10 @@ const Scope* Scope::FindScope(const Variable* var) const {
return FindScopeInternal(var);
}
bool Scope::HasLocalVar(const std::string& name) const {
return vars_.find(name) != vars_.end();
}
void Scope::DropKids() {
SCOPE_KIDS_WRITER_LOCK
for (Scope* s : kids_) delete s;
......
......@@ -75,6 +75,10 @@ class Scope {
/// Caller doesn't own the returned Variable.
Variable* FindLocalVar(const std::string& name) const;
/// Find whether a variable in the current scope.
/// Return false if cannot find.
bool HasLocalVar(const std::string& name) const;
const Scope* parent() const { return parent_; }
/// Find the scope or an ancestor scope that contains the given variable.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册