Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 1 | /* |
Giorgio Arena | 9c67d38 | 2021-08-20 15:24:03 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019,2021 Arm Limited. |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H |
| 25 | #define ARM_COMPUTE_GRAPH_IDEVICEBACKEND_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/ITensorHandle.h" |
| 28 | #include "arm_compute/graph/Types.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
| 30 | #include "arm_compute/runtime/IMemoryManager.h" |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/IWeightsManager.h" |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 32 | |
| 33 | #include <memory> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 37 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 38 | { |
| 39 | // Forward declarations |
| 40 | class Graph; |
| 41 | class GraphContext; |
| 42 | class Tensor; |
| 43 | class INode; |
| 44 | |
| 45 | namespace backends |
| 46 | { |
| 47 | /** Device backend interface */ |
| 48 | class IDeviceBackend |
| 49 | { |
| 50 | public: |
| 51 | /** Virtual Destructor */ |
| 52 | virtual ~IDeviceBackend() = default; |
| 53 | /** Initializes the backend */ |
| 54 | virtual void initialize_backend() = 0; |
| 55 | /** Setups the given graph context |
| 56 | * |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 57 | * @param[in,out] ctx Graph context |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 58 | */ |
| 59 | virtual void setup_backend_context(GraphContext &ctx) = 0; |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 60 | /** Release the backend specific resources associated to a given graph context |
| 61 | * |
| 62 | * @param[in,out] ctx Graph context |
| 63 | */ |
| 64 | virtual void release_backend_context(GraphContext &ctx) = 0; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 65 | /** Checks if an instantiated backend is actually supported |
| 66 | * |
| 67 | * @return True if the backend is supported else false |
| 68 | */ |
| 69 | virtual bool is_backend_supported() = 0; |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 70 | /** Gets a backend memory allocator |
| 71 | * |
| 72 | * @return Backend memory allocator |
| 73 | */ |
| 74 | virtual IAllocator *backend_allocator() = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 75 | /** Create a backend Tensor |
| 76 | * |
| 77 | * @param[in] tensor The tensor we want to create a backend tensor for |
| 78 | * |
| 79 | * @return Backend tensor handle |
| 80 | */ |
| 81 | virtual std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) = 0; |
| 82 | /** Create a backend Sub-Tensor |
| 83 | * |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 84 | * @param[in] parent Parent sub-tensor handle |
| 85 | * @param[in] shape Shape of the sub-tensor |
| 86 | * @param[in] coords Starting coordinates of the sub-tensor |
| 87 | * @param[in] extend_parent Extends parent shape if true |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 88 | * |
| 89 | * @return Backend sub-tensor handle |
| 90 | */ |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 91 | virtual std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 92 | /** Configure a backend Node |
| 93 | * |
| 94 | * @note This creates an appropriate configured backend function for the given node |
| 95 | * |
| 96 | * @param[in] node The node we want to configure |
| 97 | * @param[in] ctx Context to use |
| 98 | * |
| 99 | * @return Backend execution function |
| 100 | */ |
| 101 | virtual std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) = 0; |
| 102 | /** Validate a node |
| 103 | * |
| 104 | * @param[in] node The node we want to validate |
| 105 | * |
| 106 | * @return An error status |
| 107 | */ |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 108 | virtual Status validate_node(INode &node) = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 109 | /** Create a backend memory manager given its affinity |
| 110 | * |
| 111 | * @param[in] affinity Memory Manager affinity |
| 112 | * |
| 113 | * @return Memory manager |
| 114 | */ |
| 115 | virtual std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) = 0; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 116 | /** Create a backend weights manager |
| 117 | * |
| 118 | * @return Weights manager |
| 119 | */ |
| 120 | virtual std::shared_ptr<arm_compute::IWeightsManager> create_weights_manager() = 0; |
Giorgio Arena | 9c67d38 | 2021-08-20 15:24:03 +0100 | [diff] [blame] | 121 | /** Synchronize kernels execution on the backend. On GPU, this results in a blocking call waiting for all kernels to be completed. */ |
| 122 | virtual void sync() = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 123 | }; |
| 124 | } // namespace backends |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 125 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 126 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 127 | #endif //ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H |