From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 2 Oct 2018 09:26:18 +0000 (+0900) Subject: [enco] Update Global only from CppCode (#1723) X-Git-Tag: nncc_backup~1645 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5cb167aaa300b05ef2096626be5119fdcb798c8e;p=platform%2Fcore%2Fml%2Fnnfw.git [enco] Update Global only from CppCode (#1723) With this commit, Global is updated only inside CppCode. - SubnetStructBuilder no longer updates Global. Signed-off-by: Jonghyun Park --- diff --git a/contrib/enco/core/src/CppCode.cpp b/contrib/enco/core/src/CppCode.cpp index 985614d..bf6accb 100644 --- a/contrib/enco/core/src/CppCode.cpp +++ b/contrib/enco/core/src/CppCode.cpp @@ -121,11 +121,28 @@ void CppCode::dump(std::ostream &os) const */ for (uint32_t n = 0; n < _code->ann()->count(); ++n) { - const SubnetStructBuilder builder{&global}; + SubnetStructBuilder builder; auto subnet_binder = _code->ann()->nth(n); auto subnet_struct_name = pp::fmt("Subnet_", subnet_ctx.size()); auto subnet_field_name = pp::fmt("_subnet_", subnet_ctx.size()); + + // Create global data variable + auto emit_weight = [&global, &builder](const ann::OperandID &id, const ann::Operand *info) { + if (info->weight()) + { + auto base = info->weight()->base(); + auto size = info->weight()->size(); + auto gvar = global.constant(base, size); + + auto base_exp = pp::fmt("reinterpret_cast(&", gvar, ")"); + auto size_exp = pp::fmt(size); + + builder.expr(info, base_exp, size_exp); + } + }; + subnet_binder->module()->operand()->each(emit_weight); + auto subnet_struct_content = builder.build(subnet_binder); // Emit C++ declaration diff --git a/contrib/enco/core/src/CppGen/Subnet.cpp b/contrib/enco/core/src/CppGen/Subnet.cpp index 65f71d2..4657f8f 100644 --- a/contrib/enco/core/src/CppGen/Subnet.cpp +++ b/contrib/enco/core/src/CppGen/Subnet.cpp @@ -353,14 +353,10 @@ std::unique_ptr SubnetStructBuilder::build(const ANNBinder *binder throw std::runtime_error{"Unsupported"}; } - if (info->weight()) + if (_weighted.find(info) != _weighted.end()) { - auto base = info->weight()->base(); - auto size = info->weight()->size(); - auto gvar = _global->constant(base, size); - - auto base_exp = pp::fmt("reinterpret_cast(&", gvar, ")"); - auto size_exp = pp::fmt(size); + const auto &base_exp = _base_exprs.at(info); + const auto &size_exp = _size_exprs.at(info); res->ctor() << WeightDecl{mname, id, base_exp, size_exp}; } diff --git a/contrib/enco/core/src/CppGen/Subnet.h b/contrib/enco/core/src/CppGen/Subnet.h index 9341778..0c9b1cb 100644 --- a/contrib/enco/core/src/CppGen/Subnet.h +++ b/contrib/enco/core/src/CppGen/Subnet.h @@ -18,11 +18,11 @@ #define __ENCO_CPP_GEN_SUBNET_H__ #include "ANN/Binder.h" -#include "CppGen/Global.h" #include "CppGen/MemoryContext.h" #include #include +#include namespace enco { @@ -47,16 +47,20 @@ struct SubnetStruct class SubnetStructBuilder { public: - SubnetStructBuilder(enco::Global *global) : _global{global} - { - // DO NOTHING - } + std::unique_ptr build(const ANNBinder *binder) const; public: - std::unique_ptr build(const ANNBinder *binder) const; + void expr(const ann::Operand *oper, const std::string &base, const std::string &size) + { + _weighted.insert(oper); + _base_exprs[oper] = base; + _size_exprs[oper] = size; + } private: - enco::Global *_global; + std::set _weighted; + std::map _base_exprs; + std::map _size_exprs; }; /**