blob: a64de9952e7d8bfeac3a78838638ab5a531e7401 [file] [log] [blame]
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +00001/*
Georgios Pinitas856f66e2021-04-22 21:13:21 +01002 * Copyright (c) 2020-2021 Arm Limited.
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +00003 *
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 */
SiCong Lia085a0c2020-12-02 14:54:34 +000024#include "src/runtime/CL/gemm/CLGEMMDefaultTypeMidgard.h"
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000025
26#include "arm_compute/core/CL/CLHelpers.h"
27#include "arm_compute/core/CL/CLKernelLibrary.h"
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000028#include "arm_compute/core/GPUTarget.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/kernels/gemm/ClGemmHelpers.h"
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000030
31#include <map>
32#include <utility>
33
34namespace arm_compute
35{
36namespace cl_gemm
37{
SiCong Lia085a0c2020-12-02 14:54:34 +000038CLGEMMDefaultTypeMidgard::CLGEMMDefaultTypeMidgard(GPUTarget gpu)
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000039 : ICLGEMMKernelSelection(gpu)
40{
41}
42
SiCong Lia085a0c2020-12-02 14:54:34 +000043CLGEMMKernelType CLGEMMDefaultTypeMidgard::select_kernel(const CLGEMMKernelSelectionParams &params)
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000044{
45 // _target could be used in the future to have a dedicated heuristic for each GPU IP
46 ARM_COMPUTE_UNUSED(_target);
47
SiCong Lia085a0c2020-12-02 14:54:34 +000048 using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeMidgard::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant);
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000049
50 // Configurations for Midgard architectures
51 static std::map<DataType, FunctionExecutorPtr> gemm_configs =
52 {
SiCong Lia085a0c2020-12-02 14:54:34 +000053 { DataType::F32, &CLGEMMDefaultTypeMidgard::default_f32 },
54 { DataType::F16, &CLGEMMDefaultTypeMidgard::default_f16 },
55 { DataType::QASYMM8, &CLGEMMDefaultTypeMidgard::default_q8 },
56 { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeMidgard::default_q8 },
57 { DataType::QSYMM8, &CLGEMMDefaultTypeMidgard::default_q8 },
58 { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeMidgard::default_q8 }
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000059 };
60
61 const DataType data_type = params.data_type;
62
63 if(gemm_configs.find(data_type) != gemm_configs.end())
64 {
Gian Marco Iodice026d0452020-08-28 13:52:12 +010065 return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant);
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000066 }
67
68 ARM_COMPUTE_ERROR("Not supported data type");
69}
70
SiCong Lia085a0c2020-12-02 14:54:34 +000071CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000072{
Gian Marco Iodice026d0452020-08-28 13:52:12 +010073 ARM_COMPUTE_UNUSED(n, k, b);
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000074
75 // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once
76 return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1;
77}
78
SiCong Lia085a0c2020-12-02 14:54:34 +000079CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000080{
Gian Marco Iodice026d0452020-08-28 13:52:12 +010081 ARM_COMPUTE_UNUSED(n, k, b);
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000082
83 // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once
84 return ((m != 1) && is_rhs_constant) ? CLGEMMKernelType::RESHAPED_V1 : CLGEMMKernelType::NATIVE_V1;
85}
86
SiCong Lia085a0c2020-12-02 14:54:34 +000087CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000088{
Gian Marco Iodice026d0452020-08-28 13:52:12 +010089 ARM_COMPUTE_UNUSED(m, n, k, b, is_rhs_constant);
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000090
Gian Marco Iodiceeb65f6d2020-04-15 11:42:15 +010091 return CLGEMMKernelType::NATIVE;
Gian Marco Iodice5a4fe192020-03-16 12:22:37 +000092}
93} // namespace cl_gemm
94} // namespace arm_compute