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