[enco] Generate loops correctly (#1409)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 10 Sep 2018 00:07:28 +0000 (09:07 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 10 Sep 2018 00:07:28 +0000 (09:07 +0900)
The current implementation of LoopGen assumes that Shuffle is fully
specified over the destination bag.

While previous commit addresses one specific issue, it turns out that
LoopGen still suffers from various asserts during execution, and
generates incorrect code.

This commit rewrites LoopGen to depend on TransferSequence instead of
directly using Shuffle instruction to address all of remaining issues.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/CppGen/Host.cpp

index 63bc251..0e3b1bf 100644 (file)
@@ -163,10 +163,9 @@ using TransferNest = std::vector<TransferLoop>;
 /**
  * @brief Construct nested transfer loop-nest that correponds to a given Shuffle instruction
  */
-TransferNest as_nest(const coco::Shuffle *shuffle)
+TransferNest as_nest(const TransferSequence &seq)
 {
   TransferNest nest;
-  TransferSequence seq = as_transfer_sequence(shuffle);
 
   auto beg = seq.begin();
   auto end = seq.end();
@@ -218,9 +217,10 @@ private:
     //
     // Analyze 'Shuffle' pattern, and convert it as nested loops
     //
-    auto nest = as_nest(shuffle);
-    assert(shuffle->into()->size() % loop_count(nest) == 0);
-    uint32_t window = shuffle->into()->size() / loop_count(nest);
+    auto tseq = as_transfer_sequence(shuffle);
+    auto nest = as_nest(tseq);
+    assert(tseq.size() % loop_count(nest) == 0);
+    uint32_t window = tseq.size() / loop_count(nest);
 
     //
     // Generate loop body
@@ -255,8 +255,8 @@ private:
       const auto src_base = pp::fmt("reinterpret_cast<const float *>(", _mem.base(from), ")");
       const auto dst_base = pp::fmt("reinterpret_cast<float *>(", _mem.base(into), ")");
 
-      loop_body.front().append(dst_base, "[", dst_index, " + ", n, "] = ", src_base, "[", src_index,
-                               " + ", shuffle->at(n).value(), "];");
+      loop_body.front().append(dst_base, "[", dst_index, " + ", tseq.at(n).into(), "] = ", src_base,
+                               "[", src_index, " + ", tseq.at(n).from(), "];");
     }
 
     pp::LinearDocument res;