blob: 9d2ea46fdea817f837aed519e7cc1f8d82001638 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
giuros01acce5042019-02-21 17:32:34 +00002 * Copyright (c) 2018-2019 ARM Limited.
Georgios Pinitasd8734b52017-12-22 15:27:52 +00003 *
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 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010024#ifndef __ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H__
25#define __ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H__
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/IGraphPrinter.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000028
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010029#include "arm_compute/graph/INodeVisitor.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000030
31#include <string>
32
33namespace arm_compute
34{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010035namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000036{
Alex Gildayc357c472018-03-21 13:54:09 +000037/** Graph printer visitor. */
Georgios Pinitasd8734b52017-12-22 15:27:52 +000038class DotGraphVisitor final : public DefaultNodeVisitor
39{
40public:
41 /** Default Constructor **/
42 DotGraphVisitor() = default;
43 /** Returns the output information of the last visited node
44 *
45 * @return Information of the last visited node
46 */
47 const std::string &info() const;
48
49 // Reveal parent method
50 using DefaultNodeVisitor::visit;
51
52 // Inherited methods overridden
53 void visit(ActivationLayerNode &n) override;
54 void visit(BatchNormalizationLayerNode &n) override;
Georgios Pinitase2220552018-07-20 13:23:44 +010055 void visit(ConcatenateLayerNode &n) override;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000056 void visit(ConvolutionLayerNode &n) override;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000057 void visit(DepthwiseConvolutionLayerNode &n) override;
58 void visit(EltwiseLayerNode &n) override;
giuros01acce5042019-02-21 17:32:34 +000059 void visit(FusedConvolutionBatchNormalizationNode &n) override;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000060 void visit(NormalizationLayerNode &n) override;
61 void visit(PoolingLayerNode &n) override;
62 void default_visit() override;
63
64private:
65 std::string _info{};
66};
67
68/** Graph printer interface */
69class DotGraphPrinter final : public IGraphPrinter
70{
71public:
72 // Inherited methods overridden
73 void print(const Graph &g, std::ostream &os) override;
74
75private:
76 /** Print dot graph header
77 *
78 * @param[in] g Graph
79 * @param[out] os Output stream to use
80 */
81 void print_header(const Graph &g, std::ostream &os);
82 /** Print dot graph footer
83 *
84 * @param[in] g Graph
85 * @param[out] os Output stream to use
86 */
87 void print_footer(const Graph &g, std::ostream &os);
88 /** Prints nodes in dot format
89 *
90 * @param[in] g Graph
91 * @param[out] os Output stream to use
92 */
93 void print_nodes(const Graph &g, std::ostream &os);
94 /** Prints edges in dot format
95 *
96 * @param[in] g Graph
97 * @param[out] os Output stream to use
98 */
99 void print_edges(const Graph &g, std::ostream &os);
100
101private:
102 DotGraphVisitor _dot_node_visitor = {};
103};
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100104} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000105} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100106#endif /* __ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H__ */