blob: a3612f3b5df52c9e5d94b691f153f4ef579d147d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
giuros011c9efeb2019-01-11 14:04:43 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
24#include "arm_compute/runtime/CL/functions/CLGEMM.h"
25
26#include "arm_compute/core/CL/ICLTensor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Error.h"
Gian Marco Iodice750641d2018-05-08 12:01:57 +010028#include "arm_compute/core/GPUTarget.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/Helpers.h"
30#include "arm_compute/core/TensorInfo.h"
31#include "arm_compute/core/Types.h"
Gian Marco Iodicebb36a8e2018-04-19 12:05:08 +010032#include "arm_compute/core/Utils.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include "arm_compute/core/Validate.h"
Gian Marco Iodice750641d2018-05-08 12:01:57 +010034#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035#include "arm_compute/runtime/CL/CLScheduler.h"
36#include "arm_compute/runtime/ITensorAllocator.h"
37
giuros011c9efeb2019-01-11 14:04:43 +000038namespace arm_compute
39{
Gian Marco Iodice750641d2018-05-08 12:01:57 +010040using namespace arm_compute::misc::shape_calculator;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041
Gian Marco36a0a462018-01-12 10:21:40 +000042namespace
43{
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000044inline bool is_interleaved_transposed(unsigned int m, unsigned int n, unsigned int k, DataType data_type, bool reshape_b_only_on_first_run, GPUTarget gpu_target)
Gian Marco36a0a462018-01-12 10:21:40 +000045{
46 bool flag = true;
47
Georgios Pinitasa34286e2018-09-04 12:18:50 +010048 if(gpu_target_is_in(gpu_target, GPUTarget::G52, GPUTarget::G52LIT, GPUTarget::G71, GPUTarget::G72, GPUTarget::G76))
Gian Marco36a0a462018-01-12 10:21:40 +000049 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000050 if((m > 1) && n < 16)
Gian Marco36a0a462018-01-12 10:21:40 +000051 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000052 flag = true;
Gian Marco36a0a462018-01-12 10:21:40 +000053 }
54 else
55 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000056 // COMPMID-852
57 if(k > 256 && m > 4 && is_data_type_float(data_type) && reshape_b_only_on_first_run)
58 {
59 constexpr float alpha = 3.2f;
60 constexpr float fact0 = 1.51f;
61 constexpr float fact1 = 1.66f;
62 constexpr float ops = 12.0f;
63 const float scale = k > 1024 ? 1.07f : 1.0f;
64 flag = alpha + ((n * fact0) / ops) < ((fact1 * n * scale) / ops);
65 }
66 else
67 {
68 flag = false;
69 }
Gian Marco36a0a462018-01-12 10:21:40 +000070 }
71 }
Gian Marco Iodicecda0c382018-04-23 16:16:22 +010072 else
73 {
74 // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once
75 flag = m != 1 && reshape_b_only_on_first_run;
76 }
Gian Marco36a0a462018-01-12 10:21:40 +000077
78 return flag;
79}
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000080
81inline void select_gemm_configuration(unsigned int m, unsigned int n, GEMMLHSMatrixInfo &lhs_info, GEMMRHSMatrixInfo &rhs_info)
82{
83 // Heuristic selection for GEMM
84 if(n <= 4)
85 {
86 // Configure GEMMLHSMatrixInfo
87 lhs_info.m0 = 4;
88 lhs_info.k0 = 8;
89 lhs_info.v0 = lhs_info.m0 * 16 < m ? 2 : 16;
90 lhs_info.interleave = true;
91 lhs_info.transpose = false;
92
93 // Configure GEMMRHSMatrixInfo
94 rhs_info.n0 = 2;
95 rhs_info.k0 = lhs_info.k0;
96 rhs_info.h0 = rhs_info.n0 * 16 < n ? 2 : 16;
97 rhs_info.interleave = false;
98 rhs_info.transpose = true;
99 }
100 else
101 {
102 // Configure GEMMLHSMatrixInfo
103 lhs_info.m0 = (m * n) / 24 > 2048 ? 6 : 5;
104 lhs_info.k0 = 4;
105 lhs_info.v0 = 32;
106 lhs_info.interleave = false;
107 lhs_info.transpose = false;
108
109 // Configure GEMMRHSMatrixInfo
110 rhs_info.n0 = 4;
111 rhs_info.k0 = lhs_info.k0;
112 rhs_info.h0 = 32;
113 rhs_info.interleave = true;
114 rhs_info.transpose = true;
115 }
116}
Gian Marco36a0a462018-01-12 10:21:40 +0000117} // namespace
118
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100119CLGEMM::CLGEMM(std::shared_ptr<IMemoryManager> memory_manager)
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100120 : _memory_group(std::move(memory_manager)),
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100121 _mm_kernel(),
122 _ma_kernel(),
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000123 _reshape_lhs_kernel(),
124 _reshape_rhs_kernel(),
125 _mm_reshaped_kernel(),
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100126 _tmp_a(),
127 _tmp_b(),
128 _original_b(nullptr),
129 _is_interleaved_transposed(false),
130 _run_addition(false),
131 _reshape_b_only_on_first_run(false),
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000132 _is_prepared(false),
133 _is_G76_path(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134{
135}
136
Gian Marco1d25ed52017-12-16 19:33:50 +0000137void CLGEMM::configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100138{
Georgios Pinitas78c00902018-01-09 17:33:11 +0000139 ARM_COMPUTE_ERROR_ON_NULLPTR(a, b, output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140
Georgios Pinitas78c00902018-01-09 17:33:11 +0000141 // Perform validation step
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100142 ARM_COMPUTE_ERROR_THROW_ON(validate(a->info(), b->info(), c != nullptr ? c->info() : nullptr, output->info(), alpha, beta, gemm_info));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100143
Gian Marco1d25ed52017-12-16 19:33:50 +0000144 // Check if we need to reshape the matrix B only on the first run
145 _reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run();
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +0100146 _is_prepared = gemm_info.retain_internal_weights();
Georgios Pinitas72219332018-06-05 14:56:06 +0100147 _original_b = b;
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100148
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100149 const ICLTensor *matrix_a = a;
150 const ICLTensor *matrix_b = b;
151
Gian Marco36a0a462018-01-12 10:21:40 +0000152 // Get the GPU target
153 const GPUTarget gpu_target = CLScheduler::get().target();
154
155 // Set the target for the kernels
giuros011c9efeb2019-01-11 14:04:43 +0000156 _reshape_lhs_kernel.set_target(gpu_target);
Gian Marco36a0a462018-01-12 10:21:40 +0000157 _mm_kernel.set_target(gpu_target);
158
159 // Arguments used by GEMMReshapeInfo
160 // If we pass the matrix A and matrix B reshaped to CLGEMMMatrixMultiplyKernel, we need to pass m, n, k, mult_transpose1xW_width and mult_interleave4x4_height to CLGEMMReshapeInfo
161 // in order to know how the matrices have been reshaped
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000162 DataType data_type = a->info()->data_type();
163 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
164 const unsigned int m = reinterpret_input_as_3d ? (a->info()->dimension(1) * a->info()->dimension(2)) : a->info()->dimension(1);
165 const unsigned int n = b->info()->dimension(0);
166 const unsigned int k = a->info()->dimension(0);
167 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
168 int mult_transpose1xW_width = 1;
169 int mult_interleave4x4_height = 1;
Gian Marco36a0a462018-01-12 10:21:40 +0000170
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100171 if(get_arch_from_target(gpu_target) == GPUTarget::BIFROST)
Gian Marco36a0a462018-01-12 10:21:40 +0000172 {
173 mult_transpose1xW_width = 4;
174 mult_interleave4x4_height = 2;
175 }
giuros018b6b4a92018-12-18 19:01:33 +0000176 GEMMRHSMatrixInfo rhs_info;
177 rhs_info.n0 = 16 / b->info()->element_size();
178 rhs_info.k0 = 1;
179 rhs_info.h0 = mult_transpose1xW_width;
180 rhs_info.interleave = false;
181 rhs_info.transpose = false;
Gian Marco36a0a462018-01-12 10:21:40 +0000182
giuros011c9efeb2019-01-11 14:04:43 +0000183 GEMMLHSMatrixInfo lhs_info;
184 lhs_info.m0 = 4;
185 lhs_info.k0 = 4;
186 lhs_info.v0 = mult_interleave4x4_height;
187 lhs_info.interleave = true;
188 lhs_info.transpose = true;
189
Gian Marco36a0a462018-01-12 10:21:40 +0000190 // Check if we need to reshape the matrix A and matrix B
191 _is_interleaved_transposed = is_interleaved_transposed(m, n, k, a->info()->data_type(), _reshape_b_only_on_first_run, gpu_target);
Gian Marcob5311a62017-12-13 12:48:03 +0000192
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000193 // Check if we can run the new reshaped GEMM
194 _is_G76_path = (gpu_target == GPUTarget::G76) && _is_interleaved_transposed && (data_type == DataType::F32);
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000195
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100196 // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
197 if(_is_interleaved_transposed)
198 {
199 reinterpret_input_as_3d = false;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100200
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100201 matrix_a = &_tmp_a;
202 matrix_b = &_tmp_b;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100203
Gian Marco19835e52018-01-30 13:35:54 +0000204 // Manage intermediate buffers
205 _memory_group.manage(&_tmp_a);
Georgios Pinitasae4ce7b2018-03-19 17:50:45 +0000206 if(!_reshape_b_only_on_first_run)
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000207 {
208 _memory_group.manage(&_tmp_b);
209 }
Gian Marco20d78482018-01-11 15:10:58 +0000210 // _tmp_a and _tmp_b will be auto configured in _interleave_kernel and in _transpose_kernel
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100211
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000212 if(_is_G76_path)
213 {
214 GEMMLHSMatrixInfo lhs_info;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000216 // Pick up the GEMM configuration based on M,N and K
217 select_gemm_configuration(m, n, lhs_info, rhs_info);
218
219 _reshape_lhs_kernel.configure(a, &_tmp_a, lhs_info, gemm_info.reinterpret_input_as_3d());
220 _reshape_rhs_kernel.configure(b, &_tmp_b, rhs_info);
221
222 // Configure and tune matrix multiply kernel
223 _mm_reshaped_kernel.configure(matrix_a, matrix_b, output, alpha, lhs_info, rhs_info, GEMMReshapeInfo(m, n, k, 1, 1,
224 depth_output_gemm3d, reinterpret_input_as_3d));
225 }
226 else
227 {
228 // Configure interleave kernel
giuros011c9efeb2019-01-11 14:04:43 +0000229 _reshape_lhs_kernel.configure(a, &_tmp_a, lhs_info, gemm_info.reinterpret_input_as_3d());
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000230 // Configure transpose kernel
giuros018b6b4a92018-12-18 19:01:33 +0000231 _reshape_rhs_kernel.configure(b, &_tmp_b, rhs_info);
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000232 }
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100233 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100234
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000235 if(!_is_G76_path)
236 {
237 // Configure and tune matrix multiply kernel
238 _mm_kernel.configure(matrix_a, matrix_b, output, alpha, _is_interleaved_transposed, GEMMReshapeInfo(m, n, k,
239 mult_transpose1xW_width, mult_interleave4x4_height,
240 depth_output_gemm3d, reinterpret_input_as_3d),
241 gemm_info.fp_mixed_precision());
242 CLScheduler::get().tune_kernel_static(_mm_kernel);
243 }
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100244
245 if(_is_interleaved_transposed)
246 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100247 // Allocate intermediate tensors
248 _tmp_a.allocator()->allocate();
Georgios Pinitase0437672018-05-02 14:07:55 +0100249 if(!_reshape_b_only_on_first_run)
250 {
251 _tmp_b.allocator()->allocate();
252 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100253 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100254
255 // Configure matrix addition kernel
256 if(beta != 0 && c != nullptr)
257 {
258 _ma_kernel.configure(c, output, beta);
259 _run_addition = true;
260 }
261}
262
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100263Status CLGEMM::validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info)
Georgios Pinitas78c00902018-01-09 17:33:11 +0000264{
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100265 ARM_COMPUTE_UNUSED(alpha);
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100266 ARM_COMPUTE_UNUSED(output);
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100267
268 // Check if we need to reshape the matrix B only on the first run
269 const bool reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run();
270
271 const ITensorInfo *matrix_a_info = a;
272 const ITensorInfo *matrix_b_info = b;
273
274 TensorInfo tmp_a_info{};
275 TensorInfo tmp_b_info{};
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100276
277 // Get the GPU target
278 const GPUTarget gpu_target = CLScheduler::get().target();
279
280 // Arguments used by GEMMReshapeInfo
281 // If we pass the matrix A and matrix B reshaped to CLGEMMMatrixMultiplyKernel, we need to pass m, n, k, mult_transpose1xW_width and mult_interleave4x4_height to CLGEMMReshapeInfo
282 // in order to know how the matrices have been reshaped
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000283 DataType data_type = a->data_type();
284 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
285 const unsigned int m = reinterpret_input_as_3d ? (a->dimension(1) * a->dimension(2)) : a->dimension(1);
286 const unsigned int n = b->dimension(0);
287 const unsigned int k = a->dimension(0);
288 int mult_transpose1xW_width = 1;
289 int mult_interleave4x4_height = 1;
290 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100291
292 if(get_arch_from_target(gpu_target) == GPUTarget::BIFROST)
293 {
294 mult_transpose1xW_width = 4;
295 mult_interleave4x4_height = 2;
296 }
297
giuros018b6b4a92018-12-18 19:01:33 +0000298 GEMMRHSMatrixInfo rhs_info;
299 rhs_info.n0 = 16 / b->element_size();
300 rhs_info.k0 = 1;
301 rhs_info.h0 = mult_transpose1xW_width;
302 rhs_info.interleave = false;
303 rhs_info.transpose = false;
304
giuros011c9efeb2019-01-11 14:04:43 +0000305 GEMMLHSMatrixInfo lhs_info;
306 lhs_info.m0 = 4;
307 lhs_info.k0 = 4;
308 lhs_info.v0 = mult_interleave4x4_height;
309 lhs_info.interleave = true;
310 lhs_info.transpose = true;
311
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100312 // Check if we need to reshape the matrix A and matrix B
313 const bool run_interleave_transpose = is_interleaved_transposed(m, n, k, a->data_type(), reshape_b_only_on_first_run, gpu_target);
314
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000315 // Check if we can run the new reshaped GEMM
316 const bool is_G76_path = (gpu_target == GPUTarget::G76) && run_interleave_transpose && (data_type == DataType::F32);
317
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100318 // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
319 if(run_interleave_transpose)
320 {
321 reinterpret_input_as_3d = false;
322 }
323
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100324 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(m, n, k, mult_transpose1xW_width, mult_interleave4x4_height, depth_output_gemm3d, reinterpret_input_as_3d);
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100325
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100326 if(run_interleave_transpose)
327 {
328 matrix_a_info = &tmp_a_info;
329 matrix_b_info = &tmp_b_info;
330
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000331 if(is_G76_path)
332 {
333 GEMMLHSMatrixInfo lhs_info;
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100334
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000335 // Pick up the GEMM configuration based on M,N and K
336 select_gemm_configuration(m, n, lhs_info, rhs_info);
337
338 auto_init_if_empty(tmp_a_info, a->clone()->set_tensor_shape(compute_lhs_reshaped_shape(*a, lhs_info, gemm_info.reinterpret_input_as_3d())));
339 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeLHSMatrixKernel::validate(a, &tmp_a_info, lhs_info, gemm_info.reinterpret_input_as_3d()));
340
341 auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_rhs_reshaped_shape(*b, rhs_info)));
342 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeRHSMatrixKernel::validate(b, &tmp_b_info, rhs_info));
343
344 // Validate matrix multiply
345 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMMatrixMultiplyReshapedKernel::validate(matrix_a_info, matrix_b_info, output, alpha, lhs_info, rhs_info, GEMMReshapeInfo(m, n, k, 1, 1,
346 depth_output_gemm3d, reinterpret_input_as_3d)));
347 }
348 else
349 {
350 // Validate interleave kernel
giuros011c9efeb2019-01-11 14:04:43 +0000351 auto_init_if_empty(tmp_a_info, a->clone()->set_tensor_shape(compute_lhs_reshaped_shape(*a, lhs_info, gemm_info.reinterpret_input_as_3d())));
352 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeLHSMatrixKernel::validate(a, &tmp_a_info, lhs_info, gemm_info.reinterpret_input_as_3d()));
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000353 // Validate transpose kernel
giuros018b6b4a92018-12-18 19:01:33 +0000354 auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_rhs_reshaped_shape(*b, rhs_info)));
355 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeRHSMatrixKernel::validate(b, &tmp_b_info, rhs_info));
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000356 }
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100357 }
358
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000359 if(!is_G76_path)
360 {
361 // Validate matrix multiply
362 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMMatrixMultiplyKernel::validate(matrix_a_info, matrix_b_info, output, alpha, run_interleave_transpose, reshape_info, gpu_target, gemm_info.fp_mixed_precision()));
363 }
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100364
365 if(beta != 0 && c != nullptr)
366 {
367 // Validate matrix addition kernel
Giorgio Arena0f170392018-07-18 16:13:12 +0100368 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMMatrixAdditionKernel::validate(c, output, beta));
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100369 }
370
Georgios Pinitas78c00902018-01-09 17:33:11 +0000371 return Status{};
372}
373
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100374void CLGEMM::run()
375{
Georgios Pinitase0437672018-05-02 14:07:55 +0100376 prepare();
377
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100378 _memory_group.acquire();
379
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100380 if(_is_interleaved_transposed)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100381 {
382 // Run interleave kernel
giuros011c9efeb2019-01-11 14:04:43 +0000383 CLScheduler::get().enqueue(_reshape_lhs_kernel, false);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100384
Georgios Pinitase0437672018-05-02 14:07:55 +0100385 if(!_reshape_b_only_on_first_run)
Gian Marco1d25ed52017-12-16 19:33:50 +0000386 {
387 // Run transpose kernel
giuros018b6b4a92018-12-18 19:01:33 +0000388 CLScheduler::get().enqueue(_reshape_rhs_kernel, false);
Gian Marco1d25ed52017-12-16 19:33:50 +0000389 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100390 }
391
392 // Run matrix multiply kernel
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000393 if(_is_G76_path)
394 {
395 CLScheduler::get().enqueue(_mm_reshaped_kernel, !_run_addition);
396 }
397 else
398 {
399 CLScheduler::get().enqueue(_mm_kernel, !_run_addition);
400 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100401
402 // Run matrix addition kernel
403 if(_run_addition)
404 {
405 CLScheduler::get().enqueue(_ma_kernel);
406 }
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100407
408 _memory_group.release();
Georgios Pinitase0437672018-05-02 14:07:55 +0100409}
Georgios Pinitas82b51482018-04-24 15:14:12 +0100410
Georgios Pinitase0437672018-05-02 14:07:55 +0100411void CLGEMM::prepare()
412{
413 if(!_is_prepared)
414 {
415 if(_is_interleaved_transposed && _reshape_b_only_on_first_run)
416 {
Georgios Pinitas72219332018-06-05 14:56:06 +0100417 // Run transpose kernel and mark original weights tensor as unused
Georgios Pinitase0437672018-05-02 14:07:55 +0100418 _tmp_b.allocator()->allocate();
giuros018b6b4a92018-12-18 19:01:33 +0000419 CLScheduler::get().enqueue(_reshape_rhs_kernel, false);
Georgios Pinitase0437672018-05-02 14:07:55 +0100420 _original_b->mark_as_unused();
421 }
422 CLScheduler::get().queue().finish();
423 _is_prepared = true;
424 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100425}
giuros011c9efeb2019-01-11 14:04:43 +0000426} // namespace arm_compute