From 9f5d1026f5aa70c5517a499fabb69e495f05421a 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, 8 Oct 2018 12:53:24 +0900 Subject: [PATCH] [coco] Introduce Load op (#1769) This commit introduces Load op which serves as a leaf node of tree-like Op structure. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Load.h | 59 +++++++++++++++++++++++++++ contrib/coco/core/include/coco/IR/Op.lst | 1 + contrib/coco/core/include/coco/IR/OpManager.h | 1 + contrib/coco/core/src/IR/Load.cpp | 41 +++++++++++++++++++ contrib/coco/core/src/IR/OpManager.cpp | 7 ++++ 5 files changed, 109 insertions(+) create mode 100644 contrib/coco/core/include/coco/IR/Load.h create mode 100644 contrib/coco/core/src/IR/Load.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 index 0000000..0107a1b --- /dev/null +++ b/contrib/coco/core/include/coco/IR/Load.h @@ -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 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__ diff --git a/contrib/coco/core/include/coco/IR/Op.lst b/contrib/coco/core/include/coco/IR/Op.lst index 6bad25c..7da5756 100644 --- a/contrib/coco/core/include/coco/IR/Op.lst +++ b/contrib/coco/core/include/coco/IR/Op.lst @@ -4,6 +4,7 @@ // OP(Name) +OP(Load) OP(Conv2D) OP(MaxPool2D) OP(AvgPool2D) diff --git a/contrib/coco/core/include/coco/IR/OpManager.h b/contrib/coco/core/include/coco/IR/OpManager.h index 3134be7..724221f 100644 --- a/contrib/coco/core/include/coco/IR/OpManager.h +++ b/contrib/coco/core/include/coco/IR/OpManager.h @@ -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 index 0000000..237e745 --- /dev/null +++ b/contrib/coco/core/src/IR/Load.cpp @@ -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 + +namespace coco +{ + +Load::Load() : _obj{this} +{ + // DO NOTHING +} + +std::set Load::uses(void) const +{ + std::set res; + + if (auto obj = object()) + { + res.insert(obj); + } + + return res; +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/OpManager.cpp b/contrib/coco/core/src/IR/OpManager.cpp index 9f814e9..13e33cf 100644 --- a/contrib/coco/core/src/IR/OpManager.cpp +++ b/contrib/coco/core/src/IR/OpManager.cpp @@ -25,6 +25,13 @@ using nncc::foundation::make_unique; namespace coco { +template <> Load *OpManager::create(void) +{ + auto op = make_unique(); + modulize(op.get()); + return take(std::move(op)); +} + template <> Conv2D *OpManager::create(void) { auto op = make_unique(); -- 2.7.4