From 21073d2befbe9a41ae7200adb8b006b345c44a1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 23 Jul 2018 10:26:23 +0900 Subject: [PATCH] [coco] Add 'FeatureInstr' class (#752) 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 --- contrib/coco/core/include/coco/IR/Instr.h | 38 +++++++++++++++++++++++++++++++ contrib/coco/core/src/IR/Instr.cpp | 20 ++++++++++++++++ contrib/coco/core/src/IR/Instr.test.cpp | 32 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index bd7c5be..b398466 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -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 *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__ diff --git a/contrib/coco/core/src/IR/Instr.cpp b/contrib/coco/core/src/IR/Instr.cpp index dbf3f5a..5a36ffe 100644 --- a/contrib/coco/core/src/IR/Instr.cpp +++ b/contrib/coco/core/src/IR/Instr.cpp @@ -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 diff --git a/contrib/coco/core/src/IR/Instr.test.cpp b/contrib/coco/core/src/IR/Instr.test.cpp index 9e3b254..fad6cee 100644 --- a/contrib/coco/core/src/IR/Instr.test.cpp +++ b/contrib/coco/core/src/IR/Instr.test.cpp @@ -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 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 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 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); +} -- 2.7.4