[enco] Replace Generic with BCHW layout in Caffe frontend (#1597)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 20 Sep 2018 05:48:47 +0000 (14:48 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 20 Sep 2018 05:48:47 +0000 (14:48 +0900)
This commit replaces all the use of GenericFeatureLayout with BCHW
layout.

This change eliminates the need for reorder call, which speeds up IR
build.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/frontend/caffe/src/Frontend.cpp

index 5cb589c..6a3935f 100644 (file)
@@ -3,6 +3,8 @@
 #include "PoolingSpec.h"
 #include "ConcatSpec.h"
 
+#include <coco/IR/FeatureLayouts.h>
+
 #include <nncc/core/ADT/feature/CHWLayout.h>
 #include <nncc/core/ADT/kernel/Shape.h>
 #include <nncc/core/ADT/kernel/Overlay.h>
@@ -194,24 +196,18 @@ enco::Bundle Frontend::load(void) const
       const auto ifm_shape = shape_ctx.at(ifm_name);
       auto ifm_bag = bag_ctx.at(ifm_name);
       auto ifm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ifm_shape));
-      auto ifm_layout = make_unique<coco::GenericFeatureLayout>(ifm_obj->shape());
-
-      ifm_layout->reorder(feature::CHWLayout{});
 
       ifm_obj->bag(ifm_bag);
-      ifm_obj->layout(std::move(ifm_layout));
+      ifm_obj->layout(coco::FeatureLayouts::BCHW::create(ifm_obj->shape()));
 
       // Create an object for an output feature map
       const auto ofm_name = layer.top(0);
       const auto ofm_shape = spec.ofm_shape();
       auto ofm_bag = m->entity()->bag()->create(num_elements(ofm_shape));
       auto ofm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ofm_shape));
-      auto ofm_layout = make_unique<coco::GenericFeatureLayout>(ofm_obj->shape());
-
-      ofm_layout->reorder(feature::CHWLayout{});
 
       ofm_obj->bag(ofm_bag);
-      ofm_obj->layout(std::move(ofm_layout));
+      ofm_obj->layout(coco::FeatureLayouts::BCHW::create(ofm_obj->shape()));
 
       // Create an object for kernel
       const auto ker_shape = spec.ker_shape();
@@ -297,24 +293,18 @@ enco::Bundle Frontend::load(void) const
       const auto ifm_shape = shape_ctx.at(ifm_name);
       auto ifm_bag = bag_ctx.at(ifm_name);
       auto ifm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ifm_shape));
-      auto ifm_layout = make_unique<coco::GenericFeatureLayout>(ifm_obj->shape());
-
-      ifm_layout->reorder(feature::CHWLayout{});
 
       ifm_obj->bag(ifm_bag);
-      ifm_obj->layout(std::move(ifm_layout));
+      ifm_obj->layout(coco::FeatureLayouts::BCHW::create(ifm_obj->shape()));
 
       // Create an object for an output feature map
       const auto ofm_name = layer.top(0);
       const auto ofm_shape = spec.ofm_shape();
       auto ofm_bag = m->entity()->bag()->create(num_elements(ofm_shape));
       auto ofm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ofm_shape));
-      auto ofm_layout = make_unique<coco::GenericFeatureLayout>(ofm_obj->shape());
-
-      ofm_layout->reorder(feature::CHWLayout{});
 
       ofm_obj->bag(ofm_bag);
-      ofm_obj->layout(std::move(ofm_layout));
+      ofm_obj->layout(coco::FeatureLayouts::BCHW::create(ofm_obj->shape()));
 
       using PoolingOpBuilder = std::function<coco::Op *(coco::Module * m, const PoolingSpec &spec)>;
 
@@ -393,23 +383,17 @@ enco::Bundle Frontend::load(void) const
       const auto ifm_shape = shape_ctx.at(ifm_name);
       auto ifm_bag = bag_ctx.at(ifm_name);
       auto ifm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ifm_shape));
-      auto ifm_layout = make_unique<coco::GenericFeatureLayout>(ifm_obj->shape());
-
-      ifm_layout->reorder(feature::CHWLayout{});
 
       ifm_obj->bag(ifm_bag);
-      ifm_obj->layout(std::move(ifm_layout));
+      ifm_obj->layout(coco::FeatureLayouts::BCHW::create(ifm_obj->shape()));
 
       const auto ofm_name = layer.top(0);
       const auto ofm_shape = ifm_shape;
       auto ofm_bag = m->entity()->bag()->create(num_elements(ofm_shape));
       auto ofm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ofm_shape));
-      auto ofm_layout = make_unique<coco::GenericFeatureLayout>(ofm_obj->shape());
-
-      ofm_layout->reorder(feature::CHWLayout{});
 
       ofm_obj->bag(ofm_bag);
-      ofm_obj->layout(std::move(ofm_layout));
+      ofm_obj->layout(coco::FeatureLayouts::BCHW::create(ofm_obj->shape()));
 
       // Create a ReLU op
       auto op = m->entity()->op()->create<coco::ReLU>();