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