Commit db594969 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

add option to nbench to generate only a dot file (#2781)

parent 57d637bc
...@@ -65,9 +65,10 @@ bool pass::VisualizeTree::run_on_module(vector<shared_ptr<Function>>& functions) ...@@ -65,9 +65,10 @@ bool pass::VisualizeTree::run_on_module(vector<shared_ptr<Function>>& functions)
return false; return false;
} }
pass::VisualizeTree::VisualizeTree(const string& file_name, node_modifiers_t nm) pass::VisualizeTree::VisualizeTree(const string& file_name, node_modifiers_t nm, bool dot_only)
: m_name{file_name} : m_name{file_name}
, m_node_modifiers{nm} , m_node_modifiers{nm}
, m_dot_only(dot_only)
{ {
} }
...@@ -177,6 +178,8 @@ void pass::VisualizeTree::render() const ...@@ -177,6 +178,8 @@ void pass::VisualizeTree::render() const
out << "}\n"; out << "}\n";
out.close(); out.close();
if (!m_dot_only)
{
#ifndef _WIN32 #ifndef _WIN32
stringstream ss; stringstream ss;
ss << "dot -T" << get_file_ext() << " " << dot_file << " -o " << m_name; ss << "dot -T" << get_file_ext() << " " << dot_file << " -o " << m_name;
...@@ -188,4 +191,5 @@ void pass::VisualizeTree::render() const ...@@ -188,4 +191,5 @@ void pass::VisualizeTree::render() const
} }
#endif #endif
} }
}
} }
...@@ -41,7 +41,9 @@ class ngraph::pass::VisualizeTree : public ModulePass ...@@ -41,7 +41,9 @@ class ngraph::pass::VisualizeTree : public ModulePass
public: public:
using node_modifiers_t = using node_modifiers_t =
std::function<void(const Node& node, std::vector<std::string>& attributes)>; std::function<void(const Node& node, std::vector<std::string>& attributes)>;
VisualizeTree(const std::string& file_name, node_modifiers_t nm = nullptr); VisualizeTree(const std::string& file_name,
node_modifiers_t nm = nullptr,
bool dot_only = false);
bool run_on_module(std::vector<std::shared_ptr<ngraph::Function>>&) override; bool run_on_module(std::vector<std::shared_ptr<ngraph::Function>>&) override;
static std::string get_file_ext(); static std::string get_file_ext();
...@@ -57,4 +59,5 @@ private: ...@@ -57,4 +59,5 @@ private:
std::unordered_map<std::type_index, std::function<void(const Node&, std::ostream& ss)>> std::unordered_map<std::type_index, std::function<void(const Node&, std::ostream& ss)>>
m_ops_to_details; m_ops_to_details;
node_modifiers_t m_node_modifiers = nullptr; node_modifiers_t m_node_modifiers = nullptr;
bool m_dot_only;
}; };
...@@ -197,6 +197,7 @@ int main(int argc, char** argv) ...@@ -197,6 +197,7 @@ int main(int argc, char** argv)
bool visualize = false; bool visualize = false;
int warmup_iterations = 1; int warmup_iterations = 1;
bool copy_data = true; bool copy_data = true;
bool dot_file = false;
for (size_t i = 1; i < argc; i++) for (size_t i = 1; i < argc; i++)
{ {
...@@ -237,6 +238,10 @@ int main(int argc, char** argv) ...@@ -237,6 +238,10 @@ int main(int argc, char** argv)
{ {
visualize = true; visualize = true;
} }
else if (arg == "--dot")
{
dot_file = true;
}
else if (arg == "-d" || arg == "--directory") else if (arg == "-d" || arg == "--directory")
{ {
directory = argv[++i]; directory = argv[++i];
...@@ -294,6 +299,7 @@ OPTIONS ...@@ -294,6 +299,7 @@ OPTIONS
--timing_detail Gather detailed timing --timing_detail Gather detailed timing
-w|--warmup_iterations Number of warm-up iterations -w|--warmup_iterations Number of warm-up iterations
--no_copy_data Disable copy of input/result data every iteration --no_copy_data Disable copy of input/result data every iteration
--dot Generate graphviz dot file
)###"; )###";
return 1; return 1;
} }
...@@ -339,10 +345,10 @@ OPTIONS ...@@ -339,10 +345,10 @@ OPTIONS
{ {
shared_ptr<Function> f = deserialize(model); shared_ptr<Function> f = deserialize(model);
auto model_file_name = ngraph::file_util::get_file_name(model) + std::string(".") + auto model_file_name = ngraph::file_util::get_file_name(model) + std::string(".") +
pass::VisualizeTree::get_file_ext(); (dot_file ? "dot" : pass::VisualizeTree::get_file_ext());
pass::Manager pass_manager; pass::Manager pass_manager;
pass_manager.register_pass<pass::VisualizeTree>(model_file_name); pass_manager.register_pass<pass::VisualizeTree>(model_file_name, nullptr, true);
pass_manager.run_passes(f); pass_manager.run_passes(f);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment