Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | f1df346 | 2018-01-31 09:13:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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/NEON/functions/NEGEMM.h" |
| 25 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/CPP/Validate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/Helpers.h" |
| 29 | #include "arm_compute/core/ITensor.h" |
| 30 | #include "arm_compute/core/TensorInfo.h" |
| 31 | #include "arm_compute/core/Types.h" |
| 32 | #include "arm_compute/core/Validate.h" |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/NEON/functions/NEGEMMAssemblyDispatch.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 37 | #include "support/ToolchainSupport.h" |
| 38 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | #include <cmath> |
| 40 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 41 | using namespace arm_compute::misc::shape_calculator; |
| 42 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 43 | namespace arm_compute |
| 44 | { |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 45 | NEGEMM::NEGEMM(std::shared_ptr<IMemoryManager> memory_manager) |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 46 | : _memory_group(memory_manager), _interleave_kernel(), _transpose_kernel(), _mm_kernel(), _asm_glue(memory_manager), _ma_kernel(), _tmp_a(), _tmp_b(), _original_b(nullptr), |
| 47 | _run_vector_matrix_multiplication(false), _run_addition(false), _reshape_b_only_on_first_run(false), _is_prepared(false) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | { |
| 49 | } |
| 50 | |
Gian Marco | 1d25ed5 | 2017-12-16 19:33:50 +0000 | [diff] [blame] | 51 | void NEGEMM::configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, float alpha, float beta, const GEMMInfo &gemm_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | { |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 53 | ARM_COMPUTE_ERROR_THROW_ON(NEGEMM::validate(a->info(), b->info(), (c != nullptr) ? c->info() : nullptr, d->info(), alpha, beta, gemm_info)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 54 | |
Gian Marco | 1d25ed5 | 2017-12-16 19:33:50 +0000 | [diff] [blame] | 55 | // Check if we need to reshape the matrix B only on the first run |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 56 | _is_prepared = false; |
Gian Marco | 1d25ed5 | 2017-12-16 19:33:50 +0000 | [diff] [blame] | 57 | _reshape_b_only_on_first_run = gemm_info.reshape_b_only_on_first_run(); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 58 | _run_vector_matrix_multiplication = a->info()->dimension(1) < 2; |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 59 | _original_b = b; |
Pablo Tello | 7fad9b1 | 2018-03-14 17:55:27 +0000 | [diff] [blame] | 60 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 61 | bool run_optimised = c == nullptr && bool(NEGEMMAssemblyDispatch::validate(a->info(), b->info(), d->info(), alpha, beta, _reshape_b_only_on_first_run)); |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 62 | if(run_optimised) |
| 63 | { |
| 64 | _asm_glue.configure(a, b, d, alpha, beta, _reshape_b_only_on_first_run); |
| 65 | run_optimised = _asm_glue.is_configured(); |
| 66 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 67 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 68 | // Check if the first input tensor is a vector. |
| 69 | // If so, all the kernels for reshaping the tensors can be skipped |
| 70 | if(_run_vector_matrix_multiplication) |
| 71 | { |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 72 | if(!run_optimised) |
Michele Di Giorgio | 5b6904b | 2018-01-29 12:24:14 +0000 | [diff] [blame] | 73 | { |
| 74 | // Configure the matrix multiply kernel |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 75 | _mm_kernel.configure(a, b, d, alpha, false); |
Michele Di Giorgio | 5b6904b | 2018-01-29 12:24:14 +0000 | [diff] [blame] | 76 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 77 | |
| 78 | // Configure matrix addition kernel |
| 79 | if(beta != 0 && c != nullptr) |
| 80 | { |
| 81 | _ma_kernel.configure(c, d, beta); |
| 82 | _run_addition = true; |
| 83 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | } |
| 85 | else |
| 86 | { |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 87 | if(!run_optimised) |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 88 | { |
| 89 | TensorShape shape_tmp_a = a->info()->tensor_shape(); |
| 90 | TensorShape shape_tmp_b = b->info()->tensor_shape(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 92 | shape_tmp_a.set(0, a->info()->dimension(0) * 4); |
| 93 | shape_tmp_a.set(1, std::ceil(a->info()->dimension(1) / 4.0f)); |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 94 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 95 | const unsigned int transpose_w = 16 / data_size_from_type(b->info()->data_type()); |
| 96 | shape_tmp_b.set(0, b->info()->dimension(1) * transpose_w); |
| 97 | shape_tmp_b.set(1, std::ceil(b->info()->dimension(0) / static_cast<float>(transpose_w))); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 99 | TensorInfo info_a(shape_tmp_a, 1, a->info()->data_type()); |
| 100 | TensorInfo info_b(shape_tmp_b, 1, b->info()->data_type()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 102 | _tmp_a.allocator()->init(info_a); |
| 103 | _tmp_b.allocator()->init(info_b); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 105 | // Manage intermediate buffers |
| 106 | _memory_group.manage(&_tmp_a); |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 107 | if(!_reshape_b_only_on_first_run) |
| 108 | { |
| 109 | _memory_group.manage(&_tmp_b); |
| 110 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 111 | |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 112 | int m = a->info()->dimension(1); |
| 113 | int n = b->info()->dimension(0); |
| 114 | int k = a->info()->dimension(0); |
| 115 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 116 | // Configure interleave kernel |
| 117 | _interleave_kernel.configure(a, &_tmp_a); |
| 118 | |
| 119 | // Configure transpose kernel |
| 120 | _transpose_kernel.configure(b, &_tmp_b); |
| 121 | |
| 122 | // Configure matrix multiplication kernel |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 123 | _mm_kernel.configure(&_tmp_a, &_tmp_b, d, alpha, true, GEMMReshapeInfo(m, n, k)); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 124 | |
| 125 | // Allocate once the all configure methods have been called |
| 126 | _tmp_a.allocator()->allocate(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 127 | if(!_reshape_b_only_on_first_run) |
| 128 | { |
| 129 | _tmp_b.allocator()->allocate(); |
| 130 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 131 | |
| 132 | // Configure matrix addition kernel |
| 133 | if(beta != 0 && c != nullptr) |
| 134 | { |
| 135 | _ma_kernel.configure(c, d, beta); |
| 136 | _run_addition = true; |
| 137 | } |
| 138 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 142 | Status NEGEMM::validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info) |
| 143 | { |
| 144 | ARM_COMPUTE_UNUSED(alpha); |
| 145 | |
| 146 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(a); |
| 147 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(a, 1, DataType::F32, DataType::F16); |
| 148 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(a, b, output); |
| 149 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(a->dimension(0) != b->dimension(1), "The product AB is defined only if the number of columns in A is equal to the number of rows in B"); |
| 150 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_a_reshaped(), "Matrix A already reshaped is not supported"); |
| 151 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(gemm_info.is_b_reshaped(), "Matrix B already reshaped is not supported"); |
| 152 | |
| 153 | if(c != nullptr) |
| 154 | { |
| 155 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(c, 1, DataType::F32, DataType::F16); |
| 156 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(a, c); |
| 157 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(a->dimension(1) != c->dimension(1), "The C matrix must have the same number of rows as the matrix A"); |
| 158 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(b->dimension(0) != c->dimension(0), "The C matrix must have the same number of columns as the matrix B"); |
| 159 | } |
| 160 | |
| 161 | if(output->total_size() != 0) |
| 162 | { |
| 163 | ARM_COMPUTE_RETURN_ERROR_ON(b->dimension(0) != output->dimension(0)); |
| 164 | ARM_COMPUTE_RETURN_ERROR_ON(a->dimension(1) != output->dimension(1)); |
| 165 | } |
| 166 | |
| 167 | // Check if the first input tensor is a vector. |
| 168 | const bool run_vector_matrix_multiplication = a->dimension(1) < 2; |
| 169 | // Check if we need to reshape the matrix A and matrix B |
| 170 | const bool run_interleave_transpose = !run_vector_matrix_multiplication && !(gemm_info.reshape_b_only_on_first_run()); |
| 171 | // Check if we need to run the optimized assembly kernel |
| 172 | const bool run_optimised = c == nullptr && bool(NEGEMMAssemblyDispatch::validate(a, b, output, alpha, beta, true)); |
| 173 | |
| 174 | const ITensorInfo *matrix_a_info = a; |
| 175 | const ITensorInfo *matrix_b_info = b; |
| 176 | |
| 177 | TensorInfo tmp_a_info{}; |
| 178 | TensorInfo tmp_b_info{}; |
| 179 | TensorInfo tmp_output_info = *output->clone(); |
| 180 | |
| 181 | // Arguments used by GEMMReshapeInfo |
| 182 | // If we pass the matrix A and matrix B reshaped to NEGEMMMatrixMultiplyKernel, we need to pass m, n, k, mult_transpose1xW_width and mult_interleave4x4_height to NEGEMMReshapeInfo |
| 183 | // in order to know how the matrices have been reshaped |
| 184 | const int m = a->dimension(1); |
| 185 | const int n = b->dimension(0); |
| 186 | const int k = a->dimension(0); |
| 187 | int mult_transpose1xW_width = 1; |
| 188 | int mult_interleave4x4_height = 1; |
| 189 | |
| 190 | const GEMMReshapeInfo reshape_info = GEMMReshapeInfo(m, n, k, mult_transpose1xW_width, mult_interleave4x4_height, gemm_info.depth_output_gemm3d()); |
| 191 | |
| 192 | // Initialize shapes |
| 193 | if(run_interleave_transpose) |
| 194 | { |
| 195 | matrix_a_info = &tmp_a_info; |
| 196 | auto_init_if_empty(tmp_a_info, a->clone()->set_tensor_shape(compute_interleaved_shape(*a, mult_interleave4x4_height))); |
| 197 | |
| 198 | matrix_b_info = &tmp_b_info; |
| 199 | auto_init_if_empty(tmp_b_info, b->clone()->set_tensor_shape(compute_transpose1xW_with_element_size_shape(*b, mult_transpose1xW_width))); |
| 200 | |
| 201 | auto_init_if_empty(tmp_output_info, matrix_a_info->clone()->set_tensor_shape(compute_mm_shape(*matrix_a_info, *matrix_b_info, run_interleave_transpose, reshape_info))); |
| 202 | } |
| 203 | |
| 204 | // Validate kernels |
| 205 | if(run_optimised && run_interleave_transpose) |
| 206 | { |
| 207 | /* Interleave */ |
| 208 | TensorShape tensor_shape0{ matrix_a_info->tensor_shape() }; |
| 209 | tensor_shape0.set(0, k); |
| 210 | tensor_shape0.set(1, m); |
| 211 | |
| 212 | const TensorInfo tensor_info0 = matrix_a_info->clone()->set_tensor_shape(tensor_shape0); |
| 213 | const TensorInfo tensor_info_reshaped0 = matrix_a_info->clone()->set_tensor_shape(compute_interleaved_shape(tensor_info0, mult_interleave4x4_height)); |
| 214 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(matrix_a_info, &tensor_info_reshaped0); |
| 215 | |
| 216 | if(n != 0) /* Transpose */ |
| 217 | { |
| 218 | TensorShape tensor_shape1{ matrix_b_info->tensor_shape() }; |
| 219 | tensor_shape1.set(0, n); |
| 220 | tensor_shape1.set(1, k); |
| 221 | |
| 222 | const TensorInfo tensor_info1 = matrix_b_info->clone()->set_tensor_shape(tensor_shape1); |
| 223 | const TensorInfo tensor_info_reshaped1 = matrix_b_info->clone()->set_tensor_shape(compute_transpose1xW_with_element_size_shape(tensor_info1, mult_transpose1xW_width)); |
| 224 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(matrix_b_info, &tensor_info_reshaped1); |
| 225 | } |
| 226 | |
| 227 | if(output->total_size() != 0) |
| 228 | { |
| 229 | if(n != 0) |
| 230 | { |
| 231 | ARM_COMPUTE_RETURN_ERROR_ON(tmp_output_info.dimension(0) != static_cast<size_t>(n)); |
| 232 | } |
| 233 | ARM_COMPUTE_RETURN_ERROR_ON(tmp_output_info.dimension(1) != static_cast<size_t>(m)); |
| 234 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(matrix_a_info, &tmp_output_info); |
| 235 | } |
| 236 | } |
| 237 | else if(run_vector_matrix_multiplication) |
| 238 | { |
| 239 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMMatrixMultiplyKernel::validate(a, b, output, alpha, false, reshape_info)); |
| 240 | |
| 241 | if(beta != 0 && c != nullptr) |
| 242 | { |
| 243 | // Validate matrix addition kernel |
| 244 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(c, output); |
| 245 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(c, output); |
| 246 | } |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | if(run_interleave_transpose) |
| 251 | { |
| 252 | // Validate interleave kernel |
| 253 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMInterleave4x4Kernel::validate(a, matrix_a_info)); |
| 254 | |
| 255 | // Validate transpose kernel |
| 256 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMTranspose1xWKernel::validate(b, matrix_b_info)); |
| 257 | } |
| 258 | |
| 259 | // Validate matrix multiply |
| 260 | ARM_COMPUTE_RETURN_ON_ERROR(NEGEMMMatrixMultiplyKernel::validate(matrix_a_info, matrix_b_info, &tmp_output_info, alpha, run_interleave_transpose, reshape_info)); |
| 261 | |
| 262 | if(beta != 0 && c != nullptr) |
| 263 | { |
| 264 | // Validate matrix addition kernel |
| 265 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(c, &tmp_output_info); |
| 266 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(c, &tmp_output_info); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return Status{}; |
| 271 | } |
| 272 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 273 | void NEGEMM::run() |
| 274 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 275 | prepare(); |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 276 | |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 277 | if(_asm_glue.is_configured()) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 278 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 279 | _memory_group.acquire(); |
Pablo Tello | eb82fd2 | 2018-02-23 13:43:50 +0000 | [diff] [blame] | 280 | _asm_glue.run(); |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 281 | _memory_group.release(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 282 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 283 | else |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 284 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 285 | _memory_group.acquire(); |
| 286 | |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 287 | if(!_run_vector_matrix_multiplication) |
| 288 | { |
| 289 | // Run interleave kernel |
| 290 | NEScheduler::get().schedule(&_interleave_kernel, Window::DimY); |
| 291 | |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 292 | if(!_reshape_b_only_on_first_run) |
Gian Marco | 1d25ed5 | 2017-12-16 19:33:50 +0000 | [diff] [blame] | 293 | { |
| 294 | // Run transpose kernel |
| 295 | NEScheduler::get().schedule(&_transpose_kernel, Window::DimY); |
| 296 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | NEScheduler::get().schedule(&_mm_kernel, _run_vector_matrix_multiplication ? Window::DimX : Window::DimY); |
| 300 | |
| 301 | _memory_group.release(); |
| 302 | |
| 303 | // Run matrix addition kernel |
| 304 | if(_run_addition) |
| 305 | { |
| 306 | NEScheduler::get().schedule(&_ma_kernel, Window::DimY); |
| 307 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 308 | } |
| 309 | } |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 310 | |
| 311 | void NEGEMM::prepare() |
| 312 | { |
| 313 | if(!_is_prepared) |
| 314 | { |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 315 | if(_asm_glue.is_configured()) |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 316 | { |
| 317 | ARM_COMPUTE_ERROR_ON(!_original_b->is_used()); |
| 318 | |
| 319 | _asm_glue.prepare(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 320 | } |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 321 | else if(_reshape_b_only_on_first_run && !_run_vector_matrix_multiplication && !_asm_glue.is_configured()) |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 322 | { |
| 323 | ARM_COMPUTE_ERROR_ON(!_original_b->is_used()); |
| 324 | |
| 325 | _tmp_b.allocator()->allocate(); |
| 326 | NEScheduler::get().schedule(&_transpose_kernel, Window::DimY); |
| 327 | _original_b->mark_as_unused(); |
| 328 | } |
| 329 | |
| 330 | _is_prepared = true; |
| 331 | } |
| 332 | } |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 333 | } // namespace arm_compute |