blob: 6e9782f77a6cd75f90451a26996a688eec7b52fc [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +01001/*
Jenkins6a7771e2020-05-28 11:28:36 +01002 * Copyright (c) 2017-2020 ARM Limited.
Kaizen8938bd32017-09-28 14:38:23 +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/CL/functions/CLDirectConvolutionLayer.h"
25
Anthony Barbier8140e1e2017-12-14 23:48:46 +000026#include "arm_compute/core/CL/ICLTensor.h"
Kaizen8938bd32017-09-28 14:38:23 +010027#include "arm_compute/core/CL/kernels/CLDirectConvolutionLayerKernel.h"
28#include "arm_compute/core/PixelValue.h"
29#include "arm_compute/core/Utils.h"
30#include "arm_compute/core/Validate.h"
31#include "arm_compute/runtime/CL/CLScheduler.h"
32
33using namespace arm_compute;
34
35CLDirectConvolutionLayer::CLDirectConvolutionLayer()
Jenkinsb3a371b2018-05-23 11:36:53 +010036 : _direct_conv_kernel(), _input_border_handler(), _activationlayer_function(), _is_activationlayer_enabled(false)
Kaizen8938bd32017-09-28 14:38:23 +010037{
38}
39
Jenkinsb3a371b2018-05-23 11:36:53 +010040void CLDirectConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
Kaizen8938bd32017-09-28 14:38:23 +010041{
Jenkins6a7771e2020-05-28 11:28:36 +010042 configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info);
43}
44
45void CLDirectConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
46 const PadStrideInfo &conv_info,
47 const ActivationLayerInfo &act_info)
48{
Kaizen8938bd32017-09-28 14:38:23 +010049 // Set GPU target
50 _direct_conv_kernel.set_target(CLScheduler::get().target());
51
52 // Configure direct convolution
Jenkins6a7771e2020-05-28 11:28:36 +010053 _direct_conv_kernel.configure(compile_context, input, weights, biases, output, conv_info);
Kaizen8938bd32017-09-28 14:38:23 +010054
55 // Configure border handler
Anthony Barbier8140e1e2017-12-14 23:48:46 +000056 PixelValue &&zero_value(0.f);
57 if(is_data_type_quantized_asymmetric(input->info()->data_type()))
58 {
Jenkins6a7771e2020-05-28 11:28:36 +010059 zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
Anthony Barbier8140e1e2017-12-14 23:48:46 +000060 }
Jenkins6a7771e2020-05-28 11:28:36 +010061 _input_border_handler.configure(compile_context, input, _direct_conv_kernel.border_size(), BorderMode::CONSTANT, zero_value);
Jenkinsb3a371b2018-05-23 11:36:53 +010062
63 // Tune kernels
64 CLScheduler::get().tune_kernel_static(_direct_conv_kernel);
65
66 _is_activationlayer_enabled = act_info.enabled();
67
68 //Configure Activation Layer
69 if(_is_activationlayer_enabled)
70 {
Jenkins6a7771e2020-05-28 11:28:36 +010071 _activationlayer_function.configure(compile_context, output, nullptr, act_info);
Jenkinsb3a371b2018-05-23 11:36:53 +010072 }
Anthony Barbier8140e1e2017-12-14 23:48:46 +000073}
74
Jenkinsb3a371b2018-05-23 11:36:53 +010075Status CLDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
76 const ActivationLayerInfo &act_info)
Anthony Barbier8140e1e2017-12-14 23:48:46 +000077{
Jenkinsb3a371b2018-05-23 11:36:53 +010078 ARM_COMPUTE_RETURN_ON_ERROR(CLDirectConvolutionLayerKernel::validate(input, weights, biases, output, conv_info, CLScheduler::get().target()));
79 if(act_info.enabled())
80 {
81 ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(output, nullptr, act_info));
82 }
83 return Status{};
Kaizen8938bd32017-09-28 14:38:23 +010084}
85
86void CLDirectConvolutionLayer::run()
87{
88 // Run border handler
89 CLScheduler::get().enqueue(_input_border_handler, false);
90
91 // Run direct convolution
92 CLScheduler::get().enqueue(_direct_conv_kernel);
Jenkinsb3a371b2018-05-23 11:36:53 +010093
94 //Run Activation Layer
95 if(_is_activationlayer_enabled)
96 {
97 _activationlayer_function.run();
98 }
Kaizen8938bd32017-09-28 14:38:23 +010099}