blob: 74867ff64f1c7ab120674aaca74706b4946eae7d [file] [log] [blame]
steniu0127b386c2017-07-18 17:37:43 +01001/*
Sheri Zhang1efed922021-03-10 22:43:38 +00002 * Copyright (c) 2017-2021 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/PixelValue.h"
28#include "arm_compute/core/Utils.h"
29#include "arm_compute/core/Validate.h"
30#include "arm_compute/runtime/CL/CLScheduler.h"
Sheri Zhang1efed922021-03-10 22:43:38 +000031#include "src/runtime/gpu/cl/operators/ClActivation.h"
32#include "src/runtime/gpu/cl/operators/ClDirectConvolution.h"
steniu0127b386c2017-07-18 17:37:43 +010033
Sheri Zhang1efed922021-03-10 22:43:38 +000034namespace arm_compute
35{
36struct CLDirectConvolutionLayer::Impl
37{
38 const ICLTensor *src{ nullptr };
39 const ICLTensor *weights{ nullptr };
40 const ICLTensor *biases{ nullptr };
41 ICLTensor *dst{ nullptr };
42 std::unique_ptr<opencl::ClDirectConvolution> op{ nullptr };
43};
steniu0127b386c2017-07-18 17:37:43 +010044
45CLDirectConvolutionLayer::CLDirectConvolutionLayer()
Sheri Zhang1efed922021-03-10 22:43:38 +000046 : _impl(std::make_unique<Impl>())
steniu0127b386c2017-07-18 17:37:43 +010047{
48}
Sheri Zhang1efed922021-03-10 22:43:38 +000049CLDirectConvolutionLayer::CLDirectConvolutionLayer(CLDirectConvolutionLayer &&) = default;
50CLDirectConvolutionLayer &CLDirectConvolutionLayer::operator=(CLDirectConvolutionLayer &&) = default;
51CLDirectConvolutionLayer::~CLDirectConvolutionLayer() = default;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010052
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000053void 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 +010054{
Manuel Bottini2b84be52020-04-08 10:15:51 +010055 configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info);
56}
57
58void CLDirectConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
Sheri Zhang1efed922021-03-10 22:43:38 +000059 const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
Manuel Bottini2b84be52020-04-08 10:15:51 +010060{
Michele Di Giorgio97e25802021-03-25 12:37:45 +000061 ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
Gian Marco Iodice1246b632017-08-16 18:38:32 +010062
Sheri Zhang1efed922021-03-10 22:43:38 +000063 _impl->src = input;
64 _impl->weights = weights;
65 _impl->biases = biases;
66 _impl->dst = output;
steniu0127b386c2017-07-18 17:37:43 +010067
Sheri Zhang1efed922021-03-10 22:43:38 +000068 _impl->op = std::make_unique<opencl::ClDirectConvolution>();
Michele Di Giorgio97e25802021-03-25 12:37:45 +000069 _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), conv_info, act_info);
steniu0127b386c2017-07-18 17:37:43 +010070}
71
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000072Status CLDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
73 const ActivationLayerInfo &act_info)
Georgios Pinitas30902ed2017-11-14 15:32:57 +000074{
Sheri Zhang1efed922021-03-10 22:43:38 +000075 return opencl::ClDirectConvolution::validate(input, weights, biases, output, conv_info, act_info);
Georgios Pinitas30902ed2017-11-14 15:32:57 +000076}
77
steniu0127b386c2017-07-18 17:37:43 +010078void CLDirectConvolutionLayer::run()
79{
Sheri Zhang1efed922021-03-10 22:43:38 +000080 ITensorPack pack;
81 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
82 pack.add_tensor(TensorType::ACL_SRC_1, _impl->weights);
83 pack.add_tensor(TensorType::ACL_SRC_2, _impl->biases);
84 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
85 _impl->op->run(pack);
steniu0127b386c2017-07-18 17:37:43 +010086}
Sheri Zhang1efed922021-03-10 22:43:38 +000087}