blob: 2fa2f3b62711e0cbf99c8b664a160b1410b85c92 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Georgios Pinitas7097e3c2019-02-20 18:11:42 +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_UTILS_H__
25#define __ARM_COMPUTE_GRAPH_UTILS_H__
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/Graph.h"
28#include "arm_compute/graph/PassManager.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000029
30namespace arm_compute
31{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010032namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000033{
34// Forward Declaration
35class GraphContext;
36
37/** Returns the tensor descriptor of a given tensor
38 *
39 * @param[in] g Graph that the tensor belongs to
40 * @param[in] tid Tensor ID
41 *
42 * @return Tensor descriptor if tensor was found else empty descriptor
43 */
44inline TensorDescriptor get_tensor_descriptor(const Graph &g, TensorID tid)
45{
46 const Tensor *tensor = g.tensor(tid);
47 return (tensor != nullptr) ? tensor->desc() : TensorDescriptor();
48}
49/** Sets an accessor on a given tensor
50 *
51 * @param[in] tensor Tensor to set the accessor to
52 * @param[in] accessor Accessor to set
53 *
54 * @return True if accessor was set else false
55 */
56inline Status set_tensor_accessor(Tensor *tensor, std::unique_ptr<ITensorAccessor> accessor)
57{
58 ARM_COMPUTE_RETURN_ERROR_ON(tensor == nullptr);
59 tensor->set_accessor(std::move(accessor));
60
61 return Status{};
62}
63/** Checks if a specific target is supported
64 *
65 * @param[in] target Target to check
66 *
67 * @return True if target is support else false
68 */
69bool is_target_supported(Target target);
70/** Returns default target for execution
71 *
72 * @note If an OpenCL backend exists then OpenCL is returned,
73 * else if the NEON backend exists returns NEON as target.
74 * If no backends are registered an error is raised.
75 *
76 * @return Default target
77 */
78Target get_default_target();
79/** Forces a single target to all graph constructs
80 *
81 * @param[in] g Graph to force target on
82 * @param[in] target Target to force
83 */
84void force_target_to_graph(Graph &g, Target target);
85/** Creates a default @ref PassManager
86 *
Georgios Pinitasfbb80542018-03-27 17:15:49 +010087 * @param[in] target Target to create the pass manager for
88 *
Georgios Pinitasd8734b52017-12-22 15:27:52 +000089 * @return A PassManager with default mutating passes
90 */
Georgios Pinitasfbb80542018-03-27 17:15:49 +010091PassManager create_default_pass_manager(Target target);
Georgios Pinitas7097e3c2019-02-20 18:11:42 +000092/** Setups requested backend context if it exists, is supported and hasn't been initialized already.
Georgios Pinitasd8734b52017-12-22 15:27:52 +000093 *
Georgios Pinitas7097e3c2019-02-20 18:11:42 +000094 * @param[in,out] ctx Graph Context.
95 * @param[in] target Target to setup the backend for.
Georgios Pinitasd8734b52017-12-22 15:27:52 +000096 */
Georgios Pinitas7097e3c2019-02-20 18:11:42 +000097void setup_requested_backend_context(GraphContext &ctx, Target target);
Anthony Barbierb6eb3532018-08-08 13:20:04 +010098/** Default releases the graph context if not done manually
99 *
100 * @param[in,out] ctx Graph Context
101 */
102void release_default_graph_context(GraphContext &ctx);
Georgios Pinitascac13b12018-04-27 19:07:19 +0100103/** Get size of a tensor's given dimension depending on its layout
104 *
105 * @param[in] descriptor Descriptor
106 * @param[in] data_layout_dimension Tensor data layout dimension
107 *
108 * @return Size of requested dimension
109 */
110size_t get_dimension_size(const TensorDescriptor &descriptor, const DataLayoutDimension data_layout_dimension);
111/** Get index of a tensor's given dimension depending on its layout
112 *
Georgios Pinitas9e4824c2019-04-12 13:15:58 +0100113 * @param[in] data_layout Data layout of the tensor
Georgios Pinitascac13b12018-04-27 19:07:19 +0100114 * @param[in] data_layout_dimension Tensor data layout dimension
115 *
116 * @return Idx of given dimension
117 */
Georgios Pinitas9e4824c2019-04-12 13:15:58 +0100118size_t get_dimension_idx(DataLayout data_layout, const DataLayoutDimension data_layout_dimension);
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100119/** Get the list of driving nodes of a given node
120 *
121 * @param[in] node Node to find the driving node of
122 *
123 * @return A list with the driving node of a given node
124 */
125std::vector<NodeIdxPair> get_driving_nodes(const INode &node);
126/** Configures tensor
127 *
128 * @param[in, out] tensor Tensor to configure
129 */
130void configure_tensor(Tensor *tensor);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100131} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000132} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100133#endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */