blob: f1c2cf969f58b3ab77c1022136e439a460345738 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Manuel Bottini327225d2021-04-13 13:09:30 +01002 * Copyright (c) 2017-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44: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/NEON/functions/NEDirectConvolutionLayer.h"
25
26#include "arm_compute/core/PixelValue.h"
27#include "arm_compute/core/Utils.h"
28#include "arm_compute/core/Validate.h"
29#include "arm_compute/runtime/NEON/NEScheduler.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/cpu/operators/CpuDirectConv2d.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000033namespace arm_compute
34{
Manuel Bottini327225d2021-04-13 13:09:30 +010035struct NEDirectConvolutionLayer::Impl
36{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010037 ITensor *src{nullptr};
38 const ITensor *weights{nullptr};
39 const ITensor *bias{nullptr};
40 ITensor *dst{nullptr};
41 std::unique_ptr<cpu::CpuDirectConv2d> op{nullptr};
Manuel Bottini327225d2021-04-13 13:09:30 +010042};
Michalis Spyrouebcebf12020-10-21 00:04:14 +010043
Georgios Pinitas658039b2017-09-15 16:30:50 +010044NEDirectConvolutionLayer::NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
Manuel Bottini327225d2021-04-13 13:09:30 +010045 : _memory_manager(std::move(memory_manager)), _impl(std::make_unique<Impl>())
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046{
47}
Manuel Bottini327225d2021-04-13 13:09:30 +010048NEDirectConvolutionLayer::~NEDirectConvolutionLayer() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050void NEDirectConvolutionLayer::configure(ITensor *input,
51 const ITensor *weights,
52 const ITensor *bias,
53 ITensor *output,
54 const PadStrideInfo &conv_info,
55 const ActivationLayerInfo &act_info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056{
Manuel Bottini327225d2021-04-13 13:09:30 +010057 _impl->src = input;
58 _impl->weights = weights;
59 _impl->bias = bias;
60 _impl->dst = output;
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010061 _impl->op = std::make_unique<cpu::CpuDirectConv2d>(_memory_manager);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 _impl->op->configure(input->info(), weights->info(), (bias != nullptr ? bias->info() : nullptr), output->info(),
63 conv_info, act_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010064}
65
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010066Status NEDirectConvolutionLayer::validate(const ITensorInfo *input,
67 const ITensorInfo *weights,
68 const ITensorInfo *bias,
69 const ITensorInfo *output,
70 const PadStrideInfo &conv_info,
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000071 const ActivationLayerInfo &act_info)
Michalis Spyrouafa5d812017-11-30 14:25:57 +000072{
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010073 return cpu::CpuDirectConv2d::validate(input, weights, bias, output, conv_info, act_info);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000074}
75
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076void NEDirectConvolutionLayer::run()
77{
Manuel Bottini327225d2021-04-13 13:09:30 +010078 ITensorPack pack;
79 pack.add_tensor(TensorType::ACL_SRC_0, _impl->src);
80 pack.add_tensor(TensorType::ACL_SRC_1, _impl->weights);
81 pack.add_tensor(TensorType::ACL_SRC_2, _impl->bias);
82 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
83 _impl->op->run(pack);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084}
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000085} // namespace arm_compute