[moco-tf] Introduce Restart PhaseRunner (#6667)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 19 Aug 2019 05:05:22 +0000 (14:05 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 19 Aug 2019 05:05:22 +0000 (14:05 +0900)
This will introduce Restart type PhaseRunner that restarts from the beginning when there is any change in the transformation list

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/moco-tf/src/Phase.cpp
compiler/moco-tf/src/Phase.h

index 2f4d0ad..6764691 100644 (file)
@@ -66,5 +66,42 @@ void PhaseRunner<PhaseStrategy::Saturate>::run(const Phase &phase) const
   INFO(l) << "PhaseRunner<Saturate> - done";
 }
 
+void PhaseRunner<PhaseStrategy::Restart>::run(const Phase &phase) const
+{
+  LOGGER(l);
+
+  INFO(l) << "==============================================================";
+  INFO(l) << "PhaseRunner<Restart>";
+
+  INFO(l) << "Initial graph";
+  INFO(l) << fmt(_graph);
+
+  for (bool changed = true; changed;)
+  {
+    changed = false;
+
+    for (auto &tr : phase)
+    {
+      INFO(l) << "--------------------------------------------------------------";
+      INFO(l) << "Before " << transform_name(tr.get());
+
+      if (tr->run(_graph))
+      {
+        changed = true;
+      }
+
+      INFO(l) << "After " << transform_name(tr.get()) << " (changed: " << to_char(changed) << ")";
+      INFO(l) << fmt(_graph);
+
+      if (changed)
+      {
+        break;
+      }
+    }
+  }
+
+  INFO(l) << "PhaseRunner<Restart> - done";
+}
+
 } // namespace tf
 } // namespace moco
index 509eb68..cb1854b 100644 (file)
@@ -36,6 +36,8 @@ enum class PhaseStrategy
 {
   // Run all the transforms until there is no transform that makes a change
   Saturate,
+  // Same as Saturate but will restart from the first when there is a change
+  Restart,
 };
 
 template <PhaseStrategy S> class PhaseRunner;
@@ -55,6 +57,21 @@ private:
   loco::Graph *_graph;
 };
 
+template <> class PhaseRunner<PhaseStrategy::Restart>
+{
+public:
+  PhaseRunner(loco::Graph *graph) : _graph{graph}
+  {
+    // DO NOTHING
+  }
+
+public:
+  void run(const Phase &) const;
+
+private:
+  loco::Graph *_graph;
+};
+
 } // namespace tf
 } // namespace moco