From 4029ae66af6a4d9be9429dcb3a612d0899d5b2ce 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: Tue, 23 Oct 2018 14:14:16 +0900 Subject: [PATCH] [enco] Enumerate host allocation correctly (#1942) The current implementation("intermediates") cannot enumerate a bag as a host allocation if this bag is shared by multiple ANN subnet, but not accessed by host (ANN-incompatible) block. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/CppCode.cpp | 75 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/contrib/enco/core/src/CppCode.cpp b/contrib/enco/core/src/CppCode.cpp index 7ef0cb8..db24a3a 100644 --- a/contrib/enco/core/src/CppCode.cpp +++ b/contrib/enco/core/src/CppCode.cpp @@ -66,6 +66,79 @@ private: uint32_t _var_count = 0; }; +/** + * @brief Enumerate a set of Bag accessed by a given instruction + * + * Supported instruction: + * "Shuffle" + */ +class AccessedBagAccumulator : public coco::Instr::Visitor +{ +public: + AccessedBagAccumulator(std::set *out) : _out{out} + { + // Validate "out" + assert(_out != nullptr); + } + +public: + void visit(const coco::Shuffle *shuffle) override + { + assert(shuffle->from() != nullptr); + assert(shuffle->into() != nullptr); + + _out->insert(shuffle->from()); + _out->insert(shuffle->into()); + } + +private: + std::set *_out; +}; + +/** + * @brief Return a set of bags that SHOULD have a host allocation + */ +std::set hosted(const enco::Code *code) +{ + std::set res; + + auto m = code->module(); + auto ann_ctx = enco::SubnetManager::context(m); + + for (auto blk = m->block()->head(); blk; blk = blk->next()) + { + if (auto ann_binder = ann_ctx->find(blk)) + { + // Case: The current block is ANN-compatible + + // Each ANN input SHOULD have a corresponding host allocation + for (uint32_t n = 0; n < ann_binder->module()->input()->size(); ++n) + { + res.insert(ann_binder->input(n)); + } + + // Each ANN output SHOULD have a corresponding host allocation + for (uint32_t n = 0; n < ann_binder->module()->output()->size(); ++n) + { + res.insert(ann_binder->output(n)); + } + } + else + { + // Every bag that ANN-incompatible block accesses SHOULD have a corresponding host allocation + AccessedBagAccumulator acc{&res}; + + for (auto ins = blk->instr()->head(); ins; ins = ins->next()) + { + ins->accept(acc); + } + } + } + + return res; +} + +// WARN Deprecated /** @brief Return a set of Bag to be allocated */ // NOTE An input/output bag may be included in the retrun set of "intermediates" std::set intermediates(const enco::Code *code) @@ -244,7 +317,7 @@ void CppCode::dump(std::ostream &os) const } // Set dedicated memory reigion for intermediate buffer(s) - for (const auto &bag : intermediates(_code)) + for (const auto &bag : hosted(_code)) { // Skip if a bag is already allocated if (mem.member(bag)) -- 2.7.4