From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 23 Oct 2018 01:57:39 +0000 (+0900) Subject: [enco] Emit Bag's initial data as global data (#1940) X-Git-Tag: nncc_backup~1491 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f39a91fae44c37dae800f6e7cc424774ad46bc0;p=platform%2Fcore%2Fml%2Fnnfw.git [enco] Emit Bag's initial data as global data (#1940) With this commit, global data that global data generation pass emits includes bag's weight values (in addition to weight values for ANN operands). Signed-off-by: Jonghyun Park --- diff --git a/contrib/enco/core/src/Transforms/GlobalDataGeneration.cpp b/contrib/enco/core/src/Transforms/GlobalDataGeneration.cpp index f0c4dc8..f45b63a 100644 --- a/contrib/enco/core/src/Transforms/GlobalDataGeneration.cpp +++ b/contrib/enco/core/src/Transforms/GlobalDataGeneration.cpp @@ -83,6 +83,8 @@ namespace { std::map data_offset_ctx; +std::map bag_data_offset_ctx; + std::map name_offset_ctx; std::map dims_offset_ctx; @@ -93,6 +95,12 @@ namespace enco GlobalOffset GlobalData::data_offset(const ann::Operand *o) { return data_offset_ctx.at(o); } +GlobalOffset GlobalData::data_offset(const coco::Bag *bag) +{ + assert(bag_data_offset_ctx.find(bag) != bag_data_offset_ctx.end()); + return bag_data_offset_ctx.at(bag); +} + GlobalOffset GlobalData::name_offset(const coco::Input *in) { return name_offset_ctx.at(in); } GlobalOffset GlobalData::dims_offset(const coco::Input *in) { return dims_offset_ctx.at(in); } @@ -102,10 +110,39 @@ GlobalOffset GlobalData::dims_offset(const coco::Output *out) { return dims_offs void generate_global_data(std::ostream &os, enco::Code *code) { auto m = code->module(); + auto d = code->data(); + auto ann_ctx = enco::SubnetManager::context(m); auto global = make_unique(os); + // + // Emit Bag's weight + // + for (uint32_t n = 0; n < m->entity()->bag()->size(); ++n) + { + auto bag = m->entity()->bag()->at(n); + + if (!d->allocated(bag)) + { + // Skip if the weight value does not exist for a given bag + continue; + } + + // NOTE The current implementation assumes that all the values are of float(fp32) type + // TODO Support non-float values + auto span = d->f32()->weight(bag); + + assert(span.data() != nullptr); + assert(span.size() > 0); + + auto const base = reinterpret_cast(span.data()); + uint32_t const size = span.size() * sizeof(float); + + assert(bag_data_offset_ctx.find(bag) == bag_data_offset_ctx.end()); + bag_data_offset_ctx[bag] = global->constant(base, size); + } + for (uint32_t n = 0; n < ann_ctx->count(); ++n) { auto binder = ann_ctx->nth(n); diff --git a/contrib/enco/core/src/Transforms/GlobalDataGeneration.h b/contrib/enco/core/src/Transforms/GlobalDataGeneration.h index fd7b382..4334314 100644 --- a/contrib/enco/core/src/Transforms/GlobalDataGeneration.h +++ b/contrib/enco/core/src/Transforms/GlobalDataGeneration.h @@ -29,6 +29,13 @@ using GlobalOffset = uint32_t; struct GlobalData { static GlobalOffset data_offset(const ann::Operand *); + /** + * @brief Return the weight offset of a given bag + * + * @note The behavior of "data_offset" is undefined if a bag has no weight. + */ + static GlobalOffset data_offset(const coco::Bag *); + static GlobalOffset name_offset(const coco::Input *); static GlobalOffset dims_offset(const coco::Input *); static GlobalOffset name_offset(const coco::Output *);