From abc6353d6243e2f3d1f7b0329182a4fc8d4b3539 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Wed, 19 Dec 2018 14:17:23 +1000 Subject: [PATCH] Increment/decrement UseCount for outputs so that we don't prematurely free a re-used output that is used for a dead output (output with zero users). --- onnxruntime/core/framework/allocation_planner.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/framework/allocation_planner.cc b/onnxruntime/core/framework/allocation_planner.cc index c13d60b71fab7..277a6ff2ac1e2 100644 --- a/onnxruntime/core/framework/allocation_planner.cc +++ b/onnxruntime/core/framework/allocation_planner.cc @@ -389,6 +389,7 @@ class PlannerImpl { if (node_output->Exists()) { MLValueIndex index = Index(node_output->Name()); ProcessDef(index, node_output); + ++UseCount(index); if (strcmp(default_allocator_info.name, CPU) != 0) { // By default, outputs of this node are allocated on the default device allocator, // except for outputs marked for allocation in MemoryType: @@ -528,7 +529,7 @@ class PlannerImpl { if (node_output->Exists()) { auto& sym = node_output->Name(); auto original = Buffer(Index(sym)); - if (0 == UseCount(original)) + if (0 == --UseCount(original)) freelist_.push_front(FreeBufferInfo(original, program_counter)); } }