From 9bbc1fe9c1a02aebee3c1fbed701020357d82bf9 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: Tue, 2 Oct 2018 19:03:15 +0900 Subject: [PATCH] [coco] Introduce FeatureShape alias (#1727) This commit introduces FeatureShape type in coco (which is an alias of nncc::core::ADT::feature::Shape) for ease of use. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/FeatureLayout.h | 5 ++-- contrib/coco/core/include/coco/IR/FeatureLayouts.h | 22 ++++++++-------- contrib/coco/core/include/coco/IR/FeatureObject.h | 6 ++--- contrib/coco/core/include/coco/IR/FeatureShape.h | 29 ++++++++++++++++++++++ contrib/coco/core/include/coco/IR/ObjectManager.h | 4 +-- 5 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 contrib/coco/core/include/coco/IR/FeatureShape.h diff --git a/contrib/coco/core/include/coco/IR/FeatureLayout.h b/contrib/coco/core/include/coco/IR/FeatureLayout.h index c8544a0..a24fe0c 100644 --- a/contrib/coco/core/include/coco/IR/FeatureLayout.h +++ b/contrib/coco/core/include/coco/IR/FeatureLayout.h @@ -18,8 +18,7 @@ #define __COCO_IR_FEATURE_LAYOUT_H__ #include "coco/IR/ElemID.h" - -#include +#include "coco/IR/FeatureShape.h" namespace coco { @@ -41,7 +40,7 @@ struct FeatureLayout virtual const ID *id(void) const = 0; virtual uint32_t batch(void) const = 0; - virtual const nncc::core::ADT::feature::Shape &shape(void) const = 0; + virtual const FeatureShape &shape(void) const = 0; virtual ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const = 0; }; diff --git a/contrib/coco/core/include/coco/IR/FeatureLayouts.h b/contrib/coco/core/include/coco/IR/FeatureLayouts.h index 54f7ad7..d5cb869 100644 --- a/contrib/coco/core/include/coco/IR/FeatureLayouts.h +++ b/contrib/coco/core/include/coco/IR/FeatureLayouts.h @@ -35,7 +35,7 @@ namespace FeatureLayouts class BCHW final : public FeatureLayout { private: - BCHW(uint32_t batch, const nncc::core::ADT::feature::Shape &shape) : _batch{batch}, _shape{shape} + BCHW(uint32_t batch, const FeatureShape &shape) : _batch{batch}, _shape{shape} { // DO NOTHING } @@ -45,16 +45,16 @@ public: const FeatureLayout::ID *id(void) const override { return uid(); } uint32_t batch(void) const override { return _batch; } - const nncc::core::ADT::feature::Shape &shape(void) const override { return _shape; } + const FeatureShape &shape(void) const override { return _shape; } ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override; private: uint32_t _batch; - nncc::core::ADT::feature::Shape _shape; + FeatureShape _shape; public: - static std::unique_ptr create(const nncc::core::ADT::feature::Shape &shape); + static std::unique_ptr create(const FeatureShape &shape); }; /** @@ -63,7 +63,7 @@ public: class BHWC : public coco::FeatureLayout { private: - BHWC(uint32_t batch, const nncc::core::ADT::feature::Shape &shape) : _batch{batch}, _shape{shape} + BHWC(uint32_t batch, const FeatureShape &shape) : _batch{batch}, _shape{shape} { // DO NOTHING } @@ -73,16 +73,16 @@ public: const FeatureLayout::ID *id(void) const override { return uid(); } uint32_t batch(void) const override { return _batch; } - const nncc::core::ADT::feature::Shape &shape(void) const override { return _shape; } + const FeatureShape &shape(void) const override { return _shape; } coco::ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override; private: uint32_t _batch; - nncc::core::ADT::feature::Shape _shape; + FeatureShape _shape; public: - static std::unique_ptr create(const nncc::core::ADT::feature::Shape &shape); + static std::unique_ptr create(const FeatureShape &shape); }; /** @@ -91,14 +91,14 @@ public: class Generic final : public FeatureLayout { public: - Generic(const nncc::core::ADT::feature::Shape &shape); + Generic(const FeatureShape &shape); public: static const FeatureLayout::ID *uid(void); const FeatureLayout::ID *id(void) const override { return uid(); } uint32_t batch(void) const override { return _batch; } - const nncc::core::ADT::feature::Shape &shape(void) const override { return _shape; } + const FeatureShape &shape(void) const override { return _shape; } ElemID &at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col); ElemID at(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const override; @@ -110,7 +110,7 @@ private: private: uint32_t _batch; - nncc::core::ADT::feature::Shape _shape; + FeatureShape _shape; private: std::vector _content; diff --git a/contrib/coco/core/include/coco/IR/FeatureObject.h b/contrib/coco/core/include/coco/IR/FeatureObject.h index e618526..62cf42c 100644 --- a/contrib/coco/core/include/coco/IR/FeatureObject.h +++ b/contrib/coco/core/include/coco/IR/FeatureObject.h @@ -18,10 +18,10 @@ #define __COCO_IR_FEATURE_OBJECT_H__ #include "coco/IR/Object.h" +#include "coco/IR/FeatureShape.h" #include "coco/IR/FeatureLayout.h" #include "coco/IR/ElemID.h" -#include #include #include @@ -36,7 +36,7 @@ class FeatureObject final : public Object { public: FeatureObject() = default; - explicit FeatureObject(const nncc::core::ADT::feature::Shape &shape); + explicit FeatureObject(const FeatureShape &shape); public: ~FeatureObject(); @@ -49,7 +49,7 @@ public: const FeatureObject *asFeature(void) const override { return this; } public: - const nncc::core::ADT::feature::Shape &shape(void) const; + const FeatureShape &shape(void) const; public: ElemID at(uint32_t ch, uint32_t row, uint32_t col) const; diff --git a/contrib/coco/core/include/coco/IR/FeatureShape.h b/contrib/coco/core/include/coco/IR/FeatureShape.h new file mode 100644 index 0000000..6ef5dc1 --- /dev/null +++ b/contrib/coco/core/include/coco/IR/FeatureShape.h @@ -0,0 +1,29 @@ +/* + * 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_FEATURE_SHAPE_H__ +#define __COCO_IR_FEATURE_SHAPE_H__ + +#include + +namespace coco +{ + +using FeatureShape = nncc::core::ADT::feature::Shape; + +} // namespace coco + +#endif // __COCO_IR_FEATURE_SHAPE_H__ diff --git a/contrib/coco/core/include/coco/IR/ObjectManager.h b/contrib/coco/core/include/coco/IR/ObjectManager.h index 585ca03..e23abbb 100644 --- a/contrib/coco/core/include/coco/IR/ObjectManager.h +++ b/contrib/coco/core/include/coco/IR/ObjectManager.h @@ -18,6 +18,7 @@ #define __COCO_IR_OBJECT_MANAGER_H__ #include "coco/IR/Object.h" +#include "coco/IR/FeatureShape.h" #include "coco/IR/FeatureObject.forward.h" #include "coco/IR/KernelObject.forward.h" #include "coco/IR/EntityBuilder.h" @@ -25,7 +26,6 @@ #include "coco/ADT/PtrManager.h" #include "coco/ADT/PtrLink.h" -#include #include namespace coco @@ -37,7 +37,7 @@ public: ObjectManager(Module *m = nullptr) { module(m); } public: - FeatureObject *create(const nncc::core::ADT::feature::Shape &shape); + FeatureObject *create(const FeatureShape &shape); KernelObject *create(const nncc::core::ADT::kernel::Shape &shape); template T *create(void); -- 2.7.4