From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 10 Aug 2018 08:57:23 +0000 (+0900) Subject: [coco] Introduce FeatureObjectInfo (#964) X-Git-Tag: nncc_backup~2204 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37e3fe0fe27fd2a8b0e31de7d97ffaf6c20b4a69;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Introduce FeatureObjectInfo (#964) * [coco] Introduce FeatureObjectInfo This commit introduce FeatureObjectInfo class which internally manages mutable information related with each FeatureObject. Signed-off-by: Jonghyun Park * Use correct incorrect ifdef guard --- diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.h b/contrib/coco/core/include/coco/IR/FeatureObject.h index 7b3bfbd..0c36145 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObject.h +++ b/contrib/coco/core/include/coco/IR/FeatureObject.h @@ -2,6 +2,7 @@ #define __COCO_IR_FEATURE_OBJECT_H__ #include "coco/IR/Object.h" +#include "coco/IR/FeatureObjectInfo.h" #include "coco/IR/ElemID.h" #include @@ -18,21 +19,18 @@ namespace coco class FeatureObject final : public Object { public: - explicit FeatureObject(const PtrLink *link, - const nncc::core::ADT::feature::Shape &shape); + explicit FeatureObject(std::unique_ptr &&info, + const PtrLink *link); public: - virtual ~FeatureObject() = default; + ~FeatureObject(); public: FeatureObject *asFeature(void) override { return this; } const FeatureObject *asFeature(void) const override { return this; } public: - const nncc::core::ADT::feature::Shape &shape(void) const { return _shape; } - -private: - nncc::core::ADT::feature::Shape const _shape; + const nncc::core::ADT::feature::Shape &shape(void) const; public: ElemID &at(uint32_t ch, uint32_t row, uint32_t col); @@ -43,6 +41,8 @@ public: template void reorder(void) { reorder(LayoutImpl{}); } private: + std::unique_ptr _info; + std::vector _map; }; diff --git a/contrib/coco/core/include/coco/IR/FeatureObjectInfo.forward.h b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.forward.h new file mode 100644 index 0000000..84456d2 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.forward.h @@ -0,0 +1,11 @@ +#ifndef __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__ +#define __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__ + +namespace coco +{ + +class FeatureObjectInfo; + +} // namespace coco + +#endif // __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__ diff --git a/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h new file mode 100644 index 0000000..86f659d --- /dev/null +++ b/contrib/coco/core/include/coco/IR/FeatureObjectInfo.h @@ -0,0 +1,26 @@ +#ifndef __COCO_IR_FEATURE_OBJECT_INFO_H__ +#define __COCO_IR_FEATURE_OBJECT_INFO_H__ + +#include + +namespace coco +{ + +class FeatureObjectInfo final +{ +public: + FeatureObjectInfo(const nncc::core::ADT::feature::Shape &shape) : _shape{shape} + { + // DO NOTHING + } + +public: + const nncc::core::ADT::feature::Shape &shape(void) const { return _shape; } + +private: + nncc::core::ADT::feature::Shape const _shape; +}; + +} // namespace coco + +#endif // __COCO_IR_FEATURE_OBJECT_INFO_H__ diff --git a/contrib/coco/core/src/IR/FeatureObject.cpp b/contrib/coco/core/src/IR/FeatureObject.cpp index 36aa772..8c63c41 100644 --- a/contrib/coco/core/src/IR/FeatureObject.cpp +++ b/contrib/coco/core/src/IR/FeatureObject.cpp @@ -1,4 +1,5 @@ #include "coco/IR/FeatureObject.h" +#include "coco/IR/FeatureObjectInfo.h" #include @@ -12,32 +13,39 @@ static nncc::core::ADT::feature::CHWLayout l{}; namespace coco { -FeatureObject::FeatureObject(const PtrLink *link, - const nncc::core::ADT::feature::Shape &shape) - : Object{link}, _shape{shape} +FeatureObject::FeatureObject(std::unique_ptr &&info, + const PtrLink *link) + : Object{link}, _info(std::move(info)) { - _map.resize(nncc::core::ADT::feature::num_elements(shape)); + _map.resize(nncc::core::ADT::feature::num_elements(shape())); } +FeatureObject::~FeatureObject() +{ + // DO NOTHING +} + +const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); } + ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) { - return _map.at(l.offset(_shape, ch, row, col)); + return _map.at(l.offset(shape(), ch, row, col)); } const ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) const { - return _map.at(l.offset(_shape, ch, row, col)); + return _map.at(l.offset(shape(), ch, row, col)); } void FeatureObject::reorder(const nncc::core::ADT::feature::Layout &l) { - for (uint32_t ch = 0; ch < _shape.depth(); ++ch) + for (uint32_t ch = 0; ch < shape().depth(); ++ch) { - for (uint32_t row = 0; row < _shape.height(); ++row) + for (uint32_t row = 0; row < shape().height(); ++row) { - for (uint32_t col = 0; col < _shape.width(); ++col) + for (uint32_t col = 0; col < shape().width(); ++col) { - at(ch, row, col) = ElemID{l.offset(_shape, ch, row, col)}; + at(ch, row, col) = ElemID{l.offset(shape(), ch, row, col)}; } } } diff --git a/contrib/coco/core/src/IR/FeatureObject.test.cpp b/contrib/coco/core/src/IR/FeatureObject.test.cpp index f3726f0..2139f19 100644 --- a/contrib/coco/core/src/IR/FeatureObject.test.cpp +++ b/contrib/coco/core/src/IR/FeatureObject.test.cpp @@ -1,4 +1,7 @@ #include "coco/IR/FeatureObject.h" +#include "coco/IR/FeatureObjectInfo.h" + +#include #include #include @@ -6,6 +9,7 @@ #include using namespace nncc::core::ADT; +using nncc::foundation::make_unique; namespace { @@ -14,7 +18,8 @@ class FeatureObjectTest : public ::testing::Test protected: coco::FeatureObject *allocate(const feature::Shape &shape) { - auto o = new coco::FeatureObject{&_bag_link, shape}; + auto info = make_unique(shape); + auto o = new coco::FeatureObject{std::move(info), &_bag_link}; _allocated.emplace_back(o); return o; } diff --git a/contrib/coco/core/src/IR/FeatureObjectInfo.test.cpp b/contrib/coco/core/src/IR/FeatureObjectInfo.test.cpp new file mode 100644 index 0000000..54d9e1b --- /dev/null +++ b/contrib/coco/core/src/IR/FeatureObjectInfo.test.cpp @@ -0,0 +1,11 @@ +#include "coco/IR/FeatureObjectInfo.h" + +#include + +TEST(FeatureObjectInfoTest, constructor) +{ + const nncc::core::ADT::feature::Shape shape{1, 3, 3}; + const coco::FeatureObjectInfo info{shape}; + + ASSERT_EQ(info.shape(), shape); +} diff --git a/contrib/coco/core/src/IR/ObjectManager.cpp b/contrib/coco/core/src/IR/ObjectManager.cpp index 8692749..d7d1e3d 100644 --- a/contrib/coco/core/src/IR/ObjectManager.cpp +++ b/contrib/coco/core/src/IR/ObjectManager.cpp @@ -1,6 +1,7 @@ #include "coco/IR/ObjectManager.h" #include "coco/IR/FeatureObject.h" +#include "coco/IR/FeatureObjectInfo.h" #include "coco/IR/KernelObject.h" #include @@ -12,7 +13,8 @@ namespace coco FeatureObject *ObjectManager::create(const nncc::core::ADT::feature::Shape &shape) { - return take(make_unique(_link, shape)); + auto info = make_unique(shape); + return take(make_unique(std::move(info), _link)); } KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape)