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_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" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 36 | namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 37 | { |
| 38 | // Forward declarations |
| 39 | class Graph; |
| 40 | class GraphContext; |
| 41 | class Tensor; |
| 42 | class INode; |
| 43 | |
| 44 | namespace backends |
| 45 | { |
| 46 | /** Device backend interface */ |
| 47 | class IDeviceBackend |
| 48 | { |
| 49 | public: |
| 50 | /** Virtual Destructor */ |
| 51 | virtual ~IDeviceBackend() = default; |
| 52 | /** Initializes the backend */ |
| 53 | virtual void initialize_backend() = 0; |
| 54 | /** Setups the given graph context |
| 55 | * |
| 56 | * @param[in] ctx Graph context |
| 57 | */ |
| 58 | virtual void setup_backend_context(GraphContext &ctx) = 0; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 59 | /** Checks if an instantiated backend is actually supported |
| 60 | * |
| 61 | * @return True if the backend is supported else false |
| 62 | */ |
| 63 | virtual bool is_backend_supported() = 0; |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 64 | /** Gets a backend memory allocator |
| 65 | * |
| 66 | * @return Backend memory allocator |
| 67 | */ |
| 68 | virtual IAllocator *backend_allocator() = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 69 | /** Create a backend Tensor |
| 70 | * |
| 71 | * @param[in] tensor The tensor we want to create a backend tensor for |
| 72 | * |
| 73 | * @return Backend tensor handle |
| 74 | */ |
| 75 | virtual std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) = 0; |
| 76 | /** Create a backend Sub-Tensor |
| 77 | * |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 78 | * @param[in] parent Parent sub-tensor handle |
| 79 | * @param[in] shape Shape of the sub-tensor |
| 80 | * @param[in] coords Starting coordinates of the sub-tensor |
| 81 | * @param[in] extend_parent Extends parent shape if true |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 82 | * |
| 83 | * @return Backend sub-tensor handle |
| 84 | */ |
Georgios Pinitas | ee33ea5 | 2018-03-08 16:01:29 +0000 | [diff] [blame] | 85 | 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] | 86 | /** Configure a backend Node |
| 87 | * |
| 88 | * @note This creates an appropriate configured backend function for the given node |
| 89 | * |
| 90 | * @param[in] node The node we want to configure |
| 91 | * @param[in] ctx Context to use |
| 92 | * |
| 93 | * @return Backend execution function |
| 94 | */ |
| 95 | virtual std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) = 0; |
| 96 | /** Validate a node |
| 97 | * |
| 98 | * @param[in] node The node we want to validate |
| 99 | * |
| 100 | * @return An error status |
| 101 | */ |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 102 | virtual Status validate_node(INode &node) = 0; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 103 | /** Create a backend memory manager given its affinity |
| 104 | * |
| 105 | * @param[in] affinity Memory Manager affinity |
| 106 | * |
| 107 | * @return Memory manager |
| 108 | */ |
| 109 | virtual std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) = 0; |
| 110 | }; |
| 111 | } // namespace backends |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 112 | } // namespace graph |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 113 | } // namespace arm_compute |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 114 | #endif //__ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H__ |