@@ -337,6 +337,7 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
337
337
338
338
std::unique_ptr<GarbageCollector<Tensor>> gc;
339
339
if (max_memory_size >= 0 ) {
340
+ ctx->ResetReferenceCount ();
340
341
#ifdef PADDLE_WITH_CUDA
341
342
if (platform::is_gpu_place (place_)) {
342
343
gc.reset (new DefaultStreamGarbageCollector<Tensor>(
@@ -357,11 +358,11 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
357
358
std::vector<std::string> erase_vars;
358
359
for (auto & input : op->Inputs ()) {
359
360
for (auto & input_name : input.second ) {
360
- auto it = ctx->ref_cnts_ .find (input_name);
361
- if (it == ctx->ref_cnts_ .end ()) continue ;
361
+ auto it = ctx->cur_ref_cnts_ .find (input_name);
362
+ if (it == ctx->cur_ref_cnts_ .end ()) continue ;
362
363
if (it->second == 1 ) { // should delete it
363
364
erase_vars.emplace_back (input_name);
364
- ctx->ref_cnts_ .erase (input_name);
365
+ ctx->cur_ref_cnts_ .erase (input_name);
365
366
} else {
366
367
--(it->second );
367
368
}
@@ -370,11 +371,11 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
370
371
371
372
for (auto & output : op->Outputs ()) {
372
373
for (auto & output_name : output.second ) {
373
- auto it = ctx->ref_cnts_ .find (output_name);
374
- if (it == ctx->ref_cnts_ .end ()) continue ;
374
+ auto it = ctx->cur_ref_cnts_ .find (output_name);
375
+ if (it == ctx->cur_ref_cnts_ .end ()) continue ;
375
376
if (it->second == 1 ) {
376
377
erase_vars.emplace_back (output_name);
377
- ctx->ref_cnts_ .erase (output_name);
378
+ ctx->cur_ref_cnts_ .erase (output_name);
378
379
} else {
379
380
--(it->second );
380
381
}
0 commit comments