blob: c451bd4b4c2fee815070328d6682529fae0ddc54 [file] [log] [blame]
steniu0127b386c2017-07-18 17:37:43 +01001/*
Georgios Pinitasc0d1c862018-03-23 15:13:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
steniu0127b386c2017-07-18 17:37:43 +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
Georgios Pinitas6fdfaa82017-11-29 14:27:24 +000026#include "arm_compute/core/CL/ICLTensor.h"
steniu0127b386c2017-07-18 17:37:43 +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()
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000036 : _direct_conv_kernel(), _input_border_handler(), _activationlayer_function(), _is_activationlayer_enabled(false)
steniu0127b386c2017-07-18 17:37:43 +010037{
38}
39
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000040void CLDirectConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
steniu0127b386c2017-07-18 17:37:43 +010041{
Gian Marco Iodice1246b632017-08-16 18:38:32 +010042 // Set GPU target
43 _direct_conv_kernel.set_target(CLScheduler::get().target());
44
45 // Configure direct convolution
steniu0127b386c2017-07-18 17:37:43 +010046 _direct_conv_kernel.configure(input, weights, biases, output, conv_info);
47
Gian Marco Iodice1246b632017-08-16 18:38:32 +010048 // Configure border handler
Georgios Pinitas6fdfaa82017-11-29 14:27:24 +000049 PixelValue &&zero_value(0.f);
50 if(is_data_type_quantized_asymmetric(input->info()->data_type()))
51 {
52 zero_value = PixelValue(static_cast<uint8_t>(input->info()->quantization_info().offset));
53 }
54 _input_border_handler.configure(input, _direct_conv_kernel.border_size(), BorderMode::CONSTANT, zero_value);
Georgios Pinitasc0d1c862018-03-23 15:13:15 +000055
56 // Tune kernels
57 CLScheduler::get().tune_kernel_static(_direct_conv_kernel);
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000058
59 _is_activationlayer_enabled = act_info.enabled();
60
61 //Configure Activation Layer
62 if(_is_activationlayer_enabled)
63 {
64 _activationlayer_function.configure(output, nullptr, act_info);
65 }
steniu0127b386c2017-07-18 17:37:43 +010066}
67
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000068Status CLDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
69 const ActivationLayerInfo &act_info)
Georgios Pinitas30902ed2017-11-14 15:32:57 +000070{
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000071 ARM_COMPUTE_RETURN_ON_ERROR(CLDirectConvolutionLayerKernel::validate(input, weights, biases, output, conv_info, CLScheduler::get().target()));
72 if(act_info.enabled())
73 {
74 ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(output, nullptr, act_info));
75 }
76 return Status{};
Georgios Pinitas30902ed2017-11-14 15:32:57 +000077}
78
steniu0127b386c2017-07-18 17:37:43 +010079void CLDirectConvolutionLayer::run()
80{
Gian Marco Iodice1246b632017-08-16 18:38:32 +010081 // Run border handler
steniu0127b386c2017-07-18 17:37:43 +010082 CLScheduler::get().enqueue(_input_border_handler, false);
Gian Marco Iodice1246b632017-08-16 18:38:32 +010083
84 // Run direct convolution
steniu0127b386c2017-07-18 17:37:43 +010085 CLScheduler::get().enqueue(_direct_conv_kernel);
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000086
87 //Run Activation Layer
88 if(_is_activationlayer_enabled)
89 {
90 _activationlayer_function.run();
91 }
steniu0127b386c2017-07-18 17:37:43 +010092}