blob: ab1d8b8866ef40320fa3ca46a01f1392cc75fc7e [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
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"
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010028#include "arm_compute/graph/ITensorObject.h"
29#include "arm_compute/graph/SubTensor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010030#include "arm_compute/graph/Tensor.h"
31#include "arm_compute/graph/Types.h"
32#include "support/ToolchainSupport.h"
33
34#include <memory>
35
36namespace arm_compute
37{
38class IFunction;
39
40namespace graph
41{
42/** Graph class */
43class Graph final
44{
45public:
46 /** Constructor */
47 Graph();
48 /** Destructor */
49 ~Graph();
50 /** Prevent instances from being copy constructed */
51 Graph(const Graph &) = delete;
52 /** Prevent instances from being copy assigned */
53 const Graph &operator=(const Graph &) = delete;
54 /** Prevent instances from being move constructed */
55 Graph(Graph &&) = delete;
56 /** Prevent instances from being move assigned */
57 Graph &operator=(Graph &&) = delete;
58 /** Executes the graph */
59 void run();
60 /** Adds a node to the graph
61 *
62 * @param[in] node Node to add
63 */
64 void add_node(std::unique_ptr<INode> node);
65 /** Adds a tensor to the graph
66 *
67 * @param[in] tensor Tensor to add
68 */
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010069 void add_tensor_object(std::unique_ptr<ITensorObject> tensor);
Isabella Gottardib28f29d2017-11-09 17:05:07 +000070 /** Finalizes the current node's configuration
71 */
72 static bool opencl_is_available();
Anthony Barbier2a07e182017-08-04 18:20:27 +010073 /** Manually sets the output of the current node
74 *
75 * @param[in] tmp Output info to set
76 */
77 void set_temp(TensorInfo &&tmp);
Michalis Spyroue4720822017-10-02 17:44:52 +010078
Georgios Pinitasff421f22017-10-04 16:53:58 +010079 /** Returns the graph hints that are currently used
80 *
81 * @return Graph hints
82 */
83 GraphHints &hints();
Anthony Barbier2a07e182017-08-04 18:20:27 +010084
85private:
86 class Private;
87 std::unique_ptr<Private> _pimpl; /**< Internal implementation class */
88};
89
90/** Overloaded stream operator to add a tensor through its tensor info to the graph
91 *
92 * @param[in, out] graph Graph to add the tensor
93 * @param[in] info Tensor information of the tensor to be added
94 *
95 * @return Updated graph
96 */
97Graph &operator<<(Graph &graph, TensorInfo &&info);
98/** Overloaded stream operator to add a tensor to the graph
99 *
100 * @param[in, out] graph Graph to add the tensor
101 * @param[in] tensor Tensor to be added
102 *
103 * @return Updated graph
104 */
105Graph &operator<<(Graph &graph, Tensor &&tensor);
Georgios Pinitase2c82fe2017-10-02 18:51:47 +0100106/** Overloaded stream operator to add a sub-tensor to the graph
107 *
108 * @param[in, out] graph Graph to add the tensor
109 * @param[in] sub_tensor Sub-tensor to be added
110 *
111 * @return Updated graph
112 */
113Graph &operator<<(Graph &graph, SubTensor &&sub_tensor);
Georgios Pinitasff421f22017-10-04 16:53:58 +0100114/** Overloaded stream operator to provide a target hint to the graph
Anthony Barbier2a07e182017-08-04 18:20:27 +0100115 *
Georgios Pinitasff421f22017-10-04 16:53:58 +0100116 * @param[in, out] graph Graph to provide the hint to
117 * @param[in] target_hint Target hint to be considered
Anthony Barbier2a07e182017-08-04 18:20:27 +0100118 *
119 * @return Updated graph
120 */
Georgios Pinitasff421f22017-10-04 16:53:58 +0100121Graph &operator<<(Graph &graph, TargetHint target_hint);
122/** Overloaded stream operator to provide a convolution method hint to the graph
123 *
124 * @param[in, out] graph Graph to provide the hint to
125 * @param[in] conv_method_hint Convolution method hint to be considered
126 *
127 * @return Updated graph
128 */
129Graph &operator<<(Graph &graph, ConvolutionMethodHint conv_method_hint);
Anthony Barbier2a07e182017-08-04 18:20:27 +0100130/** Overloaded stream operator to add a node to the graph
131 *
132 * @param[in, out] graph Graph to add the tensor
133 * @param[in] node Node to be added
134 *
135 * @return Updated graph
136 */
137template <typename Node>
138Graph &operator<<(Graph &graph, Node node)
139{
140 graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node)));
141 return graph;
142}
143} // namespace graph
144} // namespace arm_compute
145#endif /* __ARM_COMPUTE_GRAPH_GRAPH_H__ */