blob: fa01c914c5bff2863fc60a4aa3adc1e58d6ff73f [file] [log] [blame]
Gian Marco Iodiced2fab732018-03-02 11:18:12 +00001/*
Georgios Pinitas856f66e2021-04-22 21:13:21 +01002 * Copyright (c) 2018-2021 Arm Limited.
Gian Marco Iodiced2fab732018-03-02 11:18:12 +00003 *
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/CLWinogradConvolutionLayer.h"
25
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010026#include "arm_compute/core/CL/CLKernelLibrary.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000027#include "arm_compute/core/CL/ICLTensor.h"
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010028#include "arm_compute/core/KernelDescriptors.h"
29#include "src/core/CL/ICLKernel.h"
30#include "src/core/helpers/MemoryHelpers.h"
31#include "src/runtime/gpu/cl/operators/ClWinogradConv2d.h"
32#include "support/Cast.h"
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000033
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010034namespace arm_compute
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010035{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010036struct CLWinogradConvolutionLayer::Impl
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010037{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010038 const ICLTensor *src{ nullptr };
39 const ICLTensor *weights{ nullptr };
40 const ICLTensor *biases{ nullptr };
41 ICLTensor *dst{ nullptr };
42 std::unique_ptr<opencl::ClWinogradConv2d> op{ nullptr };
43 ITensorPack run_pack{};
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010044 MemoryGroup memory_group{};
45 WorkspaceData<CLTensor> workspace_tensors{};
46 bool is_prepared{ false };
47};
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010048
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000049CLWinogradConvolutionLayer::CLWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010050 : _impl(std::make_unique<Impl>())
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000051{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010052 _impl->memory_group = MemoryGroup(memory_manager);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000053}
54
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010055CLWinogradConvolutionLayer::~CLWinogradConvolutionLayer() = default;
56
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010057void CLWinogradConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info,
58 bool enable_fast_math)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000059{
Manuel Bottini2b84be52020-04-08 10:15:51 +010060 configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info, enable_fast_math);
61}
62
63void CLWinogradConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010064 const PadStrideInfo &conv_info,
Manuel Bottini2b84be52020-04-08 10:15:51 +010065 const ActivationLayerInfo &act_info, bool enable_fast_math)
66{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010067 _impl->src = input;
68 _impl->weights = weights;
69 _impl->biases = biases;
70 _impl->dst = output;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000071
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010072 _impl->op = std::make_unique<opencl::ClWinogradConv2d>();
73 _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr ? biases->info() : nullptr), output->info(), conv_info, act_info, enable_fast_math);
Gian Marco Iodice247f52c2018-03-22 11:24:56 +000074
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010075 _impl->run_pack =
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010076 {
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010077 { TensorType::ACL_SRC_0, _impl->src },
78 { TensorType::ACL_SRC_1, _impl->weights },
79 { TensorType::ACL_SRC_2, _impl->biases },
80 { TensorType::ACL_DST, _impl->dst }
81 };
Georgios Pinitas2b147ee2021-07-08 18:14:45 +010082 _impl->workspace_tensors = manage_workspace<CLTensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack, _impl->run_pack);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000083}
84
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000085Status CLWinogradConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010086 const ActivationLayerInfo &act_info, bool enable_fast_math)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000087{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010088 return opencl::ClWinogradConv2d::validate(input, weights, biases, output, conv_info, act_info, enable_fast_math);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000089}
90
91void CLWinogradConvolutionLayer::run()
92{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010093 MemoryGroupResourceScope scope_mg(_impl->memory_group);
Georgios Pinitase0437672018-05-02 14:07:55 +010094 prepare();
Manuel Bottinic6f4ec32021-05-18 18:41:56 +010095 _impl->op->run(_impl->run_pack);
Georgios Pinitase0437672018-05-02 14:07:55 +010096}
Georgios Pinitas82b51482018-04-24 15:14:12 +010097
Georgios Pinitase0437672018-05-02 14:07:55 +010098void CLWinogradConvolutionLayer::prepare()
99{
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100100 if(!_impl->is_prepared)
Georgios Pinitase0437672018-05-02 14:07:55 +0100101 {
Georgios Pinitas2b147ee2021-07-08 18:14:45 +0100102 _impl->op->prepare(_impl->run_pack);
103
104 // Release Preparation tensors
105 release_prepare_tensors(_impl->workspace_tensors, _impl->run_pack);
106 _impl->run_pack.remove_tensor(TensorType::ACL_SRC_1);
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100107 _impl->is_prepared = true;
Georgios Pinitase0437672018-05-02 14:07:55 +0100108 }
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000109}
Manuel Bottinic6f4ec32021-05-18 18:41:56 +0100110} // namespace arm_compute