blob: 4ddd0ab4caa6d6f516f917b6c356def6449354ce [file] [log] [blame]
Frank Lei8cdfdb82018-01-02 16:49:33 +08001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Frank Lei8cdfdb82018-01-02 16:49:33 +08003 *
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/GCDepthwiseConvolutionLayer.h"
25
26#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h"
27#include "arm_compute/core/PixelValue.h"
28#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
Matthew Bentham92046462020-03-07 22:15:55 +000029#include "support/MemorySupport.h"
Frank Lei8cdfdb82018-01-02 16:49:33 +080030
31using namespace arm_compute;
32
Frank Lei4406fd62018-02-01 14:47:14 +080033GCDepthwiseConvolutionLayer3x3::GCDepthwiseConvolutionLayer3x3()
Georgios Pinitas60e98252018-10-22 16:17:20 +010034 : _kernel(nullptr), _border_handler(), _shift_handler(), _activationlayer_function(), _is_activationlayer_enabled(false)
Frank Lei4406fd62018-02-01 14:47:14 +080035{
36}
37
Georgios Pinitas60e98252018-10-22 16:17:20 +010038void GCDepthwiseConvolutionLayer3x3::configure(IGCTensor *input, const IGCTensor *weights, const IGCTensor *biases, IGCTensor *output, const PadStrideInfo &conv_info,
Usama Arife73686a2019-04-08 17:30:48 +010039 unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation)
Frank Lei8cdfdb82018-01-02 16:49:33 +080040{
Usama Arife73686a2019-04-08 17:30:48 +010041 ARM_COMPUTE_ERROR_ON(dilation.x() != 1 || dilation.y() != 1);
42 ARM_COMPUTE_UNUSED(dilation);
Frank Lei8cdfdb82018-01-02 16:49:33 +080043 auto k = arm_compute::support::cpp14::make_unique<GCDepthwiseConvolutionLayer3x3Kernel>();
Giorgio Arena76572242018-04-04 17:44:26 +010044 k->configure(input, weights, biases, output, conv_info, depth_multiplier);
Frank Lei8cdfdb82018-01-02 16:49:33 +080045 _kernel = std::move(k);
46
47 // Configure border handler
Manuel Bottini55e16782019-01-15 13:21:57 +000048 _border_handler.configure(input, _kernel->border_size(), BorderMode::CONSTANT, PixelValue());
Frank Lei4406fd62018-02-01 14:47:14 +080049
50 _shift_handler.configure(input);
Georgios Pinitas60e98252018-10-22 16:17:20 +010051
52 //Configure Activation Layer
53 _is_activationlayer_enabled = act_info.enabled();
54
55 if(_is_activationlayer_enabled)
56 {
57 _activationlayer_function.configure(output, nullptr, act_info);
58 }
Frank Lei4406fd62018-02-01 14:47:14 +080059}
60
61void GCDepthwiseConvolutionLayer3x3::run()
62{
63 GCScheduler::get().dispatch(_shift_handler, false);
64 GCScheduler::get().memory_barrier();
65 GCScheduler::get().dispatch(_border_handler, false);
66 GCScheduler::get().memory_barrier();
67 GCScheduler::get().dispatch(*_kernel);
Georgios Pinitas60e98252018-10-22 16:17:20 +010068
69 // Run Activation Layer
70 if(_is_activationlayer_enabled)
71 {
72 _activationlayer_function.run();
73 }
Frank Lei8cdfdb82018-01-02 16:49:33 +080074}