From ff310e537aabb456a6f6d65063b84cf036dcb6e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 17 Sep 2018 15:50:44 +0900 Subject: [PATCH] [coco] Remove links for child-parent relation update (#1522) This commit eliminates all the use of PtrLink as a mean to update child-parent relation between DLinkedList::Head and DLinkedList::Node. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/ADT/DLinkedList.h | 3 +- contrib/coco/core/include/coco/IR/Block.h | 4 +- contrib/coco/core/include/coco/IR/BlockManager.h | 11 ------ contrib/coco/core/include/coco/IR/InstrManager.h | 6 +-- contrib/coco/core/include/coco/IR/Shuffle.h | 3 +- contrib/coco/core/include/coco/IR/UnitF.h | 3 +- contrib/coco/core/src/ADT/DLinkedList.test.cpp | 49 ++++++++---------------- contrib/coco/core/src/IR/Block.test.cpp | 4 +- contrib/coco/core/src/IR/BlockManager.cpp | 5 +-- contrib/coco/core/src/IR/BlockManager.test.cpp | 6 +-- contrib/coco/core/src/IR/Instr.test.cpp | 4 +- contrib/coco/core/src/IR/InstrManager.cpp | 4 +- contrib/coco/core/src/IR/InstrManager.test.cpp | 6 +-- contrib/coco/core/src/IR/Module.cpp | 13 ++----- contrib/coco/core/src/IR/Shuffle.test.cpp | 3 +- 15 files changed, 35 insertions(+), 89 deletions(-) diff --git a/contrib/coco/core/include/coco/ADT/DLinkedList.h b/contrib/coco/core/include/coco/ADT/DLinkedList.h index 3eee697..6890ab0 100644 --- a/contrib/coco/core/include/coco/ADT/DLinkedList.h +++ b/contrib/coco/core/include/coco/ADT/DLinkedList.h @@ -15,8 +15,7 @@ template struct DLinkedList class Head { public: - // TODO _link is no longer used - Head(Parent *parent, PtrLink *link) : _parent{parent} + Head(Parent *parent) : _parent{parent} { _head = nullptr; _tail = nullptr; diff --git a/contrib/coco/core/include/coco/IR/Block.h b/contrib/coco/core/include/coco/IR/Block.h index af1eed0..003615d 100644 --- a/contrib/coco/core/include/coco/IR/Block.h +++ b/contrib/coco/core/include/coco/IR/Block.h @@ -21,9 +21,7 @@ using BlockList = DLinkedList::Head; class Block final : public DLinkedList::Node { public: - // TODO Update constructor - Block(const PtrLink *, PtrLink *instr_link) - : _instr{this, instr_link} + Block() : _instr{this} { // DO NOTHING } diff --git a/contrib/coco/core/include/coco/IR/BlockManager.h b/contrib/coco/core/include/coco/IR/BlockManager.h index 8ee311f..82e2dd6 100644 --- a/contrib/coco/core/include/coco/IR/BlockManager.h +++ b/contrib/coco/core/include/coco/IR/BlockManager.h @@ -11,17 +11,6 @@ namespace coco class BlockManager final : public PtrManager { public: - BlockManager(const PtrLink *block_link, PtrLink *instr_link) - : _block_link{block_link}, _instr_link{instr_link} - { - // DO NOTHING - } - -private: - const PtrLink *const _block_link; - PtrLink *const _instr_link; - -public: Block *create(void); public: diff --git a/contrib/coco/core/include/coco/IR/InstrManager.h b/contrib/coco/core/include/coco/IR/InstrManager.h index 902fbcf..133e4c4 100644 --- a/contrib/coco/core/include/coco/IR/InstrManager.h +++ b/contrib/coco/core/include/coco/IR/InstrManager.h @@ -22,9 +22,8 @@ namespace coco class InstrManager final : public PtrManager { public: - InstrManager(PtrLink *op_link, const PtrLink *instr_link, - const PtrLink *obj_link) - : _op_link{op_link}, _instr_link{instr_link}, _obj_link{obj_link} + InstrManager(PtrLink *op_link, const PtrLink *obj_link) + : _op_link{op_link}, _obj_link{obj_link} { // DO NOTHING } @@ -42,7 +41,6 @@ public: private: PtrLink *const _op_link; - const PtrLink *const _instr_link; const PtrLink *const _obj_link; }; diff --git a/contrib/coco/core/include/coco/IR/Shuffle.h b/contrib/coco/core/include/coco/IR/Shuffle.h index fe5eeb4..cc22b9f 100644 --- a/contrib/coco/core/include/coco/IR/Shuffle.h +++ b/contrib/coco/core/include/coco/IR/Shuffle.h @@ -18,8 +18,7 @@ namespace coco class Shuffle final : public Instr, public Bag::Reader, public Bag::Updater { public: - // TODO Update constructor interface - Shuffle(const PtrLink *) : _from{this}, _into{this} + Shuffle() : _from{this}, _into{this} { // DO NOTHING } diff --git a/contrib/coco/core/include/coco/IR/UnitF.h b/contrib/coco/core/include/coco/IR/UnitF.h index 011416d..e2a0c38 100644 --- a/contrib/coco/core/include/coco/IR/UnitF.h +++ b/contrib/coco/core/include/coco/IR/UnitF.h @@ -17,8 +17,7 @@ class UnitF final : public FeatureInstr { public: // TODO Update constructor - UnitF(PtrLink *op_link, const PtrLink *, - const PtrLink *obj_link) + UnitF(PtrLink *op_link, const PtrLink *obj_link) : FeatureInstr{obj_link}, _op_link{op_link} { _step.instr(this); diff --git a/contrib/coco/core/src/ADT/DLinkedList.test.cpp b/contrib/coco/core/src/ADT/DLinkedList.test.cpp index c97ca69..56f7264 100644 --- a/contrib/coco/core/src/ADT/DLinkedList.test.cpp +++ b/contrib/coco/core/src/ADT/DLinkedList.test.cpp @@ -13,7 +13,7 @@ using ChildList = coco::DLinkedList::Head; class Parent { public: - Parent(coco::PtrLink *link) : _list{this, link} + Parent() : _list{this} { // DO NOTHING } @@ -27,12 +27,7 @@ private: class Child final : public coco::DLinkedList::Node { -public: - // TODO Update constructor - Child(const coco::PtrLink *) - { - // DO NOTHING - } + // DO NOTHING }; } // namespace @@ -46,13 +41,12 @@ template <> ChildList *DLinkedList::head(Parent *p) { return p->c TEST(ADT_DLINKED_LINK, insert_two_elements) { - auto link = new coco::PtrLink<::Child, ::Parent>{}; - auto parent = new ::Parent{link}; + auto parent = new ::Parent; ASSERT_EQ(parent->children()->head(), nullptr); ASSERT_EQ(parent->children()->tail(), nullptr); - auto child_1 = new ::Child{link}; + auto child_1 = new ::Child; ASSERT_EQ(child_1->parent(), nullptr); ASSERT_EQ(child_1->prev(), nullptr); @@ -67,7 +61,7 @@ TEST(ADT_DLINKED_LINK, insert_two_elements) ASSERT_EQ(parent->children()->head(), child_1); ASSERT_EQ(parent->children()->tail(), child_1); - auto child_2 = new ::Child{link}; + auto child_2 = new ::Child; ASSERT_EQ(child_2->parent(), nullptr); ASSERT_EQ(child_2->prev(), nullptr); @@ -89,16 +83,14 @@ TEST(ADT_DLINKED_LINK, insert_two_elements) delete child_2; delete child_1; delete parent; - delete link; } TEST(ADT_DLINKED_LINK, insertBefore) { - auto link = new coco::PtrLink<::Child, ::Parent>{}; - auto parent = new ::Parent{link}; + auto parent = new ::Parent; - auto child_1 = new ::Child{link}; - auto child_2 = new ::Child{link}; + auto child_1 = new ::Child; + auto child_2 = new ::Child; parent->children()->append(child_1); child_2->insertBefore(child_1); @@ -117,16 +109,14 @@ TEST(ADT_DLINKED_LINK, insertBefore) delete child_2; delete child_1; delete parent; - delete link; } TEST(ADT_DLINKED_LINK, prepend_after_append) { - auto link = new coco::PtrLink<::Child, ::Parent>{}; - auto parent = new ::Parent{link}; + auto parent = new ::Parent; - auto child_1 = new ::Child{link}; - auto child_2 = new ::Child{link}; + auto child_1 = new ::Child; + auto child_2 = new ::Child; parent->children()->append(child_1); parent->children()->prepend(child_2); @@ -143,16 +133,14 @@ TEST(ADT_DLINKED_LINK, prepend_after_append) delete child_2; delete child_1; delete parent; - delete link; } TEST(ADT_DLINKED_LINK, detach) { - auto link = new coco::PtrLink<::Child, ::Parent>{}; - auto parent = new ::Parent{link}; + auto parent = new ::Parent; - auto child_1 = new ::Child{link}; - auto child_2 = new ::Child{link}; + auto child_1 = new ::Child; + auto child_2 = new ::Child; parent->children()->append(child_1); parent->children()->append(child_2); @@ -182,16 +170,14 @@ TEST(ADT_DLINKED_LINK, detach) delete child_2; delete child_1; delete parent; - delete link; } TEST(ADT_DLINKED_LINK, node_destructor) { - auto link = new coco::PtrLink<::Child, ::Parent>{}; - auto parent = new ::Parent{link}; + auto parent = new ::Parent; - auto child_1 = new ::Child{link}; - auto child_2 = new ::Child{link}; + auto child_1 = new ::Child; + auto child_2 = new ::Child; parent->children()->append(child_1); parent->children()->append(child_2); @@ -209,5 +195,4 @@ TEST(ADT_DLINKED_LINK, node_destructor) ASSERT_EQ(parent->children()->tail(), nullptr); delete parent; - delete link; } diff --git a/contrib/coco/core/src/IR/Block.test.cpp b/contrib/coco/core/src/IR/Block.test.cpp index 3a4c689..a3c3ab7 100644 --- a/contrib/coco/core/src/IR/Block.test.cpp +++ b/contrib/coco/core/src/IR/Block.test.cpp @@ -4,9 +4,7 @@ TEST(IR_BLOCK, default_block_has_empty_instr_list) { - coco::PtrLink block_link; - coco::PtrLink instr_link; - coco::Block blk{&block_link, &instr_link}; + coco::Block blk; ASSERT_TRUE(blk.instr()->empty()); ASSERT_EQ(blk.instr()->head(), nullptr); diff --git a/contrib/coco/core/src/IR/BlockManager.cpp b/contrib/coco/core/src/IR/BlockManager.cpp index 38ca33f..4118bd5 100644 --- a/contrib/coco/core/src/IR/BlockManager.cpp +++ b/contrib/coco/core/src/IR/BlockManager.cpp @@ -7,10 +7,7 @@ namespace coco { -Block *BlockManager::create(void) -{ - return take(nncc::foundation::make_unique(_block_link, _instr_link)); -} +Block *BlockManager::create(void) { return take(nncc::foundation::make_unique()); } void BlockManager::destroy(Block *blk) { diff --git a/contrib/coco/core/src/IR/BlockManager.test.cpp b/contrib/coco/core/src/IR/BlockManager.test.cpp index 90751a9..f283281 100644 --- a/contrib/coco/core/src/IR/BlockManager.test.cpp +++ b/contrib/coco/core/src/IR/BlockManager.test.cpp @@ -13,16 +13,12 @@ public: // Create a coco::BlockManager for testing coco::BlockManager *allocate(void) { - auto p = new coco::BlockManager{&_block_link, &_instr_link}; + auto p = new coco::BlockManager; _allocated.emplace_back(p); return p; } private: - coco::PtrLink _block_link; - coco::PtrLink _instr_link; - -private: std::vector> _allocated; }; } // namespace diff --git a/contrib/coco/core/src/IR/Instr.test.cpp b/contrib/coco/core/src/IR/Instr.test.cpp index 9528bd7..296c6ce 100644 --- a/contrib/coco/core/src/IR/Instr.test.cpp +++ b/contrib/coco/core/src/IR/Instr.test.cpp @@ -15,8 +15,6 @@ protected: coco::PtrLink obj_link; coco::PtrLink op_link; - // TODO Rename link as instr_link - coco::PtrLink link; coco::ObjectManager obj_mgr{&obj_link}; coco::OpManager op_mgr{&op_link, &obj_link}; @@ -109,7 +107,7 @@ public: protected: coco::UnitF *allocate(void) { - auto ins = new coco::UnitF{&op_link, &link, &obj_link}; + auto ins = new coco::UnitF{&op_link, &obj_link}; _allocated.emplace_back(ins); return ins; } diff --git a/contrib/coco/core/src/IR/InstrManager.cpp b/contrib/coco/core/src/IR/InstrManager.cpp index cf3a8a9..c8fd868 100644 --- a/contrib/coco/core/src/IR/InstrManager.cpp +++ b/contrib/coco/core/src/IR/InstrManager.cpp @@ -11,12 +11,12 @@ namespace coco template <> UnitF *InstrManager::create(void) { - return take(nncc::foundation::make_unique(_op_link, _instr_link, _obj_link)); + return take(nncc::foundation::make_unique(_op_link, _obj_link)); } template <> Shuffle *InstrManager::create(void) { - return take(nncc::foundation::make_unique(_instr_link)); + return take(nncc::foundation::make_unique()); } void InstrManager::destroy(Instr *ins) diff --git a/contrib/coco/core/src/IR/InstrManager.test.cpp b/contrib/coco/core/src/IR/InstrManager.test.cpp index 61183d7..25aa636 100644 --- a/contrib/coco/core/src/IR/InstrManager.test.cpp +++ b/contrib/coco/core/src/IR/InstrManager.test.cpp @@ -12,18 +12,16 @@ public: protected: coco::PtrLink op_link; - coco::PtrLink ins_link; coco::PtrLink obj_link; - coco::InstrManager mgr{&op_link, &ins_link, &obj_link}; + coco::InstrManager mgr{&op_link, &obj_link}; }; } // namespace TEST(IR_INSTR_MANAGER, create_UnitF) { coco::PtrLink op_link; - coco::PtrLink link; coco::PtrLink obj_link; - coco::InstrManager mgr{&op_link, &link, &obj_link}; + coco::InstrManager mgr{&op_link, &obj_link}; // Conv2D { diff --git a/contrib/coco/core/src/IR/Module.cpp b/contrib/coco/core/src/IR/Module.cpp index 2a10a58..1fdeadc 100644 --- a/contrib/coco/core/src/IR/Module.cpp +++ b/contrib/coco/core/src/IR/Module.cpp @@ -69,8 +69,6 @@ class ModuleImpl final : public coco::Module public: std::unique_ptr> _obj_link; std::unique_ptr> _op_link; - std::unique_ptr> _instr_link; - std::unique_ptr> _block_link; public: coco::EntityManager *entity(void) override { return _entity.get(); } @@ -114,8 +112,6 @@ std::unique_ptr Module::create(void) { auto obj_link = make_unique>(); auto op_link = make_unique>(); - auto ins_link = make_unique>(); - auto blk_link = make_unique>(); auto m = make_unique<::ModuleImpl>(); @@ -124,22 +120,19 @@ std::unique_ptr Module::create(void) mgr->_bag = make_unique(); mgr->_object = make_unique(obj_link.get()); mgr->_op = make_unique(op_link.get(), obj_link.get()); - mgr->_instr = make_unique(op_link.get(), ins_link.get(), obj_link.get()); - mgr->_block = make_unique(blk_link.get(), ins_link.get()); + mgr->_instr = make_unique(op_link.get(), obj_link.get()); + mgr->_block = make_unique(); mgr->_input = make_unique(); mgr->_output = make_unique(); } m->_entity = std::move(mgr); - // NOTE BlockManager and BlockList SHOULD share 'blk_link' - m->_block = make_unique(m.get(), blk_link.get()); + m->_block = make_unique(m.get()); m->_input = make_unique(); m->_output = make_unique(); m->_obj_link = std::move(obj_link); m->_op_link = std::move(op_link); - m->_instr_link = std::move(ins_link); - m->_block_link = std::move(blk_link); return std::move(m); } diff --git a/contrib/coco/core/src/IR/Shuffle.test.cpp b/contrib/coco/core/src/IR/Shuffle.test.cpp index 3145e26..813fe18 100644 --- a/contrib/coco/core/src/IR/Shuffle.test.cpp +++ b/contrib/coco/core/src/IR/Shuffle.test.cpp @@ -14,14 +14,13 @@ public: protected: coco::Shuffle *allocate(void) { - auto ins = new coco::Shuffle{&instr_link}; + auto ins = new coco::Shuffle; _allocated.emplace_back(ins); return ins; } protected: coco::PtrLink bag_link; - coco::PtrLink instr_link; private: std::vector> _allocated; -- 2.7.4