Compute Library
 21.02
CLGEMMDefaultTypeMidgard.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Arm Limited.
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  */
25 
30 
31 #include <map>
32 #include <utility>
33 
34 namespace arm_compute
35 {
36 namespace cl_gemm
37 {
40 {
41 }
42 
44 {
45  // _target could be used in the future to have a dedicated heuristic for each GPU IP
46  ARM_COMPUTE_UNUSED(_target);
47 
48  using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeMidgard::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant);
49 
50  // Configurations for Midgard architectures
51  static std::map<DataType, FunctionExecutorPtr> gemm_configs =
52  {
53  { 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 }
59  };
60 
61  const DataType data_type = params.data_type;
62 
63  if(gemm_configs.find(data_type) != gemm_configs.end())
64  {
65  return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant);
66  }
67 
68  ARM_COMPUTE_ERROR("Not supported data type");
69 }
70 
71 CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
72 {
73  ARM_COMPUTE_UNUSED(n, k, b);
74 
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 
79 CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
80 {
81  ARM_COMPUTE_UNUSED(n, k, b);
82 
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 
87 CLGEMMKernelType CLGEMMDefaultTypeMidgard::default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
88 {
89  ARM_COMPUTE_UNUSED(m, n, k, b, is_rhs_constant);
90 
92 }
93 } // namespace cl_gemm
94 } // namespace arm_compute
unsigned int m
Number of rows for the lhs matrix.
Definition: CLTypes.h:54
OpenCL GEMM kernel selection parameters.
Definition: CLTypes.h:52
SimpleTensor< float > b
Definition: DFT.cpp:157
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams &params) override
Given the input parameters passed through CLGEMMKernelSelectionParams, this method returns the CLGEMM...
Midgard based OpenCL GEMMKernel selection.
1 channel, 1 F32 per channel
CLGEMMKernelType
OpenCL GEMM kernel types.
Definition: CLTypes.h:31
Basic interface for the GEMM kernel selection.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
Native GEMM kernel with fixed block size.
const DataType data_type
Definition: Im2Col.cpp:150
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
quantized, asymmetric fixed-point 8-bit number unsigned
bool is_rhs_constant
True if the content of the rhs matrix is constant.
Definition: CLTypes.h:58
quantized, symmetric fixed-point 8-bit number
quantized, symmetric per channel fixed-point 8-bit number
unsigned int b
Batch size.
Definition: CLTypes.h:57
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
Native GEMM kernel with configurable block size.
unsigned int n
Number of columns for the rhs matrix.
Definition: CLTypes.h:55
quantized, asymmetric fixed-point 8-bit number signed
DataType
Available data types.
Definition: Types.h:77
Reshaped GEMM kernel where both lhs and rhs matrices are reshaped.
unsigned int k
Number of rows for the rhs matrix.
Definition: CLTypes.h:56