Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018 ARM Limited. |
| 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/NEGEMMConvolutionLayer.h" |
| 25 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Size2D.h" |
| 27 | #include "arm_compute/core/Utils.h" |
| 28 | #include "arm_compute/core/Validate.h" |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
| 31 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
| 32 | #include "support/ToolchainSupport.h" |
| 33 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 34 | #include <cmath> |
| 35 | #include <tuple> |
| 36 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 37 | using namespace arm_compute; |
| 38 | using namespace arm_compute::misc::shape_calculator; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 39 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 40 | NEConvolutionLayerReshapeWeights::NEConvolutionLayerReshapeWeights() |
| 41 | : _weights_reshape_kernel() |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 45 | void NEConvolutionLayerReshapeWeights::configure(const ITensor *weights, const ITensor *biases, ITensor *output) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 46 | { |
| 47 | // Perform validation step |
| 48 | ARM_COMPUTE_ERROR_ON_NULLPTR(weights, output); |
| 49 | ARM_COMPUTE_ERROR_THROW_ON(NEConvolutionLayerReshapeWeights::validate(weights->info(), |
| 50 | (biases != nullptr) ? biases->info() : nullptr, |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 51 | output->info())); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 52 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 53 | const bool append_biases = (biases != nullptr) && !is_data_type_quantized_asymmetric(weights->info()->data_type()); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 54 | const ITensor *biases_to_use = (append_biases) ? biases : nullptr; |
| 55 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 56 | _weights_reshape_kernel.configure(weights, biases_to_use, output); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 57 | |
| 58 | output->info()->set_quantization_info(weights->info()->quantization_info()); |
| 59 | } |
| 60 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 61 | Status NEConvolutionLayerReshapeWeights::validate(const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 62 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 63 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(weights); |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 64 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 66 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 67 | if(biases != nullptr) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 68 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 69 | const int idx_kernels = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::BATCHES); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 70 | ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized_asymmetric(weights->data_type())); |
| 71 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(idx_kernels)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 74 | } |
| 75 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 76 | if((output != nullptr) && (output->total_size() != 0)) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 77 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 78 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, output); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 79 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 80 | NEWeightsReshapeKernel::validate(weights, biases, output); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return Status{}; |
| 84 | } |
| 85 | |
| 86 | void NEConvolutionLayerReshapeWeights::run() |
| 87 | { |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 88 | NEScheduler::get().schedule(&_weights_reshape_kernel, 3); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 91 | NEGEMMConvolutionLayer::NEGEMMConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager) |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 92 | : _memory_group(memory_manager), _reshape_weights(), _im2col_kernel(), _mm_gemm(), _mm_gemmlowp(memory_manager), _gemmlowp_output_stage(), _col2im_kernel(), _activationlayer_function(), |
| 93 | _add_bias_kernel(), _original_weights(nullptr), _im2col_output(), _weights_reshaped(), _gemm_output(), _tmp_output(), _data_layout(DataLayout::NCHW), _append_bias(false), _skip_im2col(false), |
| 94 | _skip_col2im(false), _is_quantized(false), _is_activationlayer_enabled(false), _is_prepared(false) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 98 | void NEGEMMConvolutionLayer::configure_mm(const ITensor *input, const ITensor *weights, ITensor *output, int gemm_3d_depth) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 99 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 100 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights); |
| 101 | ARM_COMPUTE_ERROR_THROW_ON(validate_mm(input->info(), weights->info(), output->info(), gemm_3d_depth, _skip_im2col)); |
| 102 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 103 | if(_is_quantized) |
| 104 | { |
| 105 | // Since we need negative offsets for computing convolution, we need to change QuantizationInfo() |
| 106 | // Extract and negate input and weights offset |
| 107 | const QuantizationInfo input_quantization_info = input->info()->quantization_info(); |
| 108 | const QuantizationInfo weights_quantization_info = weights->info()->quantization_info(); |
| 109 | |
| 110 | input->info()->set_quantization_info(QuantizationInfo(input_quantization_info.scale, -input_quantization_info.offset)); |
| 111 | weights->info()->set_quantization_info(QuantizationInfo(weights_quantization_info.scale, -weights_quantization_info.offset)); |
| 112 | |
| 113 | _mm_gemmlowp.configure(input, weights, output, GEMMInfo(false, false, true /* Reshape weights only for the first run*/)); |
| 114 | |
| 115 | // Revert back QuantizatioInfo as input and weights could be used in other convolution layers |
| 116 | input->info()->set_quantization_info(input_quantization_info); |
| 117 | weights->info()->set_quantization_info(weights_quantization_info); |
| 118 | } |
| 119 | else |
| 120 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 121 | // Configure matrix multiply function |
| 122 | _mm_gemm.configure(input, weights, nullptr, output, 1.0f, 0.0f, GEMMInfo(false, false, true /* Reshape weights only for the first run*/, gemm_3d_depth, |
| 123 | _skip_im2col /* Reinterpret the input as 3D if im2col is skipped */)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 127 | Status NEGEMMConvolutionLayer::validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, int gemm_3d_depth, bool skip_im2col) |
| 128 | { |
| 129 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
| 130 | |
| 131 | const GEMMInfo &gemm_info = GEMMInfo(false, false, true /* Reshape weights only for the first run */, gemm_3d_depth, skip_im2col); |
| 132 | if(is_quantized) |
| 133 | { |
| 134 | // Since we need negative offsets for computing convolution, we need to change QuantizationInfo() |
| 135 | // Extract and negate input and weights offset |
| 136 | const QuantizationInfo input_quantization_info = input->quantization_info(); |
| 137 | const QuantizationInfo weights_quantization_info = weights->quantization_info(); |
| 138 | |
| 139 | std::unique_ptr<ITensorInfo> input_qa = input->clone(); |
| 140 | std::unique_ptr<ITensorInfo> weights_qa = weights->clone(); |
| 141 | input_qa->set_quantization_info(QuantizationInfo(input_quantization_info.scale, -input_quantization_info.offset)); |
| 142 | weights_qa->set_quantization_info(QuantizationInfo(weights_quantization_info.scale, -weights_quantization_info.offset)); |
| 143 | |
| 144 | // Perform validation step on GEMMLowp |
| 145 | NEGEMMLowpMatrixMultiplyCore::validate(input_qa.get(), weights_qa.get(), output, gemm_info); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | // Perform validation step on Matrix multiply function |
| 150 | NEGEMM::validate(input, weights, nullptr, output, 1.0f, 0.0f, gemm_info); |
| 151 | } |
| 152 | return Status{}; |
| 153 | } |
| 154 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 155 | void NEGEMMConvolutionLayer::configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 156 | const Size2D &dilation, const ActivationLayerInfo &act_info) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 157 | { |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 158 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 159 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 160 | ARM_COMPUTE_ERROR_THROW_ON(NEGEMMConvolutionLayer::validate(input->info(), |
| 161 | weights->info(), |
| 162 | biases != nullptr ? biases->info() : nullptr, |
| 163 | output->info(), |
| 164 | conv_info, |
| 165 | weights_info, |
| 166 | dilation, |
| 167 | act_info)); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 168 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 169 | const DataType data_type = input->info()->data_type(); |
| 170 | const DataLayout data_layout = input->info()->data_layout(); |
| 171 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 172 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 173 | const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 174 | const int idx_kernels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 175 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 176 | const unsigned int kernel_width = weights->info()->dimension(idx_width); |
| 177 | const unsigned int kernel_height = weights->info()->dimension(idx_height); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 178 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 179 | _is_prepared = weights_info.retain_internal_weights(); |
| 180 | _original_weights = weights; |
| 181 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 182 | _data_layout = data_layout; |
| 183 | _skip_im2col = (data_layout == DataLayout::NHWC && kernel_width == 1 && kernel_height == 1 && conv_info.stride().first == 1 && conv_info.stride().second == 1) && !_is_quantized; |
| 184 | _skip_col2im = (data_layout == DataLayout::NHWC) && !_is_quantized; |
| 185 | _append_bias = (biases != nullptr) && (!_is_quantized); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 186 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 187 | // TODO (giaiod01): Validate GEMM3D |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 188 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 189 | const bool is_nhwc = _data_layout == DataLayout::NHWC; |
| 190 | const ITensor *gemm_input_to_use = input; |
| 191 | ITensor *gemm_output_to_use = output; |
| 192 | ITensor *gemm_output_staged_to_use = output; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 193 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 194 | const unsigned bias_element = (_append_bias && !_skip_im2col) ? 1 : 0; |
| 195 | const ITensor *biases_to_use = (_append_bias && !_skip_im2col) ? biases : nullptr; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 196 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 197 | // Get parameters from conv_info |
| 198 | unsigned int stride_x = 0; |
| 199 | unsigned int stride_y = 0; |
| 200 | std::tie(stride_x, stride_y) = conv_info.stride(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 201 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 202 | // Get convolved dimensions |
| 203 | unsigned int conv_w = 0; |
| 204 | unsigned int conv_h = 0; |
| 205 | std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(idx_width), |
| 206 | input->info()->dimension(idx_height), |
| 207 | kernel_width, |
| 208 | kernel_height, |
| 209 | conv_info, |
| 210 | dilation); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 211 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 212 | unsigned int mat_weights_cols = weights->info()->dimension(idx_kernels); |
| 213 | unsigned int mat_weights_rows = weights->info()->dimension(idx_width) * weights->info()->dimension(idx_height) * weights->info()->dimension(idx_channel) + bias_element; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 214 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 215 | // _weights_reshaped will be auto configured in the kernel. |
| 216 | // Just append biases and do not transpose 1xW as it will be reshaped in NEGEMM |
| 217 | _reshape_weights.configure(weights, biases_to_use, &_weights_reshaped); |
| 218 | |
| 219 | weights = &_weights_reshaped; |
| 220 | |
| 221 | // Create tensor to store im2col reshaped inputs |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 222 | if(!_skip_im2col) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 223 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 224 | // Calculate im2col shape |
| 225 | // For NEON the batch size is on the fourth dimension |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 226 | // TODO (giaiod01): Auto-initialize the output shape of im2col COMPMID-1482 |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 227 | TensorShape shape_im2col = input->info()->tensor_shape(); |
| 228 | shape_im2col.set(0, mat_weights_rows); |
| 229 | shape_im2col.set(1, conv_w * conv_h); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 230 | shape_im2col.set(2, 1); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 231 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 232 | _im2col_output.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col)); |
| 233 | _memory_group.manage(&_im2col_output); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 234 | |
Gian Marco Iodice | 215b4ea | 2018-06-28 16:29:29 +0100 | [diff] [blame] | 235 | // Configure |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 236 | _im2col_kernel.configure(input, &_im2col_output, Size2D(kernel_width, kernel_height), conv_info, _append_bias, false, false, dilation); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 237 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 238 | // Update GEMM input |
| 239 | gemm_input_to_use = &_im2col_output; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 240 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 241 | else if(_append_bias) |
| 242 | { |
| 243 | // Configure add bias kernel |
| 244 | _add_bias_kernel.configure(output, biases, output, ConvertPolicy::SATURATE); |
| 245 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 246 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 247 | // Create GEMM output tensor |
| 248 | if(!is_nhwc || _is_quantized) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 249 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 250 | // Calculate GEMM output shape |
| 251 | TensorShape shape_gemm = _im2col_output.info()->tensor_shape(); |
| 252 | shape_gemm.set(0, mat_weights_cols); |
| 253 | shape_gemm.set(1, conv_w * conv_h); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 254 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 255 | // GEMM output should be S32 for acquiring raw integer accumulator without quantized postprocessing for quantized asymmetric input. |
| 256 | const DataType gemm_data_type = _is_quantized ? DataType::S32 : data_type; |
| 257 | // FIXME: input->clone() doesn't work with subtensors for grouped convolutions. |
| 258 | TensorInfo info_gemm(shape_gemm, 1, gemm_data_type); |
| 259 | info_gemm.set_quantization_info(output->info()->quantization_info()); |
| 260 | _gemm_output.allocator()->init(info_gemm); |
| 261 | _memory_group.manage(&_gemm_output); |
| 262 | |
| 263 | // Update GEMM output |
| 264 | gemm_output_to_use = &_gemm_output; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 267 | // Configure and tune GEMM |
| 268 | configure_mm(gemm_input_to_use, weights, gemm_output_to_use, (data_layout == DataLayout::NHWC) ? conv_h : 1); |
| 269 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 270 | if(!_skip_im2col) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 271 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 272 | _im2col_output.allocator()->allocate(); |
| 273 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 274 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 275 | // Configure output stage for quantized case |
| 276 | if(_is_quantized) |
| 277 | { |
| 278 | const QuantizationInfo output_quant_info = (output->info()->total_size() == 0) ? input->info()->quantization_info() : output->info()->quantization_info(); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 279 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 280 | float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale; |
| 281 | int output_multiplier, output_shift; |
| 282 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 283 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 284 | _memory_group.manage(&_tmp_output); |
| 285 | gemm_output_staged_to_use = &_tmp_output; |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 286 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 287 | _gemmlowp_output_stage.configure(gemm_output_to_use, biases, gemm_output_staged_to_use, output_multiplier, output_shift, output_quant_info.offset); |
| 288 | } |
| 289 | |
| 290 | if(!_skip_col2im) |
| 291 | { |
| 292 | // Configure and tune Col2Im |
| 293 | _col2im_kernel.configure(_is_quantized ? gemm_output_staged_to_use : gemm_output_to_use, output, Size2D(conv_w, conv_h)); |
| 294 | } |
| 295 | |
| 296 | if(!is_nhwc || _is_quantized) |
| 297 | { |
| 298 | _tmp_output.allocator()->allocate(); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 299 | _gemm_output.allocator()->allocate(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 302 | ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(idx_width) != conv_w) || (output->info()->dimension(idx_height) != conv_h), |
| 303 | "Output shape does not match the expected one"); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 304 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 305 | //Configure Activation Layer |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 306 | _is_activationlayer_enabled = act_info.enabled(); |
| 307 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 308 | if(_is_activationlayer_enabled) |
| 309 | { |
| 310 | _activationlayer_function.configure(output, nullptr, act_info); |
| 311 | } |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 312 | |
| 313 | ARM_COMPUTE_UNUSED(weights_info); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | Status NEGEMMConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 317 | const WeightsInfo &weights_info, const Size2D &dilation, const ActivationLayerInfo &act_info) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 318 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 319 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
| 320 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights_info.are_reshaped(), "Weights already reshaped are not supported!"); |
| 321 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
| 322 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 323 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, weights); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 324 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 325 | const DataLayout data_layout = input->data_layout(); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 326 | const DataType data_type = input->data_type(); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 327 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 328 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 329 | const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 330 | const int idx_kernels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 331 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 332 | const unsigned int kernel_width = weights->dimension(idx_width); |
| 333 | const unsigned int kernel_height = weights->dimension(idx_height); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 334 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 335 | TensorInfo im2col_reshaped_info, info_gemm, tmp_info, weights_reshaped_info; |
| 336 | const ITensorInfo *gemm_input_to_use = input; |
| 337 | const ITensorInfo *gemm_output_to_use = output; |
| 338 | const ITensorInfo *gemm_output_staged_to_use = output; |
| 339 | const ITensorInfo *weights_to_use = weights; |
Ioan-Cristian Szabo | b4e3e1c | 2017-11-30 17:17:17 +0000 | [diff] [blame] | 340 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 341 | const bool is_nhwc = data_layout == DataLayout::NHWC; |
| 342 | const bool is_quantized = is_data_type_quantized_asymmetric(data_type); |
| 343 | bool skip_im2col = (data_layout == DataLayout::NHWC && kernel_width == 1 && kernel_height == 1) && !is_quantized; |
| 344 | const bool append_bias = (biases != nullptr) && (!is_quantized); |
| 345 | const unsigned bias_element = (append_bias && !skip_im2col) ? 1 : 0; |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 346 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 347 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_channel) != input->dimension(idx_channel)); |
| 348 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 349 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 350 | // Validate biases |
| 351 | if(biases != nullptr) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 352 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 353 | if(is_quantized) |
| 354 | { |
| 355 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases); |
| 360 | } |
| 361 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(idx_kernels)); |
| 362 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 363 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 364 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 365 | if(act_info.enabled()) |
| 366 | { |
| 367 | ARM_COMPUTE_ERROR_ON(act_info.b() > act_info.a()); |
| 368 | } |
| 369 | |
| 370 | // Get convolved dimensions |
| 371 | unsigned int conv_w = 0; |
| 372 | unsigned int conv_h = 0; |
| 373 | |
| 374 | std::tie(conv_w, conv_h) = scaled_dimensions(input->dimension(idx_width), |
| 375 | input->dimension(idx_height), |
| 376 | kernel_width, |
| 377 | kernel_height, |
| 378 | conv_info, |
| 379 | dilation); |
| 380 | |
| 381 | unsigned int mat_weights_cols = weights->dimension(idx_kernels); |
| 382 | unsigned int mat_weights_rows = weights->dimension(idx_width) * weights->dimension(idx_height) * weights->dimension(idx_channel) + bias_element; |
| 383 | |
| 384 | // Output tensor auto inizialization if not yet initialized |
| 385 | ARM_COMPUTE_RETURN_ON_ERROR(NEConvolutionLayerReshapeWeights::validate(weights, is_quantized ? nullptr : biases, nullptr)); |
| 386 | weights_reshaped_info = TensorInfo(compute_weights_reshaped_shape(*weights, append_bias), 1, data_type); |
| 387 | weights_to_use = &weights_reshaped_info; |
| 388 | |
| 389 | // TODO (giaiod01): Validate GEMM3D |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 390 | |
| 391 | if(!skip_im2col) |
| 392 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 393 | // Create tensor info for im2col reshaped inputs |
| 394 | // For NEON the batch size is on the fourth dimension |
| 395 | // TODO (giaiod01): Use auto-init COMPMID-1277 |
| 396 | TensorShape shape_im2col = input->tensor_shape(); |
| 397 | shape_im2col.set(0, mat_weights_rows); |
| 398 | shape_im2col.set(1, conv_w * conv_h); |
| 399 | shape_im2col.set(2, 1); |
| 400 | |
| 401 | im2col_reshaped_info = TensorInfo(shape_im2col, 1, data_type); |
| 402 | im2col_reshaped_info.set_quantization_info(input->quantization_info()); |
| 403 | |
| 404 | ARM_COMPUTE_RETURN_ON_ERROR(NEIm2ColKernel::validate(input, &im2col_reshaped_info, Size2D(kernel_width, kernel_height), conv_info, append_bias, false, false, dilation)); |
| 405 | gemm_input_to_use = &im2col_reshaped_info; |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 406 | } |
| 407 | else if(append_bias) |
| 408 | { |
| 409 | // Validate add bias kernel |
| 410 | ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAdditionKernel::validate(output, biases, output, ConvertPolicy::SATURATE)); |
| 411 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 412 | |
| 413 | // Create GEMM output tensor |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 414 | if(!is_nhwc || is_quantized) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 415 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 416 | TensorShape shape_gemm = gemm_input_to_use->tensor_shape(); |
| 417 | shape_gemm.set(0, mat_weights_cols); |
| 418 | shape_gemm.set(1, conv_w * conv_h); |
| 419 | const DataType gemm_data_type = is_quantized ? DataType::S32 : data_type; |
| 420 | // GEMM output should be S32 for acquiring raw integer accumulator without quantized postprocessing for quantized asymmetric input. |
| 421 | info_gemm = TensorInfo(shape_gemm, 1, gemm_data_type); |
| 422 | info_gemm.set_quantization_info(output->quantization_info()); |
Gian Marco Iodice | a72300a | 2018-04-12 11:41:26 +0100 | [diff] [blame] | 423 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 424 | gemm_output_to_use = &info_gemm; |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 425 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 426 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 427 | ARM_COMPUTE_RETURN_ON_ERROR(validate_mm(gemm_input_to_use, weights_to_use, gemm_output_to_use, (data_layout == DataLayout::NHWC) ? conv_h : 1, skip_im2col)); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 428 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 429 | if(is_quantized) |
| 430 | { |
| 431 | float multiplier = input->quantization_info().scale * weights_to_use->quantization_info().scale / output->quantization_info().scale; |
| 432 | int output_multiplier, output_shift; |
| 433 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
| 434 | |
| 435 | tmp_info = TensorInfo(gemm_output_to_use->tensor_shape(), 1, DataType::QASYMM8); |
| 436 | tmp_info.set_quantization_info(output->quantization_info()); |
| 437 | gemm_output_staged_to_use = &tmp_info; |
| 438 | |
| 439 | // Validate output stage for quantized case |
| 440 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(gemm_output_to_use, biases, gemm_output_staged_to_use, output->quantization_info().offset); |
| 441 | } |
| 442 | |
| 443 | // Validate Col2Im |
| 444 | if(!is_nhwc || is_quantized) |
| 445 | { |
| 446 | ARM_COMPUTE_RETURN_ON_ERROR(NECol2ImKernel::validate(is_quantized ? gemm_output_staged_to_use : gemm_output_to_use, |
| 447 | output, |
| 448 | Size2D(conv_w, conv_h))); |
| 449 | } |
| 450 | |
| 451 | //Validate Activation Layer |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 452 | if(act_info.enabled()) |
| 453 | { |
| 454 | ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(output, nullptr, act_info)); |
| 455 | } |
| 456 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 457 | return Status{}; |
| 458 | } |
| 459 | |
| 460 | void NEGEMMConvolutionLayer::run() |
| 461 | { |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 462 | prepare(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 463 | |
| 464 | _memory_group.acquire(); |
| 465 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 466 | if(!_skip_im2col) |
| 467 | { |
| 468 | // Run input reshaping |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 469 | unsigned int y_dim = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 470 | NEScheduler::get().schedule(&_im2col_kernel, y_dim); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 471 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 472 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 473 | // Runs NEGEMM or NEGEMMLowpMatrixMultiplyCore functions |
| 474 | if(_is_quantized) |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 475 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 476 | // Run gemmlowp |
| 477 | _mm_gemmlowp.run(); |
| 478 | |
| 479 | // Run output stage |
| 480 | _gemmlowp_output_stage.run(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 481 | } |
| 482 | else |
| 483 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 484 | // Run gemm |
| 485 | _mm_gemm.run(); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 488 | if(_skip_im2col && _append_bias) |
| 489 | { |
| 490 | NEScheduler::get().schedule(&_add_bias_kernel, Window::DimY); |
| 491 | } |
| 492 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 493 | // Reshape output matrix |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 494 | if(!_skip_col2im) |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 495 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 496 | NEScheduler::get().schedule(&_col2im_kernel, Window::DimY); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 497 | } |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 498 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 499 | if(_is_activationlayer_enabled) |
| 500 | { |
| 501 | _activationlayer_function.run(); |
| 502 | } |
| 503 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 504 | _memory_group.release(); |
| 505 | } |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 506 | |
| 507 | void NEGEMMConvolutionLayer::prepare() |
| 508 | { |
| 509 | if(!_is_prepared) |
| 510 | { |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 511 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 512 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 513 | // Run weights reshaping and mark original weights tensor as unused |
| 514 | _weights_reshaped.allocator()->allocate(); |
| 515 | _reshape_weights.run(); |
| 516 | _original_weights->mark_as_unused(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 517 | |
Gian Marco Iodice | 597a856 | 2018-08-01 15:06:06 +0100 | [diff] [blame] | 518 | // Prepare GEMM |
| 519 | _is_quantized ? _mm_gemmlowp.prepare() : _mm_gemm.prepare(); |
Georgios Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 520 | if(!_weights_reshaped.is_used()) |
| 521 | { |
| 522 | _weights_reshaped.allocator()->free(); |
| 523 | } |
| 524 | |
| 525 | _is_prepared = true; |
| 526 | } |
| 527 | } |