Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 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 | |
Matthew Bentham | 1d06204 | 2023-07-06 13:13:59 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/Tensor.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 29 | #include "src/common/utils/Log.h" |
| 30 | #include "src/core/helpers/MemoryHelpers.h" |
| 31 | #include "src/cpu/operators/CpuAddMulAdd.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | struct NEAddMulAdd::Impl |
| 36 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 37 | std::unique_ptr<cpu::CpuAddMulAdd> op{nullptr}; |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 38 | WorkspaceData<Tensor> workspace_tensors{}; |
| 39 | ITensorPack run_pack{}; |
| 40 | MemoryGroup memory_group{}; |
| 41 | }; |
| 42 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | NEAddMulAdd::NEAddMulAdd(std::shared_ptr<IMemoryManager> memory_manager) : _impl(std::make_unique<Impl>()) |
Gunes Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 44 | { |
| 45 | _impl->memory_group = MemoryGroup(std::move(memory_manager)); |
| 46 | } |
| 47 | |
| 48 | NEAddMulAdd::~NEAddMulAdd() = default; |
| 49 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | void 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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 58 | { |
| 59 | ARM_COMPUTE_LOG_PARAMS(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info); |
| 60 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 61 | _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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 64 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | _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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | _impl->workspace_tensors = manage_workspace<Tensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack); |
| 71 | } |
| 72 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 73 | Status 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 Bayir | ae72a46 | 2023-01-29 13:24:24 +0000 | [diff] [blame] | 81 | { |
| 82 | return cpu::CpuAddMulAdd::validate(input1, input2, bn_mul, bn_add, add_output, final_output, policy, act_info); |
| 83 | } |
| 84 | |
| 85 | void NEAddMulAdd::run() |
| 86 | { |
| 87 | _impl->op->run(_impl->run_pack); |
| 88 | } |
| 89 | } // namespace arm_compute |