Unverified Commit e45caeb9 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

enable visualize graph even if graphviz is not installed because it just doesn't matter (#2225)

parent fb17d2b7
...@@ -151,9 +151,8 @@ std::string pass::VisualizeTree::get_file_ext() ...@@ -151,9 +151,8 @@ std::string pass::VisualizeTree::get_file_ext()
void pass::VisualizeTree::render() const void pass::VisualizeTree::render() const
{ {
#ifdef GRAPHVIZ_FOUND auto dot_file = m_name + ".dot";
auto tmp_file = m_name + ".tmp"; ofstream out(dot_file);
ofstream out(tmp_file);
if (out) if (out)
{ {
out << "digraph ngraph\n{\n"; out << "digraph ngraph\n{\n";
...@@ -163,15 +162,12 @@ void pass::VisualizeTree::render() const ...@@ -163,15 +162,12 @@ void pass::VisualizeTree::render() const
stringstream ss; stringstream ss;
ss << "dot -T" << get_file_ext() << " " << tmp_file << " -o " << m_name; ss << "dot -T" << get_file_ext() << " " << dot_file << " -o " << m_name;
auto cmd = ss.str(); auto cmd = ss.str();
auto stream = popen(cmd.c_str(), "r"); auto stream = popen(cmd.c_str(), "r");
if (stream) if (stream)
{ {
pclose(stream); pclose(stream);
} }
remove(tmp_file.c_str());
} }
#endif
} }
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "ngraph/function.hpp" #include "ngraph/function.hpp"
#include "ngraph/graph_util.hpp" #include "ngraph/graph_util.hpp"
#include "ngraph/ngraph.hpp" #include "ngraph/ngraph.hpp"
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/serializer.hpp" #include "ngraph/serializer.hpp"
#include "util/all_close.hpp" #include "util/all_close.hpp"
#include "util/autodiff/backprop_function.hpp" #include "util/autodiff/backprop_function.hpp"
...@@ -409,3 +411,16 @@ TEST(graph_util, test_subgraph_topological_sort_control_dependencies) ...@@ -409,3 +411,16 @@ TEST(graph_util, test_subgraph_topological_sort_control_dependencies)
std::list<std::shared_ptr<Node>> expected{A, D, add, mul}; std::list<std::shared_ptr<Node>> expected{A, D, add, mul};
ASSERT_EQ(expected, sorted); ASSERT_EQ(expected, sorted);
} }
TEST(pass, visualize_tree)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto C = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>((A + B) * C, ParameterVector{A, B, C});
ngraph::pass::Manager pm;
pm.register_pass<pass::VisualizeTree>("test_viz.png");
pm.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