[coco] Extract Conv2D class (#1245)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 30 Aug 2018 05:28:56 +0000 (14:28 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 30 Aug 2018 05:28:56 +0000 (14:28 +0900)
This commit extracts the declaration/implementation/test of Conv2D
class into a dedicated header/source/test file.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Conv2D.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/Op.h
contrib/coco/core/include/coco/IR/OpManager.h
contrib/coco/core/src/IR/Conv2D.cpp [new file with mode: 0644]
contrib/coco/core/src/IR/Conv2D.test.cpp [moved from contrib/coco/core/src/IR/Op.test.cpp with 98% similarity]
contrib/coco/core/src/IR/Op.cpp

diff --git a/contrib/coco/core/include/coco/IR/Conv2D.h b/contrib/coco/core/include/coco/IR/Conv2D.h
new file mode 100644 (file)
index 0000000..b1802ca
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef __COCO_IR_CONV2D_H__
+#define __COCO_IR_CONV2D_H__
+
+#include "coco/IR/Op.h"
+#include "coco/IR/KernelObject.h"
+#include "coco/IR/Padding2D.h"
+#include "coco/IR/UseSlot.h"
+
+namespace coco
+{
+
+/**
+ * @brief 2D Convolution over 3D Feature Map with 4D kernel
+ *
+ * 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, public Object::Use
+{
+public:
+  explicit Conv2D(const PtrLink<Op, Instr> *, const PtrLink<Object, ObjectInfo> *);
+
+public:
+  std::set<Object *> uses(void) const override;
+
+public:
+  Conv2D *asConv2D(void) override { return this; }
+  const Conv2D *asConv2D(void) const override { return this; }
+
+public:
+  Instr *loc(void) override { return parent(); }
+
+private:
+  UseSlot<KernelObject> _ker;
+
+public:
+  KernelObject *ker(void) const { return _ker.value(); }
+  void ker(KernelObject *ker);
+
+public:
+  Padding2D *pad(void) { return &_pad; }
+  const Padding2D *pad(void) const { return &_pad; }
+
+private:
+  const PtrLink<Op, Instr> *const _op_link;
+
+private:
+  void get(const PtrLink<Op, Instr> **out) const override { *out = _op_link; }
+
+private:
+  Padding2D _pad;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_CONV2D_H__
index 73b8780..5629699 100644 (file)
@@ -80,55 +80,4 @@ public:
 
 } // namespace coco
 
-#include "coco/IR/KernelObject.h"
-#include "coco/IR/Padding2D.h"
-#include "coco/IR/UseSlot.h"
-
-namespace coco
-{
-
-/**
- * @brief 2D Convolution over 3D Feature Map with 4D kernel
- *
- * 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, public Object::Use
-{
-public:
-  explicit Conv2D(const PtrLink<Op, Instr> *, const PtrLink<Object, ObjectInfo> *);
-
-public:
-  std::set<Object *> uses(void) const override;
-
-public:
-  Conv2D *asConv2D(void) override { return this; }
-  const Conv2D *asConv2D(void) const override { return this; }
-
-public:
-  Instr *loc(void) override { return parent(); }
-
-private:
-  UseSlot<KernelObject> _ker;
-
-public:
-  KernelObject *ker(void) const { return _ker.value(); }
-  void ker(KernelObject *ker);
-
-public:
-  Padding2D *pad(void) { return &_pad; }
-  const Padding2D *pad(void) const { return &_pad; }
-
-private:
-  const PtrLink<Op, Instr> *const _op_link;
-
-private:
-  void get(const PtrLink<Op, Instr> **out) const override { *out = _op_link; }
-
-private:
-  Padding2D _pad;
-};
-
-} // namespace coco
-
 #endif // __COCO_IR_OP_H__
index a1415b5..624a729 100644 (file)
@@ -2,6 +2,7 @@
 #define __COCO_IR_OP_MANAGER_H__
 
 #include "coco/IR/Op.h"
+#include "coco/IR/Conv2D.h"
 #include "coco/IR/Instr.forward.h"
 
 #include "coco/IR/Object.forward.h"
diff --git a/contrib/coco/core/src/IR/Conv2D.cpp b/contrib/coco/core/src/IR/Conv2D.cpp
new file mode 100644 (file)
index 0000000..0aacbb0
--- /dev/null
@@ -0,0 +1,26 @@
+#include "coco/IR/Conv2D.h"
+
+namespace coco
+{
+
+Conv2D::Conv2D(const PtrLink<Op, Instr> *op_link, const PtrLink<Object, ObjectInfo> *obj_link)
+    : _op_link{op_link}, _ker{obj_link, this}
+{
+  // DO NOTHING
+}
+
+std::set<Object *> Conv2D::uses(void) const
+{
+  std::set<Object *> res;
+
+  if (ker())
+  {
+    res.insert(ker());
+  }
+
+  return res;
+}
+
+void Conv2D::ker(KernelObject *ker) { _ker.value(ker); }
+
+} // namespace coco
similarity index 98%
rename from contrib/coco/core/src/IR/Op.test.cpp
rename to contrib/coco/core/src/IR/Conv2D.test.cpp
index dd543be..68e2048 100644 (file)
@@ -1,4 +1,4 @@
-#include "coco/IR/Op.h"
+#include "coco/IR/Conv2D.h"
 #include "coco/IR/ObjectManager.h"
 
 #include <vector>
@@ -67,9 +67,6 @@ TEST_F(Conv2DTest, asConv2D)
   ASSERT_EQ(mutable_base->asConv2D(), immutable_base->asConv2D());
 }
 
-//
-// Conv2D
-//
 namespace
 {
 struct IsConv2D : public coco::Op::DefaultVisitor<bool>
index 8d1e6a6..977d5f8 100644 (file)
@@ -1,8 +1,5 @@
 #include "coco/IR/Op.h"
 
-//
-// Op
-//
 #include <cassert>
 
 namespace coco
@@ -16,30 +13,3 @@ Instr *Op::parent(void) const
   return op_link->find(this);
 }
 } // namespace coco
-//
-// Conv2D
-//
-namespace coco
-{
-
-Conv2D::Conv2D(const PtrLink<Op, Instr> *op_link, const PtrLink<Object, ObjectInfo> *obj_link)
-    : _op_link{op_link}, _ker{obj_link, this}
-{
-  // DO NOTHING
-}
-
-std::set<Object *> Conv2D::uses(void) const
-{
-  std::set<Object *> res;
-
-  if (ker())
-  {
-    res.insert(ker());
-  }
-
-  return res;
-}
-
-void Conv2D::ker(KernelObject *ker) { _ker.value(ker); }
-
-} // namespace coco