[coco] Rename GenericKernelLayout class (#2026)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 31 Oct 2018 01:05:55 +0000 (10:05 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 31 Oct 2018 01:05:55 +0000 (10:05 +0900)
This commit renames GenericKernelLayout class as Generic class under
KernelLayouts namespace, which makes it consistent with other layout
classes.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR.h
contrib/coco/core/include/coco/IR/GenericKernelLayout.h [deleted file]
contrib/coco/core/include/coco/IR/KernelLayouts.h
contrib/coco/core/include/coco/IR/KernelObject.h
contrib/coco/core/src/IR.test.cpp
contrib/coco/core/src/IR/GenericKernelLayout.cpp [deleted file]
contrib/coco/core/src/IR/KernelLayouts.cpp
contrib/coco/core/src/IR/KernelObject.cpp

index 8fa4091..aa7ad57 100644 (file)
@@ -20,6 +20,7 @@
 #include "coco/IR/Bag.h"
 #include "coco/IR/Object.h"
 #include "coco/IR/FeatureLayouts.h"
+#include "coco/IR/KernelLayouts.h"
 
 #include "coco/IR/Op.h"
 #include "coco/IR/Instr.h"
diff --git a/contrib/coco/core/include/coco/IR/GenericKernelLayout.h b/contrib/coco/core/include/coco/IR/GenericKernelLayout.h
deleted file mode 100644 (file)
index c629bce..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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_GENERIC_KERNEL_LAYOUT_H__
-#define __COCO_IR_GENERIC_KERNEL_LAYOUT_H__
-
-#include "coco/IR/KernelLayout.h"
-
-#include <nncc/core/ADT/kernel/Layout.h>
-
-#include <vector>
-#include <memory>
-
-namespace coco
-{
-
-class GenericKernelLayout final : public KernelLayout
-{
-private:
-  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);
-  ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const override;
-
-  void reorder(const nncc::core::ADT::kernel::Layout &l);
-  template <typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
-
-private:
-  nncc::core::ADT::kernel::Shape _shape;
-
-private:
-  std::vector<ElemID> _content;
-
-public:
-  static std::unique_ptr<GenericKernelLayout> create(const nncc::core::ADT::kernel::Shape &shape);
-};
-
-} // namespace coco
-
-#endif // __COCO_IR_GENERIC_KERNEL_LAYOUT_H__
index 35c5e2c..0a04cf1 100644 (file)
@@ -19,6 +19,9 @@
 
 #include "coco/IR/KernelLayout.h"
 
+#include <nncc/core/ADT/kernel/Layout.h>
+
+#include <vector>
 #include <memory>
 
 namespace coco
@@ -78,6 +81,36 @@ public:
   static std::unique_ptr<NHWC> create(const nncc::core::ADT::kernel::Shape &shape);
 };
 
+/**
+ * @brief Generic Kernel Layout
+ */
+class Generic final : public KernelLayout
+{
+private:
+  Generic(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);
+  ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const override;
+
+  void reorder(const nncc::core::ADT::kernel::Layout &l);
+  template <typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
+
+private:
+  nncc::core::ADT::kernel::Shape _shape;
+
+private:
+  std::vector<ElemID> _content;
+
+public:
+  static std::unique_ptr<Generic> create(const nncc::core::ADT::kernel::Shape &shape);
+};
+
 } // namespace KernelLayouts
 } // namespace coco
 
index 47d74d5..a497055 100644 (file)
@@ -18,7 +18,7 @@
 #define __COCO_IR_KERNEL_OBJECT_H__
 
 #include "coco/IR/Object.h"
-#include "coco/IR/GenericKernelLayout.h"
+#include "coco/IR/KernelLayout.h"
 #include "coco/IR/ElemID.h"
 
 #include <nncc/core/ADT/kernel/Shape.h>
index 4ad9267..911a3c0 100644 (file)
@@ -136,7 +136,7 @@ TEST(IR, caffe_conv)
 
     const nncc::core::ADT::kernel::Shape ker_shape{1, 1, 3, 3};
     auto ker_bag = m->entity()->bag()->create(num_elements(ker_shape));
-    auto ker_layout = coco::GenericKernelLayout::create(ker_shape);
+    auto ker_layout = coco::KernelLayouts::Generic::create(ker_shape);
 
     ker_layout->reorder<NCHWLayout>();
 
diff --git a/contrib/coco/core/src/IR/GenericKernelLayout.cpp b/contrib/coco/core/src/IR/GenericKernelLayout.cpp
deleted file mode 100644 (file)
index aa1e01b..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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/GenericKernelLayout.h"
-
-#include <nncc/core/ADT/kernel/NCHWLayout.h>
-
-#include <cassert>
-
-using nncc::core::ADT::kernel::num_elements;
-using nncc::core::ADT::kernel::Shape;
-
-namespace
-{
-
-nncc::core::ADT::kernel::NCHWLayout l;
-
-} // namespace
-
-namespace coco
-{
-
-GenericKernelLayout::GenericKernelLayout(const nncc::core::ADT::kernel::Shape &shape)
-    : _shape{shape}
-{
-  _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));
-}
-
-ElemID GenericKernelLayout::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
-{
-  return _content.at(l.offset(_shape, n, ch, row, col));
-}
-
-void GenericKernelLayout::reorder(const nncc::core::ADT::kernel::Layout &l)
-{
-  for (uint32_t n = 0; n < shape().count(); ++n)
-  {
-    for (uint32_t ch = 0; ch < shape().depth(); ++ch)
-    {
-      for (uint32_t row = 0; row < shape().height(); ++row)
-      {
-        for (uint32_t col = 0; col < shape().width(); ++col)
-        {
-          at(n, ch, row, col) = ElemID{l.offset(shape(), n, ch, row, col)};
-        }
-      }
-    }
-  }
-}
-
-std::unique_ptr<GenericKernelLayout> GenericKernelLayout::create(const Shape &shape)
-{
-  return std::unique_ptr<GenericKernelLayout>{new GenericKernelLayout{shape}};
-}
-
-} // namespace coco
index f360a9b..6e9a157 100644 (file)
@@ -23,6 +23,9 @@
 
 using namespace nncc::core::ADT::kernel;
 
+using nncc::core::ADT::kernel::num_elements;
+using nncc::core::ADT::kernel::Shape;
+
 //
 // NCHW Layout
 //
@@ -86,3 +89,67 @@ std::unique_ptr<NHWC> NHWC::create(const nncc::core::ADT::kernel::Shape &shape)
 
 } // namespace KernelLayouts
 } // namespace coco
+
+//
+// Generic Layout
+//
+namespace
+{
+
+nncc::core::ADT::kernel::NCHWLayout l;
+
+} // namespace
+
+namespace coco
+{
+namespace KernelLayouts
+{
+
+Generic::Generic(const nncc::core::ADT::kernel::Shape &shape) : _shape{shape}
+{
+  _content.resize(num_elements(_shape));
+}
+
+const KernelLayout::ID *Generic::uid(void)
+{
+  struct LayoutID final : public KernelLayout::ID
+  {
+  };
+  static LayoutID id;
+  return &id;
+}
+
+ElemID &Generic::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col)
+{
+  return _content.at(l.offset(_shape, n, ch, row, col));
+}
+
+ElemID Generic::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
+{
+  return _content.at(l.offset(_shape, n, ch, row, col));
+}
+
+void Generic::reorder(const nncc::core::ADT::kernel::Layout &l)
+{
+  for (uint32_t n = 0; n < shape().count(); ++n)
+  {
+    for (uint32_t ch = 0; ch < shape().depth(); ++ch)
+    {
+      for (uint32_t row = 0; row < shape().height(); ++row)
+      {
+        for (uint32_t col = 0; col < shape().width(); ++col)
+        {
+          at(n, ch, row, col) = ElemID{l.offset(shape(), n, ch, row, col)};
+        }
+      }
+    }
+  }
+}
+
+std::unique_ptr<Generic> Generic::create(const Shape &shape)
+{
+  return std::unique_ptr<Generic>{new Generic{shape}};
+}
+
+} // namespace KernelLayouts
+} // namespace coco
index 9f17ef8..507c666 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "coco/IR/KernelObject.h"
+#include "coco/IR/KernelLayouts.h"
 
 #include <nncc/core/ADT/kernel/NCHWLayout.h>
 #include <nncc/foundation/Memory.h>
@@ -26,7 +27,7 @@ namespace coco
 
 KernelObject::KernelObject(const nncc::core::ADT::kernel::Shape &shape)
 {
-  _layout = GenericKernelLayout::create(shape);
+  _layout = KernelLayouts::Generic::create(shape);
 }
 
 KernelObject::~KernelObject()