Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +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 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/Size2D.h" |
| 27 | #include "arm_compute/core/Utils.h" |
| 28 | #include "arm_compute/core/Validate.h" |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +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 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 34 | #include <cmath> |
| 35 | #include <tuple> |
| 36 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 37 | using namespace arm_compute; |
| 38 | using namespace arm_compute::misc::shape_calculator; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 39 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 40 | NEConvolutionLayerReshapeWeights::NEConvolutionLayerReshapeWeights() |
| 41 | : _weights_reshape_kernel() |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 45 | void NEConvolutionLayerReshapeWeights::configure(const ITensor *weights, const ITensor *biases, ITensor *output) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +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, |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 51 | output->info())); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 52 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 53 | const bool append_biases = (biases != nullptr) && !is_data_type_quantized_asymmetric(weights->info()->data_type()); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 54 | const ITensor *biases_to_use = (append_biases) ? biases : nullptr; |
| 55 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 56 | _weights_reshape_kernel.configure(weights, biases_to_use, output); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 57 | |
| 58 | output->info()->set_quantization_info(weights->info()->quantization_info()); |
| 59 | } |
| 60 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 61 | Status NEConvolutionLayerReshapeWeights::validate(const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 62 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 63 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(weights); |
| 64 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 66 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 67 | if(biases != nullptr) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 68 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 69 | const int idx_kernels = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::BATCHES); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +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); |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 72 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(idx_kernels)); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 74 | } |
| 75 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 76 | if((output != nullptr) && (output->total_size() != 0)) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 77 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 78 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, output); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 79 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 80 | NEWeightsReshapeKernel::validate(weights, biases, output); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | return Status{}; |
| 84 | } |
| 85 | |
| 86 | void NEConvolutionLayerReshapeWeights::run() |
| 87 | { |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 88 | NEScheduler::get().schedule(&_weights_reshape_kernel, 3); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 91 | NEGEMMConvolutionLayer::NEGEMMConvolutionLayer(const std::shared_ptr<IMemoryManager> &memory_manager) |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [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(), _reshape_layer(), _original_weights(nullptr), _im2col_output(), _weights_reshaped(), _gemm_output(), _tmp_output(), _data_layout(DataLayout::NCHW), _append_bias(false), |
| 94 | _skip_im2col(false), _skip_col2im(false), _is_quantized(false), _is_activationlayer_enabled(false), _is_prepared(false) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 98 | void NEGEMMConvolutionLayer::configure_mm(const ITensor *input, const ITensor *weights, ITensor *output, int gemm_3d_depth) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 99 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [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 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +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 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [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 */)); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 127 | Status NEGEMMConvolutionLayer::validate_mm(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, int gemm_3d_depth, bool skip_im2col) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 128 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 129 | const bool is_quantized = is_data_type_quantized_asymmetric(input->data_type()); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 130 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 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) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 133 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 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(); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 138 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 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 | return NEGEMMLowpMatrixMultiplyCore::validate(input_qa.get(), weights_qa.get(), output, gemm_info); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 146 | } |
| 147 | else |
| 148 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 149 | // Perform validation step on Matrix multiply function |
| 150 | return NEGEMM::validate(input, weights, nullptr, output, 1.0f, 0.0f, gemm_info); |
| 151 | } |
| 152 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 153 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 154 | Status NEGEMMConvolutionLayer::validate_gemm3d(DataType data_type, int gemm_3d_depth, bool skip_im2col) |
| 155 | { |
| 156 | const bool is_quantized = is_data_type_quantized_asymmetric(data_type); |
| 157 | const DataType output_gemm_data_type = is_quantized ? DataType::S32 : data_type; |
| 158 | const unsigned int mult_y = skip_im2col ? 1U : gemm_3d_depth; |
| 159 | const unsigned int mult_z = skip_im2col ? gemm_3d_depth : 1U; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 160 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 161 | // Set dummy tensor shapes for the validation |
| 162 | const TensorInfo dummy_input_info(TensorShape(4U, 4U * mult_y, 1U * mult_z), 1, data_type); |
| 163 | const TensorInfo dummy_weights_info(TensorShape(4U, 4U), 1, data_type); |
| 164 | const TensorInfo dummy_output_info(TensorShape(4U, 4U, gemm_3d_depth), 1, output_gemm_data_type); |
| 165 | |
| 166 | return validate_mm(&dummy_input_info, &dummy_weights_info, &dummy_output_info, gemm_3d_depth, skip_im2col); |
| 167 | } |
| 168 | |
| 169 | void NEGEMMConvolutionLayer::configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info, |
| 170 | const Size2D &dilation, const ActivationLayerInfo &act_info, unsigned int num_groups) |
| 171 | { |
| 172 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
| 173 | ARM_COMPUTE_UNUSED(num_groups); |
| 174 | ARM_COMPUTE_ERROR_THROW_ON(NEGEMMConvolutionLayer::validate(input->info(), |
| 175 | weights->info(), |
| 176 | biases != nullptr ? biases->info() : nullptr, |
| 177 | output->info(), |
| 178 | conv_info, |
| 179 | weights_info, |
| 180 | dilation, |
| 181 | act_info, |
| 182 | num_groups)); |
| 183 | |
| 184 | const DataType data_type = input->info()->data_type(); |
| 185 | const DataLayout data_layout = input->info()->data_layout(); |
| 186 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 187 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 188 | const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 189 | const int idx_kernels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
| 190 | |
| 191 | const unsigned int kernel_width = weights->info()->dimension(idx_width); |
| 192 | const unsigned int kernel_height = weights->info()->dimension(idx_height); |
| 193 | |
| 194 | _is_prepared = weights_info.retain_internal_weights(); |
| 195 | _original_weights = weights; |
| 196 | _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 197 | _data_layout = data_layout; |
| 198 | _skip_im2col = (data_layout == DataLayout::NHWC && kernel_width == 1 && kernel_height == 1 && conv_info.stride().first == 1 && conv_info.stride().second == 1); |
| 199 | _skip_col2im = data_layout == DataLayout::NHWC; |
| 200 | _append_bias = (biases != nullptr) && (!_is_quantized); |
| 201 | |
| 202 | const ITensor *gemm_input_to_use = input; |
| 203 | ITensor *gemm_output_to_use = output; |
| 204 | ITensor *gemm_output_staged_to_use = output; |
| 205 | |
| 206 | // Get convolved dimensions |
| 207 | unsigned int conv_w = 0; |
| 208 | unsigned int conv_h = 0; |
| 209 | std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(idx_width), |
| 210 | input->info()->dimension(idx_height), |
| 211 | kernel_width, |
| 212 | kernel_height, |
| 213 | conv_info, |
| 214 | dilation); |
| 215 | |
| 216 | // Check if GEMM3D is supported |
| 217 | if(_skip_col2im) |
| 218 | { |
| 219 | // If not supported, we need to perform im2col and col2im (or reshape layer) |
| 220 | if(!bool(validate_gemm3d(input->info()->data_type(), conv_h, _skip_im2col))) |
| 221 | { |
| 222 | _skip_im2col = false; |
| 223 | _skip_col2im = false; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 227 | const unsigned bias_element = (_append_bias && !_skip_im2col) ? 1 : 0; |
| 228 | const ITensor *biases_to_use = (_append_bias && !_skip_im2col) ? biases : nullptr; |
| 229 | |
| 230 | // Get parameters from conv_info |
| 231 | unsigned int stride_x = 0; |
| 232 | unsigned int stride_y = 0; |
| 233 | std::tie(stride_x, stride_y) = conv_info.stride(); |
| 234 | |
| 235 | unsigned int mat_weights_cols = weights->info()->dimension(idx_kernels); |
| 236 | unsigned int mat_weights_rows = weights->info()->dimension(idx_width) * weights->info()->dimension(idx_height) * weights->info()->dimension(idx_channel) + bias_element; |
| 237 | |
| 238 | // _weights_reshaped will be auto configured in the kernel. |
| 239 | // Just append biases and do not transpose 1xW as it will be reshaped in NEGEMM |
| 240 | _reshape_weights.configure(weights, biases_to_use, &_weights_reshaped); |
| 241 | |
| 242 | // Create tensor to store im2col reshaped inputs |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 243 | if(!_skip_im2col) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 244 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 245 | // Calculate im2col shape |
| 246 | // For NEON the batch size is on the fourth dimension |
| 247 | TensorShape shape_im2col = input->info()->tensor_shape(); |
| 248 | shape_im2col.set(0, mat_weights_rows); |
| 249 | shape_im2col.set(1, conv_w * conv_h); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 250 | shape_im2col.set(2, 1); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 251 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 252 | _im2col_output.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_im2col)); |
| 253 | _memory_group.manage(&_im2col_output); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 254 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 255 | // Configure |
| 256 | _im2col_kernel.configure(input, &_im2col_output, Size2D(kernel_width, kernel_height), conv_info, _append_bias, dilation); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 257 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 258 | // Update GEMM input |
| 259 | gemm_input_to_use = &_im2col_output; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 260 | } |
| 261 | else if(_append_bias) |
| 262 | { |
| 263 | // Configure add bias kernel |
| 264 | _add_bias_kernel.configure(output, biases, output, ConvertPolicy::SATURATE); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 267 | // Create temporary GEMM output tensor in case we cannot skip col2im |
| 268 | if(!_skip_col2im) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 269 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 270 | // Calculate GEMM output shape |
| 271 | TensorShape shape_gemm = _im2col_output.info()->tensor_shape(); |
| 272 | shape_gemm.set(0, mat_weights_cols); |
| 273 | shape_gemm.set(1, conv_w * conv_h); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 274 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 275 | // GEMM output should be S32 for acquiring raw integer accumulator without quantized postprocessing for quantized asymmetric input. |
| 276 | const DataType gemm_data_type = _is_quantized ? DataType::S32 : data_type; |
| 277 | TensorInfo info_gemm(shape_gemm, 1, gemm_data_type); |
| 278 | info_gemm.set_quantization_info(output->info()->quantization_info()); |
| 279 | _gemm_output.allocator()->init(info_gemm); |
| 280 | _memory_group.manage(&_gemm_output); |
| 281 | |
| 282 | // Update GEMM output |
| 283 | gemm_output_to_use = &_gemm_output; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 286 | // Configure GEMM |
| 287 | configure_mm(gemm_input_to_use, &_weights_reshaped, gemm_output_to_use, _skip_col2im ? conv_h : 1); |
| 288 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 289 | if(!_skip_im2col) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 290 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 291 | _im2col_output.allocator()->allocate(); |
| 292 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 293 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 294 | // Configure output stage for quantized case |
| 295 | if(_is_quantized) |
| 296 | { |
| 297 | const QuantizationInfo output_quant_info = (output->info()->total_size() == 0) ? input->info()->quantization_info() : output->info()->quantization_info(); |
| 298 | |
| 299 | float multiplier = input->info()->quantization_info().scale * weights->info()->quantization_info().scale / output_quant_info.scale; |
| 300 | int output_multiplier, output_shift; |
| 301 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
| 302 | |
| 303 | _memory_group.manage(&_tmp_output); |
| 304 | gemm_output_staged_to_use = &_tmp_output; |
| 305 | |
| 306 | _gemmlowp_output_stage.configure(gemm_output_to_use, biases, gemm_output_staged_to_use, output_multiplier, output_shift, output_quant_info.offset); |
| 307 | } |
| 308 | |
| 309 | if(!_skip_col2im) |
| 310 | { |
| 311 | if(_data_layout == DataLayout::NCHW) |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 312 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 313 | // Configure col2im |
| 314 | _col2im_kernel.configure(_is_quantized ? gemm_output_staged_to_use : gemm_output_to_use, output, Size2D(conv_w, conv_h)); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 315 | } |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 316 | else |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 317 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 318 | // Configure reshape layer |
| 319 | _reshape_layer.configure(_is_quantized ? gemm_output_staged_to_use : gemm_output_to_use, output); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 320 | } |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 321 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 322 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 323 | if(_is_quantized) |
| 324 | { |
| 325 | _tmp_output.allocator()->allocate(); |
| 326 | } |
| 327 | |
| 328 | if(!_skip_col2im) |
| 329 | { |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 330 | _gemm_output.allocator()->allocate(); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 333 | ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(idx_width) != conv_w) || (output->info()->dimension(idx_height) != conv_h), |
| 334 | "Output shape does not match the expected one"); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 335 | |
| 336 | //Configure Activation Layer |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 337 | _is_activationlayer_enabled = act_info.enabled(); |
| 338 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 339 | if(_is_activationlayer_enabled) |
| 340 | { |
| 341 | _activationlayer_function.configure(output, nullptr, act_info); |
| 342 | } |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 343 | |
| 344 | ARM_COMPUTE_UNUSED(weights_info); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | Status NEGEMMConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 348 | const WeightsInfo &weights_info, const Size2D &dilation, const ActivationLayerInfo &act_info, unsigned int num_groups) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 349 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 350 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output); |
| 351 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights_info.are_reshaped(), "Weights already reshaped are not supported!"); |
| 352 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::F16, DataType::F32); |
| 353 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 354 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, weights); |
| 355 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups > 1, "Grouping (num_groups != 1) is not supported on NEON"); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 356 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 357 | const DataLayout data_layout = input->data_layout(); |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 358 | const DataType data_type = input->data_type(); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 359 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 360 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 361 | const int idx_channel = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL); |
| 362 | const int idx_kernels = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 363 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 364 | const unsigned int kernel_width = weights->dimension(idx_width); |
| 365 | const unsigned int kernel_height = weights->dimension(idx_height); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 366 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 367 | TensorInfo im2col_reshaped_info, info_gemm, tmp_info, weights_reshaped_info; |
| 368 | const ITensorInfo *gemm_input_to_use = input; |
| 369 | const ITensorInfo *gemm_output_to_use = output; |
| 370 | const ITensorInfo *gemm_output_staged_to_use = output; |
| 371 | const ITensorInfo *weights_to_use = weights; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 372 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 373 | const bool is_quantized = is_data_type_quantized_asymmetric(data_type); |
| 374 | const bool append_bias = (biases != nullptr) && (!is_quantized); |
| 375 | bool skip_im2col = (data_layout == DataLayout::NHWC && kernel_width == 1 && kernel_height == 1 && conv_info.stride().first == 1 && conv_info.stride().second == 1); |
| 376 | bool skip_col2im = data_layout == DataLayout::NHWC; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 377 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 378 | // Get convolved dimensions |
| 379 | unsigned int conv_w = 0; |
| 380 | unsigned int conv_h = 0; |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 381 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 382 | std::tie(conv_w, conv_h) = scaled_dimensions(input->dimension(idx_width), |
| 383 | input->dimension(idx_height), |
| 384 | kernel_width, |
| 385 | kernel_height, |
| 386 | conv_info, |
| 387 | dilation); |
| 388 | |
| 389 | // Check if GEMM3D is supported |
| 390 | if(skip_col2im) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 391 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 392 | // If not supported, we need to perform im2col and col2im (or reshape layer) |
| 393 | if(!bool(validate_gemm3d(input->data_type(), conv_h, skip_im2col))) |
| 394 | { |
| 395 | skip_im2col = false; |
| 396 | skip_col2im = false; |
| 397 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 398 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 399 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 400 | const unsigned bias_element = (append_bias && !skip_im2col) ? 1 : 0; |
| 401 | const ITensorInfo *biases_to_use = (append_bias && !skip_im2col) ? biases : nullptr; |
| 402 | |
| 403 | ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_channel) != input->dimension(idx_channel)); |
| 404 | ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4); |
| 405 | |
| 406 | // Validate biases |
| 407 | if(biases != nullptr) |
| 408 | { |
| 409 | if(is_quantized) |
| 410 | { |
| 411 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32); |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases); |
| 416 | } |
| 417 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != weights->dimension(idx_kernels)); |
| 418 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 419 | } |
| 420 | |
| 421 | if(act_info.enabled()) |
| 422 | { |
| 423 | ARM_COMPUTE_ERROR_ON(act_info.b() > act_info.a()); |
| 424 | } |
| 425 | |
| 426 | unsigned int mat_weights_cols = weights->dimension(idx_kernels); |
| 427 | unsigned int mat_weights_rows = weights->dimension(idx_width) * weights->dimension(idx_height) * weights->dimension(idx_channel) + bias_element; |
| 428 | |
| 429 | // Output tensor auto inizialization if not yet initialized |
| 430 | ARM_COMPUTE_RETURN_ON_ERROR(NEConvolutionLayerReshapeWeights::validate(weights, biases_to_use, nullptr)); |
| 431 | weights_reshaped_info = TensorInfo(compute_weights_reshaped_shape(*weights, (append_bias && !skip_im2col)), 1, data_type); |
| 432 | weights_to_use = &weights_reshaped_info; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 433 | |
| 434 | if(!skip_im2col) |
| 435 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 436 | // Create tensor info for im2col reshaped inputs |
| 437 | // For NEON the batch size is on the fourth dimension |
| 438 | TensorShape shape_im2col = input->tensor_shape(); |
| 439 | shape_im2col.set(0, mat_weights_rows); |
| 440 | shape_im2col.set(1, conv_w * conv_h); |
| 441 | shape_im2col.set(2, 1); |
| 442 | |
| 443 | im2col_reshaped_info = TensorInfo(shape_im2col, 1, data_type); |
| 444 | im2col_reshaped_info.set_quantization_info(input->quantization_info()); |
| 445 | |
| 446 | ARM_COMPUTE_RETURN_ON_ERROR(NEIm2ColKernel::validate(input, &im2col_reshaped_info, Size2D(kernel_width, kernel_height), conv_info, append_bias, dilation)); |
| 447 | gemm_input_to_use = &im2col_reshaped_info; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 448 | } |
| 449 | else if(append_bias) |
| 450 | { |
| 451 | // Validate add bias kernel |
| 452 | ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAdditionKernel::validate(output, biases, output, ConvertPolicy::SATURATE)); |
| 453 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 454 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 455 | // Create temporary GEMM output tensor in case we cannot skip col2im |
| 456 | if(!skip_col2im) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 457 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 458 | TensorShape shape_gemm = gemm_input_to_use->tensor_shape(); |
| 459 | shape_gemm.set(0, mat_weights_cols); |
| 460 | shape_gemm.set(1, conv_w * conv_h); |
| 461 | const DataType gemm_data_type = is_quantized ? DataType::S32 : data_type; |
| 462 | // GEMM output should be S32 for acquiring raw integer accumulator without quantized postprocessing for quantized asymmetric input. |
| 463 | info_gemm = TensorInfo(shape_gemm, 1, gemm_data_type); |
| 464 | info_gemm.set_quantization_info(output->quantization_info()); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 465 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 466 | gemm_output_to_use = &info_gemm; |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 469 | ARM_COMPUTE_RETURN_ON_ERROR(validate_mm(gemm_input_to_use, weights_to_use, gemm_output_to_use, skip_col2im ? conv_h : 1, skip_im2col)); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 470 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 471 | if(is_quantized) |
| 472 | { |
| 473 | float multiplier = input->quantization_info().scale * weights_to_use->quantization_info().scale / output->quantization_info().scale; |
| 474 | int output_multiplier, output_shift; |
| 475 | quantization::calculate_quantized_multiplier_less_than_one(multiplier, &output_multiplier, &output_shift); |
| 476 | |
| 477 | tmp_info = TensorInfo(gemm_output_to_use->tensor_shape(), 1, DataType::QASYMM8); |
| 478 | tmp_info.set_quantization_info(output->quantization_info()); |
| 479 | gemm_output_staged_to_use = &tmp_info; |
| 480 | |
| 481 | // Validate output stage for quantized case |
| 482 | NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(gemm_output_to_use, biases, gemm_output_staged_to_use, output->quantization_info().offset); |
| 483 | } |
| 484 | |
| 485 | // Validate Col2Im/ReshapeLayer |
| 486 | if(!skip_col2im && (data_layout == DataLayout::NCHW)) |
| 487 | { |
| 488 | ARM_COMPUTE_RETURN_ON_ERROR(NECol2ImKernel::validate(is_quantized ? gemm_output_staged_to_use : gemm_output_to_use, |
| 489 | output, |
| 490 | Size2D(conv_w, conv_h))); |
| 491 | } |
| 492 | |
| 493 | //Validate Activation Layer |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 494 | if(act_info.enabled()) |
| 495 | { |
| 496 | ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(output, nullptr, act_info)); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | return Status{}; |
| 500 | } |
| 501 | |
| 502 | void NEGEMMConvolutionLayer::run() |
| 503 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 504 | prepare(); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 505 | |
| 506 | _memory_group.acquire(); |
| 507 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 508 | if(!_skip_im2col) |
| 509 | { |
| 510 | // Run input reshaping |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 511 | unsigned int y_dim = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 512 | NEScheduler::get().schedule(&_im2col_kernel, y_dim); |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 513 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 514 | |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 515 | // Runs NEGEMM or NEGEMMLowpMatrixMultiplyCore functions |
| 516 | if(_is_quantized) |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 517 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 518 | // Run gemmlowp |
| 519 | _mm_gemmlowp.run(); |
| 520 | |
| 521 | // Run output stage |
| 522 | _gemmlowp_output_stage.run(); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 523 | } |
| 524 | else |
| 525 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 526 | // Run gemm |
| 527 | _mm_gemm.run(); |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 530 | if(_skip_im2col && _append_bias) |
| 531 | { |
| 532 | NEScheduler::get().schedule(&_add_bias_kernel, Window::DimY); |
| 533 | } |
| 534 | |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 535 | // Reshape output matrix |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 536 | if(!_skip_col2im) |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 537 | { |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 538 | if(_data_layout == DataLayout::NCHW) |
| 539 | { |
| 540 | NEScheduler::get().schedule(&_col2im_kernel, Window::DimY); |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | _reshape_layer.run(); |
| 545 | } |
Jenkins | b3a371b | 2018-05-23 11:36:53 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if(_is_activationlayer_enabled) |
| 549 | { |
| 550 | _activationlayer_function.run(); |
| 551 | } |
Anthony Barbier | 06ea048 | 2018-02-22 15:45:35 +0000 | [diff] [blame] | 552 | |
| 553 | _memory_group.release(); |
| 554 | } |
Jenkins | 52ba29e | 2018-08-29 15:32:11 +0000 | [diff] [blame^] | 555 | |
| 556 | void NEGEMMConvolutionLayer::prepare() |
| 557 | { |
| 558 | if(!_is_prepared) |
| 559 | { |
| 560 | ARM_COMPUTE_ERROR_ON(!_original_weights->is_used()); |
| 561 | |
| 562 | // Run weights reshaping and mark original weights tensor as unused |
| 563 | _weights_reshaped.allocator()->allocate(); |
| 564 | _reshape_weights.run(); |
| 565 | _original_weights->mark_as_unused(); |
| 566 | |
| 567 | // Prepare GEMM |
| 568 | _is_quantized ? _mm_gemmlowp.prepare() : _mm_gemm.prepare(); |
| 569 | if(!_weights_reshaped.is_used()) |
| 570 | { |
| 571 | _weights_reshaped.allocator()->free(); |
| 572 | } |
| 573 | |
| 574 | _is_prepared = true; |
| 575 | } |
| 576 | } |