xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/NEON/functions/NEDirectConvolutionLayer.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
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"
30 #include "src/cpu/operators/CpuDirectConv2d.h"
31 
32 namespace arm_compute
33 {
34 struct NEDirectConvolutionLayer::Impl
35 {
36     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 };
41 };
42 
NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)43 NEDirectConvolutionLayer::NEDirectConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
44     : _memory_manager(std::move(memory_manager)), _impl(std::make_unique<Impl>())
45 {
46 }
47 NEDirectConvolutionLayer::~NEDirectConvolutionLayer() = default;
48 
configure(ITensor * input,const ITensor * weights,const ITensor * bias,ITensor * output,const PadStrideInfo & conv_info,const ActivationLayerInfo & act_info)49 void NEDirectConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
50 {
51     _impl->src     = input;
52     _impl->weights = weights;
53     _impl->bias    = bias;
54     _impl->dst     = output;
55     _impl->op      = std::make_unique<cpu::CpuDirectConv2d>(_memory_manager);
56     _impl->op->configure(input->info(), weights->info(), (bias != nullptr ? bias->info() : nullptr), output->info(), conv_info, act_info);
57 }
58 
validate(const ITensorInfo * input,const ITensorInfo * weights,const ITensorInfo * bias,const ITensorInfo * output,const PadStrideInfo & conv_info,const ActivationLayerInfo & act_info)59 Status NEDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &conv_info,
60                                           const ActivationLayerInfo &act_info)
61 {
62     return cpu::CpuDirectConv2d::validate(input, weights, bias, output, conv_info, act_info);
63 }
64 
run()65 void NEDirectConvolutionLayer::run()
66 {
67     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);
73 }
74 } // namespace arm_compute
75