blob: d0db8766d9d63d6cfd6612710d0f1df1a839b773 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Gian Marco20d78482018-01-11 15:10:58 +00002 * Copyright (c) 2017-2018 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
38using namespace arm_compute;
Gian Marco Iodice750641d2018-05-08 12:01:57 +010039using namespace arm_compute::misc::shape_calculator;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010040
Gian Marco36a0a462018-01-12 10:21:40 +000041namespace
42{
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000043inline 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 +000044{
45 bool flag = true;
46
Georgios Pinitasa34286e2018-09-04 12:18:50 +010047 if(gpu_target_is_in(gpu_target, GPUTarget::G52, GPUTarget::G52LIT, GPUTarget::G71, GPUTarget::G72, GPUTarget::G76))
Gian Marco36a0a462018-01-12 10:21:40 +000048 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000049 if((m > 1) && n < 16)
Gian Marco36a0a462018-01-12 10:21:40 +000050 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000051 flag = true;
Gian Marco36a0a462018-01-12 10:21:40 +000052 }
53 else
54 {
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000055 // COMPMID-852
56 if(k > 256 && m > 4 && is_data_type_float(data_type) && reshape_b_only_on_first_run)
57 {
58 constexpr float alpha = 3.2f;
59 constexpr float fact0 = 1.51f;
60 constexpr float fact1 = 1.66f;
61 constexpr float ops = 12.0f;
62 const float scale = k > 1024 ? 1.07f : 1.0f;
63 flag = alpha + ((n * fact0) / ops) < ((fact1 * n * scale) / ops);
64 }
65 else
66 {
67 flag = false;
68 }
Gian Marco36a0a462018-01-12 10:21:40 +000069 }
70 }
Gian Marco Iodicecda0c382018-04-23 16:16:22 +010071 else
72 {
73 // We reshape the matrices only if we do not have the vector-by-matrix case and we reshape the matrix B only once
74 flag = m != 1 && reshape_b_only_on_first_run;
75 }
Gian Marco36a0a462018-01-12 10:21:40 +000076
77 return flag;
78}
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +000079
80inline void select_gemm_configuration(unsigned int m, unsigned int n, GEMMLHSMatrixInfo &lhs_info, GEMMRHSMatrixInfo &rhs_info)
81{
82 // Heuristic selection for GEMM
83 if(n <= 4)
84 {
85 // Configure GEMMLHSMatrixInfo
86 lhs_info.m0 = 4;
87 lhs_info.k0 = 8;
88 lhs_info.v0 = lhs_info.m0 * 16 < m ? 2 : 16;
89 lhs_info.interleave = true;
90 lhs_info.transpose = false;
91
92 // Configure GEMMRHSMatrixInfo
93 rhs_info.n0 = 2;
94 rhs_info.k0 = lhs_info.k0;
95 rhs_info.h0 = rhs_info.n0 * 16 < n ? 2 : 16;
96 rhs_info.interleave = false;
97 rhs_info.transpose = true;
98 }
99 else
100 {
101 // Configure GEMMLHSMatrixInfo
102 lhs_info.m0 = (m * n) / 24 > 2048 ? 6 : 5;
103 lhs_info.k0 = 4;
104 lhs_info.v0 = 32;
105 lhs_info.interleave = false;
106 lhs_info.transpose = false;
107
108 // Configure GEMMRHSMatrixInfo
109 rhs_info.n0 = 4;
110 rhs_info.k0 = lhs_info.k0;
111 rhs_info.h0 = 32;
112 rhs_info.interleave = true;
113 rhs_info.transpose = true;
114 }
115}
Gian Marco36a0a462018-01-12 10:21:40 +0000116} // namespace
117
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100118CLGEMM::CLGEMM(std::shared_ptr<IMemoryManager> memory_manager)
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100119 : _memory_group(std::move(memory_manager)),
120 _interleave_kernel(),
121 _transpose_kernel(),
122 _mm_kernel(),
123 _ma_kernel(),
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000124 _reshape_lhs_kernel(),
125 _reshape_rhs_kernel(),
126 _mm_reshaped_kernel(),
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100127 _tmp_a(),
128 _tmp_b(),
129 _original_b(nullptr),
130 _is_interleaved_transposed(false),
131 _run_addition(false),
132 _reshape_b_only_on_first_run(false),
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000133 _is_prepared(false),
134 _is_G76_path(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135{
136}
137
Gian Marco1d25ed52017-12-16 19:33:50 +0000138void 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 +0100139{
Georgios Pinitas78c00902018-01-09 17:33:11 +0000140 ARM_COMPUTE_ERROR_ON_NULLPTR(a, b, output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141
Georgios Pinitas78c00902018-01-09 17:33:11 +0000142 // Perform validation step
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100143 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 +0100144
Gian Marco1d25ed52017-12-16 19:33:50 +0000145 // Check if we need to reshape the matrix B only on the first run
146 _reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run();
Michele Di Giorgioba1ffe92018-08-22 14:28:30 +0100147 _is_prepared = gemm_info.retain_internal_weights();
Georgios Pinitas72219332018-06-05 14:56:06 +0100148 _original_b = b;
Gian Marco Iodice1246b632017-08-16 18:38:32 +0100149
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100150 const ICLTensor *matrix_a = a;
151 const ICLTensor *matrix_b = b;
152
Gian Marco36a0a462018-01-12 10:21:40 +0000153 // Get the GPU target
154 const GPUTarget gpu_target = CLScheduler::get().target();
155
156 // Set the target for the kernels
157 _interleave_kernel.set_target(gpu_target);
158 _mm_kernel.set_target(gpu_target);
159
160 // Arguments used by GEMMReshapeInfo
161 // 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
162 // in order to know how the matrices have been reshaped
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000163 DataType data_type = a->info()->data_type();
164 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
165 const unsigned int m = reinterpret_input_as_3d ? (a->info()->dimension(1) * a->info()->dimension(2)) : a->info()->dimension(1);
166 const unsigned int n = b->info()->dimension(0);
167 const unsigned int k = a->info()->dimension(0);
168 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
169 int mult_transpose1xW_width = 1;
170 int mult_interleave4x4_height = 1;
Gian Marco36a0a462018-01-12 10:21:40 +0000171
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100172 if(get_arch_from_target(gpu_target) == GPUTarget::BIFROST)
Gian Marco36a0a462018-01-12 10:21:40 +0000173 {
174 mult_transpose1xW_width = 4;
175 mult_interleave4x4_height = 2;
176 }
177
178 // Check if we need to reshape the matrix A and matrix B
179 _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 +0000180
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000181 // Check if we can run the new reshaped GEMM
182 _is_G76_path = (gpu_target == GPUTarget::G76) && _is_interleaved_transposed && (data_type == DataType::F32);
183 ;
184
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100185 // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
186 if(_is_interleaved_transposed)
187 {
188 reinterpret_input_as_3d = false;
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100189
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100190 matrix_a = &_tmp_a;
191 matrix_b = &_tmp_b;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100192
Gian Marco19835e52018-01-30 13:35:54 +0000193 // Manage intermediate buffers
194 _memory_group.manage(&_tmp_a);
Georgios Pinitasae4ce7b2018-03-19 17:50:45 +0000195 if(!_reshape_b_only_on_first_run)
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000196 {
197 _memory_group.manage(&_tmp_b);
198 }
Gian Marco20d78482018-01-11 15:10:58 +0000199 // _tmp_a and _tmp_b will be auto configured in _interleave_kernel and in _transpose_kernel
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100200
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000201 if(_is_G76_path)
202 {
203 GEMMLHSMatrixInfo lhs_info;
204 GEMMRHSMatrixInfo rhs_info;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100205
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000206 // Pick up the GEMM configuration based on M,N and K
207 select_gemm_configuration(m, n, lhs_info, rhs_info);
208
209 _reshape_lhs_kernel.configure(a, &_tmp_a, lhs_info, gemm_info.reinterpret_input_as_3d());
210 _reshape_rhs_kernel.configure(b, &_tmp_b, rhs_info);
211
212 // Configure and tune matrix multiply kernel
213 _mm_reshaped_kernel.configure(matrix_a, matrix_b, output, alpha, lhs_info, rhs_info, GEMMReshapeInfo(m, n, k, 1, 1,
214 depth_output_gemm3d, reinterpret_input_as_3d));
215 }
216 else
217 {
218 // Configure interleave kernel
219 _interleave_kernel.configure(a, &_tmp_a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d());
220
221 // Configure transpose kernel
222 _transpose_kernel.configure(b, &_tmp_b, mult_transpose1xW_width);
223 }
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100224 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100225
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000226 if(!_is_G76_path)
227 {
228 // Configure and tune matrix multiply kernel
229 _mm_kernel.configure(matrix_a, matrix_b, output, alpha, _is_interleaved_transposed, GEMMReshapeInfo(m, n, k,
230 mult_transpose1xW_width, mult_interleave4x4_height,
231 depth_output_gemm3d, reinterpret_input_as_3d),
232 gemm_info.fp_mixed_precision());
233 CLScheduler::get().tune_kernel_static(_mm_kernel);
234 }
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100235
236 if(_is_interleaved_transposed)
237 {
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100238 // Allocate intermediate tensors
239 _tmp_a.allocator()->allocate();
Georgios Pinitase0437672018-05-02 14:07:55 +0100240 if(!_reshape_b_only_on_first_run)
241 {
242 _tmp_b.allocator()->allocate();
243 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100244 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100245
246 // Configure matrix addition kernel
247 if(beta != 0 && c != nullptr)
248 {
249 _ma_kernel.configure(c, output, beta);
250 _run_addition = true;
251 }
252}
253
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100254Status 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 +0000255{
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100256 ARM_COMPUTE_UNUSED(alpha);
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100257 ARM_COMPUTE_UNUSED(output);
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100258
259 // Check if we need to reshape the matrix B only on the first run
260 const bool reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run();
261
262 const ITensorInfo *matrix_a_info = a;
263 const ITensorInfo *matrix_b_info = b;
264
265 TensorInfo tmp_a_info{};
266 TensorInfo tmp_b_info{};
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100267
268 // Get the GPU target
269 const GPUTarget gpu_target = CLScheduler::get().target();
270
271 // Arguments used by GEMMReshapeInfo
272 // 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
273 // in order to know how the matrices have been reshaped
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000274 DataType data_type = a->data_type();
275 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
276 const unsigned int m = reinterpret_input_as_3d ? (a->dimension(1) * a->dimension(2)) : a->dimension(1);
277 const unsigned int n = b->dimension(0);
278 const unsigned int k = a->dimension(0);
279 int mult_transpose1xW_width = 1;
280 int mult_interleave4x4_height = 1;
281 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100282
283 if(get_arch_from_target(gpu_target) == GPUTarget::BIFROST)
284 {
285 mult_transpose1xW_width = 4;
286 mult_interleave4x4_height = 2;
287 }
288
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100289 // Check if we need to reshape the matrix A and matrix B
290 const bool run_interleave_transpose = is_interleaved_transposed(m, n, k, a->data_type(), reshape_b_only_on_first_run, gpu_target);
291
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000292 // Check if we can run the new reshaped GEMM
293 const bool is_G76_path = (gpu_target == GPUTarget::G76) && run_interleave_transpose && (data_type == DataType::F32);
294
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100295 // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
296 if(run_interleave_transpose)
297 {
298 reinterpret_input_as_3d = false;
299 }
300
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100301 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 +0100302
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100303 if(run_interleave_transpose)
304 {
305 matrix_a_info = &tmp_a_info;
306 matrix_b_info = &tmp_b_info;
307
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000308 if(is_G76_path)
309 {
310 GEMMLHSMatrixInfo lhs_info;
311 GEMMRHSMatrixInfo rhs_info;
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100312
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000313 // Pick up the GEMM configuration based on M,N and K
314 select_gemm_configuration(m, n, lhs_info, rhs_info);
315
316 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())));
317 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeLHSMatrixKernel::validate(a, &tmp_a_info, lhs_info, gemm_info.reinterpret_input_as_3d()));
318
319 auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_rhs_reshaped_shape(*b, rhs_info)));
320 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeRHSMatrixKernel::validate(b, &tmp_b_info, rhs_info));
321
322 // Validate matrix multiply
323 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,
324 depth_output_gemm3d, reinterpret_input_as_3d)));
325 }
326 else
327 {
328 // Validate interleave kernel
329 auto_init_if_empty(tmp_a_info, a->clone()->set_tensor_shape(compute_interleaved_shape(*a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d())));
330 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMInterleave4x4Kernel::validate(a, &tmp_a_info, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d()));
331
332 // Validate transpose kernel
333 auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_transpose1xW_with_element_size_shape(*b, mult_transpose1xW_width)));
334 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMTranspose1xWKernel::validate(b, &tmp_b_info, mult_transpose1xW_width));
335 }
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100336 }
337
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000338 if(!is_G76_path)
339 {
340 // Validate matrix multiply
341 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()));
342 }
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100343
344 if(beta != 0 && c != nullptr)
345 {
346 // Validate matrix addition kernel
Giorgio Arena0f170392018-07-18 16:13:12 +0100347 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMMatrixAdditionKernel::validate(c, output, beta));
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100348 }
349
Georgios Pinitas78c00902018-01-09 17:33:11 +0000350 return Status{};
351}
352
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100353void CLGEMM::run()
354{
Georgios Pinitase0437672018-05-02 14:07:55 +0100355 prepare();
356
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100357 _memory_group.acquire();
358
Gian Marco Iodiceedfa9f42017-08-15 11:45:22 +0100359 if(_is_interleaved_transposed)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100360 {
361 // Run interleave kernel
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000362 if(_is_G76_path)
363 {
364 CLScheduler::get().enqueue(_reshape_lhs_kernel, false);
365 }
366 else
367 {
368 CLScheduler::get().enqueue(_interleave_kernel, false);
369 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100370
Georgios Pinitase0437672018-05-02 14:07:55 +0100371 if(!_reshape_b_only_on_first_run)
Gian Marco1d25ed52017-12-16 19:33:50 +0000372 {
373 // Run transpose kernel
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000374 if(_is_G76_path)
375 {
376 CLScheduler::get().enqueue(_reshape_rhs_kernel, false);
377 }
378 else
379 {
380 CLScheduler::get().enqueue(_transpose_kernel, false);
381 }
Gian Marco1d25ed52017-12-16 19:33:50 +0000382 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100383 }
384
385 // Run matrix multiply kernel
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000386 if(_is_G76_path)
387 {
388 CLScheduler::get().enqueue(_mm_reshaped_kernel, !_run_addition);
389 }
390 else
391 {
392 CLScheduler::get().enqueue(_mm_kernel, !_run_addition);
393 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100394
395 // Run matrix addition kernel
396 if(_run_addition)
397 {
398 CLScheduler::get().enqueue(_ma_kernel);
399 }
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +0100400
401 _memory_group.release();
Georgios Pinitase0437672018-05-02 14:07:55 +0100402}
Georgios Pinitas82b51482018-04-24 15:14:12 +0100403
Georgios Pinitase0437672018-05-02 14:07:55 +0100404void CLGEMM::prepare()
405{
406 if(!_is_prepared)
407 {
408 if(_is_interleaved_transposed && _reshape_b_only_on_first_run)
409 {
Georgios Pinitas72219332018-06-05 14:56:06 +0100410 // Run transpose kernel and mark original weights tensor as unused
Georgios Pinitase0437672018-05-02 14:07:55 +0100411 _tmp_b.allocator()->allocate();
Gian Marco Iodicebf9731e2018-12-12 10:18:04 +0000412 if(_is_G76_path)
413 {
414 CLScheduler::get().enqueue(_reshape_rhs_kernel, false);
415 }
416 else
417 {
418 CLScheduler::get().enqueue(_transpose_kernel, false);
419 }
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}