[neurun] Refine DotDumper (#6347)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 8 Aug 2019 01:44:01 +0000 (10:44 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 8 Aug 2019 01:44:01 +0000 (10:44 +0900)
- Rename method `dumpIfNeeded` to `dump`
- Rename enum `OPTION` to `DotDumper::Level` and update comments
- Take out config fetching from class `DotDumper`

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/core/src/compiler/Compiler.cc
runtimes/neurun/core/src/dumper/dot/DotDumper.cc
runtimes/neurun/core/src/dumper/dot/DotDumper.h

index 693dc92..b8d3170 100644 (file)
@@ -70,14 +70,16 @@ void Compiler::compile(void)
    *************************************************************/
 
   // dump graph to .dot
-  neurun::dumper::dot::DotDumper dot_dumper(*_graph);
-  dot_dumper.dumpIfNeeded("before_lower");
+  auto dump_level =
+      static_cast<dumper::dot::DotDumper::Level>(util::getConfigInt(util::config::GRAPH_DOT_DUMP));
+  neurun::dumper::dot::DotDumper dot_dumper(*_graph, dump_level);
+  dot_dumper.dump("before_lower");
 
   // Lower: decide backend
   _graph->lower();
   _state = State::LOWERED;
 
-  dot_dumper.dumpIfNeeded("after_lower");
+  dot_dumper.dump("after_lower");
 
   const std::string executor_str = util::getConfigString(util::config::EXECUTOR);
 
index 18c3a95..f20713d 100644 (file)
@@ -34,12 +34,13 @@ namespace dot
 
 using namespace neurun::graph;
 
-void DotDumper::dumpIfNeeded(const std::string &tag)
+void DotDumper::dump(const std::string &tag)
 {
-  if (_option == OPTIONS::DUMP_OFF)
+  if (_level == Level::OFF)
   {
     return;
   }
+
   neurun::dumper::dot::DotBuilder dot_builder;
 
   auto &operations = _graph.operations();
@@ -82,7 +83,7 @@ void DotDumper::dumpIfNeeded(const std::string &tag)
 
   operands.iterate([&](const model::OperandIndex &index, const model::Operand &object) {
     bool showing_cond = false;
-    if (_option == OPTIONS::SHOW_CONSTANTS)
+    if (_level == Level::ALL)
     {
       showing_cond = true;
     }
index a36c956..4ccaac8 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include "graph/Graph.h"
-#include "util/ConfigSource.h"
 
 #ifndef __NEURUN_DUMPER_DOT_DOT_DUMPER_H__
 #define __NEURUN_DUMPER_DOT_DOT_DUMPER_H__
@@ -27,20 +26,18 @@ namespace dumper
 namespace dot
 {
 
-enum OPTIONS
-{
-  DUMP_OFF = 0,  // Don't dump
-  DEFAULT = 1,   // Show default dot graph
-  SHOW_CONSTANTS // Show dot graph with input constants
-};
-
 class DotDumper
 {
 public:
-  DotDumper(const neurun::graph::Graph &graph) : _graph(graph)
+  enum Level
   {
-    _option = util::getConfigInt(util::config::GRAPH_DOT_DUMP);
-  }
+    OFF = 0,               //< Do not dump
+    ALL_BUT_CONSTANTS = 1, //< Emit all operations and operands but constants
+    ALL = 2                //< Emit all operations and operands
+  };
+
+public:
+  DotDumper(const neurun::graph::Graph &graph, Level level) : _graph(graph), _level{level} {}
 
 public:
   /**
@@ -49,11 +46,11 @@ public:
    * @param[in] tag    The name of dot file that would be created
    * @return N/A
    */
-  void dumpIfNeeded(const std::string &tag);
+  void dump(const std::string &tag);
 
 private:
   const neurun::graph::Graph &_graph;
-  uint32_t _option;
+  Level _level;
 };
 
 } // namespace dot