Compute Library
 21.02
GCDeviceBackend.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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  */
25 
35 
43 
45 
46 namespace arm_compute
47 {
48 namespace graph
49 {
50 namespace backends
51 {
52 /** Register GLES backend */
53 static detail::BackendRegistrar<GCDeviceBackend> GCDeviceBackend_registrar(Target::GC);
54 
56  : _initialized(false), _allocator()
57 {
58 }
59 
61 {
62  // Setup Scheduler
64 }
65 
67 {
68  //Nothing to do
69  ARM_COMPUTE_UNUSED(ctx);
70 }
71 
73 {
74  // Force backend initialization
75  if(!_initialized)
76  {
78  _initialized = true;
79  }
80 
81  // Setup a management backend
82  if(ctx.memory_management_ctx(Target::GC) == nullptr)
83  {
84  MemoryManagerContext mm_ctx;
85  mm_ctx.target = Target::GC;
88  mm_ctx.cross_group = std::make_shared<MemoryGroup>(mm_ctx.cross_mm);
89  mm_ctx.allocator = &_allocator;
90 
91  ctx.insert_memory_management_ctx(std::move(mm_ctx));
92  }
93 }
94 
96 {
98 }
99 
101 {
102  return &_allocator;
103 }
104 
105 std::unique_ptr<ITensorHandle> GCDeviceBackend::create_tensor(const Tensor &tensor)
106 {
107  // Get tensor descriptor
108  const TensorDescriptor &tensor_desc = tensor.desc();
109  ARM_COMPUTE_ERROR_ON(tensor_desc.target != Target::GC);
110 
111  // Create backend tensor handle
112  TensorInfo info(tensor_desc.shape, 1, tensor_desc.data_type, tensor_desc.quant_info);
113  info.set_data_layout(tensor_desc.layout);
114 
115  return std::make_unique<GCTensorHandle>(info);
116 }
117 
118 std::unique_ptr<ITensorHandle> GCDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent)
119 {
120  ARM_COMPUTE_UNUSED(parent, shape, coords, extend_parent);
121  ARM_COMPUTE_ERROR("GLES backend has no sub-tensor support!");
122  return nullptr;
123 }
124 
125 std::unique_ptr<arm_compute::IFunction> GCDeviceBackend::configure_node(INode &node, GraphContext &ctx)
126 {
127  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Configuring GC node with ID : " << node.id() << std::endl);
129 
130  // Configure node
131  return GCFunctionFactory::create(&node, ctx);
132 }
133 
135 {
136  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GC node with ID : " << node.id() << std::endl);
138 
139  return GCNodeValidator::validate(&node);
140 }
141 
142 std::shared_ptr<arm_compute::IMemoryManager> GCDeviceBackend::create_memory_manager(MemoryManagerAffinity affinity)
143 {
144  if(affinity == MemoryManagerAffinity::Offset)
145  {
146  ARM_COMPUTE_LOG_GRAPH_WARNING("GC Backend does not support offset affinity memory management!");
147  return nullptr;
148  }
149 
150  auto lifetime_mgr = std::make_shared<BlobLifetimeManager>();
151  auto pool_mgr = std::make_shared<PoolManager>();
152  auto mm = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
153 
154  return mm;
155 }
156 
157 std::shared_ptr<arm_compute::IWeightsManager> GCDeviceBackend::create_weights_manager()
158 {
159  return nullptr;
160 }
161 } // namespace backends
162 } // namespace graph
163 } // namespace arm_compute
static std::unique_ptr< arm_compute::IFunction > create(INode *node, GraphContext &ctx)
Create a backend execution function depending on the node type.
std::shared_ptr< arm_compute::IWeightsManager > create_weights_manager() override
Create a backend weights manager.
Shape of a tensor.
Definition: TensorShape.h:39
std::unique_ptr< ITensorHandle > create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) override
Create a backend Sub-Tensor.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
Target assigned_target() const
Returns assigned target for this node.
Definition: INode.cpp:198
IAllocator * backend_allocator() override
Gets a backend memory allocator.
static Status validate(INode *node)
Validate a node.
std::shared_ptr< arm_compute::IMemoryGroup > cross_group
Cross-function memory group.
Definition: GraphContext.h:45
Status validate_node(INode &node) override
Validate a node.
bool insert_memory_management_ctx(MemoryManagerContext &&memory_ctx)
Inserts a memory manager context.
bool is_backend_supported() override
Checks if an instantiated backend is actually supported.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void initialize_backend() override
Initializes the backend.
Status class.
Definition: Error.h:52
bool opengles31_is_available()
Check if the OpenGL ES 3.1 API is available at runtime.
Definition: OpenGLES.cpp:160
Copyright (c) 2017-2021 Arm Limited.
void release_backend_context(GraphContext &ctx) override
Release the backend specific resources associated to a given graph context.
TensorDescriptor & desc()
TensorInfo metadata accessor.
Definition: Tensor.cpp:40
static GCScheduler & get()
Access the scheduler singleton.
Definition: GCScheduler.cpp:70
GLES compute capable target device.
QuantizationInfo quant_info
Quantization info.
Node interface.
Definition: INode.h:45
ITensorInfo & set_data_layout(const DataLayout &data_layout) override
Set the data layout of the tensor.
Definition: TensorInfo.cpp:386
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
std::unique_ptr< arm_compute::IFunction > configure_node(INode &node, GraphContext &ctx) override
Configure a backend Node.
Coordinates of an item.
Definition: Coordinates.h:37
NodeID id() const
Returns node&#39;s ID.
Definition: INode.cpp:102
Tensor handle interface object.
Definition: ITensorHandle.h:38
void setup_backend_context(GraphContext &ctx) override
Setups the given graph context.
std::shared_ptr< arm_compute::IMemoryManager > intra_mm
Intra-function memory manager.
Definition: GraphContext.h:43
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_LOG_GRAPH_WARNING(x)
Definition: Logger.h:58
std::shared_ptr< arm_compute::IMemoryManager > cross_mm
Cross-function memory manager.
Definition: GraphContext.h:44
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50
Contains structs required for memory management.
Definition: GraphContext.h:40
std::shared_ptr< arm_compute::IMemoryManager > create_memory_manager(MemoryManagerAffinity affinity) override
Create a backend memory manager given its affinity.
Allocator interface.
Definition: IAllocator.h:35
Interface to enqueue GLES kernels and get/set the GLES CommandQueue.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
IAllocator * allocator
Backend allocator to use.
Definition: GraphContext.h:46
std::unique_ptr< ITensorHandle > create_tensor(const Tensor &tensor) override
Create a backend Tensor.
MemoryManagerContext * memory_management_ctx(Target target)
Gets a memory manager context for a given target.
void default_init()
Initialises the context and command queue used by the scheduler to default values and sets a default ...
Definition: GCScheduler.cpp:48
MemoryManagerAffinity
Backend Memory Manager affinity.
Definition: Types.h:194
Tensor object.
Definition: Tensor.h:41