[coco] AvgPool2D as a Op tree node (#1816)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 11 Oct 2018 00:43:44 +0000 (09:43 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 11 Oct 2018 00:43:44 +0000 (09:43 +0900)
With this commit, AvgPool2D may serve as a node of Op tree.

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

index 7295cc1..2978edb 100644 (file)
@@ -18,6 +18,7 @@
 #define __COCO_IR_AVG_POOL_2D_H__
 
 #include "coco/IR/Op.h"
+#include "coco/IR/Part.h"
 #include "coco/IR/Window2D.h"
 #include "coco/IR/Padding2D.h"
 #include "coco/IR/Stride2D.h"
@@ -55,6 +56,10 @@ public:
   const AvgPool2D *asAvgPool2D(void) const override { return this; }
 
 public:
+  Op *arg(void) const { return _arg.child(); }
+  void arg(Op *arg) { _arg.child(arg); }
+
+public:
   Divisor divisor(void) const { return _divisor; }
   void divisor(const Divisor &divisor) { _divisor = divisor; }
 
@@ -71,6 +76,10 @@ public:
   const Stride2D *stride(void) const { return &_stride; }
 
 private:
+  // @brief An argument of AvgPool2D operation (= IFM)
+  Part _arg;
+
+private:
   Divisor _divisor = Divisor::Unknown;
 
   Window2D _window;
index 1dcf09b..2b70a12 100644 (file)
@@ -19,7 +19,7 @@
 namespace coco
 {
 
-AvgPool2D::AvgPool2D()
+AvgPool2D::AvgPool2D() : _arg{this}
 {
   // DO NOTHING
 }
@@ -28,6 +28,15 @@ std::set<Object *> AvgPool2D::uses(void) const
 {
   // NOTE AvgPool2D accesses no object except IFM/OFM
   std::set<Object *> res;
+
+  if (auto ifm = arg())
+  {
+    for (auto obj : ifm->uses())
+    {
+      res.insert(obj);
+    }
+  }
+
   return res;
 }
 
index 5fdda62..c94f01f 100644 (file)
@@ -61,6 +61,9 @@ TEST_F(AvgPool2DTest, initialization)
   // parent() should be nullptr on construction
   ASSERT_EQ(op->parent(), nullptr);
 
+  // arg() should be nullptr on construction
+  ASSERT_EQ(immutable_ptr->arg(), nullptr);
+
   // divisor() SHOULD be unknow on construction
   ASSERT_EQ(immutable_ptr->divisor(), coco::AvgPool2D::Divisor::Unknown);