arm_compute v17.09
[platform/upstream/armcl.git] / arm_compute / graph / Graph.h
1 /*
2  * Copyright (c) 2017 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  */
24 #ifndef __ARM_COMPUTE_GRAPH_GRAPH_H__
25 #define __ARM_COMPUTE_GRAPH_GRAPH_H__
26
27 #include "arm_compute/graph/INode.h"
28 #include "arm_compute/graph/Tensor.h"
29 #include "arm_compute/graph/Types.h"
30 #include "support/ToolchainSupport.h"
31
32 #include <memory>
33
34 namespace arm_compute
35 {
36 class IFunction;
37
38 namespace graph
39 {
40 /** Graph class */
41 class Graph final
42 {
43 public:
44     /** Constructor */
45     Graph();
46     /** Destructor */
47     ~Graph();
48     /** Prevent instances from being copy constructed */
49     Graph(const Graph &) = delete;
50     /** Prevent instances from being copy assigned */
51     const Graph &operator=(const Graph &) = delete;
52     /** Prevent instances from being move constructed */
53     Graph(Graph &&) = delete;
54     /** Prevent instances from being move assigned */
55     Graph &operator=(Graph &&) = delete;
56     /** Executes the graph */
57     void run();
58     /** Adds a node to the graph
59      *
60      * @param[in] node Node to add
61      */
62     void add_node(std::unique_ptr<INode> node);
63     /** Adds a tensor to the graph
64      *
65      * @param[in] tensor Tensor to add
66      */
67     void add_tensor(std::unique_ptr<Tensor> tensor);
68     /** Sets an execution hint to the graph
69      *
70      * @note Hint is propagated to the following node and as per name
71      *       its just a hint/preference to be considered by the graph executor
72      *
73      * @param[in] hint execution hint
74      */
75     void set_hint(Hint hint);
76     /** Manually sets the output of the current node
77      *
78      * @param[in] tmp Output info to set
79      */
80     void set_temp(TensorInfo &&tmp);
81
82     /** Sets whether to enable information print out
83      *
84      * @param[in] is_enabled Set to true if need info printed out
85      */
86     void set_info_enablement(bool is_enabled);
87
88 private:
89     class Private;
90     std::unique_ptr<Private> _pimpl; /**< Internal implementation class */
91 };
92
93 /** Overloaded stream operator to add a tensor through its tensor info to the graph
94  *
95  * @param[in, out] graph Graph to add the tensor
96  * @param[in]      info  Tensor information of the tensor to be added
97  *
98  * @return Updated graph
99  */
100 Graph &operator<<(Graph &graph, TensorInfo &&info);
101 /** Overloaded stream operator to add a tensor to the graph
102  *
103  * @param[in, out] graph  Graph to add the tensor
104  * @param[in]      tensor Tensor to be added
105  *
106  * @return Updated graph
107  */
108 Graph &operator<<(Graph &graph, Tensor &&tensor);
109 /** Overloaded stream operator to provide an execution hint to the graph
110  *
111  * @param[in, out] graph Graph to provide the hint to
112  * @param[in]      hint  Execution hint to be considered
113  *
114  * @return Updated graph
115  */
116 Graph &operator<<(Graph &graph, Hint hint);
117 /** Overloaded stream operator to add a node to the graph
118  *
119  * @param[in, out] graph Graph to add the tensor
120  * @param[in]      node  Node to be added
121  *
122  * @return Updated graph
123  */
124 template <typename Node>
125 Graph &operator<<(Graph &graph, Node node)
126 {
127     graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node)));
128     return graph;
129 }
130 } // namespace graph
131 } // namespace arm_compute
132 #endif /* __ARM_COMPUTE_GRAPH_GRAPH_H__ */