From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 6 Sep 2018 10:37:00 +0000 (+0900) Subject: [coco] Initialize BagLink via non-virtual method (#1390) X-Git-Tag: nncc_backup~1896 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15fe340a9b7602ff21cf9b6aed201aaf732a2da0;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Initialize BagLink via non-virtual method (#1390) This commit deprecates virtual get method, and introduces non-virtual setBagLink method. This will allows us to use Bag Link inside destructor. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.h b/contrib/coco/core/include/coco/IR/FeatureObject.h index 5f11e9c..0beba33 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObject.h +++ b/contrib/coco/core/include/coco/IR/FeatureObject.h @@ -27,7 +27,6 @@ public: private: void get(ObjectInfo **) const override; - void get(const PtrLink **out) const override; public: FeatureObject *asFeature(void) override { return this; } @@ -46,7 +45,6 @@ public: private: std::unique_ptr _info; - const PtrLink *const _link; std::vector _map; }; diff --git a/contrib/coco/core/include/coco/IR/KernelObject.h b/contrib/coco/core/include/coco/IR/KernelObject.h index 1b50bcb..88c9f2a 100644 --- a/contrib/coco/core/include/coco/IR/KernelObject.h +++ b/contrib/coco/core/include/coco/IR/KernelObject.h @@ -27,7 +27,6 @@ public: private: void get(ObjectInfo **) const override; - void get(const PtrLink **out) const override; public: KernelObject *asKernel(void) override { return this; } @@ -46,7 +45,6 @@ public: private: std::unique_ptr _info; - const PtrLink *const _link; std::vector _map; }; diff --git a/contrib/coco/core/include/coco/IR/Object.h b/contrib/coco/core/include/coco/IR/Object.h index 2d36d9a..cde9132 100644 --- a/contrib/coco/core/include/coco/IR/Object.h +++ b/contrib/coco/core/include/coco/IR/Object.h @@ -40,7 +40,7 @@ public: protected: virtual void get(ObjectInfo **) const = 0; - virtual void get(const PtrLink **) const = 0; + void setBagLink(const PtrLink *); private: coco::Bag *_bag; @@ -63,6 +63,9 @@ private: public: Def *def(void) const; const User *user(void) const; + +private: + const PtrLink *_bag_link; }; } // namespace coco diff --git a/contrib/coco/core/src/IR/FeatureObject.cpp b/contrib/coco/core/src/IR/FeatureObject.cpp index 42967c4..41aba73 100644 --- a/contrib/coco/core/src/IR/FeatureObject.cpp +++ b/contrib/coco/core/src/IR/FeatureObject.cpp @@ -15,8 +15,9 @@ namespace coco FeatureObject::FeatureObject(std::unique_ptr &&info, const PtrLink *link) - : _info(std::move(info)), _link{link} + : _info(std::move(info)) { + setBagLink(link); _map.resize(nncc::core::ADT::feature::num_elements(shape())); } @@ -26,7 +27,6 @@ FeatureObject::~FeatureObject() } void FeatureObject::get(ObjectInfo **out) const { *out = _info.get(); } -void FeatureObject::get(const PtrLink **out) const { *out = _link; } const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); } diff --git a/contrib/coco/core/src/IR/KernelObject.cpp b/contrib/coco/core/src/IR/KernelObject.cpp index fcd2c25..d05c9a9 100644 --- a/contrib/coco/core/src/IR/KernelObject.cpp +++ b/contrib/coco/core/src/IR/KernelObject.cpp @@ -15,8 +15,9 @@ namespace coco KernelObject::KernelObject(std::unique_ptr &&info, const PtrLink *link) - : _info{std::move(info)}, _link{link} + : _info{std::move(info)} { + setBagLink(link); _map.resize(nncc::core::ADT::kernel::num_elements(shape())); } @@ -26,7 +27,6 @@ KernelObject::~KernelObject() } void KernelObject::get(ObjectInfo **out) const { *out = _info.get(); } -void KernelObject::get(const PtrLink **out) const { *out = _link; } const nncc::core::ADT::kernel::Shape &KernelObject::shape(void) const { return _info->shape(); } diff --git a/contrib/coco/core/src/IR/Object.cpp b/contrib/coco/core/src/IR/Object.cpp index eba9529..838c06c 100644 --- a/contrib/coco/core/src/IR/Object.cpp +++ b/contrib/coco/core/src/IR/Object.cpp @@ -13,6 +13,8 @@ Object::Object() : _bag{nullptr} // DO NOTHING } +void Object::setBagLink(const PtrLink *bag_link) { _bag_link = bag_link; } + void Object::bag(coco::Bag *bag) { if (_bag != nullptr) @@ -48,11 +50,8 @@ ObjectInfo *Object::info(void) const BagInfo *Object::info(const Bag *bag) const { - const PtrLink *link = nullptr; - get(&link); - assert(link != nullptr); - - return link->find(bag); + assert(_bag_link != nullptr); + return _bag_link->find(bag); } Object::Def *Object::def(void) const { return info()->def(); } diff --git a/contrib/coco/core/src/IR/Object.test.cpp b/contrib/coco/core/src/IR/Object.test.cpp index 99ba140..2305bbe 100644 --- a/contrib/coco/core/src/IR/Object.test.cpp +++ b/contrib/coco/core/src/IR/Object.test.cpp @@ -34,11 +34,12 @@ public: public: std::unique_ptr info; - const coco::PtrLink *link; + +public: + void link(const coco::PtrLink *link) { setBagLink(link); } private: void get(coco::ObjectInfo **out) const override { *out = info.get(); } - void get(const coco::PtrLink **out) const override { *out = link; } }; } // namespace mock } // namespace @@ -66,7 +67,7 @@ TEST_F(ObjectTest, bag_update) ::mock::Object obj; obj.info = make_unique(); - obj.link = &link; + obj.link(&link); obj.bag(bag);