Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 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 | */ |
| 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 Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 29 | #include "support/MemorySupport.h" |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 30 | |
| 31 | using namespace arm_compute; |
| 32 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 33 | GCDepthwiseConvolutionLayer3x3::GCDepthwiseConvolutionLayer3x3() |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 34 | : _kernel(nullptr), _border_handler(), _shift_handler(), _activationlayer_function(), _is_activationlayer_enabled(false) |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 38 | void GCDepthwiseConvolutionLayer3x3::configure(IGCTensor *input, const IGCTensor *weights, const IGCTensor *biases, IGCTensor *output, const PadStrideInfo &conv_info, |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 39 | unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation) |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 40 | { |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 41 | ARM_COMPUTE_ERROR_ON(dilation.x() != 1 || dilation.y() != 1); |
| 42 | ARM_COMPUTE_UNUSED(dilation); |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 43 | auto k = arm_compute::support::cpp14::make_unique<GCDepthwiseConvolutionLayer3x3Kernel>(); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 44 | k->configure(input, weights, biases, output, conv_info, depth_multiplier); |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 45 | _kernel = std::move(k); |
| 46 | |
| 47 | // Configure border handler |
Manuel Bottini | 55e1678 | 2019-01-15 13:21:57 +0000 | [diff] [blame] | 48 | _border_handler.configure(input, _kernel->border_size(), BorderMode::CONSTANT, PixelValue()); |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 49 | |
| 50 | _shift_handler.configure(input); |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 51 | |
| 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 Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void 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 Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 68 | |
| 69 | // Run Activation Layer |
| 70 | if(_is_activationlayer_enabled) |
| 71 | { |
| 72 | _activationlayer_function.run(); |
| 73 | } |
Frank Lei | 8cdfdb8 | 2018-01-02 16:49:33 +0800 | [diff] [blame] | 74 | } |