[coco] Introduce NHWC kernel layout (#1738)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 4 Oct 2018 03:05:25 +0000 (12:05 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 4 Oct 2018 03:05:25 +0000 (12:05 +0900)
This commit introduces pre-defined (optimized) implementation of NHWC
kernel layout.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/KernelLayouts.h
contrib/coco/core/src/IR/KernelLayouts.cpp

index 66ffb40..25cdb0d 100644 (file)
@@ -49,6 +49,29 @@ public:
   static std::unique_ptr<NCHW> create(const nncc::core::ADT::kernel::Shape &shape);
 };
 
+/**
+ * @brief NHWC Kernel Layout
+ */
+class NHWC final : public KernelLayout
+{
+private:
+  NHWC(const nncc::core::ADT::kernel::Shape &shape) : _shape{shape}
+  {
+    // DO NOTHING
+  }
+
+public:
+  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;
+
+private:
+  nncc::core::ADT::kernel::Shape _shape;
+
+public:
+  static std::unique_ptr<NHWC> create(const nncc::core::ADT::kernel::Shape &shape);
+};
+
 } // namespace KernelLayouts
 } // namespace coco
 
index c103966..7587721 100644 (file)
@@ -17,6 +17,7 @@
 #include "coco/IR/KernelLayouts.h"
 
 #include <nncc/core/ADT/kernel/NCHWLayout.h>
+#include <nncc/core/ADT/kernel/NHWCLayout.h>
 
 #include <cassert>
 
@@ -44,3 +45,26 @@ std::unique_ptr<NCHW> NCHW::create(const nncc::core::ADT::kernel::Shape &shape)
 
 } // namespace KernelLayouts
 } // namespace coco
+
+//
+// NHWC Layout
+//
+namespace coco
+{
+namespace KernelLayouts
+{
+
+ElemID NHWC::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
+{
+  static NHWCLayout l;
+  return ElemID{l.offset(_shape, n, ch, row, col)};
+}
+
+std::unique_ptr<NHWC> NHWC::create(const nncc::core::ADT::kernel::Shape &shape)
+{
+  // NOTE It is impossible to use make_unique here as the constructor is private
+  return std::unique_ptr<NHWC>{new NHWC{shape}};
+}
+
+} // namespace KernelLayouts
+} // namespace coco