From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Mon, 1 Oct 2018 02:21:11 +0000 (+0900) Subject: [coco] Support Object destruction (#1685) X-Git-Tag: nncc_backup~1670 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c149ea1d1399ec67cfa75c193b9579f9a3861ba;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Support Object destruction (#1685) * [coco] Support Object destruction This commit introduces 'destroy' method in ObjectManager, which allows users to destruct Object(s) allocated via ObjectManager. Signed-off-by: Jonghyun Park * Fix typos --- diff --git a/contrib/coco/core/include/coco/IR/ObjectManager.h b/contrib/coco/core/include/coco/IR/ObjectManager.h index 3cf8912..585ca03 100644 --- a/contrib/coco/core/include/coco/IR/ObjectManager.h +++ b/contrib/coco/core/include/coco/IR/ObjectManager.h @@ -41,6 +41,15 @@ public: KernelObject *create(const nncc::core::ADT::kernel::Shape &shape); template T *create(void); + +public: + /** + * @brief Destroy (= deallocate) an Object entity + * + * NOTE An Object SHOULD HAVE NO DEF & USES to be destructed + * NOTE An Object WILL BE unlinked from its dependent bag (if has) on destruction + */ + void destroy(Object *o); }; } // namespace coco diff --git a/contrib/coco/core/src/IR/ObjectManager.cpp b/contrib/coco/core/src/IR/ObjectManager.cpp index f829475..fdb223f 100644 --- a/contrib/coco/core/src/IR/ObjectManager.cpp +++ b/contrib/coco/core/src/IR/ObjectManager.cpp @@ -53,4 +53,11 @@ KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape) return take(std::move(kernel)); } +void ObjectManager::destroy(Object *o) +{ + assert(o->def() == nullptr); + assert(o->uses()->size() == 0); + release(o); +} + } // namespace coco diff --git a/contrib/coco/core/src/IR/ObjectManager.test.cpp b/contrib/coco/core/src/IR/ObjectManager.test.cpp index 206807c..4e80a6d 100644 --- a/contrib/coco/core/src/IR/ObjectManager.test.cpp +++ b/contrib/coco/core/src/IR/ObjectManager.test.cpp @@ -15,6 +15,7 @@ */ #include "coco/IR/ObjectManager.h" +#include "coco/IR/BagManager.h" #include "coco/IR/FeatureObject.h" #include "coco/IR/KernelObject.h" @@ -58,3 +59,19 @@ TEST(IR_OBJECT_MANAGER, create_feature_with_template) ASSERT_EQ(feature->layout(), nullptr); } + +TEST(IR_OBJECT_MANAGER, destroy) +{ + coco::BagManager bag_mgr; + coco::ObjectManager obj_mgr; + + auto bag = bag_mgr.create(3); + auto feature = obj_mgr.create(); + + feature->bag(bag); + + obj_mgr.destroy(feature); + + // Object SHOULD BE unlinked from its dependent bag on destruction + ASSERT_EQ(bag->deps()->size(), 0); +}