xref: /aosp_15_r20/external/ComputeLibrary/src/runtime/NEON/functions/NEAddMulAdd.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2023 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 
25 #include "arm_compute/runtime/NEON/functions/NEAddMulAdd.h"
26 
27 #include "src/common/utils/Log.h"
28 #include "src/core/helpers/MemoryHelpers.h"
29 #include "src/cpu/operators/CpuAddMulAdd.h"
30 
31 namespace arm_compute
32 {
33 struct NEAddMulAdd::Impl
34 {
35     std::unique_ptr<cpu::CpuAddMulAdd> op{ nullptr };
36     WorkspaceData<Tensor>              workspace_tensors{};
37     ITensorPack                        run_pack{};
38     MemoryGroup                        memory_group{};
39 };
40 
NEAddMulAdd(std::shared_ptr<IMemoryManager> memory_manager)41 NEAddMulAdd::NEAddMulAdd(std::shared_ptr<IMemoryManager> memory_manager)
42     : _impl(std::make_unique<Impl>())
43 {
44     _impl->memory_group = MemoryGroup(std::move(memory_manager));
45 }
46 
47 NEAddMulAdd::~NEAddMulAdd() = default;
48 
configure(ITensor * input1,ITensor * input2,ITensor * bn_mul,ITensor * bn_add,ITensor * add_output,ITensor * final_output,const ConvertPolicy policy,const ActivationLayerInfo & act_info)49 void NEAddMulAdd::configure(ITensor *input1, ITensor *input2, ITensor *bn_mul, ITensor *bn_add, ITensor *add_output,
50                             ITensor *final_output, const ConvertPolicy policy, const ActivationLayerInfo &act_info)
51 {
52     ARM_COMPUTE_LOG_PARAMS(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info);
53 
54     _impl->op           = std::make_unique<cpu::CpuAddMulAdd>();
55     _impl->op->configure(input1->info(), input2->info(), bn_mul->info(),
56                          bn_add->info(), add_output != nullptr ? add_output->info() : nullptr, final_output->info(), policy, act_info);
57 
58     _impl->run_pack =
59     {
60         { TensorType::ACL_SRC_0, input1 },
61         { TensorType::ACL_SRC_1, input2 },
62         { TensorType::ACL_SRC_2, bn_mul },
63         { TensorType::ACL_SRC_3, bn_add },
64         { TensorType::ACL_DST_0, add_output },
65         { TensorType::ACL_DST_1, final_output },
66     };
67 
68     _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
69 }
70 
validate(const ITensorInfo * input1,const ITensorInfo * input2,const ITensorInfo * bn_mul,const ITensorInfo * bn_add,const ITensorInfo * add_output,const ITensorInfo * final_output,ConvertPolicy policy,const ActivationLayerInfo & act_info)71 Status NEAddMulAdd::validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *bn_mul,
72                              const ITensorInfo *bn_add, const ITensorInfo *add_output, const ITensorInfo *final_output,
73                              ConvertPolicy policy, const ActivationLayerInfo &act_info)
74 {
75     return cpu::CpuAddMulAdd::validate(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info);
76 }
77 
run()78 void NEAddMulAdd::run()
79 {
80     _impl->op->run(_impl->run_pack);
81 }
82 } // namespace arm_compute
83