Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 1 | /* |
Gian Marco | 7b4d547 | 2018-01-10 15:56:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 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 | */ |
| 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 Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 32 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 34 | |
| 35 | using namespace arm_compute; |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 36 | using namespace arm_compute::misc::shape_calculator; |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 37 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 38 | namespace |
| 39 | { |
| 40 | inline 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 Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 44 | if(gpu_target_is_in(gpu_target, |
| 45 | GPUTarget::G71, GPUTarget::G72, GPUTarget::G76, |
| 46 | GPUTarget::G51, GPUTarget::G51BIG, GPUTarget::G51LIT, |
| 47 | GPUTarget::G52, GPUTarget::G52LIT)) |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 48 | { |
| 49 | // COMPMID-852 |
| 50 | if(k > 256 && m > 4 && reshape_b_only_on_first_run) |
| 51 | { |
| 52 | flag = ((0.72f + n * 0.10766f) < (n * 0.1284f)); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | flag = false; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return flag; |
| 61 | } |
| 62 | } // namespace |
| 63 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 64 | CLGEMMLowpMatrixMultiplyCore::CLGEMMLowpMatrixMultiplyCore(std::shared_ptr<IMemoryManager> memory_manager) |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 65 | : _memory_group(std::move(memory_manager)), |
| 66 | _mm_kernel(), |
| 67 | _mtx_a_reshape_kernel(), |
| 68 | _mtx_b_reshape_kernel(), |
| 69 | _mtx_a_reduction_kernel(), |
| 70 | _mtx_b_reduction_kernel(), |
| 71 | _offset_contribution_kernel(), |
| 72 | _vector_sum_col(), |
| 73 | _vector_sum_row(), |
| 74 | _tmp_a(), |
| 75 | _tmp_b(), |
| 76 | _original_b(nullptr), |
| 77 | _a_offset(0), |
| 78 | _b_offset(0), |
| 79 | _is_interleaved_transposed(true), |
| 80 | _reshape_b_only_on_first_run(false), |
| 81 | _is_prepared(false) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 82 | { |
| 83 | } |
| 84 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 85 | void CLGEMMLowpMatrixMultiplyCore::configure(const ICLTensor *a, const ICLTensor *b, ICLTensor *output, const GEMMInfo &gemm_info) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 86 | { |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 87 | ARM_COMPUTE_ERROR_ON_NULLPTR(a, b, output); |
| 88 | ARM_COMPUTE_UNUSED(gemm_info); |
| 89 | ARM_COMPUTE_ERROR_THROW_ON(CLGEMMLowpMatrixMultiplyCore::validate(a->info(), b->info(), output->info(), gemm_info)); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 90 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 91 | _is_prepared = false; |
| 92 | _original_b = b; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 93 | _reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run(); |
| 94 | _a_offset = a->info()->quantization_info().offset; |
| 95 | _b_offset = b->info()->quantization_info().offset; |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 96 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 97 | // Get the GPU target |
| 98 | const GPUTarget gpu_target = CLScheduler::get().target(); |
Gian Marco | 7b4d547 | 2018-01-10 15:56:30 +0000 | [diff] [blame] | 99 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 100 | // Set the target for the kernels |
| 101 | _mtx_a_reshape_kernel.set_target(gpu_target); |
| 102 | _mm_kernel.set_target(gpu_target); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 103 | |
| 104 | const ICLTensor *matrix_a = a; |
| 105 | const ICLTensor *matrix_b = b; |
| 106 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 107 | // Arguments used by GEMMReshapeInfo |
| 108 | // 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 |
| 109 | // in order to know how the matrices have been reshaped |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 110 | bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d(); |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 111 | const int m = a->info()->dimension(1); |
| 112 | const int n = b->info()->dimension(0); |
| 113 | const int k = a->info()->dimension(0); |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 114 | const int depth_output_gemm3d = gemm_info.depth_output_gemm3d(); |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 115 | constexpr int mult_transpose1xW_width = 1; |
| 116 | constexpr int mult_interleave4x4_height = 1; |
| 117 | |
| 118 | // Check if we need to reshape the matrix A and matrix B |
| 119 | _is_interleaved_transposed = is_interleaved_transposed(m, n, k, _reshape_b_only_on_first_run, gpu_target); |
| 120 | |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 121 | // if _is_interleaved_transposed is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D |
| 122 | if(_is_interleaved_transposed) |
| 123 | { |
| 124 | reinterpret_input_as_3d = false; |
| 125 | } |
| 126 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 127 | if(_is_interleaved_transposed) |
| 128 | { |
| 129 | matrix_a = &_tmp_a; |
| 130 | matrix_b = &_tmp_b; |
| 131 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 132 | _memory_group.manage(&_tmp_a); |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 133 | if(!_reshape_b_only_on_first_run) |
| 134 | { |
| 135 | _memory_group.manage(&_tmp_b); |
| 136 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 137 | |
| 138 | // Configure interleave kernel |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 139 | _mtx_a_reshape_kernel.configure(a, &_tmp_a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d()); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 140 | |
| 141 | // Configure transpose kernel |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 142 | _mtx_b_reshape_kernel.configure(b, &_tmp_b, mult_transpose1xW_width); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 143 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 144 | // Configure matrix multiply kernel |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 145 | _mm_kernel.configure(matrix_a, matrix_b, output, _is_interleaved_transposed, GEMMReshapeInfo(m, n, k, |
| 146 | mult_transpose1xW_width, mult_interleave4x4_height, |
| 147 | depth_output_gemm3d, reinterpret_input_as_3d)); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 148 | |
| 149 | // Initialize matrix B reduction kernel only if _a_offset is not equal to 0 |
| 150 | if(_a_offset != 0) |
| 151 | { |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 152 | TensorInfo info_vector_sum_col(compute_reductionA_shape(*b->info()), 1, DataType::S32); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 153 | _vector_sum_col.allocator()->init(info_vector_sum_col); |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 154 | if(!_reshape_b_only_on_first_run) |
| 155 | { |
| 156 | _memory_group.manage(&_vector_sum_col); |
| 157 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 158 | |
| 159 | // Configure Matrix B reduction kernel |
| 160 | _mtx_b_reduction_kernel.configure(b, &_vector_sum_col); |
| 161 | } |
| 162 | |
| 163 | // Initialize Matrix A reduction kernel only if _b_offset is not equal to 0 |
| 164 | if(_b_offset != 0) |
| 165 | { |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 166 | TensorInfo info_vector_sum_row(compute_reductionB_shape(*a->info()), 1, DataType::S32); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 167 | _vector_sum_row.allocator()->init(info_vector_sum_row); |
| 168 | _memory_group.manage(&_vector_sum_row); |
| 169 | |
| 170 | // Configure matrix A reduction kernel |
| 171 | _mtx_a_reduction_kernel.configure(a, &_vector_sum_row); |
| 172 | } |
| 173 | |
| 174 | // Configure offset contribution kernel |
| 175 | _offset_contribution_kernel.configure(output, _a_offset == 0 ? nullptr : &_vector_sum_col, _b_offset == 0 ? nullptr : &_vector_sum_row, a->info()->dimension(0), _a_offset, _b_offset); |
| 176 | |
| 177 | // Allocate tensors |
| 178 | if(_is_interleaved_transposed) |
| 179 | { |
| 180 | _tmp_a.allocator()->allocate(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 181 | if(!_reshape_b_only_on_first_run) |
| 182 | { |
| 183 | _tmp_b.allocator()->allocate(); |
| 184 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 187 | if(_a_offset != 0 && !_reshape_b_only_on_first_run) |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 188 | { |
| 189 | _vector_sum_col.allocator()->allocate(); |
| 190 | } |
| 191 | |
| 192 | if(_b_offset != 0) |
| 193 | { |
| 194 | _vector_sum_row.allocator()->allocate(); |
| 195 | } |
| 196 | } |
| 197 | |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 198 | Status CLGEMMLowpMatrixMultiplyCore::validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *output, const GEMMInfo &gemm_info) |
| 199 | { |
| 200 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(a, 1, DataType::QASYMM8); |
| 201 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::S32); |
| 202 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(a, b); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 203 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_a_reshaped(), "Matrix A already reshaped is not supported"); |
| 204 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_b_reshaped(), "Matrix B already reshaped is not supported"); |
| 205 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 206 | int32_t a_offset = a->quantization_info().offset; |
| 207 | int32_t b_offset = b->quantization_info().offset; |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 208 | |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 209 | const int m = a->dimension(1); |
| 210 | const int n = b->dimension(0); |
| 211 | const int k = a->dimension(0); |
| 212 | constexpr int mult_transpose1xW_width = 1; |
| 213 | constexpr int mult_interleave4x4_height = 1; |
| 214 | bool reinterpret_input_as_3d = gemm_info.reinterpret_input_as_3d(); |
| 215 | const int depth_output_gemm3d = gemm_info.depth_output_gemm3d(); |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 216 | |
| 217 | bool reshape_matrices = is_interleaved_transposed(m, n, k, gemm_info.reshape_b_only_on_first_run(), CLScheduler::get().target()); |
| 218 | |
Georgios Pinitas | ebf6b8a | 2018-09-24 16:31:08 +0100 | [diff] [blame^] | 219 | // if reshape_matrices is set, force reinterpret_input_as_3d to be false as the output of CLGEMMInterleaveKernel will be 2D |
| 220 | if(reshape_matrices) |
| 221 | { |
| 222 | reinterpret_input_as_3d = false; |
| 223 | } |
| 224 | |
| 225 | const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(m, n, k, mult_transpose1xW_width, mult_interleave4x4_height, depth_output_gemm3d, reinterpret_input_as_3d); |
| 226 | |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 227 | if(reshape_matrices) |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 228 | { |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 229 | TensorInfo info_a(compute_interleaved_shape(*a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d()), 1, a->data_type()); |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 230 | TensorInfo info_b(compute_transpose1xW_with_element_size_shape(*b, mult_transpose1xW_width), 1, b->data_type()); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 231 | |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 232 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMInterleave4x4Kernel::validate(a, &info_a, mult_interleave4x4_height, gemm_info.reinterpret_input_as_3d())); |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 233 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMTranspose1xWKernel::validate(b, &info_b, mult_transpose1xW_width)); |
| 234 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyKernel::validate(&info_a, &info_b, output, reshape_matrices, reshape_info)); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 235 | } |
| 236 | else |
| 237 | { |
Gian Marco | 19835e5 | 2018-01-30 13:35:54 +0000 | [diff] [blame] | 238 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyKernel::validate(a, b, output, reshape_matrices, reshape_info)); |
Georgios Pinitas | 358ca20 | 2017-12-07 16:47:52 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | TensorInfo info_vector_sum_col, info_vector_sum_row; |
| 242 | |
| 243 | // Validate matrix B reduction kernel only if _a_offset is not equal to 0 |
| 244 | if(a_offset != 0) |
| 245 | { |
| 246 | info_vector_sum_col = TensorInfo(compute_reductionA_shape(*b), 1, DataType::S32); |
| 247 | |
| 248 | // Configure Matrix B reduction kernel |
| 249 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixBReductionKernel::validate(b, &info_vector_sum_col)); |
| 250 | } |
| 251 | |
| 252 | // Validate Matrix A reduction kernel only if _b_offset is not equal to 0 |
| 253 | if(b_offset != 0) |
| 254 | { |
| 255 | info_vector_sum_row = TensorInfo(compute_reductionB_shape(*a), 1, DataType::S32); |
| 256 | |
| 257 | // Configure matrix A reduction kernel |
| 258 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixAReductionKernel::validate(a, &info_vector_sum_row)); |
| 259 | } |
| 260 | |
| 261 | // Validate offset contribution kernel |
| 262 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpOffsetContributionKernel::validate(output, |
| 263 | a_offset == 0 ? nullptr : &info_vector_sum_col, |
| 264 | b_offset == 0 ? nullptr : &info_vector_sum_row, |
| 265 | a_offset, b_offset)); |
| 266 | |
| 267 | return Status{}; |
| 268 | } |
| 269 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 270 | void CLGEMMLowpMatrixMultiplyCore::run() |
| 271 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 272 | prepare(); |
| 273 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 274 | _memory_group.acquire(); |
| 275 | |
| 276 | if(_is_interleaved_transposed) |
| 277 | { |
| 278 | // Run reshape matrix A |
| 279 | CLScheduler::get().enqueue(_mtx_a_reshape_kernel, false); |
| 280 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 281 | if(!_reshape_b_only_on_first_run) |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 282 | { |
| 283 | // Run reshape matrix B |
| 284 | CLScheduler::get().enqueue(_mtx_b_reshape_kernel, false); |
| 285 | } |
| 286 | } |
| 287 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 288 | // Run matrix B reduction kernel only if _a_offset is not equal to 0 |
| 289 | if(_a_offset != 0 && !_reshape_b_only_on_first_run) |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 290 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 291 | CLScheduler::get().enqueue(_mtx_b_reduction_kernel, false); |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // Run matrix multiply |
| 295 | CLScheduler::get().enqueue(_mm_kernel, false); |
| 296 | |
| 297 | // Run matrix A reduction kernel only if _b_offset is not equal to 0 |
| 298 | if(_b_offset != 0) |
| 299 | { |
| 300 | CLScheduler::get().enqueue(_mtx_a_reduction_kernel, false); |
| 301 | } |
| 302 | |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 303 | // Run offset contribution kernel |
| 304 | CLScheduler::get().enqueue(_offset_contribution_kernel, true); |
| 305 | |
| 306 | _memory_group.release(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 307 | } |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 308 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 309 | void CLGEMMLowpMatrixMultiplyCore::prepare() |
| 310 | { |
| 311 | if(!_is_prepared) |
| 312 | { |
| 313 | if(_is_interleaved_transposed && _reshape_b_only_on_first_run) |
| 314 | { |
| 315 | ARM_COMPUTE_ERROR_ON(!_original_b->is_used()); |
| 316 | |
| 317 | // Run reshape kernel and mark original weights tensor as unused |
| 318 | _tmp_b.allocator()->allocate(); |
| 319 | CLScheduler::get().enqueue(_mtx_b_reshape_kernel, false); |
| 320 | _original_b->mark_as_unused(); |
| 321 | } |
| 322 | |
| 323 | // Run matrix B reduction kernel only if _a_offset is not equal to 0 |
| 324 | if(_a_offset != 0 && _reshape_b_only_on_first_run) |
| 325 | { |
| 326 | _vector_sum_col.allocator()->allocate(); |
| 327 | CLScheduler::get().enqueue(_mtx_b_reduction_kernel, false); |
| 328 | } |
| 329 | |
| 330 | CLScheduler::get().queue().finish(); |
| 331 | _is_prepared = true; |
| 332 | } |
Gian Marco | 05288a2 | 2017-11-21 10:57:50 +0000 | [diff] [blame] | 333 | } |