visualize_tree.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
16 
17 #pragma once
18 
19 #include <functional>
20 #include <set>
21 #include <sstream>
22 #include <string>
23 #include <typeindex>
24 #include <typeinfo>
25 #include <unordered_map>
26 #include <utility>
27 
28 #include "ngraph/pass/pass.hpp"
29 
30 class HeightMap;
31 
32 using visualize_tree_ops_map_t =
33  std::unordered_map<ngraph::Node::type_info_t,
34  std::function<void(const ngraph::Node&, std::ostream& ss)>>;
35 
36 namespace ngraph
37 {
38  namespace pass
39  {
40  class NGRAPH_API VisualizeTree : public FunctionPass
41  {
42  public:
43  NGRAPH_RTTI_DECLARATION;
44 
45  using node_modifiers_t =
46  std::function<void(const Node& node, std::vector<std::string>& attributes)>;
47  VisualizeTree(const std::string& file_name,
48  node_modifiers_t nm = nullptr,
49  bool dot_only = false);
50  bool run_on_function(std::shared_ptr<ngraph::Function>) override;
51 
52  void set_ops_to_details(const visualize_tree_ops_map_t& ops_map)
53  {
54  m_ops_to_details = ops_map;
55  }
56 
57  protected:
58  void add_node_arguments(std::shared_ptr<Node> node,
59  std::unordered_map<Node*, HeightMap>& height_maps,
60  size_t& fake_node_ctr);
61  std::string add_attributes(std::shared_ptr<Node> node);
62  virtual std::string get_attributes(std::shared_ptr<Node> node);
63  virtual std::string get_node_name(std::shared_ptr<Node> node);
64  std::string get_constant_value(std::shared_ptr<Node> node, size_t max_elements = 7);
65 
66  void render() const;
67 
68  std::stringstream m_ss;
69  std::string m_name;
70  std::set<std::shared_ptr<Node>> m_nodes_with_attributes;
71  visualize_tree_ops_map_t m_ops_to_details;
72  node_modifiers_t m_node_modifiers = nullptr;
73  bool m_dot_only;
74  static const int max_jump_distance;
75  };
76  }
77 }
Definition: node.hpp:132
Definition: pass.hpp:106
Definition: visualize_tree.hpp:41
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39