giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 1 | /* |
Giuseppe Rossini | 0a958cb | 2020-01-16 16:38:56 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2019-2020 ARM Limited. |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +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/CL/functions/CLGEMMDeconvolutionLayer.h" |
| 25 | |
| 26 | #include "arm_compute/core/Helpers.h" |
| 27 | #include "arm_compute/core/Validate.h" |
| 28 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 29 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
| 30 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 31 | #include "utils/TypePrinter.h" |
| 32 | |
| 33 | #include <memory> |
| 34 | #include <tuple> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace |
| 39 | { |
| 40 | std::pair<Coordinates, Coordinates> compute_start_end_slice_coordinates(const ITensorInfo &output_info, const PadStrideInfo &deconv_info, bool is_nchw) |
| 41 | { |
| 42 | Coordinates start; |
| 43 | Coordinates end; |
| 44 | |
| 45 | if(is_nchw) |
| 46 | { |
| 47 | start.set(0, deconv_info.pad_left()); |
| 48 | start.set(1, deconv_info.pad_top()); |
| 49 | end.set(0, output_info.dimension(0) - deconv_info.pad_right()); |
| 50 | end.set(1, output_info.dimension(1) - deconv_info.pad_bottom()); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | start.set(0, 0); |
| 55 | start.set(1, deconv_info.pad_left()); |
| 56 | start.set(2, deconv_info.pad_top()); |
| 57 | |
| 58 | end.set(0, output_info.dimension(0)); |
| 59 | end.set(1, output_info.dimension(1) - deconv_info.pad_right()); |
| 60 | end.set(2, output_info.dimension(2) - deconv_info.pad_bottom()); |
| 61 | } |
| 62 | |
| 63 | return { start, end }; |
| 64 | } |
| 65 | } // namespace |
| 66 | |
| 67 | CLGEMMDeconvolutionLayer::CLGEMMDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager) // NOLINT |
| 68 | : _memory_group(std::move(memory_manager)), |
| 69 | _mm_gemm(), |
| 70 | _mm_gemmlowp(), |
| 71 | _gemmlowp_output_stage(), |
| 72 | _permute_input_to_nhwc(), |
| 73 | _permute_weights_to_nhwc(), |
| 74 | _reshape_weights(), |
| 75 | _transpose_weights(), |
| 76 | _deconv_reshape(), |
| 77 | _slice_gemm(), |
| 78 | _gemmlowp_final(), |
| 79 | _reshaped_weights(), |
| 80 | _reshaped_weights_t(), |
| 81 | _permuted_input(), |
| 82 | _permuted_weights(), |
| 83 | _gemm_output(), |
| 84 | _slice_gemm_input(), |
| 85 | _original_weights(), |
| 86 | _is_prepared(false), |
| 87 | _padded_input(false), |
| 88 | _is_nchw(false), |
| 89 | _is_quantized(false) |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | Status CLGEMMDeconvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, const ITensorInfo *output, const PadStrideInfo &deconv_info) |
| 94 | { |
| 95 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
| 96 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F32, DataType::F16, DataType::QASYMM8); |
| 97 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 98 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, weights); |
| 99 | |
| 100 | DataLayout data_layout = input->data_layout(); |
| 101 | const bool padded_input = deconv_info.pad_bottom() > 0 || deconv_info.pad_left() > 0 || deconv_info.pad_right() > 0 || deconv_info.pad_top() > 0; |
| 102 | const bool is_nchw = input->data_layout() == DataLayout::NCHW; |
| 103 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
| 104 | |
| 105 | const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 106 | const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 107 | const size_t idx_b = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
| 108 | |
| 109 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_w) != deconv_info.stride().first); |
| 110 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_h) != deconv_info.stride().second); |
| 111 | |
| 112 | TensorShape nhwc_weights_shape = weights->tensor_shape(); |
| 113 | TensorShape nhwc_input_shape = input->tensor_shape(); |
| 114 | |
| 115 | if(is_nchw) |
| 116 | { |
| 117 | permute(nhwc_weights_shape, PermutationVector(2, 0, 1)); |
| 118 | permute(nhwc_input_shape, PermutationVector(2, 0, 1)); |
| 119 | |
| 120 | TensorInfo nhwc_input_info = input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(nhwc_input_shape).set_data_layout(DataLayout::NCHW); |
| 121 | |
| 122 | TensorInfo nhwc_weights_info = weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(nhwc_weights_shape).set_data_layout(DataLayout::NCHW); |
| 123 | |
| 124 | CLPermute::validate(weights, &nhwc_weights_info, PermutationVector(2, 0, 1)); |
| 125 | CLPermute::validate(input, &nhwc_input_info, PermutationVector(2, 0, 1)); |
| 126 | } |
| 127 | |
| 128 | const TensorShape reshaped_shape = TensorShape(nhwc_weights_shape[0], nhwc_weights_shape[1] * nhwc_weights_shape[2] * nhwc_weights_shape[3]); |
| 129 | const TensorInfo reshaped_info = weights->clone()->set_tensor_shape(reshaped_shape).set_data_layout(DataLayout::NCHW).set_is_resizable(true); |
| 130 | ARM_COMPUTE_RETURN_ON_ERROR(CLReshapeLayer::validate(weights, &reshaped_info)); |
| 131 | |
| 132 | TensorShape transposed_shape(reshaped_shape[1], reshaped_shape[0]); |
| 133 | const TensorInfo reshaped_t_info = reshaped_info.clone()->set_is_resizable(true).set_tensor_shape(transposed_shape); |
| 134 | ARM_COMPUTE_RETURN_ON_ERROR(CLTranspose::validate(&reshaped_info, &reshaped_t_info)); |
| 135 | |
| 136 | TensorShape gemm_output_shape(weights->dimension(idx_w) * weights->dimension(idx_h) * weights->dimension(idx_b), |
| 137 | input->dimension(idx_w), |
| 138 | input->dimension(idx_h), |
| 139 | input->dimension(idx_b)); |
| 140 | |
| 141 | TensorInfo gemm_output_info = reshaped_t_info.clone()->set_tensor_shape(gemm_output_shape).set_is_resizable(true); |
| 142 | GEMMInfo gemm_info(false, false, true, input->dimension(idx_h), true); |
| 143 | |
| 144 | if(is_quantized) |
| 145 | { |
| 146 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyCore::validate(&input->clone()->set_tensor_shape(nhwc_input_shape), &reshaped_t_info, nullptr, &gemm_output_info.set_data_type(DataType::S32), |
| 147 | gemm_info)); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMM::validate(&input->clone()->set_tensor_shape(nhwc_input_shape).set_is_resizable(true), &reshaped_t_info, nullptr, &gemm_output_info, 1.0f, 0.0f, gemm_info)); |
| 152 | } |
| 153 | |
Matthew Jackson | b9070a4 | 2019-08-22 16:13:27 +0100 | [diff] [blame] | 154 | const PadStrideInfo stride_info(deconv_info.stride().first, deconv_info.stride().second); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 155 | auto out_dims = deconvolution_output_dimensions(input->dimension(idx_w), input->dimension(idx_h), weights->dimension(idx_w), weights->dimension(idx_h), stride_info); |
| 156 | const TensorShape deconv_shape = misc::shape_calculator::compute_deconvolution_output_shape(out_dims, *input, *weights); |
| 157 | TensorInfo col2im_output_info = gemm_output_info.clone()->set_tensor_shape(deconv_shape).set_is_resizable(true); |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 158 | |
| 159 | if(padded_input && is_quantized) |
| 160 | { |
| 161 | const auto start_end = compute_start_end_slice_coordinates(col2im_output_info, deconv_info, is_nchw); |
| 162 | ARM_COMPUTE_RETURN_ON_ERROR(CLDeconvolutionReshapeOutputKernel::validate(&gemm_output_info, bias, &col2im_output_info, input, weights, deconv_info)); |
| 163 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&col2im_output_info, nullptr, |
| 164 | &col2im_output_info.clone()->set_is_resizable(true).set_data_type(DataType::QASYMM8))); |
| 165 | ARM_COMPUTE_RETURN_ON_ERROR(CLSlice::validate(&col2im_output_info.clone()->set_is_resizable(true).set_data_type(DataType::QASYMM8), output, start_end.first, start_end.second)); |
| 166 | } |
| 167 | else if(padded_input) |
| 168 | { |
| 169 | const auto start_end = compute_start_end_slice_coordinates(col2im_output_info, deconv_info, is_nchw); |
| 170 | ARM_COMPUTE_RETURN_ON_ERROR(CLDeconvolutionReshapeOutputKernel::validate(&gemm_output_info, bias, &col2im_output_info, input, weights, deconv_info)); |
| 171 | ARM_COMPUTE_RETURN_ON_ERROR(CLSlice::validate(&col2im_output_info, output, start_end.first, start_end.second)); |
| 172 | } |
| 173 | else if(is_quantized) |
| 174 | { |
| 175 | ARM_COMPUTE_RETURN_ON_ERROR(CLDeconvolutionReshapeOutputKernel::validate(&gemm_output_info, bias, &col2im_output_info, input, weights, deconv_info)); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 176 | |
| 177 | const UniformQuantizationInfo iq_info = input->quantization_info().uniform(); |
| 178 | const UniformQuantizationInfo wq_info = weights->quantization_info().uniform(); |
| 179 | const UniformQuantizationInfo oq_info = output->quantization_info().uniform(); |
| 180 | |
| 181 | float multiplier = iq_info.scale * wq_info.scale / oq_info.scale; |
| 182 | int output_multiplier(0); |
| 183 | int output_shift(0); |
| 184 | ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift)); |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 185 | ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&col2im_output_info, nullptr, output)); |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | ARM_COMPUTE_RETURN_ON_ERROR(CLDeconvolutionReshapeOutputKernel::validate(&gemm_output_info, bias, output, input, weights, deconv_info)); |
| 190 | } |
| 191 | |
| 192 | return Status{}; |
| 193 | } |
| 194 | |
| 195 | void CLGEMMDeconvolutionLayer::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &deconv_info) |
| 196 | { |
| 197 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 198 | ARM_COMPUTE_ERROR_THROW_ON(CLGEMMDeconvolutionLayer::validate(input->info(), |
| 199 | weights->info(), |
| 200 | bias != nullptr ? bias->info() : nullptr, |
| 201 | output->info(), |
| 202 | deconv_info)); |
| 203 | |
| 204 | _original_weights = weights; |
| 205 | _padded_input = deconv_info.pad_bottom() > 0 || deconv_info.pad_left() > 0 || deconv_info.pad_right() > 0 || deconv_info.pad_top() > 0; |
| 206 | _is_nchw = input->info()->data_layout() == DataLayout::NCHW; |
| 207 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 208 | |
| 209 | const ICLTensor *input_to_use = input; |
| 210 | const ICLTensor *weights_to_use = weights; |
| 211 | |
| 212 | // If the data layout is NCHW, transform everything in NHWC. Another alternative could be to |
| 213 | // do an outer product in NCHW and then an accumulation through a reduction. This would have two |
| 214 | // drawbacks: first, the outer product is less efficient than a full GEMM. Second, the reduction |
| 215 | // might be slower than GEMM. |
| 216 | if(_is_nchw) |
| 217 | { |
| 218 | _memory_group.manage(&_permuted_input); |
| 219 | _permute_input_to_nhwc.configure(input, &_permuted_input, PermutationVector(2U, 0U, 1U)); |
| 220 | |
| 221 | _permute_weights_to_nhwc.configure(weights, &_permuted_weights, PermutationVector(2U, 0U, 1U)); |
| 222 | |
| 223 | input_to_use = &_permuted_input; |
| 224 | weights_to_use = &_permuted_weights; |
| 225 | } |
| 226 | |
| 227 | // Reshape the input weights. The weights will be reshaped only once during the call to prepare() |
| 228 | _reshaped_weights.allocator()->init(TensorInfo(TensorShape(weights_to_use->info()->dimension(0), |
| 229 | weights_to_use->info()->dimension(1) * weights_to_use->info()->dimension(2) * weights_to_use->info()->dimension(3)), |
| 230 | 1, |
| 231 | input->info()->data_type(), weights->info()->quantization_info())); |
| 232 | |
| 233 | _reshape_weights.configure(weights_to_use, &_reshaped_weights); |
| 234 | _transpose_weights.configure(&_reshaped_weights, &_reshaped_weights_t); |
| 235 | |
| 236 | const size_t idx_h = get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::HEIGHT); |
| 237 | GEMMInfo gemm_info(false, false, true, input->info()->dimension(idx_h), true); |
| 238 | |
| 239 | // Configure output stage for asymmetric quantized types |
| 240 | if(_is_quantized) |
| 241 | { |
Giuseppe Rossini | 0a958cb | 2020-01-16 16:38:56 +0000 | [diff] [blame^] | 242 | // gemmlowp adds the offsets (instead of subtracting them). Thus, we need to negate the original |
| 243 | // and restore them back to make it work properly. |
| 244 | QuantizationInfo iq_info = input->info()->quantization_info(); |
| 245 | QuantizationInfo wq_info = weights->info()->quantization_info(); |
| 246 | |
| 247 | input_to_use->info()->set_quantization_info(QuantizationInfo(iq_info.uniform().scale, -iq_info.uniform().offset)); |
| 248 | _reshaped_weights_t.info()->set_quantization_info(QuantizationInfo(wq_info.uniform().scale, -wq_info.uniform().offset)); |
| 249 | |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 250 | _mm_gemmlowp.configure(input_to_use, &_reshaped_weights_t, nullptr, &_gemm_output, gemm_info); |
Giuseppe Rossini | 0a958cb | 2020-01-16 16:38:56 +0000 | [diff] [blame^] | 251 | |
| 252 | input_to_use->info()->set_quantization_info(iq_info); |
| 253 | _reshaped_weights_t.info()->set_quantization_info(wq_info); |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 254 | } |
| 255 | else |
| 256 | { |
| 257 | _mm_gemm.configure(input_to_use, &_reshaped_weights_t, nullptr, &_gemm_output, 1.f, 0.0f, gemm_info); |
| 258 | } |
| 259 | |
| 260 | if(_is_nchw) |
| 261 | { |
| 262 | _permuted_input.allocator()->allocate(); |
| 263 | } |
| 264 | |
| 265 | ICLTensor *deconv_reshape_output = nullptr; |
| 266 | ICLTensor *slice_output = nullptr; |
| 267 | ICLTensor *output_stage_output = nullptr; |
| 268 | |
| 269 | if(_padded_input && _is_quantized) |
| 270 | { |
| 271 | _memory_group.manage(&_slice_gemm_input); |
| 272 | _memory_group.manage(&_gemmlowp_final); |
| 273 | deconv_reshape_output = &_gemmlowp_final; |
| 274 | output_stage_output = &_slice_gemm_input; |
| 275 | slice_output = output; |
| 276 | } |
| 277 | else if(_padded_input) |
| 278 | { |
| 279 | _memory_group.manage(&_slice_gemm_input); |
| 280 | deconv_reshape_output = &_slice_gemm_input; |
| 281 | slice_output = output; |
| 282 | } |
| 283 | else if(_is_quantized) |
| 284 | { |
| 285 | _memory_group.manage(&_gemmlowp_final); |
| 286 | deconv_reshape_output = &_gemmlowp_final; |
| 287 | output_stage_output = output; |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | deconv_reshape_output = output; |
| 292 | } |
| 293 | |
| 294 | // Configure a Col2Im call to reshape the output of GEMM |
| 295 | _deconv_reshape.configure(&_gemm_output, bias, deconv_reshape_output, input->info(), weights->info(), deconv_info); |
| 296 | _gemm_output.allocator()->allocate(); |
| 297 | |
| 298 | if(_is_quantized) |
| 299 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 300 | const UniformQuantizationInfo iq_info = input->info()->quantization_info().uniform(); |
| 301 | const UniformQuantizationInfo wq_info = weights->info()->quantization_info().uniform(); |
Manuel Bottini | 279814b | 2019-10-25 10:28:28 +0100 | [diff] [blame] | 302 | const UniformQuantizationInfo oq_info = output->info()->quantization_info().uniform(); |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 303 | |
| 304 | float multiplier = iq_info.scale * wq_info.scale / oq_info.scale; |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 305 | int output_multiplier(0); |
| 306 | int output_shift(0); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 307 | quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift); |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 308 | _gemmlowp_output_stage.configure(&_gemmlowp_final, nullptr, output_stage_output, output_multiplier, output_shift, oq_info.offset); |
giuros01 | 46a49a0 | 2019-04-01 13:50:22 +0100 | [diff] [blame] | 309 | _gemmlowp_final.allocator()->allocate(); |
| 310 | } |
| 311 | |
| 312 | // If the input was padded, the output needs to be sliced. |
| 313 | if(_padded_input) |
| 314 | { |
| 315 | const auto start_end = compute_start_end_slice_coordinates(*deconv_reshape_output->info(), deconv_info, _is_nchw); |
| 316 | _slice_gemm.configure(&_slice_gemm_input, slice_output, start_end.first, start_end.second); |
| 317 | _slice_gemm_input.allocator()->allocate(); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void CLGEMMDeconvolutionLayer::run() |
| 322 | { |
| 323 | prepare(); |
| 324 | |
| 325 | MemoryGroupResourceScope scope_mg(_memory_group); |
| 326 | |
| 327 | if(_is_nchw) |
| 328 | { |
| 329 | _permute_input_to_nhwc.run(); |
| 330 | } |
| 331 | |
| 332 | if(_is_quantized) |
| 333 | { |
| 334 | _mm_gemmlowp.run(); |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | _mm_gemm.run(); |
| 339 | } |
| 340 | |
| 341 | CLScheduler::get().enqueue(_deconv_reshape, false); |
| 342 | |
| 343 | if(_is_quantized) |
| 344 | { |
| 345 | _gemmlowp_output_stage.run(); |
| 346 | } |
| 347 | |
| 348 | if(_padded_input) |
| 349 | { |
| 350 | _slice_gemm.run(); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | void CLGEMMDeconvolutionLayer::prepare() |
| 355 | { |
| 356 | if(!_is_prepared) |
| 357 | { |
| 358 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 359 | |
| 360 | if(_is_nchw) |
| 361 | { |
| 362 | _permuted_weights.allocator()->allocate(); |
| 363 | _permute_weights_to_nhwc.run(); |
| 364 | } |
| 365 | |
| 366 | _reshaped_weights.allocator()->allocate(); |
| 367 | _reshape_weights.run(); |
| 368 | |
| 369 | if(_is_nchw) |
| 370 | { |
| 371 | _permuted_weights.allocator()->free(); |
| 372 | } |
| 373 | |
| 374 | _reshaped_weights_t.allocator()->allocate(); |
| 375 | _transpose_weights.run(); |
| 376 | |
| 377 | // Prepare gemm |
| 378 | if(!_is_quantized) |
| 379 | { |
| 380 | _mm_gemm.prepare(); |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | _mm_gemmlowp.prepare(); |
| 385 | } |
| 386 | |
| 387 | // Free resources |
| 388 | if(!_reshaped_weights_t.is_used()) |
| 389 | { |
| 390 | _reshaped_weights_t.allocator()->free(); |
| 391 | } |
| 392 | |
| 393 | _original_weights->mark_as_unused(); |
| 394 | _is_prepared = true; |
| 395 | } |
| 396 | } |
| 397 | } // namespace arm_compute |