blob: 0185598965dfc53b85f7cbdacf68f29e9b7ed9f9 [file] [log] [blame]
Georgios Pinitasfbb80542018-03-27 17:15:49 +01001/*
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#include "arm_compute/graph/backends/GLES/GCDeviceBackend.h"
Georgios Pinitasfbb80542018-03-27 17:15:49 +010025
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010026#include "arm_compute/graph/Graph.h"
27#include "arm_compute/graph/GraphContext.h"
28#include "arm_compute/graph/INode.h"
29#include "arm_compute/graph/Logger.h"
30#include "arm_compute/graph/Tensor.h"
31#include "arm_compute/graph/backends/BackendRegistrar.h"
32#include "arm_compute/graph/backends/GLES/GCFunctionFactory.h"
33#include "arm_compute/graph/backends/GLES/GCNodeValidator.h"
34#include "arm_compute/graph/backends/GLES/GCTensorHandle.h"
Georgios Pinitasfbb80542018-03-27 17:15:49 +010035
36#include "arm_compute/core/TensorInfo.h"
37#include "arm_compute/runtime/BlobLifetimeManager.h"
38#include "arm_compute/runtime/GLES_COMPUTE/GCBufferAllocator.h"
39#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
40#include "arm_compute/runtime/MemoryManagerOnDemand.h"
41#include "arm_compute/runtime/PoolManager.h"
42
43#include "support/ToolchainSupport.h"
44
45namespace arm_compute
46{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010047namespace graph
Georgios Pinitasfbb80542018-03-27 17:15:49 +010048{
49namespace backends
50{
51/** Register GLES backend */
52static detail::BackendRegistrar<GCDeviceBackend> GCDeviceBackend_registrar(Target::GC);
53
54GCDeviceBackend::GCDeviceBackend()
55 : _allocator()
56{
57}
58
59void GCDeviceBackend::initialize_backend()
60{
61 // Setup Scheduler
62 GCScheduler::get().default_init();
63}
64
65void GCDeviceBackend::setup_backend_context(GraphContext &ctx)
66{
67 // Setup a management backend
68 if(ctx.memory_management_ctx(Target::GC) == nullptr)
69 {
70 MemoryManagerContext mm_ctx;
71 mm_ctx.target = Target::GC;
72 mm_ctx.mm = create_memory_manager(MemoryManagerAffinity::Buffer);
73
74 ctx.insert_memory_management_ctx(std::move(mm_ctx));
75 }
76}
77
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010078bool GCDeviceBackend::is_backend_supported()
79{
80 return arm_compute::opengles31_is_available();
81}
82
Georgios Pinitasfbb80542018-03-27 17:15:49 +010083std::unique_ptr<ITensorHandle> GCDeviceBackend::create_tensor(const Tensor &tensor)
84{
85 // Get tensor descriptor
86 const TensorDescriptor &tensor_desc = tensor.desc();
87 ARM_COMPUTE_ERROR_ON(tensor_desc.target != Target::GC);
88
89 // Create backend tensor handle
Giorgio Arenabb54e4e2018-04-05 17:20:34 +010090 TensorInfo info(tensor_desc.shape, 1, tensor_desc.data_type, tensor_desc.quant_info);
Georgios Pinitascac13b12018-04-27 19:07:19 +010091 info.set_data_layout(tensor_desc.layout);
92 auto backend_tensor_handle = support::cpp14::make_unique<GCTensorHandle>(info);
Georgios Pinitasfbb80542018-03-27 17:15:49 +010093
94 return std::move(backend_tensor_handle);
95}
96
97std::unique_ptr<ITensorHandle> GCDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent)
98{
99 ARM_COMPUTE_UNUSED(parent, shape, coords, extend_parent);
100 ARM_COMPUTE_ERROR("GLES backend has no sub-tensor support!");
101 return nullptr;
102}
103
104std::unique_ptr<arm_compute::IFunction> GCDeviceBackend::configure_node(INode &node, GraphContext &ctx)
105{
106 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Configuring GC node with ID : " << node.id() << std::endl);
107 ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::GC);
108
109 // Configure node
110 return GCFunctionFactory::create(&node, ctx);
111}
112
113arm_compute::Status GCDeviceBackend::validate_node(INode &node)
114{
115 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GC node with ID : " << node.id() << std::endl);
116 ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::GC);
117
118 return GCNodeValidator::validate(&node);
119}
120
121std::shared_ptr<arm_compute::IMemoryManager> GCDeviceBackend::create_memory_manager(MemoryManagerAffinity affinity)
122{
123 if(affinity == MemoryManagerAffinity::Offset)
124 {
125 ARM_COMPUTE_LOG_GRAPH_WARNING("GC Backend does not support offset affinity memory management!");
126 return nullptr;
127 }
128
129 auto lifetime_mgr = std::make_shared<BlobLifetimeManager>();
130 auto pool_mgr = std::make_shared<PoolManager>();
131 auto mm = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
132
133 mm->set_allocator(&_allocator);
134
135 return mm;
136}
137} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100138} // namespace graph
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100139} // namespace arm_compute