[coco] Add 'InstrManager' class (#776)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 24 Jul 2018 06:00:26 +0000 (15:00 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 24 Jul 2018 06:00:26 +0000 (15:00 +0900)
This commit adds 'InstrManager' class which allocates and tracks instances of
'Instr' class.

The current implementation is restrictied to 'UnitF<Conv2D>'.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/InstrManager.h [new file with mode: 0644]
contrib/coco/core/src/IR/InstrManager.cpp [new file with mode: 0644]
contrib/coco/core/src/IR/InstrManager.test.cpp [new file with mode: 0644]

diff --git a/contrib/coco/core/include/coco/IR/InstrManager.h b/contrib/coco/core/include/coco/IR/InstrManager.h
new file mode 100644 (file)
index 0000000..580ae84
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __COCO_IR_INSTR_MANAGER_H__
+#define __COCO_IR_INSTR_MANAGER_H__
+
+#include "coco/IR/Instr.h"
+
+#include "coco/ADT/PtrManager.h"
+
+namespace coco
+{
+
+class InstrManager final : public PtrManager<Instr>
+{
+public:
+  InstrManager(const PtrLink<Instr, Block> *instr_link) : _instr_link{instr_link}
+  {
+    // DO NOTHING
+  }
+
+public:
+  template<typename OpImpl> UnitF<OpImpl> *createF(void);
+
+private:
+  const PtrLink<Instr, Block> * const _instr_link;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_INPUT_MANAGER_H__
diff --git a/contrib/coco/core/src/IR/InstrManager.cpp b/contrib/coco/core/src/IR/InstrManager.cpp
new file mode 100644 (file)
index 0000000..8fe525e
--- /dev/null
@@ -0,0 +1,15 @@
+#include "coco/IR/InstrManager.h"
+
+#include "coco/IR/Op.h"
+
+#include <nncc/foundation/Memory.h>
+
+namespace coco
+{
+
+template<> UnitF<Conv2D> *InstrManager::createF()
+{
+  return take(nncc::foundation::make_unique<UnitF<Conv2D>>(_instr_link));
+}
+
+} // namespace coco
diff --git a/contrib/coco/core/src/IR/InstrManager.test.cpp b/contrib/coco/core/src/IR/InstrManager.test.cpp
new file mode 100644 (file)
index 0000000..03f9e53
--- /dev/null
@@ -0,0 +1,16 @@
+#include "coco/IR/InstrManager.h"
+#include "coco/IR/Op.h"
+
+#include <gtest/gtest.h>
+
+TEST(IR_INSTR_MANAGER, create_UnitF)
+{
+  coco::PtrLink<coco::Instr, coco::Block> link;
+  coco::InstrManager mgr{&link};
+
+  // Conv2D
+  {
+    auto ins = mgr.createF<coco::Conv2D>();
+    ASSERT_NE(ins, nullptr);
+  }
+}