blob: 83deb70348df16e2d39d90422dd5e613e5cb4cb5 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
2 * Copyright (c) 2018 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 */
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 Pinitasd8734b52017-12-22 15:27:52 +000092/** Default setups the graph context if not done manually
93 *
94 * @param[in] ctx Graph Context
95 */
96void setup_default_graph_context(GraphContext &ctx);
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010097} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000098} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010099#endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */