Fix bug caused by block_id.

fea/docker_cudnn7
Liu Yiqun 7 years ago
parent 987a32dac3
commit 5419da6e7a

@ -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

Loading…
Cancel
Save