提交 c0b240aa 编写于 作者: L luotao1

try to fix distributed unit-test

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