blob: a72364791caa0cf31df9c37a29d796b96cc0554e [file] [log] [blame]
Gunes Bayirae72a462023-01-29 13:24:24 +00001/*
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
Matthew Bentham1d062042023-07-06 13:13:59 +000027#include "arm_compute/runtime/Tensor.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Gunes Bayirae72a462023-01-29 13:24:24 +000029#include "src/common/utils/Log.h"
30#include "src/core/helpers/MemoryHelpers.h"
31#include "src/cpu/operators/CpuAddMulAdd.h"
32
33namespace arm_compute
34{
35struct NEAddMulAdd::Impl
36{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010037 std::unique_ptr<cpu::CpuAddMulAdd> op{nullptr};
Gunes Bayirae72a462023-01-29 13:24:24 +000038 WorkspaceData<Tensor> workspace_tensors{};
39 ITensorPack run_pack{};
40 MemoryGroup memory_group{};
41};
42
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043NEAddMulAdd::NEAddMulAdd(std::shared_ptr<IMemoryManager> memory_manager) : _impl(std::make_unique<Impl>())
Gunes Bayirae72a462023-01-29 13:24:24 +000044{
45 _impl->memory_group = MemoryGroup(std::move(memory_manager));
46}
47
48NEAddMulAdd::~NEAddMulAdd() = default;
49
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050void NEAddMulAdd::configure(ITensor *input1,
51 ITensor *input2,
52 ITensor *bn_mul,
53 ITensor *bn_add,
54 ITensor *add_output,
55 ITensor *final_output,
56 const ConvertPolicy policy,
57 const ActivationLayerInfo &act_info)
Gunes Bayirae72a462023-01-29 13:24:24 +000058{
59 ARM_COMPUTE_LOG_PARAMS(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info);
60
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061 _impl->op = std::make_unique<cpu::CpuAddMulAdd>();
62 _impl->op->configure(input1->info(), input2->info(), bn_mul->info(), bn_add->info(),
63 add_output != nullptr ? add_output->info() : nullptr, final_output->info(), policy, act_info);
Gunes Bayirae72a462023-01-29 13:24:24 +000064
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010065 _impl->run_pack = {
66 {TensorType::ACL_SRC_0, input1}, {TensorType::ACL_SRC_1, input2}, {TensorType::ACL_SRC_2, bn_mul},
67 {TensorType::ACL_SRC_3, bn_add}, {TensorType::ACL_DST_0, add_output}, {TensorType::ACL_DST_1, final_output},
Gunes Bayirae72a462023-01-29 13:24:24 +000068 };
69
70 _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack);
71}
72
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010073Status NEAddMulAdd::validate(const ITensorInfo *input1,
74 const ITensorInfo *input2,
75 const ITensorInfo *bn_mul,
76 const ITensorInfo *bn_add,
77 const ITensorInfo *add_output,
78 const ITensorInfo *final_output,
79 ConvertPolicy policy,
80 const ActivationLayerInfo &act_info)
Gunes Bayirae72a462023-01-29 13:24:24 +000081{
82 return cpu::CpuAddMulAdd::validate(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info);
83}
84
85void NEAddMulAdd::run()
86{
87 _impl->op->run(_impl->run_pack);
88}
89} // namespace arm_compute