From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 6 Sep 2018 01:31:57 +0000 (+0900) Subject: [coco] Support Op destruction (#1369) X-Git-Tag: nncc_backup~1919 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5a9679eaa9d6146778a0ec3e74e770cbec82f8b;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Support Op destruction (#1369) This commit introduces destroy method into OpManager class, which allows users to destruct Op instances. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/OpManager.h b/contrib/coco/core/include/coco/IR/OpManager.h index 376a202..05e4f98 100644 --- a/contrib/coco/core/include/coco/IR/OpManager.h +++ b/contrib/coco/core/include/coco/IR/OpManager.h @@ -25,6 +25,13 @@ public: public: template 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 *const _op_link; const PtrLink *const _obj_link; diff --git a/contrib/coco/core/src/IR/OpManager.cpp b/contrib/coco/core/src/IR/OpManager.cpp index 8d09206..d17627a 100644 --- a/contrib/coco/core/src/IR/OpManager.cpp +++ b/contrib/coco/core/src/IR/OpManager.cpp @@ -2,6 +2,8 @@ #include +#include + using nncc::foundation::make_unique; namespace coco @@ -30,4 +32,11 @@ template <> AvgPool2D *OpManager::create(void) template <> ReLU *OpManager::create(void) { return take(make_unique(_op_link)); } +void OpManager::destroy(Op *op) +{ + assert(op->parent() == nullptr); + op->dispose(); + release(op); +} + } // namespace coco diff --git a/contrib/coco/core/src/IR/OpManager.test.cpp b/contrib/coco/core/src/IR/OpManager.test.cpp index 9f02f0e..908ea6d 100644 --- a/contrib/coco/core/src/IR/OpManager.test.cpp +++ b/contrib/coco/core/src/IR/OpManager.test.cpp @@ -43,3 +43,10 @@ TEST_F(OpManagerTest, ReLU) ASSERT_NE(obj, nullptr); } + +TEST_F(OpManagerTest, destroy) +{ + auto op = mgr.create(); + mgr.destroy(op); + ASSERT_EQ(mgr.size(), 0); +}