[coco] Support Op destruction (#1369)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 6 Sep 2018 01:31:57 +0000 (10:31 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 6 Sep 2018 01:31:57 +0000 (10:31 +0900)
This commit introduces destroy method into OpManager class, which allows
users to destruct Op instances.

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

index 376a202..05e4f98 100644 (file)
@@ -25,6 +25,13 @@ public:
 public:
   template <typename T> T *create(void);
 
+public:
+  // @brief Destroy (= deallocate) a Op instance
+  //
+  // NOTE OpManager will invoke dispose before deallocation
+  // NOTE destroy(op) WILL NOT update op->parent(). Client SHOULD detach op before destroy(op) call
+  void destroy(Op *);
+
 private:
   const PtrLink<Op, Instr> *const _op_link;
   const PtrLink<Object, ObjectInfo> *const _obj_link;
index 8d09206..d17627a 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <nncc/foundation/Memory.h>
 
+#include <cassert>
+
 using nncc::foundation::make_unique;
 
 namespace coco
@@ -30,4 +32,11 @@ template <> AvgPool2D *OpManager::create<AvgPool2D>(void)
 
 template <> ReLU *OpManager::create<ReLU>(void) { return take(make_unique<ReLU>(_op_link)); }
 
+void OpManager::destroy(Op *op)
+{
+  assert(op->parent() == nullptr);
+  op->dispose();
+  release(op);
+}
+
 } // namespace coco
index 9f02f0e..908ea6d 100644 (file)
@@ -43,3 +43,10 @@ TEST_F(OpManagerTest, ReLU)
 
   ASSERT_NE(obj, nullptr);
 }
+
+TEST_F(OpManagerTest, destroy)
+{
+  auto op = mgr.create<coco::Conv2D>();
+  mgr.destroy(op);
+  ASSERT_EQ(mgr.size(), 0);
+}