[coco] Automatic update Kernel Object's user list (#1049)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 16 Aug 2018 06:49:58 +0000 (15:49 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 16 Aug 2018 06:49:58 +0000 (15:49 +0900)
This commit revises Conv2D op class to automatically update kernel object's
user list on ker method call.

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

index 83f2ae5..f56e35f 100644 (file)
@@ -81,6 +81,7 @@ public:
 } // namespace coco
 
 #include "coco/IR/KernelObject.h"
+#include "coco/IR/UseSlot.h"
 
 namespace coco
 {
@@ -91,7 +92,7 @@ namespace coco
  * NOTE IFM and OFM are implicit. Only 4D kernel is explicit in this class
  * TODO Decide source code layout policy and extract this class if necessary
  */
-class Conv2D : public Op
+class Conv2D : public Op, public Object::Use
 {
 public:
   struct Param
@@ -103,7 +104,7 @@ public:
   };
 
 public:
-  explicit Conv2D(const PtrLink<Op, Instr> *, const Param &);
+  explicit Conv2D(const PtrLink<Op, Instr> *, const PtrLink<Object, ObjectInfo> *, const Param &);
 
 public:
   std::set<Object *> uses(void) const override;
@@ -113,10 +114,10 @@ public:
   const Conv2D *asConv2D(void) const override { return this; }
 
 private:
-  KernelObject *_ker;
+  UseSlot<KernelObject> _ker;
 
 public:
-  KernelObject *ker(void) const { return _ker; }
+  KernelObject *ker(void) const { return _ker.value(); }
   void ker(KernelObject *ker);
 
 private:
index 3cee376..2364163 100644 (file)
@@ -22,7 +22,9 @@ Instr *Op::parent(void) const
 namespace coco
 {
 
-Conv2D::Conv2D(const PtrLink<Op, Instr> *op_link, const Param &) : _op_link{op_link}, _ker{nullptr}
+Conv2D::Conv2D(const PtrLink<Op, Instr> *op_link, const PtrLink<Object, ObjectInfo> *obj_link,
+               const Param &)
+    : _op_link{op_link}, _ker{obj_link, this}
 {
   // NOTE Currently, Param class is just a placeholder
 }
@@ -31,14 +33,14 @@ std::set<Object *> Conv2D::uses(void) const
 {
   std::set<Object *> res;
 
-  if (_ker)
+  if (ker())
   {
-    res.insert(_ker);
+    res.insert(ker());
   }
 
   return res;
 }
 
-void Conv2D::ker(KernelObject *ker) { _ker = ker; }
+void Conv2D::ker(KernelObject *ker) { _ker.value(ker); }
 
 } // namespace coco
index 6cab7e7..b45b71f 100644 (file)
@@ -19,7 +19,7 @@ public:
 protected:
   coco::Conv2D *allocate(const coco::Conv2D::Param &param)
   {
-    auto op = new coco::Conv2D{&op_link, param};
+    auto op = new coco::Conv2D{&op_link, &obj_link, param};
     _allocated.emplace_back(op);
     return op;
   }
@@ -89,6 +89,10 @@ TEST_F(Conv2DTest, ker_update)
 
     ASSERT_NE(uses.find(obj), uses.end());
   }
+
+  // ker method should enlist op itself as a user of a given kernel object
+  ASSERT_EQ(obj->user()->size(), 1);
+  ASSERT_EQ(obj->user()->count(op), 1);
 }
 
 TEST_F(Conv2DTest, accept)
index d534567..d67c1dc 100644 (file)
@@ -15,7 +15,7 @@ OpManager::OpManager(const PtrLink<Op, Instr> *op_link, const PtrLink<Object, Ob
 
 Conv2D *OpManager::create(const Conv2D::Param &param)
 {
-  return take(make_unique<Conv2D>(_op_link, param));
+  return take(make_unique<Conv2D>(_op_link, _obj_link, param));
 }
 
 } // namespace coco