blob: 6399ebbef4400d51cdb8861f545e7f777174b763 [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"
29#include "src/core/CPP/Validate.h"
30#include "src/core/NEON/NEFixedPoint.h"
Dana Zlotnik256ac622022-02-02 15:06:11 +020031#include "src/core/common/Registrars.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010032#include "src/core/helpers/AutoConfiguration.h"
33#include "src/core/helpers/WindowHelpers.h"
Dana Zlotnik256ac622022-02-02 15:06:11 +020034#include "src/cpu/kernels/gemm_matrix_add/list.h"
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010035namespace arm_compute
36{
37namespace cpu
38{
39namespace kernels
40{
41namespace
42{
Dana Zlotnik256ac622022-02-02 15:06:11 +020043static const std::vector<CpuGemmMatrixAdditionKernel::GemmMatrixAddKernel> available_kernels =
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010044{
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010045 {
Dana Zlotnik256ac622022-02-02 15:06:11 +020046 "neon_fp32_gemm_matrix_add",
47 [](const DataTypeISASelectorData & data)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010048 {
Dana Zlotnik256ac622022-02-02 15:06:11 +020049 return (data.dt == DataType::F32);
50 },
51 REGISTER_FP32_NEON(neon_fp32_gemm_matrix_add)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010052 },
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010053 {
Dana Zlotnik256ac622022-02-02 15:06:11 +020054 "neon_fp16_gemm_matrix_add",
55 [](const DataTypeISASelectorData & data)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010056 {
Dana Zlotnik256ac622022-02-02 15:06:11 +020057 return (data.dt == DataType::F16) && data.isa.fp16;
58 },
59 REGISTER_FP16_NEON(neon_fp16_gemm_matrix_add)
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010060 },
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010061
Dana Zlotnik256ac622022-02-02 15:06:11 +020062};
Michele Di Giorgio93b75e02021-06-21 12:00:43 +010063} // namespace
64
65void 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 Zlotnik256ac622022-02-02 15:06:11 +020073 _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 Giorgio93b75e02021-06-21 12:00:43 +010077 // Configure kernel window
78 Window win = calculate_max_window(*src, Steps());
79 ICPPKernel::configure(win);
80}
81
82Status 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
98void 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
114const char *CpuGemmMatrixAdditionKernel::name() const
115{
116 return "CpuGemmMatrixAdditionKernel";
117}
Dana Zlotnik256ac622022-02-02 15:06:11 +0200118
119const std::vector<CpuGemmMatrixAdditionKernel::GemmMatrixAddKernel> &CpuGemmMatrixAdditionKernel::get_available_kernels()
120{
121 return available_kernels;
122}
Michele Di Giorgio93b75e02021-06-21 12:00:43 +0100123} // namespace kernels
124} // namespace cpu
125} // namespace arm_compute