From f204651e51bf74188c7471aeeb07e425b48cc049 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: Thu, 4 Oct 2018 14:15:32 +0900 Subject: [PATCH] [coco] Introduce KernelLayout::ID (#1740) This commit introduces KernelLayout::ID and extends KernelLayout interface and its concrete implementations to return its id in order to make it easy to distinguish each layout. Signed-off-by: Jonghyun Park --- .../coco/core/include/coco/IR/GenericKernelLayout.h | 3 +++ contrib/coco/core/include/coco/IR/KernelLayout.h | 15 +++++++++++++++ contrib/coco/core/include/coco/IR/KernelLayouts.h | 6 ++++++ contrib/coco/core/src/IR/GenericKernelLayout.cpp | 9 +++++++++ contrib/coco/core/src/IR/KernelLayouts.cpp | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/GenericKernelLayout.h b/contrib/coco/core/include/coco/IR/GenericKernelLayout.h index 4073973..145d7c8 100644 --- a/contrib/coco/core/include/coco/IR/GenericKernelLayout.h +++ b/contrib/coco/core/include/coco/IR/GenericKernelLayout.h @@ -32,6 +32,9 @@ public: GenericKernelLayout(const nncc::core::ADT::kernel::Shape &shape); public: + static const KernelLayout::ID *uid(void); + const KernelLayout::ID *id(void) const override { return uid(); } + const nncc::core::ADT::kernel::Shape &shape(void) const override { return _shape; } ElemID &at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col); diff --git a/contrib/coco/core/include/coco/IR/KernelLayout.h b/contrib/coco/core/include/coco/IR/KernelLayout.h index 09cc743..49aaf1a 100644 --- a/contrib/coco/core/include/coco/IR/KernelLayout.h +++ b/contrib/coco/core/include/coco/IR/KernelLayout.h @@ -31,8 +31,23 @@ namespace coco */ struct KernelLayout { + struct ID + { + virtual ~ID() = default; + }; + virtual ~KernelLayout() = default; + /** + * @brief Return the identifier of each layout + * + * REQUIRED + * + * Given l1 and l2 of KernelLayout * type, + * typeid(*l1) == typeif(*l2) SHOULD hold if l1->id() == l2->id() holds. + */ + virtual const ID *id(void) const = 0; + virtual const nncc::core::ADT::kernel::Shape &shape(void) const = 0; virtual ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const = 0; diff --git a/contrib/coco/core/include/coco/IR/KernelLayouts.h b/contrib/coco/core/include/coco/IR/KernelLayouts.h index 25cdb0d..35c5e2c 100644 --- a/contrib/coco/core/include/coco/IR/KernelLayouts.h +++ b/contrib/coco/core/include/coco/IR/KernelLayouts.h @@ -38,6 +38,9 @@ private: } public: + static const KernelLayout::ID *uid(void); + const KernelLayout::ID *id(void) const override { return uid(); } + const nncc::core::ADT::kernel::Shape &shape(void) const override { return _shape; } ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const override; @@ -61,6 +64,9 @@ private: } public: + static const KernelLayout::ID *uid(void); + const KernelLayout::ID *id(void) const override { return uid(); } + const nncc::core::ADT::kernel::Shape &shape(void) const override { return _shape; } ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const override; diff --git a/contrib/coco/core/src/IR/GenericKernelLayout.cpp b/contrib/coco/core/src/IR/GenericKernelLayout.cpp index eca3ceb..eb70e77 100644 --- a/contrib/coco/core/src/IR/GenericKernelLayout.cpp +++ b/contrib/coco/core/src/IR/GenericKernelLayout.cpp @@ -38,6 +38,15 @@ GenericKernelLayout::GenericKernelLayout(const nncc::core::ADT::kernel::Shape &s _content.resize(num_elements(_shape)); } +const KernelLayout::ID *GenericKernelLayout::uid(void) +{ + struct LayoutID final : public KernelLayout::ID + { + }; + static LayoutID id; + return &id; +} + ElemID &GenericKernelLayout::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) { return _content.at(l.offset(_shape, n, ch, row, col)); diff --git a/contrib/coco/core/src/IR/KernelLayouts.cpp b/contrib/coco/core/src/IR/KernelLayouts.cpp index 7587721..f360a9b 100644 --- a/contrib/coco/core/src/IR/KernelLayouts.cpp +++ b/contrib/coco/core/src/IR/KernelLayouts.cpp @@ -31,6 +31,15 @@ namespace coco namespace KernelLayouts { +const KernelLayout::ID *NCHW::uid(void) +{ + struct LayoutID final : public KernelLayout::ID + { + }; + static LayoutID id; + return &id; +} + ElemID NCHW::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const { static NCHWLayout l; @@ -54,6 +63,15 @@ namespace coco namespace KernelLayouts { +const KernelLayout::ID *NHWC::uid(void) +{ + struct LayoutID final : public KernelLayout::ID + { + }; + static LayoutID id; + return &id; +} + ElemID NHWC::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const { static NHWCLayout l; -- 2.7.4