From 64317ec980d35dd44f23d5a4dd8edab0b200c27d Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 8 Aug 2019 10:44:01 +0900 Subject: [PATCH] [neurun] Refine DotDumper (#6347) - 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 --- runtimes/neurun/core/src/compiler/Compiler.cc | 8 +++++--- runtimes/neurun/core/src/dumper/dot/DotDumper.cc | 7 ++++--- runtimes/neurun/core/src/dumper/dot/DotDumper.h | 23 ++++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/runtimes/neurun/core/src/compiler/Compiler.cc b/runtimes/neurun/core/src/compiler/Compiler.cc index 693dc92..b8d3170 100644 --- a/runtimes/neurun/core/src/compiler/Compiler.cc +++ b/runtimes/neurun/core/src/compiler/Compiler.cc @@ -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(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); diff --git a/runtimes/neurun/core/src/dumper/dot/DotDumper.cc b/runtimes/neurun/core/src/dumper/dot/DotDumper.cc index 18c3a95..f20713d 100644 --- a/runtimes/neurun/core/src/dumper/dot/DotDumper.cc +++ b/runtimes/neurun/core/src/dumper/dot/DotDumper.cc @@ -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; } diff --git a/runtimes/neurun/core/src/dumper/dot/DotDumper.h b/runtimes/neurun/core/src/dumper/dot/DotDumper.h index a36c956..4ccaac8 100644 --- a/runtimes/neurun/core/src/dumper/dot/DotDumper.h +++ b/runtimes/neurun/core/src/dumper/dot/DotDumper.h @@ -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 -- 2.7.4