blob: 3a0a7e634e321ad98ded17350a8b61d5c2feab50 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 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 */
Georgios Pinitasee33ea52018-03-08 16:01:29 +000091 virtual std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000092 /** 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 Pinitas28705162018-03-21 20:10:53 +0000108 virtual Status validate_node(INode &node) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000109 /** 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 Spyrou1a569a32019-09-10 17:20:34 +0100116 /** Create a backend weights manager
117 *
118 * @return Weights manager
119 */
120 virtual std::shared_ptr<arm_compute::IWeightsManager> create_weights_manager() = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000121};
122} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100123} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000124} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000125#endif //ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H