From 7daa07895999383d4eb8ea5b7b2758bb7e468176 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 20 Sep 2018 14:48:47 +0900 Subject: [PATCH] [enco] Replace Generic with BCHW layout in Caffe frontend (#1597) 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 --- contrib/enco/frontend/caffe/src/Frontend.cpp | 32 +++++++--------------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/contrib/enco/frontend/caffe/src/Frontend.cpp b/contrib/enco/frontend/caffe/src/Frontend.cpp index 5cb589c..6a3935f 100644 --- a/contrib/enco/frontend/caffe/src/Frontend.cpp +++ b/contrib/enco/frontend/caffe/src/Frontend.cpp @@ -3,6 +3,8 @@ #include "PoolingSpec.h" #include "ConcatSpec.h" +#include + #include #include #include @@ -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(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(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(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(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; @@ -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(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(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(); -- 2.7.4