Compute Library
 21.11
DotGraphPrinter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
26 #include "arm_compute/core/Error.h"
31 
32 namespace arm_compute
33 {
34 namespace graph
35 {
37 {
38  std::stringstream ss;
39  ss << n.activation_info().activation();
40  _info = ss.str();
41 }
42 
44 {
45  std::stringstream ss;
46  ss << (n.fused_activation().enabled() ? to_string(n.fused_activation().activation()) : "");
47  _info = ss.str();
48 }
49 
51 {
52  std::stringstream ss;
53  ss << "Enabled: " << n.is_enabled();
54  ss << R"( \n )";
55  ss << "Axis: " << n.concatenation_axis();
56  _info = ss.str();
57 }
58 
60 {
61  std::stringstream ss;
62  ss << n.convolution_method();
63  _info = ss.str();
64 }
65 
67 {
68  std::stringstream ss;
70  _info = ss.str();
71 }
72 
74 {
75  std::stringstream ss;
76  ss << n.eltwise_operation();
77  _info = ss.str();
78 }
79 
81 {
83  std::stringstream ss;
84  ss << "FusedConvolutionBatchNormalizationNode";
85  _info = ss.str();
86 }
87 
89 {
91  std::stringstream ss;
92  ss << "FusedConvolutionWithPostOpNode";
93  _info = ss.str();
94 }
95 
97 {
99  std::stringstream ss;
100  ss << "FusedDepthwiseConvolutionBatchNormalizationNode";
101  _info = ss.str();
102 }
103 
105 {
106  std::stringstream ss;
107  ss << n.normalization_info().type();
108  _info = ss.str();
109 }
110 
112 {
113  std::stringstream ss;
114  ss << n.pooling_info().pool_type;
115  ss << R"( \n )";
116  ss << n.pooling_info().pool_size;
117  ss << R"( \n )";
118  ss << n.pooling_info().pad_stride_info;
119  _info = ss.str();
120 }
121 
123 {
125  _info.clear();
126 }
127 
128 const std::string &DotGraphVisitor::info() const
129 {
130  return _info;
131 }
132 
133 void DotGraphPrinter::print(const Graph &g, std::ostream &os)
134 {
135  // Print header
136  print_header(g, os);
137 
138  // Print nodes
139  print_nodes(g, os);
140 
141  // Print edges
142  print_edges(g, os);
143 
144  // Print footer
145  print_footer(g, os);
146 }
147 
148 void DotGraphPrinter::print_header(const Graph &g, std::ostream &os)
149 {
150  // Print graph name
151  std::string graph_name = (g.name().empty()) ? "Graph" : g.name();
152  os << "digraph " << graph_name << "{\n";
153 }
154 
155 void DotGraphPrinter::print_footer(const Graph &g, std::ostream &os)
156 {
158  os << "}\n";
159 }
160 
161 void DotGraphPrinter::print_nodes(const Graph &g, std::ostream &os)
162 {
163  for(const auto &n : g.nodes())
164  {
165  if(n)
166  {
167  // Output node id
168  std::string node_id = std::string("n") + support::cpp11::to_string(n->id());
169  os << node_id << " ";
170 
171  // Output label
172  n->accept(_dot_node_visitor);
173 
174  std::string name = n->name().empty() ? node_id : n->name();
175  auto node_description = _dot_node_visitor.info();
176 
177  os << R"([label = ")" << name << R"( \n )" << n->assigned_target() << R"( \n )" << node_description << R"("])";
178  os << ";\n";
179  }
180  }
181 }
182 
183 void DotGraphPrinter::print_edges(const Graph &g, std::ostream &os)
184 {
185  for(const auto &e : g.edges())
186  {
187  if(e)
188  {
189  std::string source_node_id = std::string("n") + support::cpp11::to_string(e->producer_id());
190  std::string sink_node_id = std::string("n") + support::cpp11::to_string(e->consumer_id());
191  os << source_node_id << " -> " << sink_node_id << " ";
192  const Tensor *t = e->tensor();
193  ARM_COMPUTE_ERROR_ON(t == nullptr);
194  os << R"([label = ")" << t->desc().shape << R"( \n )" << t->desc().data_type << R"( \n )" << t->desc().layout << R"("])";
195  os << ";\n";
196  }
197  }
198 }
199 } // namespace graph
200 } // namespace arm_compute
void default_visit(INode &n) override
Function to be overloaded by the client and implement default behavior for the non-overloaded visitor...
bool enabled() const
Check if initialised.
Definition: Types.h:1559
DataLayoutDimension concatenation_axis() const
Concatenation axis parameter accessor.
const std::vector< std::unique_ptr< Edge > > & edges() const
Returns edges of graph.
Definition: Graph.cpp:189
NormType type() const
Get the normalization type.
Definition: Types.h:1628
std::string to_string(T &&value)
Convert integer and float values to string.
std::stringstream ss(mlgo_str)
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
DepthwiseConvolutionMethod depthwise_convolution_method() const
Depthwise convolution layer method accessor.
ActivationLayerInfo fused_activation() const
Returns fused activation.
EltwiseOperation eltwise_operation() const
Eltwise operation accessor.
const std::string & info() const
Returns the output information of the last visited node.
std::string name() const
Returns graph name.
Definition: Graph.cpp:164
Copyright (c) 2017-2021 Arm Limited.
PoolingLayerInfo pooling_info() const
Pooling metadata accessor.
void print(const Graph &g, std::ostream &os) override
Print graph.
NormalizationLayerInfo normalization_info() const
Normalization info accessor.
TensorDescriptor & desc()
TensorInfo metadata accessor.
Definition: Tensor.cpp:40
Node interface.
Definition: INode.h:46
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
bool is_enabled() const
Enabled parameter accessor.
void visit(ActivationLayerNode &n) override
Visit ActivationLayerNode.
const char * name
std::string to_string(const T &val)
Fallback method: try to use std::to_string:
Definition: TypePrinter.h:79
ConvolutionMethod convolution_method() const
Convolution layer method accessor.
Graph class.
Definition: Graph.h:53
const std::vector< NodeID > & nodes(NodeType type)
Returns graph input nodes.
Definition: Graph.cpp:174
PadStrideInfo pad_stride_info
Definition: Types.h:1261
ActivationLayerInfo activation_info() const
Activation metadata accessor.
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1544
Convolution node.
Tensor object.
Definition: Tensor.h:41