|
|
|
@ -93,6 +93,42 @@ static void CheckTensorNANOrInf(const std::string& name,
|
|
|
|
|
"Tensor %s contains NAN", name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Executor::CreateVariables(const ProgramDesc& pdesc, Scope* scope) {
|
|
|
|
|
auto& global_block = pdesc.Block(0);
|
|
|
|
|
|
|
|
|
|
const Scope* ancestor_scope = scope;
|
|
|
|
|
while (ancestor_scope->parent()) {
|
|
|
|
|
ancestor_scope = ancestor_scope->parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ancestor_scope != scope) {
|
|
|
|
|
for (auto& var : global_block.AllVars()) {
|
|
|
|
|
if (var->Name() == framework::kEmptyVarName) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (var->Persistable()) {
|
|
|
|
|
auto* ptr = const_cast<Scope*>(ancestor_scope)->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create Variable " << var->Name()
|
|
|
|
|
<< " global, which pointer is " << ptr;
|
|
|
|
|
} else {
|
|
|
|
|
auto* ptr = scope->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create Variable " << var->Name()
|
|
|
|
|
<< " locally, which pointer is " << ptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (auto& var : global_block.AllVars()) {
|
|
|
|
|
auto* ptr = scope->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create variable " << var->Name() << ", which pointer is "
|
|
|
|
|
<< ptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Executor::Run(const ProgramDesc& pdesc, Scope* scope, int block_id,
|
|
|
|
|
bool create_local_scope, bool create_vars) {
|
|
|
|
|
platform::RecordBlock b(block_id);
|
|
|
|
@ -184,8 +220,8 @@ static bool has_fetch_operators(
|
|
|
|
|
void Executor::Run(const ProgramDesc& program, Scope* scope,
|
|
|
|
|
std::map<std::string, const LoDTensor*>& feed_targets,
|
|
|
|
|
std::map<std::string, LoDTensor*>& fetch_targets,
|
|
|
|
|
const std::string& feed_holder_name,
|
|
|
|
|
const std::string& fetch_holder_name, bool create_vars) {
|
|
|
|
|
bool create_vars, const std::string& feed_holder_name,
|
|
|
|
|
const std::string& fetch_holder_name) {
|
|
|
|
|
platform::RecordBlock b(kProgramId);
|
|
|
|
|
bool has_feed_ops =
|
|
|
|
|
has_feed_operators(program.Block(0), feed_targets, feed_holder_name);
|
|
|
|
@ -281,39 +317,16 @@ std::unique_ptr<ExecutorPrepareContext> Executor::Prepare(
|
|
|
|
|
|
|
|
|
|
void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
|
|
|
|
|
bool create_local_scope, bool create_vars) {
|
|
|
|
|
auto& block = ctx->prog_.Block(ctx->block_id_);
|
|
|
|
|
|
|
|
|
|
Scope* local_scope = scope;
|
|
|
|
|
if (create_vars) {
|
|
|
|
|
if (create_local_scope) {
|
|
|
|
|
local_scope = &scope->NewScope();
|
|
|
|
|
for (auto& var : block.AllVars()) {
|
|
|
|
|
if (var->Name() == framework::kEmptyVarName) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (var->Persistable()) {
|
|
|
|
|
auto* ptr = scope->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create Variable " << var->Name()
|
|
|
|
|
<< " global, which pointer is " << ptr;
|
|
|
|
|
} else {
|
|
|
|
|
auto* ptr = local_scope->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create Variable " << var->Name()
|
|
|
|
|
<< " locally, which pointer is " << ptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (auto& var : block.AllVars()) {
|
|
|
|
|
auto* ptr = local_scope->Var(var->Name());
|
|
|
|
|
CreateTensor(ptr, var->GetType());
|
|
|
|
|
VLOG(3) << "Create variable " << var->Name() << ", which pointer is "
|
|
|
|
|
<< ptr;
|
|
|
|
|
}
|
|
|
|
|
} // if (create_local_scope)
|
|
|
|
|
} // if (create_vars)
|
|
|
|
|
|
|
|
|
|
CreateVariables(ctx->prog_, local_scope);
|
|
|
|
|
|
|
|
|
|
for (auto& op : ctx->ops_) {
|
|
|
|
|
VLOG(3) << place_ << " " << op->DebugStringEx(local_scope);
|
|
|
|
|
op->Run(*local_scope, place_);
|
|
|
|
|