[coco] Introduce KernelLayout::ID (#1740)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 4 Oct 2018 05:15:32 +0000 (14:15 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 4 Oct 2018 05:15:32 +0000 (14:15 +0900)
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 <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/GenericKernelLayout.h
contrib/coco/core/include/coco/IR/KernelLayout.h
contrib/coco/core/include/coco/IR/KernelLayouts.h
contrib/coco/core/src/IR/GenericKernelLayout.cpp
contrib/coco/core/src/IR/KernelLayouts.cpp

index 4073973..145d7c8 100644 (file)
@@ -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);
index 09cc743..49aaf1a 100644 (file)
@@ -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;
index 25cdb0d..35c5e2c 100644 (file)
@@ -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;
index eca3ceb..eb70e77 100644 (file)
@@ -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));
index 7587721..f360a9b 100644 (file)
@@ -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;