Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 945b8da | 2023-07-12 11:54:59 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2023 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 | */ |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 24 | |
| 25 | #ifndef ACL_TESTS_VALIDATION_FIXTURES_DIRECTCONVOLUTIONLAYERFIXTURE_H |
| 26 | #define ACL_TESTS_VALIDATION_FIXTURES_DIRECTCONVOLUTIONLAYERFIXTURE_H |
| 27 | |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/Helpers.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/TensorShape.h" |
| 30 | #include "arm_compute/core/Types.h" |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 32 | #include "tests/AssetsLibrary.h" |
| 33 | #include "tests/Globals.h" |
| 34 | #include "tests/IAccessor.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 35 | #include "tests/framework/Asserts.h" |
| 36 | #include "tests/framework/Fixture.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 37 | #include "tests/validation/Helpers.h" |
| 38 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 39 | #include "tests/validation/reference/ConvolutionLayer.h" |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 40 | #include "tests/validation/reference/Permute.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 41 | |
| 42 | #include <random> |
| 43 | |
| 44 | namespace arm_compute |
| 45 | { |
| 46 | namespace test |
| 47 | { |
| 48 | namespace validation |
| 49 | { |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 50 | using namespace arm_compute::misc::shape_calculator; |
| 51 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 52 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 53 | class DirectConvolutionValidationGenericFixture : public framework::Fixture |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 54 | { |
| 55 | public: |
Sheri Zhang | 681f2d4 | 2020-02-20 11:23:08 +0000 | [diff] [blame] | 56 | using TBias = typename std::conditional < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int32_t, T >::type; |
Georgios Pinitas | 540d008 | 2017-11-17 10:55:00 +0000 | [diff] [blame] | 57 | |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 58 | void setup_quantization(const TensorShape &input_shape, const TensorShape &weights_shape, QuantizationInfo &input_q_info, |
| 59 | QuantizationInfo &weights_q_info, DataType data_type) |
| 60 | { |
| 61 | const int32_t t_max = static_cast<int32_t>(std::numeric_limits<T>::max()); |
| 62 | const int32_t t_min = static_cast<int32_t>(std::numeric_limits<T>::min()); |
| 63 | |
| 64 | std::mt19937 generator(library->seed() + _hash); |
| 65 | std::uniform_real_distribution<float> distribution_float(-5.0f, 3.0f); |
| 66 | std::uniform_int_distribution<int32_t> distribution_t(t_min, t_max); |
| 67 | |
| 68 | const float scale_lhs = pow(2, distribution_float(generator)); // [2^-5, 2^3] |
| 69 | const float scale_rhs = pow(2, distribution_float(generator)); // [2^-5, 2^3] |
| 70 | |
| 71 | const int32_t offset_lhs = distribution_t(generator); |
| 72 | const int32_t offset_rhs = distribution_t(generator); |
| 73 | |
| 74 | input_q_info = QuantizationInfo(scale_lhs, offset_lhs); |
| 75 | weights_q_info = QuantizationInfo(scale_rhs, offset_rhs); |
| 76 | |
| 77 | QuantizationHint q_hint = suggest_conv_dst_q_info_and_bias(input_q_info, weights_q_info, |
| 78 | weights_shape.y() /* heights */, weights_shape.x() /* width */, input_shape.z() /* channels */, |
| 79 | data_type, 0.5f /* bias_fraction */); |
| 80 | |
| 81 | _dst_q_info = q_hint.q_info; |
| 82 | _min_bias = q_hint.bias_min; |
| 83 | _max_bias = q_hint.bias_max; |
| 84 | |
| 85 | // Do not change here as these limits are the natural limits of the associated data types and |
| 86 | // are embeded in the computation of the dst quantization info. |
| 87 | _min_u8 = 0; |
| 88 | _max_u8 = 255; |
| 89 | _min_s8 = -128; |
| 90 | _max_s8 = 127; |
| 91 | } |
| 92 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 93 | void setup(TensorShape input_shape, int stride_x, int stride_y, int pad_x, int pad_y, unsigned int kernel_size, unsigned int num_kernels, |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 94 | DataType data_type, QuantizationInfo quantization_info, ActivationLayerInfo act_info, DataLayout data_layout, bool mixed_layout = false) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 95 | { |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 96 | // This hash is used by random generators. There may be hash collisions but |
| 97 | // this is intentional as it's a very easy way to make the the current |
| 98 | // random generation process almost different for many test configurations, |
| 99 | // which were using the same set of values before. |
| 100 | _hash = input_shape[0] + input_shape[1] + input_shape[2] + input_shape[3] + |
| 101 | stride_x + stride_y + pad_x + pad_y + kernel_size + num_kernels + mixed_layout |
| 102 | + (data_layout == DataLayout::NHWC); |
| 103 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 104 | _data_type = data_type; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 105 | _mixed_layout = mixed_layout; |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 106 | |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 107 | TensorShape weights_shape(kernel_size, kernel_size, input_shape.z(), num_kernels); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 108 | const TensorShape bias_shape(num_kernels); |
| 109 | const PadStrideInfo info(stride_x, stride_y, pad_x, pad_y, DimensionRoundingType::FLOOR); |
Georgios Pinitas | 540d008 | 2017-11-17 10:55:00 +0000 | [diff] [blame] | 110 | const DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 111 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 112 | TensorInfo input_info = TensorInfo(input_shape, 1, data_type); |
| 113 | TensorInfo weights_info = TensorInfo(weights_shape, 1, data_type); |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 114 | |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 115 | const TensorShape output_shape = compute_deep_convolution_shape(input_info, weights_info, info); |
| 116 | |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 117 | QuantizationInfo input_q_info = quantization_info; |
| 118 | QuantizationInfo weights_q_info = quantization_info; |
| 119 | _dst_q_info = quantization_info; |
| 120 | |
| 121 | if(is_data_type_quantized(data_type) && (!act_info.enabled() || act_info.activation() == ActivationFunction::IDENTITY)) |
| 122 | { |
| 123 | setup_quantization(input_shape, weights_shape, input_q_info, weights_q_info, data_type); |
| 124 | } |
| 125 | |
| 126 | _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, input_q_info, weights_q_info, act_info, data_layout); |
| 127 | _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, input_q_info, weights_q_info, act_info); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 130 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 131 | DataType data_type, QuantizationInfo quantization_info, ActivationLayerInfo act_info, DataLayout data_layout) |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 132 | { |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 133 | ARM_COMPUTE_ERROR_ON(data_layout == DataLayout::UNKNOWN); |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 134 | ARM_COMPUTE_UNUSED(dilation); |
| 135 | |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 136 | // This hash is used by random generators. There may be hash collisions but |
| 137 | // this is intentional as it's a very easy way to make the the current |
| 138 | // random generation process almost different for many test configurations, |
| 139 | // which were using the same set of values before. |
| 140 | _hash = input_shape[0] + input_shape[1] + input_shape[2] + input_shape[3] + |
| 141 | weights_shape[0] + weights_shape[1] + weights_shape[2] + weights_shape[3] + dilation.x() + |
| 142 | dilation.y() + info.pad_bottom() + info.pad_left() + info.pad_right() + info.pad_top(); |
| 143 | |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 144 | _data_type = data_type; |
| 145 | |
| 146 | const DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 147 | |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 148 | QuantizationInfo input_q_info = quantization_info; |
| 149 | QuantizationInfo weights_q_info = quantization_info; |
| 150 | _dst_q_info = quantization_info; |
| 151 | |
| 152 | if(is_data_type_quantized(data_type) && (!act_info.enabled() || act_info.activation() == ActivationFunction::IDENTITY)) |
| 153 | { |
| 154 | setup_quantization(input_shape, weights_shape, input_q_info, weights_q_info, data_type); |
| 155 | } |
| 156 | |
| 157 | _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, input_q_info, weights_q_info, act_info, data_layout); |
| 158 | _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, bias_data_type, input_q_info, weights_q_info, act_info); |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 161 | protected: |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 162 | void mix_layout(FunctionType &layer, TensorType &src, TensorType &dst) |
| 163 | { |
| 164 | DataLayout data_layout = src.info()->data_layout(); |
| 165 | // Test Multi DataLayout graph cases, when the data layout changes after configure |
| 166 | src.info()->set_data_layout(data_layout == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 167 | dst.info()->set_data_layout(data_layout == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 168 | |
| 169 | // Compute Convolution function |
| 170 | layer.run(); |
| 171 | |
| 172 | // Reinstating original data layout for the test suite to properly check the values |
| 173 | src.info()->set_data_layout(data_layout); |
| 174 | dst.info()->set_data_layout(data_layout); |
| 175 | } |
| 176 | |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 177 | template <typename U> |
| 178 | void fill(U &&tensor, int i) |
| 179 | { |
| 180 | switch(tensor.data_type()) |
| 181 | { |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 182 | case DataType::QASYMM8: |
| 183 | { |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 184 | std::uniform_int_distribution<uint32_t> distribution(_min_u8, _max_u8); |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 185 | library->fill(tensor, distribution, i); |
| 186 | break; |
| 187 | } |
Sheri Zhang | 681f2d4 | 2020-02-20 11:23:08 +0000 | [diff] [blame] | 188 | case DataType::QASYMM8_SIGNED: |
| 189 | { |
Sheri Zhang | 970353e | 2020-03-19 14:29:49 +0000 | [diff] [blame] | 190 | // Use small input range to avoid all the test results being saturated at the end. |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 191 | std::uniform_int_distribution<int32_t> distribution(_min_s8, _max_s8); |
Sheri Zhang | 681f2d4 | 2020-02-20 11:23:08 +0000 | [diff] [blame] | 192 | library->fill(tensor, distribution, i); |
| 193 | break; |
| 194 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 195 | case DataType::F16: |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 196 | { |
Giorgio Arena | a8e2aeb | 2021-01-06 11:34:57 +0000 | [diff] [blame] | 197 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ -1.0f, 1.0f }; |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 198 | library->fill(tensor, distribution, i); |
| 199 | break; |
| 200 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 201 | case DataType::F32: |
| 202 | { |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 203 | std::uniform_real_distribution<float> distribution(-1.0f, 1.0f); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 204 | library->fill(tensor, distribution, i); |
| 205 | break; |
| 206 | } |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 207 | case DataType::S32: |
| 208 | { |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 209 | std::uniform_int_distribution<int32_t> distribution(_min_bias, _max_bias); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 210 | library->fill(tensor, distribution, i); |
| 211 | break; |
| 212 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 213 | default: |
| 214 | library->fill_tensor_uniform(tensor, i); |
| 215 | } |
| 216 | } |
| 217 | |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 218 | TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, const TensorShape &bias_shape, TensorShape output_shape, const PadStrideInfo &info, |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 219 | DataType data_type, DataType bias_data_type, QuantizationInfo input_q_info, QuantizationInfo weights_q_info, ActivationLayerInfo act_info, const DataLayout &data_layout) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 220 | { |
Giorgio Arena | 563494c | 2018-04-30 17:29:41 +0100 | [diff] [blame] | 221 | if(data_layout == DataLayout::NHWC) |
| 222 | { |
| 223 | permute(input_shape, PermutationVector(2U, 0U, 1U)); |
| 224 | permute(weights_shape, PermutationVector(2U, 0U, 1U)); |
| 225 | permute(output_shape, PermutationVector(2U, 0U, 1U)); |
| 226 | } |
| 227 | |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 228 | // Create tensors |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 229 | TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, input_q_info, data_layout); |
| 230 | TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, weights_q_info, data_layout); |
| 231 | TensorType bias = create_tensor<TensorType>(bias_shape, bias_data_type, 1, QuantizationInfo()); |
| 232 | TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, _dst_q_info, data_layout); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 233 | |
Manuel Bottini | f733e03 | 2021-05-19 16:15:36 +0100 | [diff] [blame] | 234 | add_padding_x({ &src, &bias, &dst }, data_layout); |
| 235 | add_padding_x({ &weights }, data_layout, input_shape[0] % 4 == 0); // Don't add left padding if cl image will be used |
| 236 | |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 237 | // Create and configure function |
| 238 | FunctionType conv; |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 239 | conv.configure(&src, &weights, &bias, &dst, info, act_info); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 240 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 241 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 242 | ARM_COMPUTE_ASSERT(weights.info()->is_resizable()); |
| 243 | ARM_COMPUTE_ASSERT(bias.info()->is_resizable()); |
| 244 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 245 | |
| 246 | // Allocate tensors |
| 247 | src.allocator()->allocate(); |
| 248 | weights.allocator()->allocate(); |
| 249 | bias.allocator()->allocate(); |
| 250 | dst.allocator()->allocate(); |
| 251 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 252 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 253 | ARM_COMPUTE_ASSERT(!weights.info()->is_resizable()); |
| 254 | ARM_COMPUTE_ASSERT(!bias.info()->is_resizable()); |
| 255 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 256 | |
| 257 | // Fill tensors |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 258 | fill(AccessorType(src), 0 + _hash); |
| 259 | fill(AccessorType(weights), 1 + _hash); |
| 260 | fill(AccessorType(bias), 2 + _hash); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 261 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 262 | if(_mixed_layout) |
| 263 | { |
| 264 | mix_layout(conv, src, dst); |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | // Compute Convolution function |
| 269 | conv.run(); |
| 270 | } |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 271 | |
| 272 | return dst; |
| 273 | } |
| 274 | |
| 275 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info, |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 276 | DataType data_type, DataType bias_data_type, QuantizationInfo input_q_info, QuantizationInfo weights_q_info, ActivationLayerInfo act_info) |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 277 | { |
| 278 | // Create reference |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 279 | SimpleTensor<T> src{ input_shape, data_type, 1, input_q_info }; |
| 280 | SimpleTensor<T> weights{ weights_shape, data_type, 1, weights_q_info }; |
| 281 | SimpleTensor<TBias> bias{ bias_shape, bias_data_type, 1, QuantizationInfo() }; |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 282 | |
| 283 | // Fill reference |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 284 | fill(src, 0 + _hash); |
| 285 | fill(weights, 1 + _hash); |
| 286 | fill(bias, 2 + _hash); |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 287 | |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 288 | SimpleTensor<T> dst = reference::convolution_layer<T>(src, weights, bias, output_shape, info, |
| 289 | Size2D(1U, 1U) /* dilation */, 1 /* num_groups */, _dst_q_info); |
| 290 | SimpleTensor<T> dst2 = (act_info.enabled()) ? reference::activation_layer<T>(dst, act_info) : dst; |
| 291 | return dst2; |
Moritz Pflanzer | cde1e8a | 2017-09-08 09:53:14 +0100 | [diff] [blame] | 292 | } |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 293 | TensorType _target{}; |
| 294 | SimpleTensor<T> _reference{}; |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 295 | QuantizationInfo _dst_q_info{}; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 296 | DataType _data_type{}; |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 297 | bool _mixed_layout{ false }; |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 298 | int32_t _hash{0}; |
| 299 | |
| 300 | // Random initialization limits |
| 301 | // Default values are previously handcrafted limits |
| 302 | // that sould be used when we don't use dynamic quantization |
| 303 | int32_t _min_bias{-5}; |
| 304 | int32_t _max_bias{5}; |
| 305 | int32_t _min_u8{0}; |
| 306 | int32_t _max_u8{50}; |
| 307 | int32_t _min_s8{-25}; |
| 308 | int32_t _max_s8{25}; |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 309 | }; |
| 310 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 311 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool mixed_layout = false> |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 312 | class DirectConvolutionValidationFixture : public DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 313 | { |
| 314 | public: |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 315 | void setup(TensorShape input_shape, int stride_x, int stride_y, int pad_x, int pad_y, unsigned int kernel_size, unsigned int num_kernels, DataType data_type, ActivationLayerInfo act_info, |
| 316 | DataLayout data_layout) |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 317 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 318 | DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(input_shape, stride_x, stride_y, pad_x, pad_y, kernel_size, num_kernels, data_type, QuantizationInfo(), |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 319 | act_info, data_layout, mixed_layout); |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 320 | } |
| 321 | }; |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 322 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 323 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool mixed_layout = false> |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 324 | class DirectConvolutionValidationQuantizedFixture : public DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 325 | { |
| 326 | public: |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 327 | void setup(TensorShape input_shape, int stride_x, int stride_y, int pad_x, int pad_y, unsigned int kernel_size, unsigned int num_kernels, DataType data_type, QuantizationInfo quantization_info, |
Giorgio Arena | e620a83 | 2020-02-17 16:33:20 +0000 | [diff] [blame] | 328 | ActivationLayerInfo act_info, DataLayout data_layout) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 329 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 330 | DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(input_shape, stride_x, stride_y, pad_x, pad_y, kernel_size, num_kernels, data_type, quantization_info, |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 331 | act_info, data_layout, mixed_layout); |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 332 | } |
| 333 | }; |
| 334 | |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 335 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 336 | class DirectConvolutionValidationWithTensorShapesQuantizedFixture : public DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 337 | { |
| 338 | public: |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 339 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, |
Giorgio Arena | e620a83 | 2020-02-17 16:33:20 +0000 | [diff] [blame] | 340 | DataType data_type, QuantizationInfo quantization_info, ActivationLayerInfo act_info, DataLayout data_layout) |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 341 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 342 | DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type, quantization_info, |
Giorgio Arena | e620a83 | 2020-02-17 16:33:20 +0000 | [diff] [blame] | 343 | act_info, data_layout); |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 344 | } |
| 345 | }; |
| 346 | |
| 347 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 348 | class DirectConvolutionValidationWithTensorShapesFixture : public DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T> |
| 349 | { |
| 350 | public: |
Alex Gilday | 7da29b6 | 2018-03-23 14:16:00 +0000 | [diff] [blame] | 351 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 352 | DataType data_type, ActivationLayerInfo act_info) |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 353 | { |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 354 | DirectConvolutionValidationGenericFixture<TensorType, AccessorType, FunctionType, T>::setup(input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type, QuantizationInfo(), |
Giorgio Arena | c0f5443 | 2018-03-16 14:02:34 +0000 | [diff] [blame] | 355 | act_info, DataLayout::NCHW); |
Jaroslaw Rzepecki | 2ecbada | 2017-11-29 13:51:34 +0000 | [diff] [blame] | 356 | } |
| 357 | }; |
| 358 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 359 | } // namespace validation |
| 360 | } // namespace test |
| 361 | } // namespace arm_compute |
Gunes Bayir | dfcd41a | 2023-10-11 09:56:05 +0100 | [diff] [blame] | 362 | |
| 363 | #endif // ACL_TESTS_VALIDATION_FIXTURES_DIRECTCONVOLUTIONLAYERFIXTURE_H |