Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 Arm Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H |
| 25 | #define ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/IGraphPrinter.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 28 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 29 | #include "arm_compute/graph/INodeVisitor.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 30 | |
| 31 | #include <string> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 35 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 36 | { |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 37 | /** Graph printer visitor. */ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 38 | class DotGraphVisitor final : public DefaultNodeVisitor |
| 39 | { |
| 40 | public: |
| 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 Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 55 | void visit(ConcatenateLayerNode &n) override; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 56 | void visit(ConvolutionLayerNode &n) override; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 57 | void visit(DepthwiseConvolutionLayerNode &n) override; |
| 58 | void visit(EltwiseLayerNode &n) override; |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 59 | void visit(FusedConvolutionBatchNormalizationNode &n) override; |
Manuel Bottini | bffb41e | 2019-06-20 16:00:27 +0100 | [diff] [blame] | 60 | void visit(FusedDepthwiseConvolutionBatchNormalizationNode &n) override; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 61 | void visit(NormalizationLayerNode &n) override; |
| 62 | void visit(PoolingLayerNode &n) override; |
| 63 | void default_visit() override; |
| 64 | |
| 65 | private: |
| 66 | std::string _info{}; |
| 67 | }; |
| 68 | |
| 69 | /** Graph printer interface */ |
| 70 | class DotGraphPrinter final : public IGraphPrinter |
| 71 | { |
| 72 | public: |
| 73 | // Inherited methods overridden |
| 74 | void print(const Graph &g, std::ostream &os) override; |
| 75 | |
| 76 | private: |
| 77 | /** Print dot graph header |
| 78 | * |
| 79 | * @param[in] g Graph |
| 80 | * @param[out] os Output stream to use |
| 81 | */ |
| 82 | void print_header(const Graph &g, std::ostream &os); |
| 83 | /** Print dot graph footer |
| 84 | * |
| 85 | * @param[in] g Graph |
| 86 | * @param[out] os Output stream to use |
| 87 | */ |
| 88 | void print_footer(const Graph &g, std::ostream &os); |
| 89 | /** Prints nodes in dot format |
| 90 | * |
| 91 | * @param[in] g Graph |
| 92 | * @param[out] os Output stream to use |
| 93 | */ |
| 94 | void print_nodes(const Graph &g, std::ostream &os); |
| 95 | /** Prints edges in dot format |
| 96 | * |
| 97 | * @param[in] g Graph |
| 98 | * @param[out] os Output stream to use |
| 99 | */ |
| 100 | void print_edges(const Graph &g, std::ostream &os); |
| 101 | |
| 102 | private: |
| 103 | DotGraphVisitor _dot_node_visitor = {}; |
| 104 | }; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 105 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 106 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /* ARM_COMPUTE_GRAPH_DOTGRAPHPRINTER_H */ |