[coco] Introduce Load op (#1769)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 8 Oct 2018 03:53:24 +0000 (12:53 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 8 Oct 2018 03:53:24 +0000 (12:53 +0900)
This commit introduces Load op which serves as a leaf node of tree-like
Op structure.

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

diff --git a/contrib/coco/core/include/coco/IR/Load.h b/contrib/coco/core/include/coco/IR/Load.h
new file mode 100644 (file)
index 0000000..0107a1b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __COCO_IR_LOAD_H__
+#define __COCO_IR_LOAD_H__
+
+#include "coco/IR/Op.h"
+#include "coco/IR/Object.h"
+#include "coco/IR/Use.h"
+
+namespace coco
+{
+
+/**
+ * @brief Load an Object
+ */
+class Load final : public Op, public Object::Consumer
+{
+public:
+  explicit Load();
+
+public:
+  Load(const Load &) = delete;
+  Load(Load &&) = delete;
+
+public:
+  std::set<Object *> uses(void) const override;
+
+public:
+  Load *asLoad(void) override { return this; }
+  const Load *asLoad(void) const override { return this; }
+
+public:
+  Instr *loc(void) override { return parent(); }
+
+public:
+  void object(Object *o) { _obj.value(o); }
+  Object *object(void) const { return _obj.value(); }
+
+private:
+  Use _obj;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_LOAD_H__
index 6bad25c..7da5756 100644 (file)
@@ -4,6 +4,7 @@
 
 // OP(Name)
 
+OP(Load)
 OP(Conv2D)
 OP(MaxPool2D)
 OP(AvgPool2D)
index 3134be7..724221f 100644 (file)
@@ -18,6 +18,7 @@
 #define __COCO_IR_OP_MANAGER_H__
 
 #include "coco/IR/Op.h"
+#include "coco/IR/Load.h"
 #include "coco/IR/Conv2D.h"
 #include "coco/IR/MaxPool2D.h"
 #include "coco/IR/AvgPool2D.h"
diff --git a/contrib/coco/core/src/IR/Load.cpp b/contrib/coco/core/src/IR/Load.cpp
new file mode 100644 (file)
index 0000000..237e745
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "coco/IR/Load.h"
+
+#include <cassert>
+
+namespace coco
+{
+
+Load::Load() : _obj{this}
+{
+  // DO NOTHING
+}
+
+std::set<Object *> Load::uses(void) const
+{
+  std::set<Object *> res;
+
+  if (auto obj = object())
+  {
+    res.insert(obj);
+  }
+
+  return res;
+}
+
+} // namespace coco
index 9f814e9..13e33cf 100644 (file)
@@ -25,6 +25,13 @@ using nncc::foundation::make_unique;
 namespace coco
 {
 
+template <> Load *OpManager::create<Load>(void)
+{
+  auto op = make_unique<Load>();
+  modulize(op.get());
+  return take(std::move(op));
+}
+
 template <> Conv2D *OpManager::create<Conv2D>(void)
 {
   auto op = make_unique<Conv2D>();