blob: 8ae92e3177f7113aca4cbe92c5e3b753820ccddb [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Giorgio Arena9c67d382021-08-20 15:24:03 +01002 * Copyright (c) 2018-2019,2021 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H
25#define ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H
Georgios Pinitasd8734b52017-12-22 15:27:52 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/ITensorHandle.h"
28#include "arm_compute/graph/Types.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000029#include "arm_compute/runtime/IFunction.h"
30#include "arm_compute/runtime/IMemoryManager.h"
Michalis Spyrou1a569a32019-09-10 17:20:34 +010031#include "arm_compute/runtime/IWeightsManager.h"
Georgios Pinitasd8734b52017-12-22 15:27:52 +000032
33#include <memory>
34
35namespace arm_compute
36{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010037namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000038{
39// Forward declarations
40class Graph;
41class GraphContext;
42class Tensor;
43class INode;
44
45namespace backends
46{
47/** Device backend interface */
48class IDeviceBackend
49{
50public:
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 Barbierb6eb3532018-08-08 13:20:04 +010057 * @param[in,out] ctx Graph context
Georgios Pinitasd8734b52017-12-22 15:27:52 +000058 */
59 virtual void setup_backend_context(GraphContext &ctx) = 0;
Anthony Barbierb6eb3532018-08-08 13:20:04 +010060 /** 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 Pinitasd9eb2752018-04-03 13:44:29 +010065 /** 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 Pinitas3d1489d2018-05-03 20:47:16 +010070 /** Gets a backend memory allocator
71 *
72 * @return Backend memory allocator
73 */
74 virtual IAllocator *backend_allocator() = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000075 /** 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 Pinitasee33ea52018-03-08 16:01:29 +000084 * @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 Pinitasd8734b52017-12-22 15:27:52 +000088 *
89 * @return Backend sub-tensor handle
90 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010091 virtual std::unique_ptr<ITensorHandle>
92 create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000093 /** Configure a backend Node
94 *
95 * @note This creates an appropriate configured backend function for the given node
96 *
97 * @param[in] node The node we want to configure
98 * @param[in] ctx Context to use
99 *
100 * @return Backend execution function
101 */
102 virtual std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) = 0;
103 /** Validate a node
104 *
105 * @param[in] node The node we want to validate
106 *
107 * @return An error status
108 */
Georgios Pinitas28705162018-03-21 20:10:53 +0000109 virtual Status validate_node(INode &node) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000110 /** Create a backend memory manager given its affinity
111 *
112 * @param[in] affinity Memory Manager affinity
113 *
114 * @return Memory manager
115 */
116 virtual std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) = 0;
Michalis Spyrou1a569a32019-09-10 17:20:34 +0100117 /** Create a backend weights manager
118 *
119 * @return Weights manager
120 */
121 virtual std::shared_ptr<arm_compute::IWeightsManager> create_weights_manager() = 0;
Giorgio Arena9c67d382021-08-20 15:24:03 +0100122 /** Synchronize kernels execution on the backend. On GPU, this results in a blocking call waiting for all kernels to be completed. */
123 virtual void sync() = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000124};
125} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100126} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000127} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000128#endif //ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H