blob: ef3d3d6055b8fcb7895e2793a0d694116b5c4d07 [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"
Georgios Pinitas7891a732021-08-20 21:39:25 +010030#include "src/cpu/operators/CpuDirectConv2d.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000032namespace arm_compute
33{
Manuel Bottini327225d2021-04-13 13:09:30 +010034struct NEDirectConvolutionLayer::Impl
35{
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010036 ITensor *src{ nullptr };
37 const ITensor *weights{ nullptr };
38 const ITensor *bias{ nullptr };
39 ITensor *dst{ nullptr };
40 std::unique_ptr<cpu::CpuDirectConv2d> op{ nullptr };
Manuel Bottini327225d2021-04-13 13:09:30 +010041};
Michalis Spyrouebcebf12020-10-21 00:04:14 +010042
Georgios Pinitas658039b2017-09-15 16:30:50 +010043NEDirectConvolutionLayer::NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
Manuel Bottini327225d2021-04-13 13:09:30 +010044 : _memory_manager(std::move(memory_manager)), _impl(std::make_unique<Impl>())
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045{
46}
Manuel Bottini327225d2021-04-13 13:09:30 +010047NEDirectConvolutionLayer::~NEDirectConvolutionLayer() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000049void NEDirectConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050{
Manuel Bottini327225d2021-04-13 13:09:30 +010051 _impl->src = input;
52 _impl->weights = weights;
53 _impl->bias = bias;
54 _impl->dst = output;
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010055 _impl->op = std::make_unique<cpu::CpuDirectConv2d>(_memory_manager);
Manuel Bottini327225d2021-04-13 13:09:30 +010056 _impl->op->configure(input->info(), weights->info(), (bias != nullptr ? bias->info() : nullptr), output->info(), conv_info, act_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010057}
58
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000059Status NEDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info,
60 const ActivationLayerInfo &act_info)
Michalis Spyrouafa5d812017-11-30 14:25:57 +000061{
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010062 return cpu::CpuDirectConv2d::validate(input, weights, bias, output, conv_info, act_info);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000063}
64
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065void NEDirectConvolutionLayer::run()
66{
Manuel Bottini327225d2021-04-13 13:09:30 +010067 ITensorPack pack;
68 pack.add_tensor(TensorType::ACL_SRC_0, _impl->src);
69 pack.add_tensor(TensorType::ACL_SRC_1, _impl->weights);
70 pack.add_tensor(TensorType::ACL_SRC_2, _impl->bias);
71 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
72 _impl->op->run(pack);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073}
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +000074} // namespace arm_compute