Compute Library
 21.02
CLGEMMDefaultTypeValhall.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 
29 
30 #include <map>
31 #include <utility>
32 
33 namespace arm_compute
34 {
35 namespace cl_gemm
36 {
39 {
40 }
41 
43 {
44  // _target could be used in the future to have a dedicated heuristic for each GPU IP
45  ARM_COMPUTE_UNUSED(_target);
46 
47  using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMDefaultTypeValhall::*)(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant);
48 
49  // Default configurations for Valhall architectures
50  static std::map<DataType, FunctionExecutorPtr> gemm_default_configs =
51  {
52  { DataType::F32, &CLGEMMDefaultTypeValhall::default_f32 },
53  { DataType::F16, &CLGEMMDefaultTypeValhall::default_f16 },
54  { DataType::QASYMM8, &CLGEMMDefaultTypeValhall::default_q8 },
55  { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeValhall::default_q8 },
56  { DataType::QSYMM8, &CLGEMMDefaultTypeValhall::default_q8 },
57  { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeValhall::default_q8 }
58  };
59 
60  // Mali-G77 configurations
61  static std::map<DataType, FunctionExecutorPtr> gemm_g77_configs =
62  {
63  { DataType::F32, &CLGEMMDefaultTypeValhall::default_f32 },
64  { DataType::F16, &CLGEMMDefaultTypeValhall::g77_f16 },
65  { DataType::QASYMM8, &CLGEMMDefaultTypeValhall::default_q8 },
66  { DataType::QASYMM8_SIGNED, &CLGEMMDefaultTypeValhall::default_q8 },
67  { DataType::QSYMM8, &CLGEMMDefaultTypeValhall::default_q8 },
68  { DataType::QSYMM8_PER_CHANNEL, &CLGEMMDefaultTypeValhall::default_q8 }
69  };
70 
71  const DataType data_type = params.data_type;
72 
73  switch(_target)
74  {
75  case GPUTarget::G77:
76  if(gemm_g77_configs.find(data_type) != gemm_g77_configs.end())
77  {
78  return (this->*gemm_g77_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant);
79  }
80  ARM_COMPUTE_ERROR("Not supported data type");
81  default:
82  if(gemm_default_configs.find(data_type) != gemm_default_configs.end())
83  {
84  return (this->*gemm_default_configs[data_type])(params.m, params.n, params.k, params.b, params.is_rhs_constant);
85  }
86  ARM_COMPUTE_ERROR("Not supported data type");
87  }
88 }
89 
90 CLGEMMKernelType CLGEMMDefaultTypeValhall::default_f32(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
91 {
92  ARM_COMPUTE_UNUSED(m, n, k, b);
93 
95 }
96 
97 CLGEMMKernelType CLGEMMDefaultTypeValhall::default_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
98 {
99  ARM_COMPUTE_UNUSED(m, n, k, b);
100 
102 }
103 
104 CLGEMMKernelType CLGEMMDefaultTypeValhall::g77_f16(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
105 {
106  if(!is_rhs_constant)
107  {
109  }
110 
111  if(m == 1)
112  {
114  }
115 
116  const float r_mn = static_cast<float>(m) / static_cast<float>(n);
117  const float r_mk = static_cast<float>(m) / static_cast<float>(k);
118  const float r_nk = static_cast<float>(n) / static_cast<float>(k);
119  const float workload = (static_cast<float>(m) * static_cast<float>(n) * static_cast<float>(b)) / 20.0f;
120 
121  if(r_mk <= 0.6817956566810608)
122  {
123  if(workload <= 801.6000061035156)
124  {
126  }
127  else
128  {
129  if(r_mn <= 0.0839829258620739)
130  {
132  }
133  else
134  {
135  if(r_mk <= 0.24917218834161758)
136  {
138  }
139  else
140  {
141  if(workload <= 2551.75)
142  {
144  }
145  else
146  {
147  if(workload <= 5061.574951171875)
148  {
150  }
151  else
152  {
154  }
155  }
156  }
157  }
158  }
159  }
160  else
161  {
162  if(r_mk <= 4.849947690963745)
163  {
164  if(workload <= 17618.4501953125)
165  {
166  if(workload <= 5224.699951171875)
167  {
169  }
170  else
171  {
172  if(r_nk <= 0.7933054566383362)
173  {
175  }
176  else
177  {
179  }
180  }
181  }
182  else
183  {
184  if(workload <= 20275.2001953125)
185  {
187  }
188  else
189  {
190  if(r_mk <= 3.07421875)
191  {
193  }
194  else
195  {
197  }
198  }
199  }
200  }
201  else
202  {
204  }
205  }
206 }
207 
208 CLGEMMKernelType CLGEMMDefaultTypeValhall::default_q8(unsigned int m, unsigned int n, unsigned int k, unsigned int b, bool is_rhs_constant)
209 {
210  ARM_COMPUTE_UNUSED(m, n, k, b);
211 
212  if(is_rhs_constant)
213  {
215  }
216  else
217  {
219  }
220 }
221 } // namespace cl_gemm
222 } // 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
1 channel, 1 F32 per channel
Reshaped GEMM kernel where only the rhs matrix is reshaped.
CLGEMMKernelType
OpenCL GEMM kernel types.
Definition: CLTypes.h:31
Reshaped GEMM kernel where both lhs and rhs matrices are reshaped.
Basic interface for the GEMM kernel selection.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
Valhall based OpenCL GEMMKernel selection.
CLGEMMKernelType select_kernel(const CLGEMMKernelSelectionParams &params) override
Given the input parameters passed through CLGEMMKernelSelectionParams, this method returns the CLGEMM...
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
unsigned int k
Number of rows for the rhs matrix.
Definition: CLTypes.h:56