[coco] Add 'ObjectManager' (#757)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 23 Jul 2018 06:38:45 +0000 (15:38 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 23 Jul 2018 06:38:45 +0000 (15:38 +0900)
* [coco] Add 'ObjectManager'

This commit adds the base implementation of 'ObjectManager'

The current implementation supports 'FeatureObject' and 'KernelObject'
construction.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Use forward headers

contrib/coco/core/include/coco/IR/FeatureObject.forward.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/KernelObject.forward.h [new file with mode: 0644]
contrib/coco/core/include/coco/IR/ObjectManager.h [new file with mode: 0644]
contrib/coco/core/src/IR/ObjectManager.cpp [new file with mode: 0644]
contrib/coco/core/src/IR/ObjectManager.test.cpp [new file with mode: 0644]

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 (file)
index 0000000..44fd954
--- /dev/null
@@ -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 (file)
index 0000000..5d0dc7a
--- /dev/null
@@ -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 (file)
index 0000000..67e99dd
--- /dev/null
@@ -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 <nncc/core/ADT/feature/Shape.h>
+#include <nncc/core/ADT/kernel/Shape.h>
+
+namespace coco
+{
+
+struct ObjectManager : public PtrManager<Object>
+{
+  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 (file)
index 0000000..099928b
--- /dev/null
@@ -0,0 +1,23 @@
+#include "coco/IR/ObjectManager.h"
+
+#include "coco/IR/FeatureObject.h"
+#include "coco/IR/KernelObject.h"
+
+#include <nncc/foundation/Memory.h>
+
+using nncc::foundation::make_unique;
+
+namespace coco
+{
+
+FeatureObject *ObjectManager::create(const nncc::core::ADT::feature::Shape &shape)
+{
+  return take(make_unique<FeatureObject>(shape));
+}
+
+KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape)
+{
+  return take(make_unique<KernelObject>(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 (file)
index 0000000..9378212
--- /dev/null
@@ -0,0 +1,35 @@
+#include "coco/IR/ObjectManager.h"
+
+#include "coco/IR/FeatureObject.h"
+#include "coco/IR/KernelObject.h"
+
+#include <gtest/gtest.h>
+
+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());
+}