[coco] Update Index-to-Element link only via GenericFeatureLayout (#1591)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 20 Sep 2018 01:43:46 +0000 (10:43 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 20 Sep 2018 01:43:46 +0000 (10:43 +0900)
This commit adjusts the role of FeatureObject and GenericFeatureLayout
classes. Now, GenericFeatureLayout (not FeatureObject) is not responsible
for Index-to-Element link update.

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
contrib/coco/core/src/IR/FeatureObject.test.cpp

index 5506e9b..eb2437a 100644 (file)
@@ -33,14 +33,9 @@ public:
   const nncc::core::ADT::feature::Shape &shape(void) const;
 
 public:
-  ElemID &at(uint32_t ch, uint32_t row, uint32_t col);
   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{}); }
-
-public:
   const GenericFeatureLayout *layout(void) const { return _layout.get(); }
   void layout(std::unique_ptr<GenericFeatureLayout> &&l) { _layout = std::move(l); }
 
index 792e476..15c04ce 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <nncc/core/ADT/kernel/NCHWLayout.h>
 
+#include <nncc/foundation/Memory.h>
+
 #include <gtest/gtest.h>
 
 #include <set>
@@ -22,6 +24,8 @@ using nncc::core::ADT::tensor::LexicalLayout;
 using nncc::core::ADT::tensor::IndexEnumerator;
 using nncc::core::ADT::tensor::num_elements;
 
+using nncc::foundation::make_unique;
+
 //
 // 'caffe_conv' test demonstrates how to translate the following Caffe network into coco IR:
 //
@@ -109,9 +113,12 @@ TEST(IR, caffe_conv)
     const nncc::core::ADT::feature::Shape ifm_shape{1, 3, 3};
     auto ifm_bag = bags["data"];
     auto ifm_obj = m->entity()->object()->create(ifm_shape);
+    auto ifm_layout = make_unique<coco::GenericFeatureLayout>(ifm_shape);
+
+    ifm_layout->reorder(CHWLayout{});
 
     ifm_obj->bag(ifm_bag);
-    ifm_obj->reorder<CHWLayout>();
+    ifm_obj->layout(std::move(ifm_layout));
 
     const nncc::core::ADT::kernel::Shape ker_shape{1, 1, 3, 3};
     auto ker_bag = m->entity()->bag()->create(num_elements(ker_shape));
@@ -123,9 +130,12 @@ TEST(IR, caffe_conv)
     const nncc::core::ADT::feature::Shape ofm_shape{1, 1, 1};
     auto ofm_bag = m->entity()->bag()->create(1 * 1 * 1);
     auto ofm_obj = m->entity()->object()->create(ofm_shape);
+    auto ofm_layout = make_unique<coco::GenericFeatureLayout>(ifm_shape);
+
+    ofm_layout->reorder(CHWLayout{});
 
     ofm_obj->bag(ofm_bag);
-    ofm_obj->reorder<CHWLayout>();
+    ofm_obj->layout(std::move(ofm_layout));
 
     // Create Conv2D operation
     //
index 8a50dd3..63c58cf 100644 (file)
@@ -23,18 +23,10 @@ FeatureObject::~FeatureObject()
 
 const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); }
 
-ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col)
-{
-  assert(_layout->batch() == 1);
-  return _layout->at(0, ch, row, col);
-}
-
 ElemID FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) const
 {
   assert(_layout->batch() == 1);
   return _layout->at(0, ch, row, col);
 }
 
-void FeatureObject::reorder(const nncc::core::ADT::feature::Layout &l) { _layout->reorder(l); }
-
 } // namespace coco
index 885244f..bfd001f 100644 (file)
@@ -38,6 +38,8 @@ TEST_F(FeatureObjectTest, ctor)
   ASSERT_EQ(o->shape(), shape);
 }
 
+// TODO Reimplement this test as a test for GenericFeatureLayout
+#if 0
 TEST_F(FeatureObjectTest, at)
 {
   const uint32_t C = 1;
@@ -73,6 +75,7 @@ TEST_F(FeatureObjectTest, at)
     }
   }
 }
+#endif
 
 TEST_F(FeatureObjectTest, asFeature)
 {