blob: 8cd9994744804f61964c320a88af692aaef63c15 [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
90 TensorInfo info(tensor_desc.shape, 1, tensor_desc.data_type);
91 auto backend_tensor_handle = support::cpp14::make_unique<GCTensorHandle>(info);
92
93 return std::move(backend_tensor_handle);
94}
95
96std::unique_ptr<ITensorHandle> GCDeviceBackend::create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent)
97{
98 ARM_COMPUTE_UNUSED(parent, shape, coords, extend_parent);
99 ARM_COMPUTE_ERROR("GLES backend has no sub-tensor support!");
100 return nullptr;
101}
102
103std::unique_ptr<arm_compute::IFunction> GCDeviceBackend::configure_node(INode &node, GraphContext &ctx)
104{
105 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Configuring GC node with ID : " << node.id() << std::endl);
106 ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::GC);
107
108 // Configure node
109 return GCFunctionFactory::create(&node, ctx);
110}
111
112arm_compute::Status GCDeviceBackend::validate_node(INode &node)
113{
114 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GC node with ID : " << node.id() << std::endl);
115 ARM_COMPUTE_ERROR_ON(node.assigned_target() != Target::GC);
116
117 return GCNodeValidator::validate(&node);
118}
119
120std::shared_ptr<arm_compute::IMemoryManager> GCDeviceBackend::create_memory_manager(MemoryManagerAffinity affinity)
121{
122 if(affinity == MemoryManagerAffinity::Offset)
123 {
124 ARM_COMPUTE_LOG_GRAPH_WARNING("GC Backend does not support offset affinity memory management!");
125 return nullptr;
126 }
127
128 auto lifetime_mgr = std::make_shared<BlobLifetimeManager>();
129 auto pool_mgr = std::make_shared<PoolManager>();
130 auto mm = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
131
132 mm->set_allocator(&_allocator);
133
134 return mm;
135}
136} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100137} // namespace graph
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100138} // namespace arm_compute