[coco] Deallocate a partial Op tree correctly (#2502)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 5 Dec 2018 23:38:45 +0000 (08:38 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 5 Dec 2018 23:38:45 +0000 (08:38 +0900)
The current implementation of destroy_all does not work for a partial Op
tree.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/src/IR/OpManager.cpp
contrib/coco/core/src/IR/OpManager.test.cpp

index ce94b2d..ad20375 100644 (file)
@@ -62,7 +62,10 @@ void OpManager::destroy_all(Op *op)
     // Insert child op nodes
     for (uint32_t n = 0; n < cur->arity(); ++n)
     {
-      q.emplace(cur->arg(n));
+      if (auto child = cur->arg(n))
+      {
+        q.emplace(child);
+      }
     }
 
     // Destroy the current op node
index 3afc2da..e9e97a5 100644 (file)
@@ -87,3 +87,13 @@ TEST_F(OpManagerTest, destroy_all)
 
   ASSERT_EQ(mgr.size(), 0);
 }
+
+TEST_F(OpManagerTest, destroy_all_partial_tree)
+{
+  // Create a (partial) Op tree
+  auto conv_op = mgr.create<coco::Conv2D>();
+
+  mgr.destroy_all(conv_op);
+
+  ASSERT_EQ(mgr.size(), 0);
+}