[coco] Add 'FeatureInstr' class (#752)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 23 Jul 2018 01:26:23 +0000 (10:26 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 23 Jul 2018 01:26:23 +0000 (10:26 +0900)
This commit adds 'FeatureInstr' class which inherits 'Instr' class.

'Featureinstr' class will serve as a base interface for all feature
-to-feature instructions.

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

index bd7c5be..b398466 100644 (file)
@@ -38,4 +38,42 @@ public:
 
 } // namespace coco
 
+#include "coco/IR/FeatureObject.h"
+
+/**
+ * @brief Explicit computation step that emits a feature map from another feature map
+ *
+ * TODO Decide source code layout policy and extract this class if necessary
+ */
+namespace coco
+{
+
+class FeatureInstr : public Instr
+{
+public:
+  FeatureInstr(const PtrLink<Instr, Block> *link) : Instr{link}, _ifm{nullptr}, _ofm{nullptr}
+  {
+    // DO NOTHING
+  }
+
+public:
+  virtual ~FeatureInstr() = default;
+
+private:
+  FeatureObject *_ifm;
+
+public:
+  FeatureObject *ifm(void) const { return _ifm; }
+  void ifm(FeatureObject *ifm);
+
+private:
+  FeatureObject *_ofm;
+
+public:
+  FeatureObject *ofm(void) const { return _ofm; }
+  void ofm(FeatureObject *ofm);
+};
+
+} // namespace coco
+
 #endif // __COCO_IR_INSTR_H__
index dbf3f5a..5a36ffe 100644 (file)
@@ -12,3 +12,23 @@ InstrList *Instr::head(void) const
 }
 
 } // namespace coco
+
+//
+// FeatureInstr
+//
+namespace coco
+{
+
+void FeatureInstr::ifm(FeatureObject *ifm)
+{
+  // TODO Update Def/Use of 'ifm'
+  _ifm = ifm;
+}
+
+void FeatureInstr::ofm(FeatureObject *ofm)
+{
+  // TODO Update Def/Use of 'ofm'
+  _ofm = ofm;
+}
+
+} // namespace coco
index 9e3b254..fad6cee 100644 (file)
@@ -11,3 +11,35 @@ TEST(IR_INSTR, ctor)
   ASSERT_EQ(ins.prev(), nullptr);
   ASSERT_EQ(ins.next(), nullptr);
 }
+
+TEST(IR_FEATURE_INSTR, ctor)
+{
+  coco::PtrLink<coco::Instr, coco::Block> link;
+  coco::FeatureInstr ins{&link};
+
+  // IFM and OFM should be initialized as nullptr
+  ASSERT_EQ(ins.ifm(), nullptr);
+  ASSERT_EQ(ins.ofm(), nullptr);
+}
+
+TEST(IR_FEATURE_INSTR, ifm_update)
+{
+  coco::PtrLink<coco::Instr, coco::Block> link;
+  coco::FeatureInstr ins{&link};
+  coco::FeatureObject obj{nncc::core::ADT::feature::Shape{1, 3, 3}};
+
+  // 'ifm(FeatureObject *)' method should affect 'ifm()' method
+  ins.ifm(&obj);
+  ASSERT_EQ(ins.ifm(), &obj);
+}
+
+TEST(IR_FEATURE_INSTR, ofm_update)
+{
+  coco::PtrLink<coco::Instr, coco::Block> link;
+  coco::FeatureInstr ins{&link};
+  coco::FeatureObject obj{nncc::core::ADT::feature::Shape{1, 3, 3}};
+
+  // 'ofm(FeatureObject *)' method should affect 'ofm()' method
+  ins.ofm(&obj);
+  ASSERT_EQ(ins.ofm(), &obj);
+}