[coco] Reorder 'FeatureObject' with feature layout (#874)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 2 Aug 2018 04:47:20 +0000 (13:47 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 2 Aug 2018 04:47:20 +0000 (13:47 +0900)
This commit introduces 'reorder' method similarly as in 'KernelObject'.

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

index c4c86d1..6b0d4a6 100644 (file)
@@ -5,6 +5,7 @@
 #include "coco/IR/ElemID.h"
 
 #include <nncc/core/ADT/feature/Shape.h>
+#include <nncc/core/ADT/feature/Layout.h>
 
 #include <vector>
 
@@ -36,6 +37,10 @@ public:
   ElemID &at(uint32_t ch, uint32_t row, uint32_t col);
   const ElemID &at(uint32_t ch, uint32_t row, uint32_t col) const;
 
+public:
+  void reorder(const nncc::core::ADT::feature::Layout &l);
+  template<typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
+
 private:
   std::vector<ElemID> _map;
 };
index 9c18f46..b130bb5 100644 (file)
@@ -111,20 +111,7 @@ TEST(IR, caffe_conv)
     auto ifm_obj = m->entity()->object()->create(ifm_shape);
 
     ifm_obj->bag(ifm_bag);
-
-    for (uint32_t ch = 0; ch < ifm_shape.depth(); ++ch)
-    {
-      for (uint32_t row = 0; row < ifm_shape.height(); ++row)
-      {
-        for (uint32_t col = 0; col < ifm_shape.width(); ++col)
-        {
-          const static CHWLayout l{};
-          const auto offset = static_cast<uint32_t>(l.offset(ifm_shape, ch, row, col));
-
-          ifm_obj->at(ch, row, col) = coco::ElemID{offset};
-        }
-      }
-    }
+    ifm_obj->reorder<CHWLayout>();
 
     const nncc::core::ADT::kernel::Shape ker_shape{1, 1, 3, 3};
     auto ker_bag = m->entity()->bag()->create(num_elements(ker_shape));
@@ -138,20 +125,7 @@ TEST(IR, caffe_conv)
     auto ofm_obj = m->entity()->object()->create(ofm_shape);
 
     ofm_obj->bag(ofm_bag);
-
-    for (uint32_t ch = 0; ch < ofm_shape.depth(); ++ch)
-    {
-      for (uint32_t row = 0; row < ofm_shape.height(); ++row)
-      {
-        for (uint32_t col = 0; col < ofm_shape.width(); ++col)
-        {
-          const static CHWLayout l{};
-          const auto offset = static_cast<uint32_t>(l.offset(ofm_shape, ch, row, col));
-
-          ofm_obj->at(ch, row, col) = coco::ElemID{offset};
-        }
-      }
-    }
+    ofm_obj->reorder<CHWLayout>();
 
     // Create Conv2D operation
     //
index 1a48fb4..725e120 100644 (file)
@@ -28,4 +28,18 @@ const ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) const
   return _map.at(l.offset(_shape, 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)};
+      }
+    }
+  }
+}
+
 } // namespace coco