Compute Library
 23.08
IDeviceBackend.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019,2021 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  */
24 #ifndef ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H
25 #define ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H
26 
32 
33 #include <memory>
34 
35 namespace arm_compute
36 {
37 namespace graph
38 {
39 // Forward declarations
40 class Graph;
41 class GraphContext;
42 class Tensor;
43 class INode;
44 
45 namespace backends
46 {
47 /** Device backend interface */
49 {
50 public:
51  /** Virtual Destructor */
52  virtual ~IDeviceBackend() = default;
53  /** Initializes the backend */
54  virtual void initialize_backend() = 0;
55  /** Setups the given graph context
56  *
57  * @param[in,out] ctx Graph context
58  */
59  virtual void setup_backend_context(GraphContext &ctx) = 0;
60  /** 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;
65  /** 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;
70  /** Gets a backend memory allocator
71  *
72  * @return Backend memory allocator
73  */
74  virtual IAllocator *backend_allocator() = 0;
75  /** 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  *
84  * @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
88  *
89  * @return Backend sub-tensor handle
90  */
91  virtual std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) = 0;
92  /** 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  */
108  virtual Status validate_node(INode &node) = 0;
109  /** 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;
116  /** Create a backend weights manager
117  *
118  * @return Weights manager
119  */
120  virtual std::shared_ptr<arm_compute::IWeightsManager> create_weights_manager() = 0;
121  /** Synchronize kernels execution on the backend. On GPU, this results in a blocking call waiting for all kernels to be completed. */
122  virtual void sync() = 0;
123 };
124 } // namespace backends
125 } // namespace graph
126 } // namespace arm_compute
127 #endif //ARM_COMPUTE_GRAPH_IDEVICEBACKEND_H
arm_compute::graph::backends::IDeviceBackend::~IDeviceBackend
virtual ~IDeviceBackend()=default
Virtual Destructor.
IWeightsManager.h
arm_compute::graph::backends::IDeviceBackend::is_backend_supported
virtual bool is_backend_supported()=0
Checks if an instantiated backend is actually supported.
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::graph::backends::IDeviceBackend
Device backend interface.
Definition: IDeviceBackend.h:48
arm_compute::graph::Tensor
Tensor object.
Definition: Tensor.h:41
arm_compute::graph::backends::IDeviceBackend::release_backend_context
virtual void release_backend_context(GraphContext &ctx)=0
Release the backend specific resources associated to a given graph context.
arm_compute::graph::MemoryManagerAffinity
MemoryManagerAffinity
Backend Memory Manager affinity.
Definition: Types.h:257
arm_compute::graph::backends::IDeviceBackend::validate_node
virtual Status validate_node(INode &node)=0
Validate a node.
arm_compute::graph::backends::IDeviceBackend::configure_node
virtual std::unique_ptr< arm_compute::IFunction > configure_node(INode &node, GraphContext &ctx)=0
Configure a backend Node.
arm_compute::graph::backends::IDeviceBackend::backend_allocator
virtual IAllocator * backend_allocator()=0
Gets a backend memory allocator.
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
IMemoryManager.h
arm_compute::graph::INode
Node interface.
Definition: INode.h:46
arm_compute::IAllocator
Allocator interface.
Definition: IAllocator.h:35
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::detail::ObjectType::Tensor
@ Tensor
arm_compute::graph::backends::IDeviceBackend::create_tensor
virtual std::unique_ptr< ITensorHandle > create_tensor(const Tensor &tensor)=0
Create a backend Tensor.
arm_compute::graph::backends::IDeviceBackend::initialize_backend
virtual void initialize_backend()=0
Initializes the backend.
arm_compute::Coordinates
Coordinates of an item.
Definition: Coordinates.h:37
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:66
Types.h
arm_compute::graph::backends::IDeviceBackend::create_weights_manager
virtual std::shared_ptr< arm_compute::IWeightsManager > create_weights_manager()=0
Create a backend weights manager.
IFunction.h
arm_compute::graph::backends::IDeviceBackend::create_subtensor
virtual std::unique_ptr< ITensorHandle > create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent)=0
Create a backend Sub-Tensor.
arm_compute::graph::backends::IDeviceBackend::create_memory_manager
virtual std::shared_ptr< arm_compute::IMemoryManager > create_memory_manager(MemoryManagerAffinity affinity)=0
Create a backend memory manager given its affinity.
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::graph::backends::IDeviceBackend::setup_backend_context
virtual void setup_backend_context(GraphContext &ctx)=0
Setups the given graph context.
arm_compute::graph::GraphContext
Graph context.
Definition: GraphContext.h:57
arm_compute::graph::ITensorHandle
Tensor handle interface object.
Definition: ITensorHandle.h:38
ITensorHandle.h
arm_compute::graph::backends::IDeviceBackend::sync
virtual void sync()=0
Synchronize kernels execution on the backend.