blob: e3217e70952f8d2f4ef3ab1d3057891325a83aa4 [file] [log] [blame]
Georgios Pinitase2c82fe2017-10-02 18:51:47 +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_SUBGRAPH_H__
25#define __ARM_COMPUTE_GRAPH_SUBGRAPH_H__
26
27#include "arm_compute/graph/Graph.h"
28#include "arm_compute/graph/INode.h"
29#include "arm_compute/graph/ITensorObject.h"
30#include "arm_compute/graph/SubTensor.h"
31#include "arm_compute/graph/Tensor.h"
32#include "arm_compute/graph/Types.h"
33#include "arm_compute/runtime/IFunction.h"
34
35#include <memory>
36
37namespace arm_compute
38{
39namespace graph
40{
41/** SubGraph class */
42class SubGraph
43{
44public:
45 /** Constructor */
46 SubGraph();
47 /** Adds a node to the graph
48 *
49 * @param[in] node Node to add
50 */
51 void add_node(std::unique_ptr<INode> node);
52 /** Adds a tensor to the graph
53 *
54 * @param[in] tensor Tensor to add
55 */
56 void add_tensor_object(std::unique_ptr<ITensorObject> tensor);
57 /** Constructs a graph from a subgraph
58 *
Georgios Pinitas1250a5a2018-01-02 13:27:37 +000059 * @param[in] ctx Parent graph context
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010060 * @param[in] input Input to the graph
61 * @param[in] output Output to the graph
62 *
63 * @return A graph
64 */
Georgios Pinitas1250a5a2018-01-02 13:27:37 +000065 std::unique_ptr<Graph> construct(const GraphContext &ctx, std::unique_ptr<ITensorObject> input, std::unique_ptr<ITensorObject> output);
Georgios Pinitase2c82fe2017-10-02 18:51:47 +010066 /** Checks if the subgraph has an input
67 *
68 * @return True if the sub-graph has an input else false
69 */
70 bool has_input() const;
71 /** Checks if the subgraph has an output
72 *
73 * @return True if the sub-graph has an output else false
74 */
75 bool has_output() const;
76
77private:
78 std::vector<std::unique_ptr<INode>> _nodes;
79 std::unique_ptr<ITensorObject> _input;
80 std::unique_ptr<ITensorObject> _output;
81};
82
83SubGraph &operator<<(SubGraph &graph, Tensor &&tensor);
84SubGraph &operator<<(SubGraph &graph, SubTensor &&sub_tensor);
85
86template <typename Node>
87SubGraph &operator<<(SubGraph &sub_graph, Node node)
88{
89 sub_graph.add_node(arm_compute::support::cpp14::make_unique<Node>(std::move(node)));
90 return sub_graph;
91}
92} // namespace graph
93} // namespace arm_compute
94#endif /* __ARM_COMPUTE_GRAPH_INODE_H__ */