[coco] Extract UnitF to a seperate file (#1365)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 6 Sep 2018 00:52:42 +0000 (09:52 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 6 Sep 2018 00:52:42 +0000 (09:52 +0900)
This commit extracts the declaration and implementation of UnitF into a
seperate file.

Note that test code is not yet extracted.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Instr.h
contrib/coco/core/include/coco/IR/InstrManager.h
contrib/coco/core/include/coco/IR/UnitF.h [new file with mode: 0644]
contrib/coco/core/src/IR/Instr.cpp
contrib/coco/core/src/IR/Instr.test.cpp
contrib/coco/core/src/IR/UnitF.cpp [new file with mode: 0644]

index f061335..83c51c8 100644 (file)
@@ -172,57 +172,4 @@ public:
 
 } // namespace coco
 
-//
-// UnitF
-//
-#include "coco/IR/Op.forward.h"
-
-namespace coco
-{
-
-/**
- * @brief Feature map-to-feature map step with single NN operation
- *
- * TODO Introduce 'FeatureOp' and use it
- */
-class UnitF final : public FeatureInstr
-{
-public:
-  UnitF(PtrLink<Op, Instr> *op_link, const PtrLink<Instr, Block> *link,
-        const PtrLink<Object, ObjectInfo> *obj_link)
-      : FeatureInstr{obj_link}, _op_link{op_link}, _link{link}, _op{nullptr}
-  {
-    // DO NOTHING
-  }
-
-public:
-  UnitF *asUnitF(void) override { return this; }
-  const UnitF *asUnitF(void) const override { return this; }
-
-public:
-  std::set<Bag *> reads(void) const override;
-  std::set<Bag *> updates(void) const override;
-
-public:
-  Instr *loc(void) override { return this; }
-
-private:
-  PtrLink<Op, Instr> *const _op_link;
-  const PtrLink<Instr, Block> *const _link;
-
-private:
-  void get(const PtrLink<Instr, Block> **out) const override { *out = _link; }
-
-private:
-  Op *_op;
-
-public:
-  Op *op(void) const { return _op; }
-
-public:
-  void op(Op *op);
-};
-
-} // namespace coco
-
 #endif // __COCO_IR_INSTR_H__
index 7b0e5ec..80654fa 100644 (file)
@@ -2,6 +2,7 @@
 #define __COCO_IR_INSTR_MANAGER_H__
 
 #include "coco/IR/Instr.h"
+#include "coco/IR/UnitF.h"
 #include "coco/IR/Shuffle.h"
 
 #include "coco/IR/Op.forward.h"
diff --git a/contrib/coco/core/include/coco/IR/UnitF.h b/contrib/coco/core/include/coco/IR/UnitF.h
new file mode 100644 (file)
index 0000000..b03ebc3
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef __COCO_IR_UNIT_F_H__
+#define __COCO_IR_UNIT_F_H__
+
+#include "coco/IR/Instr.h"
+#include "coco/IR/Op.forward.h"
+
+namespace coco
+{
+
+/**
+ * @brief Feature map-to-feature map step with single NN operation
+ *
+ * TODO Introduce 'FeatureOp' and use it
+ */
+class UnitF final : public FeatureInstr
+{
+public:
+  UnitF(PtrLink<Op, Instr> *op_link, const PtrLink<Instr, Block> *link,
+        const PtrLink<Object, ObjectInfo> *obj_link)
+      : FeatureInstr{obj_link}, _op_link{op_link}, _link{link}, _op{nullptr}
+  {
+    // DO NOTHING
+  }
+
+public:
+  UnitF *asUnitF(void) override { return this; }
+  const UnitF *asUnitF(void) const override { return this; }
+
+public:
+  std::set<Bag *> reads(void) const override;
+  std::set<Bag *> updates(void) const override;
+
+public:
+  Instr *loc(void) override { return this; }
+
+private:
+  PtrLink<Op, Instr> *const _op_link;
+  const PtrLink<Instr, Block> *const _link;
+
+private:
+  void get(const PtrLink<Instr, Block> **out) const override { *out = _link; }
+
+private:
+  Op *_op;
+
+public:
+  Op *op(void) const { return _op; }
+
+public:
+  void op(Op *op);
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_UNIT_F_H__
index 73a1b02..8f37af8 100644 (file)
@@ -24,72 +24,3 @@ void FeatureInstr::ifm(FeatureObject *ifm) { _ifm.value(ifm); }
 void FeatureInstr::ofm(FeatureObject *ofm) { _ofm.value(ofm); }
 
 } // namespace coco
-
-//
-// UnitF
-//
-#include "coco/IR/Op.h"
-
-#include <cassert>
-
-namespace
-{
-std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, const coco::Object *o)
-{
-  if (o != nullptr && o->bag() != nullptr)
-  {
-    res.insert(o->bag());
-  }
-  return res;
-}
-} // namespace
-
-namespace coco
-{
-
-std::set<Bag *> UnitF::reads(void) const
-{
-  std::set<Bag *> res;
-
-  res += ifm();
-
-  if (op() != nullptr)
-  {
-    for (auto obj : op()->uses())
-    {
-      res += obj;
-    }
-  }
-
-  return res;
-}
-
-std::set<Bag *> UnitF::updates(void) const
-{
-  std::set<Bag *> res;
-
-  res += ofm();
-
-  return res;
-}
-
-void UnitF::op(Op *op)
-{
-  if (_op != nullptr)
-  {
-    assert(_op_link->find(_op) == this);
-    _op_link->unset(_op);
-    _op = nullptr;
-  }
-
-  assert(_op == nullptr);
-
-  if (op != nullptr)
-  {
-    assert(_op_link->find(op) == nullptr);
-    _op = op;
-    _op_link->set(_op, this);
-  }
-}
-
-} // namespace coco
index a900504..b3b163e 100644 (file)
@@ -99,6 +99,8 @@ TEST_F(FeatureInstrTest, ofm_update)
   ASSERT_EQ(obj->def(), &ins);
 }
 
+// TODO Move these tests into UnitF.test.cpp
+#include "coco/IR/UnitF.h"
 #include "coco/IR/Op.h"
 
 namespace
diff --git a/contrib/coco/core/src/IR/UnitF.cpp b/contrib/coco/core/src/IR/UnitF.cpp
new file mode 100644 (file)
index 0000000..278ae15
--- /dev/null
@@ -0,0 +1,66 @@
+#include "coco/IR/UnitF.h"
+#include "coco/IR/Op.h"
+
+#include <cassert>
+
+namespace
+{
+std::set<coco::Bag *> &operator+=(std::set<coco::Bag *> &res, const coco::Object *o)
+{
+  if (o != nullptr && o->bag() != nullptr)
+  {
+    res.insert(o->bag());
+  }
+  return res;
+}
+} // namespace
+
+namespace coco
+{
+
+std::set<Bag *> UnitF::reads(void) const
+{
+  std::set<Bag *> res;
+
+  res += ifm();
+
+  if (op() != nullptr)
+  {
+    for (auto obj : op()->uses())
+    {
+      res += obj;
+    }
+  }
+
+  return res;
+}
+
+std::set<Bag *> UnitF::updates(void) const
+{
+  std::set<Bag *> res;
+
+  res += ofm();
+
+  return res;
+}
+
+void UnitF::op(Op *op)
+{
+  if (_op != nullptr)
+  {
+    assert(_op_link->find(_op) == this);
+    _op_link->unset(_op);
+    _op = nullptr;
+  }
+
+  assert(_op == nullptr);
+
+  if (op != nullptr)
+  {
+    assert(_op_link->find(op) == nullptr);
+    _op = op;
+    _op_link->set(_op, this);
+  }
+}
+
+} // namespace coco