blob: 63c963196a1e2113a805bd649c0c4fd5be2af915 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +01003 *
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#include "arm_compute/runtime/GLES_COMPUTE/functions/GCDirectConvolutionLayer.h"
25
26#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h"
27#include "arm_compute/core/GLES_COMPUTE/kernels/GCDirectConvolutionLayerKernel.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/PixelValue.h"
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080030#include "arm_compute/core/TensorInfo.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010031#include "arm_compute/core/Utils.h"
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080032#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010033
34using namespace arm_compute;
Frank Lei4406fd62018-02-01 14:47:14 +080035
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080036GCDirectConvolutionLayer::GCDirectConvolutionLayer()
37 : _kernel(nullptr), _border_handler(), _shift_handler()
38{
39}
Anthony Barbier7068f992017-10-26 15:23:08 +010040
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000041void GCDirectConvolutionLayer::configure(IGCTensor *input, const IGCTensor *weights, const IGCTensor *biases, IGCTensor *output, const PadStrideInfo &conv_info,
42 const ActivationLayerInfo &act_info)
Anthony Barbier7068f992017-10-26 15:23:08 +010043{
44 int kernel_size = weights->info()->dimension(0);
45
46 if(kernel_size == 1)
47 {
Georgios Pinitas40f51a62020-11-21 03:04:18 +000048 auto k = std::make_unique<GCDirectConvolutionLayer1x1Kernel>();
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000049 k->configure(input, weights, biases, output, conv_info, act_info);
Anthony Barbier7068f992017-10-26 15:23:08 +010050 _kernel = std::move(k);
51 }
52 else if(kernel_size == 3)
53 {
Georgios Pinitas40f51a62020-11-21 03:04:18 +000054 auto k = std::make_unique<GCDirectConvolutionLayer3x3Kernel>();
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000055 k->configure(input, weights, biases, output, conv_info, act_info);
Anthony Barbier7068f992017-10-26 15:23:08 +010056 _kernel = std::move(k);
57 }
58 else if(kernel_size == 5)
59 {
Georgios Pinitas40f51a62020-11-21 03:04:18 +000060 auto k = std::make_unique<GCDirectConvolutionLayer5x5Kernel>();
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000061 k->configure(input, weights, biases, output, conv_info, act_info);
Anthony Barbier7068f992017-10-26 15:23:08 +010062 _kernel = std::move(k);
63 }
64 else
65 {
66 ARM_COMPUTE_ERROR("kernel size unsupported!");
67 return;
68 }
69
Manuel Bottini55e16782019-01-15 13:21:57 +000070 _border_handler.configure(input, _kernel->border_size(), BorderMode::CONSTANT, PixelValue());
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080071
Frank Lei4406fd62018-02-01 14:47:14 +080072 _shift_handler.configure(input);
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080073}
74
75void GCDirectConvolutionLayer::run()
76{
Frank Lei4406fd62018-02-01 14:47:14 +080077 GCScheduler::get().dispatch(_shift_handler, false);
78 GCScheduler::get().memory_barrier();
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080079 GCScheduler::get().dispatch(_border_handler, false);
80 GCScheduler::get().memory_barrier();
81 GCScheduler::get().dispatch(*_kernel);
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000082 GCScheduler::get().memory_barrier();
83 GCScheduler::get().dispatch(_shift_handler);
Anthony Barbier7068f992017-10-26 15:23:08 +010084}