blob: fb1b70b91fd725315fbbb321828b4246610fc768 [file] [log] [blame]
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01001/*
Dana Zlotnik256ac622022-02-02 15:06:11 +02002 * Copyright (c) 2016-2022 Arm Limited.
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01003 *
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 Pinitas7891a732021-08-20 21:39:25 +010024#include "src/cpu/kernels/CpuGemmMatrixAdditionKernel.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010025
26#include "arm_compute/core/Helpers.h"
27#include "arm_compute/core/Types.h"
28#include "arm_compute/core/Validate.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Dana Zlotnik256ac622022-02-02 15:06:11 +020030#include "src/core/common/Registrars.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010031#include "src/core/CPP/Validate.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010032#include "src/core/helpers/AutoConfiguration.h"
33#include "src/core/helpers/WindowHelpers.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010034#include "src/core/NEON/NEFixedPoint.h"
Dana Zlotnik256ac622022-02-02 15:06:11 +020035#include "src/cpu/kernels/gemm_matrix_add/list.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010036namespace arm_compute
37{
38namespace cpu
39{
40namespace kernels
41{
42namespace
43{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010044static 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 Giorgio93b75e02021-06-21 12:00:43 +010050
Dana Zlotnik256ac622022-02-02 15:06:11 +020051};
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010052} // namespace
53
54void 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 Zlotnik256ac622022-02-02 15:06:11 +020062 _beta = beta;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 const auto uk = CpuGemmMatrixAdditionKernel::get_implementation(
64 DataTypeISASelectorData{src->data_type(), CPUInfo::get().get_isa()});
Dana Zlotnik256ac622022-02-02 15:06:11 +020065 ARM_COMPUTE_ERROR_ON_NULLPTR(uk);
66 _func = uk->ukernel;
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010067 // Configure kernel window
68 Window win = calculate_max_window(*src, Steps());
69 ICPPKernel::configure(win);
70}
71
72Status 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 Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 if (dst->total_size() > 0)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010081 {
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
88void 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 Thomasmathibalanafd38f02023-09-27 17:46:17 +010098 if (_beta != 0.0f)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010099 {
100 (*_func)(src, dst, window, _beta);
101 }
102}
103
104const char *CpuGemmMatrixAdditionKernel::name() const
105{
106 return "CpuGemmMatrixAdditionKernel";
107}
Dana Zlotnik256ac622022-02-02 15:06:11 +0200108
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100109const std::vector<CpuGemmMatrixAdditionKernel::GemmMatrixAddKernel> &
110CpuGemmMatrixAdditionKernel::get_available_kernels()
Dana Zlotnik256ac622022-02-02 15:06:11 +0200111{
112 return available_kernels;
113}
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100114} // namespace kernels
115} // namespace cpu
116} // namespace arm_compute