[coco] Implement reorder in GenericFeatureLayout (#1577)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 19 Sep 2018 10:34:19 +0000 (19:34 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 19 Sep 2018 10:34:19 +0000 (19:34 +0900)
This commit moves the actual implementation of reorder method from
FeaturObject into GenericFeatureLayout.

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

index 4ce8adb..24aeab4 100644 (file)
@@ -4,6 +4,7 @@
 #include "coco/IR/ElemID.h"
 
 #include <nncc/core/ADT/feature/Shape.h>
+#include <nncc/core/ADT/feature/Layout.h>
 
 #include <vector>
 
@@ -22,6 +23,8 @@ public:
   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;
 
+  void reorder(const nncc::core::ADT::feature::Layout &l);
+
 private:
   uint32_t offset(uint32_t b, uint32_t ch, uint32_t row, uint32_t col) const;
 
index 0ed0eba..8a50dd3 100644 (file)
@@ -35,18 +35,6 @@ ElemID FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) const
   return _layout->at(0, ch, row, col);
 }
 
-void FeatureObject::reorder(const nncc::core::ADT::feature::Layout &l)
-{
-  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(ch, row, col) = ElemID{l.offset(shape(), ch, row, col)};
-      }
-    }
-  }
-}
+void FeatureObject::reorder(const nncc::core::ADT::feature::Layout &l) { _layout->reorder(l); }
 
 } // namespace coco
index e784042..4de5a2e 100644 (file)
@@ -2,6 +2,8 @@
 
 #include <nncc/core/ADT/feature/CHWLayout.h>
 
+#include <cassert>
+
 using nncc::core::ADT::feature::num_elements;
 
 namespace coco
@@ -35,4 +37,20 @@ ElemID GenericFeatureLayout::at(uint32_t b, uint32_t ch, uint32_t row, uint32_t
   return _content.at(offset(b, ch, row, col));
 }
 
+void GenericFeatureLayout::reorder(const nncc::core::ADT::feature::Layout &l)
+{
+  assert(_batch == 1);
+
+  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(0, ch, row, col) = ElemID{l.offset(shape(), ch, row, col)};
+      }
+    }
+  }
+}
+
 } // namespace coco