Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +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 | #ifndef ARM_COMPUTE_TEST_CONVOLUTION_LAYER_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_CONVOLUTION_LAYER_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 30 | #include "tests/AssetsLibrary.h" |
| 31 | #include "tests/Globals.h" |
| 32 | #include "tests/IAccessor.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Fixture.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 35 | #include "tests/validation/Helpers.h" |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 36 | #include "tests/validation/reference/ActivationLayer.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 37 | #include "tests/validation/reference/ConvolutionLayer.h" |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 38 | #include "tests/validation/reference/Permute.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 39 | #include "tests/validation/reference/Utils.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 40 | |
| 41 | #include <random> |
| 42 | |
| 43 | namespace arm_compute |
| 44 | { |
Moritz Pflanzer | beabe3b | 2017-08-31 14:56:32 +0100 | [diff] [blame] | 45 | class NEConvolutionLayer; |
| 46 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 47 | namespace test |
| 48 | { |
| 49 | namespace validation |
| 50 | { |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 51 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW> |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 52 | class ConvolutionValidationGenericFixture : public framework::Fixture |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 53 | { |
| 54 | public: |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 55 | using TBias = typename std::conditional < std::is_same<typename std::decay<T>::type, uint8_t>::value |
| 56 | || std::is_same<typename std::decay<T>::type, int8_t>::value, |
| 57 | int32_t, T >::type; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 58 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 59 | public: |
| 60 | template <typename...> |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 61 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, bool reshape_weights, |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 62 | DataType data_type, DataType weights_data_type, DataLayout data_layout, QuantizationInfo quantization_info, QuantizationInfo weight_quantization_info, ActivationLayerInfo act_info) |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 63 | { |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 64 | _data_type = data_type; |
| 65 | _weights_data_type = weights_data_type; |
| 66 | _is_quantized = is_data_type_quantized_asymmetric(data_type); |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 67 | _is_bfloat16 = data_type == DataType::BFLOAT16; |
| 68 | _bias_data_type = _is_quantized ? DataType::S32 : (_is_bfloat16 ? DataType::F32 : data_type); |
| 69 | _output_data_type = _is_bfloat16 ? DataType::F32 : data_type; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 70 | _quantization_info = quantization_info; |
| 71 | _weight_quantization_info = weight_quantization_info; |
| 72 | _data_layout = data_layout; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 73 | |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 74 | _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, reshape_weights, dilation, act_info); |
| 75 | _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, dilation, act_info); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | protected: |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 79 | void regularize_values(void *values, size_t size) |
| 80 | { |
| 81 | float *fvalues = static_cast<float *>(values); |
| 82 | for(size_t i = 0; i < size; ++i) |
| 83 | { |
| 84 | fvalues[i] = float(bfloat16(fvalues[i])); |
| 85 | } |
| 86 | } |
| 87 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 88 | template <typename U> |
| 89 | void fill(U &&tensor, int i) |
| 90 | { |
| 91 | switch(tensor.data_type()) |
| 92 | { |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 93 | case DataType::QASYMM8: |
| 94 | { |
Michele Di Giorgio | ed5a492 | 2018-09-13 16:22:01 +0100 | [diff] [blame] | 95 | std::pair<int, int> bounds = get_quantized_bounds(tensor.quantization_info(), -1.0f, 1.0f); |
| 96 | std::uniform_int_distribution<uint8_t> distribution(bounds.first, bounds.second); |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 97 | library->fill(tensor, distribution, i); |
| 98 | break; |
| 99 | } |
Georgios Pinitas | 6e1791b | 2019-12-02 19:01:25 +0000 | [diff] [blame] | 100 | case DataType::QASYMM8_SIGNED: |
| 101 | { |
| 102 | std::pair<int, int> bounds = get_quantized_qasymm8_signed_bounds(tensor.quantization_info(), -1.0f, 1.0f); |
| 103 | std::uniform_int_distribution<int8_t> distribution(bounds.first, bounds.second); |
| 104 | library->fill(tensor, distribution, i); |
| 105 | break; |
| 106 | } |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 107 | case DataType::QSYMM8_PER_CHANNEL: |
| 108 | { |
| 109 | int min_bound = 128; |
| 110 | int max_bound = -127; |
| 111 | for(size_t i = 0; i < _weight_quantization_info.scale().size(); i++) |
| 112 | { |
| 113 | std::pair<int, int> bounds = get_symm_quantized_per_channel_bounds(tensor.quantization_info(), -1.0f, 1.0f, i); |
| 114 | if(bounds.first < min_bound) |
| 115 | { |
| 116 | min_bound = bounds.first; |
| 117 | } |
| 118 | if(bounds.second > max_bound) |
| 119 | { |
| 120 | max_bound = bounds.second; |
| 121 | } |
| 122 | } |
| 123 | std::uniform_int_distribution<int8_t> distribution(min_bound, max_bound); |
| 124 | library->fill(tensor, distribution, i); |
| 125 | break; |
| 126 | } |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 127 | case DataType::S32: |
| 128 | { |
| 129 | std::uniform_int_distribution<int32_t> distribution(-100, 100); |
| 130 | library->fill(tensor, distribution, i); |
| 131 | break; |
| 132 | } |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 133 | case DataType::BFLOAT16: |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 134 | case DataType::F16: |
| 135 | case DataType::F32: |
| 136 | { |
| 137 | std::uniform_real_distribution<> distribution(-1.0f, 1.0f); |
| 138 | library->fill(tensor, distribution, i); |
| 139 | break; |
| 140 | } |
| 141 | default: |
| 142 | library->fill_tensor_uniform(tensor, i); |
| 143 | } |
| 144 | } |
| 145 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 146 | TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, const TensorShape &bias_shape, TensorShape output_shape, const PadStrideInfo &info, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 147 | bool reshape_weights, const Size2D &dilation, const ActivationLayerInfo act_info) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 148 | { |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 149 | ARM_COMPUTE_ERROR_ON((input_shape[2] % weights_shape[2]) != 0); |
| 150 | |
| 151 | const unsigned int num_groups = input_shape[2] / weights_shape[2]; |
| 152 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 153 | if(_data_layout == DataLayout::NHWC) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 154 | { |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 155 | permute(input_shape, PermutationVector(2U, 0U, 1U)); |
| 156 | permute(weights_shape, PermutationVector(2U, 0U, 1U)); |
| 157 | permute(output_shape, PermutationVector(2U, 0U, 1U)); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 160 | const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 161 | const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 162 | |
| 163 | WeightsInfo weights_info(!reshape_weights, weights_shape[idx_width], weights_shape[idx_height], weights_shape[3]); |
| 164 | TensorShape reshaped_weights_shape(weights_shape); |
| 165 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 166 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 167 | TensorType src = create_tensor<TensorType>(input_shape, _data_type, 1, _quantization_info, _data_layout); |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 168 | TensorType weights = create_tensor<TensorType>(reshaped_weights_shape, _weights_data_type, 1, _weight_quantization_info, _data_layout); |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 169 | TensorType bias = create_tensor<TensorType>(bias_shape, _bias_data_type, 1, _quantization_info, _data_layout); |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 170 | TensorType dst = create_tensor<TensorType>(output_shape, _output_data_type, 1, _quantization_info, _data_layout); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 171 | |
| 172 | // Create and configure function |
| 173 | FunctionType conv; |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 174 | conv.configure(&src, &weights, &bias, &dst, info, weights_info, dilation, act_info, num_groups); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 175 | |
| 176 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 177 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 178 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 179 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 180 | |
| 181 | // Allocate tensors |
| 182 | src.allocator()->allocate(); |
| 183 | weights.allocator()->allocate(); |
| 184 | bias.allocator()->allocate(); |
| 185 | dst.allocator()->allocate(); |
| 186 | |
| 187 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 188 | ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 189 | ARM_COMPUTE_EXPECT(!bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 190 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 191 | |
| 192 | // Fill tensors |
| 193 | fill(AccessorType(src), 0); |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 194 | fill(AccessorType(weights), 1); |
| 195 | fill(AccessorType(bias), 2); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 196 | |
| 197 | // Compute NEConvolutionLayer function |
| 198 | conv.run(); |
| 199 | |
| 200 | return dst; |
| 201 | } |
| 202 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 203 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 204 | const Size2D &dilation, const ActivationLayerInfo act_info) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 205 | { |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 206 | ARM_COMPUTE_ERROR_ON((input_shape[2] % weights_shape[2]) != 0); |
| 207 | |
| 208 | const unsigned int num_groups = input_shape[2] / weights_shape[2]; |
| 209 | |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 210 | // Setup reference data types |
| 211 | const DataType src_dt = _is_bfloat16 ? DataType::F32 : _data_type; |
| 212 | const DataType weights_dt = _is_bfloat16 ? DataType::F32 : _weights_data_type; |
| 213 | const DataType bias_dt = _is_bfloat16 ? DataType::F32 : _bias_data_type; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 214 | |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 215 | // Create reference |
| 216 | SimpleTensor<T> src{ input_shape, src_dt, 1, _quantization_info }; |
| 217 | SimpleTensor<TW> weights{ weights_shape, weights_dt, 1, _weight_quantization_info }; |
| 218 | SimpleTensor<TBias> bias{ bias_shape, bias_dt, 1, _quantization_info }; |
| 219 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 220 | fill(src, 0); |
| 221 | fill(weights, 1); |
| 222 | fill(bias, 2); |
| 223 | |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 224 | // Fill with bfloat16 to perform the conversion and reduce the mismatches in the output |
| 225 | if(_is_bfloat16) |
| 226 | { |
| 227 | regularize_values(static_cast<void *>(src.data()), src.num_elements()); |
| 228 | regularize_values(static_cast<void *>(weights.data()), weights.num_elements()); |
| 229 | } |
| 230 | |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 231 | return (act_info.enabled()) ? reference::activation_layer<T>(reference::convolution_layer<T>(src, weights, bias, output_shape, info, dilation, num_groups), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 232 | act_info) : |
Gian Marco Iodice | 916d1bc | 2018-08-13 11:20:41 +0100 | [diff] [blame] | 233 | reference::convolution_layer<T>(src, weights, bias, output_shape, info, dilation, num_groups); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 236 | TensorType _target{}; |
| 237 | SimpleTensor<T> _reference{}; |
| 238 | DataType _data_type{}; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 239 | DataType _weights_data_type{}; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 240 | DataType _bias_data_type{}; |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 241 | DataType _output_data_type{}; |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 242 | DataLayout _data_layout{}; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 243 | QuantizationInfo _quantization_info{}; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 244 | QuantizationInfo _weight_quantization_info{}; |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 245 | bool _is_quantized = false; |
Georgios Pinitas | c7b183a | 2020-03-06 18:12:09 +0000 | [diff] [blame] | 246 | bool _is_bfloat16 = false; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 250 | class ConvolutionValidationFixture : public ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 251 | { |
| 252 | public: |
| 253 | template <typename...> |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 254 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, bool reshape_weights, DataType data_type, |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 255 | DataLayout data_layout, ActivationLayerInfo act_info) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 256 | { |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 257 | ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(input_shape, weights_shape, bias_shape, output_shape, info, dilation, reshape_weights, |
| 258 | data_type, data_type, data_layout, |
| 259 | QuantizationInfo(), QuantizationInfo(), act_info); |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 260 | } |
| 261 | }; |
| 262 | |
| 263 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 264 | class ConvolutionValidationQuantizedFixture : public ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T> |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 265 | { |
| 266 | public: |
| 267 | template <typename...> |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 268 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, bool reshape_weights, DataType data_type, |
Georgios Pinitas | 19ea419 | 2018-06-19 13:09:53 +0100 | [diff] [blame] | 269 | DataLayout data_layout, QuantizationInfo quantization_info, ActivationLayerInfo act_info) |
Chunosov | 5124be5 | 2017-11-22 20:42:13 +0700 | [diff] [blame] | 270 | { |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 271 | ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(input_shape, weights_shape, bias_shape, output_shape, info, dilation, reshape_weights, |
| 272 | data_type, data_type, data_layout, quantization_info, quantization_info, act_info); |
| 273 | } |
| 274 | }; |
| 275 | |
| 276 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW> |
| 277 | class ConvolutionValidationQuantizedPerChannelFixture : public ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW> |
| 278 | { |
| 279 | public: |
| 280 | template <typename...> |
| 281 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, bool reshape_weights, DataType data_type, |
| 282 | DataLayout data_layout, QuantizationInfo quantization_info, ActivationLayerInfo act_info, DataType weights_data_type) |
| 283 | { |
| 284 | std::vector<float> weights_scales{}; |
| 285 | std::mt19937 gen(library->seed()); |
| 286 | std::uniform_real_distribution<> dis(0.01f, 1); |
| 287 | for(size_t i = 0; i < output_shape[2]; ++i) |
| 288 | { |
| 289 | weights_scales.push_back(dis(gen)); |
| 290 | } |
| 291 | ConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>::setup(input_shape, weights_shape, bias_shape, output_shape, info, dilation, |
| 292 | reshape_weights, data_type, weights_data_type, data_layout, |
| 293 | quantization_info, QuantizationInfo(weights_scales), act_info); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 294 | } |
| 295 | }; |
| 296 | } // namespace validation |
| 297 | } // namespace test |
| 298 | } // namespace arm_compute |
| 299 | #endif /* ARM_COMPUTE_TEST_CONVOLUTION_LAYER_FIXTURE */ |