Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
| 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 Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_GRAPH_UTILS_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_UTILS_H__ |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/Graph.h" |
| 28 | #include "arm_compute/graph/PassManager.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 32 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 33 | { |
| 34 | // Forward Declaration |
| 35 | class 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 | */ |
| 44 | inline 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 | */ |
| 56 | inline 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 | */ |
| 69 | bool 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 | */ |
| 78 | Target 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 | */ |
| 84 | void force_target_to_graph(Graph &g, Target target); |
| 85 | /** Creates a default @ref PassManager |
| 86 | * |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 87 | * @param[in] target Target to create the pass manager for |
| 88 | * |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 89 | * @return A PassManager with default mutating passes |
| 90 | */ |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 91 | PassManager create_default_pass_manager(Target target); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 92 | /** Default setups the graph context if not done manually |
| 93 | * |
| 94 | * @param[in] ctx Graph Context |
| 95 | */ |
| 96 | void setup_default_graph_context(GraphContext &ctx); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 97 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 98 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 99 | #endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */ |