From 35fa6a73e6085397d047666a799422403f9fe272 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 15:38:45 +0900 Subject: [PATCH] [coco] Add 'ObjectManager' (#757) * [coco] Add 'ObjectManager' This commit adds the base implementation of 'ObjectManager' The current implementation supports 'FeatureObject' and 'KernelObject' construction. Signed-off-by: Jonghyun Park * Use forward headers --- .../core/include/coco/IR/FeatureObject.forward.h | 11 +++++++ .../core/include/coco/IR/KernelObject.forward.h | 11 +++++++ contrib/coco/core/include/coco/IR/ObjectManager.h | 24 +++++++++++++++ contrib/coco/core/src/IR/ObjectManager.cpp | 23 ++++++++++++++ contrib/coco/core/src/IR/ObjectManager.test.cpp | 35 ++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 contrib/coco/core/include/coco/IR/FeatureObject.forward.h create mode 100644 contrib/coco/core/include/coco/IR/KernelObject.forward.h create mode 100644 contrib/coco/core/include/coco/IR/ObjectManager.h create mode 100644 contrib/coco/core/src/IR/ObjectManager.cpp create mode 100644 contrib/coco/core/src/IR/ObjectManager.test.cpp diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.forward.h b/contrib/coco/core/include/coco/IR/FeatureObject.forward.h new file mode 100644 index 0000000..44fd954 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/FeatureObject.forward.h @@ -0,0 +1,11 @@ +#ifndef __COCO_IR_FEATURE_OBJECT_FORWARD_H__ +#define __COCO_IR_FEATURE_OBJECT_FORWARD_H__ + +namespace coco +{ + +class FeatureObject; + +} // namespace coco + +#endif // __COCO_IR_FEATURE_OBJECT_FORWARD_H__ diff --git a/contrib/coco/core/include/coco/IR/KernelObject.forward.h b/contrib/coco/core/include/coco/IR/KernelObject.forward.h new file mode 100644 index 0000000..5d0dc7a --- /dev/null +++ b/contrib/coco/core/include/coco/IR/KernelObject.forward.h @@ -0,0 +1,11 @@ +#ifndef __COCO_IR_KERNEL_OBJECT_FORWARD_H__ +#define __COCO_IR_KERNEL_OBJECT_FORWARD_H__ + +namespace coco +{ + +class KernelObject; + +} // namespace coco + +#endif // __COCO_IR_KERNEL_OBJECT_FORWARD_H__ diff --git a/contrib/coco/core/include/coco/IR/ObjectManager.h b/contrib/coco/core/include/coco/IR/ObjectManager.h new file mode 100644 index 0000000..67e99dd --- /dev/null +++ b/contrib/coco/core/include/coco/IR/ObjectManager.h @@ -0,0 +1,24 @@ +#ifndef __COCO_IR_OBJECT_MANAGER_H__ +#define __COCO_IR_OBJECT_MANAGER_H__ + +#include "coco/IR/Object.h" +#include "coco/IR/FeatureObject.forward.h" +#include "coco/IR/KernelObject.forward.h" + +#include "coco/ADT/PtrManager.h" + +#include +#include + +namespace coco +{ + +struct ObjectManager : public PtrManager +{ + FeatureObject *create(const nncc::core::ADT::feature::Shape &shape); + KernelObject *create(const nncc::core::ADT::kernel::Shape &shape); +}; + +} // namespace coco + +#endif // __COCO_IR_OBJECT_MANAGER_H__ diff --git a/contrib/coco/core/src/IR/ObjectManager.cpp b/contrib/coco/core/src/IR/ObjectManager.cpp new file mode 100644 index 0000000..099928b --- /dev/null +++ b/contrib/coco/core/src/IR/ObjectManager.cpp @@ -0,0 +1,23 @@ +#include "coco/IR/ObjectManager.h" + +#include "coco/IR/FeatureObject.h" +#include "coco/IR/KernelObject.h" + +#include + +using nncc::foundation::make_unique; + +namespace coco +{ + +FeatureObject *ObjectManager::create(const nncc::core::ADT::feature::Shape &shape) +{ + return take(make_unique(shape)); +} + +KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape) +{ + return take(make_unique(shape)); +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/ObjectManager.test.cpp b/contrib/coco/core/src/IR/ObjectManager.test.cpp new file mode 100644 index 0000000..9378212 --- /dev/null +++ b/contrib/coco/core/src/IR/ObjectManager.test.cpp @@ -0,0 +1,35 @@ +#include "coco/IR/ObjectManager.h" + +#include "coco/IR/FeatureObject.h" +#include "coco/IR/KernelObject.h" + +#include + +TEST(IR_OBJECT_MANAGER, create_feature) +{ + using nncc::core::ADT::feature::Shape; + + const Shape shape{1, 3, 3}; + + coco::ObjectManager mgr; + + auto o = mgr.create(shape); + + ASSERT_EQ(o->shape(), shape); +} + +TEST(IR_OBJECT_MANAGER, create_kernel) +{ + using nncc::core::ADT::kernel::Shape; + + const Shape shape{1, 1, 3, 3}; + + coco::ObjectManager mgr; + + auto o = mgr.create(shape); + + ASSERT_EQ(o->shape().count(), shape.count()); + ASSERT_EQ(o->shape().depth(), shape.depth()); + ASSERT_EQ(o->shape().height(), shape.height()); + ASSERT_EQ(o->shape().width(), shape.width()); +} -- 2.7.4