blob: f28cb1ab42f73035031db70c84a0d8cca354ac59 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
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 Pinitasd9eb2752018-04-03 13:44:29 +010024#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"
31
32#include <memory>
33
34namespace arm_compute
35{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010036namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +000037{
38// Forward declarations
39class Graph;
40class GraphContext;
41class Tensor;
42class INode;
43
44namespace backends
45{
46/** Device backend interface */
47class IDeviceBackend
48{
49public:
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 Pinitasd9eb2752018-04-03 13:44:29 +010059 /** 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 Pinitas3d1489d2018-05-03 20:47:16 +010064 /** Gets a backend memory allocator
65 *
66 * @return Backend memory allocator
67 */
68 virtual IAllocator *backend_allocator() = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000069 /** 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 Pinitasee33ea52018-03-08 16:01:29 +000078 * @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 Pinitasd8734b52017-12-22 15:27:52 +000082 *
83 * @return Backend sub-tensor handle
84 */
Georgios Pinitasee33ea52018-03-08 16:01:29 +000085 virtual std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000086 /** 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 Pinitas28705162018-03-21 20:10:53 +0000102 virtual Status validate_node(INode &node) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000103 /** 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 Pinitasd9eb2752018-04-03 13:44:29 +0100112} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000113} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100114#endif //__ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H__