blob: cf20bc6a7aebb9de36605565df38f2387ecd5d9f [file] [log] [blame]
Gian Marco05288a22017-11-21 10:57:50 +00001/*
Gian Marco7b4d5472018-01-10 15:56:30 +00002 * Copyright (c) 2017-2018 ARM Limited.
Gian Marco05288a22017-11-21 10:57:50 +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 */
24#include "arm_compute/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCore.h"
25
26#include "arm_compute/core/CL/ICLTensor.h"
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/Helpers.h"
29#include "arm_compute/core/TensorInfo.h"
30#include "arm_compute/core/Types.h"
31#include "arm_compute/core/Validate.h"
Georgios Pinitas358ca202017-12-07 16:47:52 +000032#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Gian Marco05288a22017-11-21 10:57:50 +000033#include "arm_compute/runtime/CL/CLScheduler.h"
34
35using namespace arm_compute;
Georgios Pinitas358ca202017-12-07 16:47:52 +000036using namespace arm_compute::misc::shape_calculator;
Gian Marco05288a22017-11-21 10:57:50 +000037
Gian Marco19835e52018-01-30 13:35:54 +000038namespace
39{
40inline bool is_interleaved_transposed(int m, int n, int k, bool reshape_b_only_on_first_run, GPUTarget gpu_target)
41{
42 bool flag = true;
43
Georgios Pinitasa34286e2018-09-04 12:18:50 +010044 if(gpu_target_is_in(gpu_target,
Gian Marco Iodice4b908652018-10-18 10:21:02 +010045 GPUTarget::G71, GPUTarget::G72,
Gian Marco Iodicee059f4f2018-11-15 15:21:17 +000046 GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT))
Gian Marco19835e52018-01-30 13:35:54 +000047 {
48 // COMPMID-852
49 if(k > 256 && m > 4 && reshape_b_only_on_first_run)
50 {
51 flag = ((0.72f + n * 0.10766f) < (n * 0.1284f));
52 }
53 else
54 {
55 flag = false;
56 }
57 }
Gian Marco Iodice4b908652018-10-18 10:21:02 +010058 else
59 {
60 flag = m > 1;
61 }
Gian Marco19835e52018-01-30 13:35:54 +000062
63 return flag;
64}
65} // namespace
66
Gian Marco05288a22017-11-21 10:57:50 +000067CLGEMMLowpMatrixMultiplyCore::CLGEMMLowpMatrixMultiplyCore(std::shared_ptr<IMemoryManager> memory_manager)
Georgios Pinitas72219332018-06-05 14:56:06 +010068 : _memory_group(std::move(memory_manager)),
69 _mm_kernel(),
70 _mtx_a_reshape_kernel(),
71 _mtx_b_reshape_kernel(),
72 _mtx_a_reduction_kernel(),
73 _mtx_b_reduction_kernel(),
74 _offset_contribution_kernel(),
Gian Marco Iodice4b908652018-10-18 10:21:02 +010075 _offset_contribution_output_stage_kernel(),
Georgios Pinitas72219332018-06-05 14:56:06 +010076 _vector_sum_col(),
77 _vector_sum_row(),
78 _tmp_a(),
79 _tmp_b(),
Gian Marco Iodice4b908652018-10-18 10:21:02 +010080 _mm_result_s32(),
Georgios Pinitas72219332018-06-05 14:56:06 +010081 _original_b(nullptr),
82 _a_offset(0),
83 _b_offset(0),
84 _is_interleaved_transposed(true),
85 _reshape_b_only_on_first_run(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +010086 _is_prepared(false),
87 _fuse_output_stage(false)
Gian Marco05288a22017-11-21 10:57:50 +000088{
89}
90
Gian Marco Iodice4b908652018-10-18 10:21:02 +010091void CLGEMMLowpMatrixMultiplyCore::configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, const GEMMInfo &gemm_info)
Gian Marco05288a22017-11-21 10:57:50 +000092{
Georgios Pinitas358ca202017-12-07 16:47:52 +000093 ARM_COMPUTE_ERROR_ON_NULLPTR(a, b, output);
Gian Marco Iodice4b908652018-10-18 10:21:02 +010094 ARM_COMPUTE_ERROR_THROW_ON(CLGEMMLowpMatrixMultiplyCore::validate(a->info(), b->info(), c != nullptr ? c->info() : nullptr, output->info(), gemm_info));
Gian Marco05288a22017-11-21 10:57:50 +000095
Georgios Pinitas72219332018-06-05 14:56:06 +010096 _is_prepared = false;
97 _original_b = b;
Chunosov5124be52017-11-22 20:42:13 +070098 _reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run();
99 _a_offset = a->info()->quantization_info().offset;
100 _b_offset = b->info()->quantization_info().offset;
Gian Marco05288a22017-11-21 10:57:50 +0000101
Gian Marco19835e52018-01-30 13:35:54 +0000102 // Get the GPU target
103 const GPUTarget gpu_target = CLScheduler::get().target();
Gian Marco7b4d5472018-01-10 15:56:30 +0000104
Gian Marco19835e52018-01-30 13:35:54 +0000105 // Set the target for the kernels
106 _mtx_a_reshape_kernel.set_target(gpu_target);
107 _mm_kernel.set_target(gpu_target);
Gian Marco05288a22017-11-21 10:57:50 +0000108
109 const ICLTensor *matrix_a = a;
110 const ICLTensor *matrix_b = b;
giuros018b6b4a92018-12-18 19:01:33 +0000111 GEMMRHSMatrixInfo rhs_info;
Gian Marco05288a22017-11-21 10:57:50 +0000112
Gian Marco19835e52018-01-30 13:35:54 +0000113 // Arguments used by GEMMReshapeInfo
114 // 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
115 // in order to know how the matrices have been reshaped
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100116 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100117 const bool unroll_block = dot8_supported(CLKernelLibrary::get().get_device());
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100118 const int m = reinterpret_input_as_3d ? (a->info()->dimension(1) * a->info()->dimension(2)) : a->info()->dimension(1);
Gian Marco19835e52018-01-30 13:35:54 +0000119 const int n = b->info()->dimension(0);
120 const int k = a->info()->dimension(0);
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100121 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
Gian Marco19835e52018-01-30 13:35:54 +0000122 constexpr int mult_transpose1xW_width = 1;
123 constexpr int mult_interleave4x4_height = 1;
giuros018b6b4a92018-12-18 19:01:33 +0000124 rhs_info.n0 = 16 / b->info()->element_size();
125 rhs_info.k0 = 1;
126 rhs_info.h0 = mult_transpose1xW_width;
127 rhs_info.interleave = false;
128 rhs_info.transpose = false;
Gian Marco19835e52018-01-30 13:35:54 +0000129
130 // Check if we need to reshape the matrix A and matrix B
131 _is_interleaved_transposed = is_interleaved_transposed(m, n, k, _reshape_b_only_on_first_run, gpu_target);
132
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100133 if(_is_interleaved_transposed)
134 {
Isabella Gottardif02e5272018-10-01 12:26:28 +0100135 // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100136 reinterpret_input_as_3d = false;
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100137
Gian Marco05288a22017-11-21 10:57:50 +0000138 matrix_a = &_tmp_a;
139 matrix_b = &_tmp_b;
140
Gian Marco05288a22017-11-21 10:57:50 +0000141 _memory_group.manage(&_tmp_a);
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100142 if(!_reshape_b_only_on_first_run)
143 {
144 _memory_group.manage(&_tmp_b);
145 }
Gian Marco05288a22017-11-21 10:57:50 +0000146
147 // Configure interleave kernel
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100148 _mtx_a_reshape_kernel.configure(a, &_tmp_a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d(), unroll_block);
Gian Marco05288a22017-11-21 10:57:50 +0000149
150 // Configure transpose kernel
giuros018b6b4a92018-12-18 19:01:33 +0000151 _mtx_b_reshape_kernel.configure(b, &_tmp_b, rhs_info);
Gian Marco05288a22017-11-21 10:57:50 +0000152 }
Gian Marco05288a22017-11-21 10:57:50 +0000153
154 // Initialize matrix B reduction kernel only if _a_offset is not equal to 0
155 if(_a_offset != 0)
156 {
Georgios Pinitas358ca202017-12-07 16:47:52 +0000157 TensorInfo info_vector_sum_col(compute_reductionA_shape(*b->info()), 1, DataType::S32);
Gian Marco05288a22017-11-21 10:57:50 +0000158 _vector_sum_col.allocator()->init(info_vector_sum_col);
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100159 if(!_reshape_b_only_on_first_run)
160 {
161 _memory_group.manage(&_vector_sum_col);
162 }
Gian Marco05288a22017-11-21 10:57:50 +0000163
164 // Configure Matrix B reduction kernel
165 _mtx_b_reduction_kernel.configure(b, &_vector_sum_col);
166 }
167
168 // Initialize Matrix A reduction kernel only if _b_offset is not equal to 0
169 if(_b_offset != 0)
170 {
Georgios Pinitas358ca202017-12-07 16:47:52 +0000171 TensorInfo info_vector_sum_row(compute_reductionB_shape(*a->info()), 1, DataType::S32);
Gian Marco05288a22017-11-21 10:57:50 +0000172 _vector_sum_row.allocator()->init(info_vector_sum_row);
173 _memory_group.manage(&_vector_sum_row);
174
175 // Configure matrix A reduction kernel
176 _mtx_a_reduction_kernel.configure(a, &_vector_sum_row);
177 }
178
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100179 // If GEMMLowpOutputStage != NONE, fuse the offset contribution with the output stage
180 if(gemm_info.gemmlowp_output_stage().type != GEMMLowpOutputStageType::NONE)
181 {
182 _fuse_output_stage = true;
183
184 _memory_group.manage(&_mm_result_s32);
185
186 // Configure matrix multiply kernel
187 _mm_kernel.configure(matrix_a, matrix_b, &_mm_result_s32, _is_interleaved_transposed, GEMMReshapeInfo(m, n, k,
188 mult_transpose1xW_width, mult_interleave4x4_height,
189 depth_output_gemm3d, reinterpret_input_as_3d));
190
191 // Configure offset contribution kernel
192 _offset_contribution_output_stage_kernel.configure(&_mm_result_s32, _a_offset == 0 ? nullptr : &_vector_sum_col, _b_offset == 0 ? nullptr : &_vector_sum_row, c, output, a->info()->dimension(0),
193 _a_offset, _b_offset, gemm_info.gemmlowp_output_stage());
194
195 _mm_result_s32.allocator()->allocate();
196 }
197 else
198 {
199 // Configure matrix multiply kernel
200 _mm_kernel.configure(matrix_a, matrix_b, output, _is_interleaved_transposed, GEMMReshapeInfo(m, n, k,
201 mult_transpose1xW_width, mult_interleave4x4_height,
202 depth_output_gemm3d, reinterpret_input_as_3d));
203
204 // Configure offset contribution kernel
205 _offset_contribution_kernel.configure(output, _a_offset == 0 ? nullptr : &_vector_sum_col, _b_offset == 0 ? nullptr : &_vector_sum_row, c, a->info()->dimension(0), _a_offset, _b_offset);
206 }
Gian Marco05288a22017-11-21 10:57:50 +0000207
208 // Allocate tensors
209 if(_is_interleaved_transposed)
210 {
211 _tmp_a.allocator()->allocate();
Georgios Pinitas72219332018-06-05 14:56:06 +0100212 if(!_reshape_b_only_on_first_run)
213 {
214 _tmp_b.allocator()->allocate();
215 }
Gian Marco05288a22017-11-21 10:57:50 +0000216 }
217
Georgios Pinitas72219332018-06-05 14:56:06 +0100218 if(_a_offset != 0 && !_reshape_b_only_on_first_run)
Gian Marco05288a22017-11-21 10:57:50 +0000219 {
220 _vector_sum_col.allocator()->allocate();
221 }
222
223 if(_b_offset != 0)
224 {
225 _vector_sum_row.allocator()->allocate();
226 }
227}
228
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100229Status CLGEMMLowpMatrixMultiplyCore::validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, const GEMMInfo &gemm_info)
Georgios Pinitas358ca202017-12-07 16:47:52 +0000230{
231 ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(a, 1, DataType::QASYMM8);
Georgios Pinitas358ca202017-12-07 16:47:52 +0000232 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(a, b);
Georgios Pinitas358ca202017-12-07 16:47:52 +0000233 ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_a_reshaped(), "Matrix A already reshaped is not supported");
234 ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_b_reshaped(), "Matrix B already reshaped is not supported");
235
Gian Marco19835e52018-01-30 13:35:54 +0000236 int32_t a_offset = a->quantization_info().offset;
237 int32_t b_offset = b->quantization_info().offset;
Georgios Pinitas358ca202017-12-07 16:47:52 +0000238
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100239 const ITensorInfo *matrix_a_info = a;
240 const ITensorInfo *matrix_b_info = b;
241
giuros018b6b4a92018-12-18 19:01:33 +0000242 TensorInfo tmp_a_info{};
243 TensorInfo tmp_b_info{};
244 GEMMRHSMatrixInfo rhs_info;
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100245
Georgios Pinitas932491f2018-09-21 16:33:15 +0100246 bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d();
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100247 const int m = reinterpret_input_as_3d ? (a->dimension(1) * a->dimension(2)) : a->dimension(1);
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100248 const int n = b->dimension(0);
249 const int k = a->dimension(0);
250 constexpr int mult_transpose1xW_width = 1;
251 constexpr int mult_interleave4x4_height = 1;
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100252 const int depth_output_gemm3d = gemm_info.depth_output_gemm3d();
giuros018b6b4a92018-12-18 19:01:33 +0000253 rhs_info.n0 = 16 / b->element_size();
254 rhs_info.k0 = 1;
255 rhs_info.h0 = mult_transpose1xW_width;
256 rhs_info.interleave = false;
257 rhs_info.transpose = false;
Gian Marco19835e52018-01-30 13:35:54 +0000258
259 bool reshape_matrices = is_interleaved_transposed(m, n, k, gemm_info.reshape_b_only_on_first_run(), CLScheduler::get().target());
260
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100261 // if reshape_matrices is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D
262 if(reshape_matrices)
263 {
264 reinterpret_input_as_3d = false;
265 }
266
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100267 const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(m, n, k, mult_transpose1xW_width, mult_interleave4x4_height, depth_output_gemm3d, reinterpret_input_as_3d);
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +0100268
Gian Marco19835e52018-01-30 13:35:54 +0000269 if(reshape_matrices)
Georgios Pinitas358ca202017-12-07 16:47:52 +0000270 {
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100271 matrix_a_info = &tmp_a_info;
272 matrix_b_info = &tmp_b_info;
Georgios Pinitas358ca202017-12-07 16:47:52 +0000273
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100274 // Validate interleave kernel
275 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())));
276 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMInterleave4x4Kernel::validate(a, &tmp_a_info, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d()));
277
278 // Validate transpose kernel
giuros018b6b4a92018-12-18 19:01:33 +0000279
280 auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_rhs_reshaped_shape(*b, rhs_info)));
281 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMReshapeRHSMatrixKernel::validate(b, &tmp_b_info, rhs_info));
Georgios Pinitas358ca202017-12-07 16:47:52 +0000282 }
Isabella Gottardic4f582e2018-10-11 19:14:55 +0100283
Georgios Pinitas358ca202017-12-07 16:47:52 +0000284 TensorInfo info_vector_sum_col, info_vector_sum_row;
285
286 // Validate matrix B reduction kernel only if _a_offset is not equal to 0
287 if(a_offset != 0)
288 {
289 info_vector_sum_col = TensorInfo(compute_reductionA_shape(*b), 1, DataType::S32);
290
291 // Configure Matrix B reduction kernel
292 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixBReductionKernel::validate(b, &info_vector_sum_col));
293 }
294
295 // Validate Matrix A reduction kernel only if _b_offset is not equal to 0
296 if(b_offset != 0)
297 {
298 info_vector_sum_row = TensorInfo(compute_reductionB_shape(*a), 1, DataType::S32);
299
300 // Configure matrix A reduction kernel
301 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixAReductionKernel::validate(a, &info_vector_sum_row));
302 }
303
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100304 if(gemm_info.gemmlowp_output_stage().type != GEMMLowpOutputStageType::NONE)
305 {
306 TensorInfo mm_result_s32_info{};
307
308 // Output tensor auto inizialitation if not yet initialized
309 auto_init_if_empty(mm_result_s32_info, a->clone()->set_tensor_shape(compute_mm_shape(*matrix_a_info, *matrix_b_info, reshape_matrices, reshape_info)).set_data_type(DataType::S32));
310
311 // Validate matrix multiply
312 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyKernel::validate(matrix_a_info, matrix_b_info, &mm_result_s32_info, reshape_matrices, reshape_info));
313
314 // Validate offset contribution kernel
315 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpOffsetContributionOutputStageKernel::validate(&mm_result_s32_info,
316 a_offset == 0 ? nullptr : &info_vector_sum_col,
317 b_offset == 0 ? nullptr : &info_vector_sum_row,
318 c,
319 output,
320 a_offset, b_offset,
321 gemm_info.gemmlowp_output_stage()));
322 }
323 else
324 {
325 // Validate matrix multiply
326 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyKernel::validate(matrix_a_info, matrix_b_info, output, reshape_matrices, reshape_info));
327
328 // Validate offset contribution kernel
329 ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpOffsetContributionKernel::validate(output,
330 a_offset == 0 ? nullptr : &info_vector_sum_col,
331 b_offset == 0 ? nullptr : &info_vector_sum_row,
332 c,
333 a_offset, b_offset));
334 }
Georgios Pinitas358ca202017-12-07 16:47:52 +0000335
336 return Status{};
337}
338
Gian Marco05288a22017-11-21 10:57:50 +0000339void CLGEMMLowpMatrixMultiplyCore::run()
340{
Georgios Pinitas72219332018-06-05 14:56:06 +0100341 prepare();
342
Gian Marco05288a22017-11-21 10:57:50 +0000343 _memory_group.acquire();
344
345 if(_is_interleaved_transposed)
346 {
347 // Run reshape matrix A
348 CLScheduler::get().enqueue(_mtx_a_reshape_kernel, false);
349
Georgios Pinitas72219332018-06-05 14:56:06 +0100350 if(!_reshape_b_only_on_first_run)
Chunosov5124be52017-11-22 20:42:13 +0700351 {
352 // Run reshape matrix B
353 CLScheduler::get().enqueue(_mtx_b_reshape_kernel, false);
354 }
355 }
356
Georgios Pinitas72219332018-06-05 14:56:06 +0100357 // Run matrix B reduction kernel only if _a_offset is not equal to 0
358 if(_a_offset != 0 && !_reshape_b_only_on_first_run)
Chunosov5124be52017-11-22 20:42:13 +0700359 {
Georgios Pinitas72219332018-06-05 14:56:06 +0100360 CLScheduler::get().enqueue(_mtx_b_reduction_kernel, false);
Gian Marco05288a22017-11-21 10:57:50 +0000361 }
362
363 // Run matrix multiply
364 CLScheduler::get().enqueue(_mm_kernel, false);
365
366 // Run matrix A reduction kernel only if _b_offset is not equal to 0
367 if(_b_offset != 0)
368 {
369 CLScheduler::get().enqueue(_mtx_a_reduction_kernel, false);
370 }
371
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100372 if(_fuse_output_stage)
373 {
374 // Run offset contribution/output stage kernel
375 CLScheduler::get().enqueue(_offset_contribution_output_stage_kernel, true);
376 }
377 else
378 {
379 // Run offset contribution kernel
380 CLScheduler::get().enqueue(_offset_contribution_kernel, true);
381 }
Gian Marco05288a22017-11-21 10:57:50 +0000382
383 _memory_group.release();
Georgios Pinitas72219332018-06-05 14:56:06 +0100384}
Chunosov5124be52017-11-22 20:42:13 +0700385
Georgios Pinitas72219332018-06-05 14:56:06 +0100386void CLGEMMLowpMatrixMultiplyCore::prepare()
387{
388 if(!_is_prepared)
389 {
390 if(_is_interleaved_transposed && _reshape_b_only_on_first_run)
391 {
392 ARM_COMPUTE_ERROR_ON(!_original_b->is_used());
393
394 // Run reshape kernel and mark original weights tensor as unused
395 _tmp_b.allocator()->allocate();
396 CLScheduler::get().enqueue(_mtx_b_reshape_kernel, false);
397 _original_b->mark_as_unused();
398 }
399
400 // Run matrix B reduction kernel only if _a_offset is not equal to 0
401 if(_a_offset != 0 && _reshape_b_only_on_first_run)
402 {
403 _vector_sum_col.allocator()->allocate();
404 CLScheduler::get().enqueue(_mtx_b_reduction_kernel, false);
405 }
406
407 CLScheduler::get().queue().finish();
408 _is_prepared = true;
409 }
Gian Marco05288a22017-11-21 10:57:50 +0000410}