[enco] Use valid bag size during DataLayoutConversion (#1933)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 23 Oct 2018 00:58:49 +0000 (09:58 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 23 Oct 2018 00:58:49 +0000 (09:58 +0900)
* [enco] Use valid bag size during DataLayoutConversion

The current implementation of "clone_feature" in data layout conversion
pass creates a new bag whose size is same as the size of a corresponding
bag.

However, this implementation may result in invalid bag mapping, especially
when the corresponding bag uses broadcasting layout (i.e. there are multiple
feature indices that map to one element in a bag).

This commit revises this buggy implementation of "clone_feature".

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Do NOT declare unused oldbag variable

contrib/enco/core/src/Transforms/DataLayoutConversion.cpp

index be496b4..31bb9c6 100644 (file)
@@ -55,11 +55,17 @@ coco::FeatureObject *clone_feature(const coco::FeatureObject *oldobj)
   auto newobj = module->entity()->object()->create(oldobj->shape());
   newobj->layout(coco::FeatureLayouts::BHWC::create(oldobj->shape()));
 
-  if (auto oldbag = oldobj->bag())
+  if (oldobj->bag() != nullptr)
   {
-    assert(oldbag->module() == module);
+    using nncc::core::ADT::feature::num_elements;
+
+    // NOTE The size of bag should be at least "BxHxWxC" as "newobj" uses BHWC layout
+    const uint32_t batch = newobj->layout()->batch();
+    const uint32_t count = num_elements(newobj->layout()->shape());
+    const uint32_t bag_size = batch * count;
+
     // Clone bag only when there is a backing bag for a given feature object
-    auto newbag = module->entity()->bag()->create(oldbag->size());
+    auto newbag = module->entity()->bag()->create(bag_size);
     newobj->bag(newbag);
   }