blob: 358d26af816e7e3a9ece6a05aade1f3541d0372d [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 *
Anthony Barbierb6eb3532018-08-08 13:20:04 +010056 * @param[in,out] ctx Graph context
Georgios Pinitasd8734b52017-12-22 15:27:52 +000057 */
58 virtual void setup_backend_context(GraphContext &ctx) = 0;
Anthony Barbierb6eb3532018-08-08 13:20:04 +010059 /** Release the backend specific resources associated to a given graph context
60 *
61 * @param[in,out] ctx Graph context
62 */
63 virtual void release_backend_context(GraphContext &ctx) = 0;
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010064 /** Checks if an instantiated backend is actually supported
65 *
66 * @return True if the backend is supported else false
67 */
68 virtual bool is_backend_supported() = 0;
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010069 /** Gets a backend memory allocator
70 *
71 * @return Backend memory allocator
72 */
73 virtual IAllocator *backend_allocator() = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000074 /** Create a backend Tensor
75 *
76 * @param[in] tensor The tensor we want to create a backend tensor for
77 *
78 * @return Backend tensor handle
79 */
80 virtual std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) = 0;
81 /** Create a backend Sub-Tensor
82 *
Georgios Pinitasee33ea52018-03-08 16:01:29 +000083 * @param[in] parent Parent sub-tensor handle
84 * @param[in] shape Shape of the sub-tensor
85 * @param[in] coords Starting coordinates of the sub-tensor
86 * @param[in] extend_parent Extends parent shape if true
Georgios Pinitasd8734b52017-12-22 15:27:52 +000087 *
88 * @return Backend sub-tensor handle
89 */
Georgios Pinitasee33ea52018-03-08 16:01:29 +000090 virtual std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +000091 /** Configure a backend Node
92 *
93 * @note This creates an appropriate configured backend function for the given node
94 *
95 * @param[in] node The node we want to configure
96 * @param[in] ctx Context to use
97 *
98 * @return Backend execution function
99 */
100 virtual std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) = 0;
101 /** Validate a node
102 *
103 * @param[in] node The node we want to validate
104 *
105 * @return An error status
106 */
Georgios Pinitas28705162018-03-21 20:10:53 +0000107 virtual Status validate_node(INode &node) = 0;
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000108 /** Create a backend memory manager given its affinity
109 *
110 * @param[in] affinity Memory Manager affinity
111 *
112 * @return Memory manager
113 */
114 virtual std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) = 0;
115};
116} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100117} // namespace graph
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000118} // namespace arm_compute
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100119#endif //__ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H__