提交 5419da6e 编写于 作者: L Liu Yiqun

Fix bug caused by block_id.

上级 987a32da
......@@ -93,8 +93,9 @@ 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);
void Executor::CreateVariables(const ProgramDesc& pdesc, Scope* scope,
int block_id) {
auto& global_block = pdesc.Block(block_id);
const Scope* ancestor_scope = scope;
while (ancestor_scope->parent()) {
......@@ -318,14 +319,11 @@ std::unique_ptr<ExecutorPrepareContext> Executor::Prepare(
void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
bool create_local_scope, bool create_vars) {
Scope* local_scope = scope;
if (create_vars) {
if (create_local_scope) {
local_scope = &scope->NewScope();
} else {
} // if (create_local_scope)
} // if (create_vars)
CreateVariables(ctx->prog_, local_scope);
if (create_vars && create_local_scope) {
local_scope = &scope->NewScope();
}
CreateVariables(ctx->prog_, local_scope, ctx->block_id_);
for (auto& op : ctx->ops_) {
VLOG(3) << place_ << " " << op->DebugStringEx(local_scope);
......
......@@ -60,7 +60,7 @@ class Executor {
static std::unique_ptr<ExecutorPrepareContext> Prepare(
const ProgramDesc& program, int block_id);
void CreateVariables(const ProgramDesc& pdesc, Scope* scope);
void CreateVariables(const ProgramDesc& pdesc, Scope* scope, int block_id);
void RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
bool create_local_scope = true,
......
......@@ -171,7 +171,7 @@ void TestInference(const std::string& dirname,
{
const bool create_vars = false;
if (!create_vars) {
executor.CreateVariables(*inference_program, scope);
executor.CreateVariables(*inference_program, scope, 0);
}
// Ignore the profiling results of the first run
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册