From f8d4d117c5d47c2913b9509904f2b11c1302d030 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: Thu, 6 Sep 2018 09:52:42 +0900 Subject: [PATCH] [coco] Extract UnitF to a seperate file (#1365) 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 --- contrib/coco/core/include/coco/IR/Instr.h | 53 ------------------ contrib/coco/core/include/coco/IR/InstrManager.h | 1 + contrib/coco/core/include/coco/IR/UnitF.h | 55 +++++++++++++++++++ contrib/coco/core/src/IR/Instr.cpp | 69 ------------------------ contrib/coco/core/src/IR/Instr.test.cpp | 2 + contrib/coco/core/src/IR/UnitF.cpp | 66 +++++++++++++++++++++++ 6 files changed, 124 insertions(+), 122 deletions(-) create mode 100644 contrib/coco/core/include/coco/IR/UnitF.h create mode 100644 contrib/coco/core/src/IR/UnitF.cpp diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index f061335..83c51c8 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -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_link, const PtrLink *link, - const PtrLink *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 reads(void) const override; - std::set updates(void) const override; - -public: - Instr *loc(void) override { return this; } - -private: - PtrLink *const _op_link; - const PtrLink *const _link; - -private: - void get(const PtrLink **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__ diff --git a/contrib/coco/core/include/coco/IR/InstrManager.h b/contrib/coco/core/include/coco/IR/InstrManager.h index 7b0e5ec..80654fa 100644 --- a/contrib/coco/core/include/coco/IR/InstrManager.h +++ b/contrib/coco/core/include/coco/IR/InstrManager.h @@ -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 index 0000000..b03ebc3 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/UnitF.h @@ -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_link, const PtrLink *link, + const PtrLink *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 reads(void) const override; + std::set updates(void) const override; + +public: + Instr *loc(void) override { return this; } + +private: + PtrLink *const _op_link; + const PtrLink *const _link; + +private: + void get(const PtrLink **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__ diff --git a/contrib/coco/core/src/IR/Instr.cpp b/contrib/coco/core/src/IR/Instr.cpp index 73a1b02..8f37af8 100644 --- a/contrib/coco/core/src/IR/Instr.cpp +++ b/contrib/coco/core/src/IR/Instr.cpp @@ -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 - -namespace -{ -std::set &operator+=(std::set &res, const coco::Object *o) -{ - if (o != nullptr && o->bag() != nullptr) - { - res.insert(o->bag()); - } - return res; -} -} // namespace - -namespace coco -{ - -std::set UnitF::reads(void) const -{ - std::set res; - - res += ifm(); - - if (op() != nullptr) - { - for (auto obj : op()->uses()) - { - res += obj; - } - } - - return res; -} - -std::set UnitF::updates(void) const -{ - std::set 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 diff --git a/contrib/coco/core/src/IR/Instr.test.cpp b/contrib/coco/core/src/IR/Instr.test.cpp index a900504..b3b163e 100644 --- a/contrib/coco/core/src/IR/Instr.test.cpp +++ b/contrib/coco/core/src/IR/Instr.test.cpp @@ -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 index 0000000..278ae15 --- /dev/null +++ b/contrib/coco/core/src/IR/UnitF.cpp @@ -0,0 +1,66 @@ +#include "coco/IR/UnitF.h" +#include "coco/IR/Op.h" + +#include + +namespace +{ +std::set &operator+=(std::set &res, const coco::Object *o) +{ + if (o != nullptr && o->bag() != nullptr) + { + res.insert(o->bag()); + } + return res; +} +} // namespace + +namespace coco +{ + +std::set UnitF::reads(void) const +{ + std::set res; + + res += ifm(); + + if (op() != nullptr) + { + for (auto obj : op()->uses()) + { + res += obj; + } + } + + return res; +} + +std::set UnitF::updates(void) const +{ + std::set 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 -- 2.7.4