Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 1 | /* |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 2 | * Copyright (c) 2016-2022 Arm Limited. |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/kernels/CpuGemmMatrixAdditionKernel.h" |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/Types.h" |
| 28 | #include "arm_compute/core/Validate.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 30 | #include "src/core/common/Registrars.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 31 | #include "src/core/CPP/Validate.h" |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 32 | #include "src/core/helpers/AutoConfiguration.h" |
| 33 | #include "src/core/helpers/WindowHelpers.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 34 | #include "src/core/NEON/NEFixedPoint.h" |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 35 | #include "src/cpu/kernels/gemm_matrix_add/list.h" |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace cpu |
| 39 | { |
| 40 | namespace kernels |
| 41 | { |
| 42 | namespace |
| 43 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 44 | static const std::vector<CpuGemmMatrixAdditionKernel::GemmMatrixAddKernel> available_kernels = { |
| 45 | {"neon_fp32_gemm_matrix_add", [](const DataTypeISASelectorData &data) { return (data.dt == DataType::F32); }, |
| 46 | REGISTER_FP32_NEON(neon_fp32_gemm_matrix_add)}, |
| 47 | {"neon_fp16_gemm_matrix_add", |
| 48 | [](const DataTypeISASelectorData &data) { return (data.dt == DataType::F16) && data.isa.fp16; }, |
| 49 | REGISTER_FP16_NEON(neon_fp16_gemm_matrix_add)}, |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 50 | |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 51 | }; |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 52 | } // namespace |
| 53 | |
| 54 | void CpuGemmMatrixAdditionKernel::configure(const ITensorInfo *src, ITensorInfo *dst, float beta) |
| 55 | { |
| 56 | ARM_COMPUTE_UNUSED(dst); |
| 57 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst); |
| 58 | |
| 59 | // Perform validation step |
| 60 | ARM_COMPUTE_ERROR_THROW_ON(CpuGemmMatrixAdditionKernel::validate(src, dst, beta)); |
| 61 | |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 62 | _beta = beta; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 63 | const auto uk = CpuGemmMatrixAdditionKernel::get_implementation( |
| 64 | DataTypeISASelectorData{src->data_type(), CPUInfo::get().get_isa()}); |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 65 | ARM_COMPUTE_ERROR_ON_NULLPTR(uk); |
| 66 | _func = uk->ukernel; |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 67 | // Configure kernel window |
| 68 | Window win = calculate_max_window(*src, Steps()); |
| 69 | ICPPKernel::configure(win); |
| 70 | } |
| 71 | |
| 72 | Status CpuGemmMatrixAdditionKernel::validate(const ITensorInfo *src, const ITensorInfo *dst, float beta) |
| 73 | { |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, dst); |
| 75 | ARM_COMPUTE_UNUSED(beta); |
| 76 | |
| 77 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src); |
| 78 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F16, DataType::F32); |
| 79 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 80 | if (dst->total_size() > 0) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 81 | { |
| 82 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst); |
| 83 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(src, dst); |
| 84 | } |
| 85 | return Status{}; |
| 86 | } |
| 87 | |
| 88 | void CpuGemmMatrixAdditionKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) |
| 89 | { |
| 90 | ARM_COMPUTE_UNUSED(info); |
| 91 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 92 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 93 | ARM_COMPUTE_ERROR_ON(tensors.empty()); |
| 94 | |
| 95 | const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC); |
| 96 | ITensor *dst = tensors.get_tensor(TensorType::ACL_DST); |
| 97 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 98 | if (_beta != 0.0f) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 99 | { |
| 100 | (*_func)(src, dst, window, _beta); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | const char *CpuGemmMatrixAdditionKernel::name() const |
| 105 | { |
| 106 | return "CpuGemmMatrixAdditionKernel"; |
| 107 | } |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 108 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 109 | const std::vector<CpuGemmMatrixAdditionKernel::GemmMatrixAddKernel> & |
| 110 | CpuGemmMatrixAdditionKernel::get_available_kernels() |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 111 | { |
| 112 | return available_kernels; |
| 113 | } |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 114 | } // namespace kernels |
| 115 | } // namespace cpu |
| 116 | } // namespace arm_compute |