Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
Jakub Sujak | c5df0c6 | 2024-01-11 10:02:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023-2024 Arm Limited. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [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 | */ |
Jakub Sujak | c5df0c6 | 2024-01-11 10:02:01 +0000 | [diff] [blame] | 24 | #ifndef ACL_TESTS_VALIDATION_FIXTURES_WINOGRADCONVOLUTIONLAYERFIXTURE_H |
| 25 | #define ACL_TESTS_VALIDATION_FIXTURES_WINOGRADCONVOLUTIONLAYERFIXTURE_H |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 30 | #include "tests/AssetsLibrary.h" |
| 31 | #include "tests/Globals.h" |
| 32 | #include "tests/IAccessor.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Fixture.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [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" |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 38 | #include "tests/validation/reference/GEMM.h" |
Giorgio Arena | 3695f9a | 2018-04-23 17:41:22 +0100 | [diff] [blame] | 39 | #include "tests/validation/reference/Permute.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 40 | #include "tests/validation/reference/Utils.h" |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 41 | #include "tests/validation/reference/Winograd.h" |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 42 | #include "utils/Utils.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 43 | |
| 44 | #include <random> |
| 45 | |
| 46 | namespace arm_compute |
| 47 | { |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 48 | namespace test |
| 49 | { |
| 50 | namespace validation |
| 51 | { |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 52 | using namespace arm_compute::misc::shape_calculator; |
| 53 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 54 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename T1 = T, bool use_bias = true, bool mixed_layout = false> |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 55 | class WinogradConvolutionLayerFastMathValidationFixture : public framework::Fixture |
| 56 | { |
| 57 | public: |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 58 | void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, |
| 59 | DataType data_type, ActivationLayerInfo act_info, const DataLayout &data_layout) |
| 60 | |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 61 | { |
| 62 | ARM_COMPUTE_UNUSED(dilation); |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 63 | _mixed_layout = mixed_layout; |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 64 | _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info, data_layout); |
| 65 | _reference = compute_reference(input_shape, weights_shape, bias_shape, info, data_type, act_info); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | protected: |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 69 | void mix_layout(FunctionType &layer, TensorType &src, TensorType &dst) |
| 70 | { |
| 71 | const DataLayout data_layout = src.info()->data_layout(); |
| 72 | // Test Multi DataLayout graph cases, when the data layout changes after configure |
| 73 | src.info()->set_data_layout(data_layout == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 74 | dst.info()->set_data_layout(data_layout == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 75 | |
| 76 | // Compute Convolution function |
| 77 | layer.run(); |
| 78 | |
| 79 | // Reinstating original data layout for the test suite to properly check the values |
| 80 | src.info()->set_data_layout(data_layout); |
| 81 | dst.info()->set_data_layout(data_layout); |
| 82 | } |
| 83 | |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 84 | template <typename U> |
| 85 | void fill(U &&tensor, int i, float min, float max) |
| 86 | { |
| 87 | switch(tensor.data_type()) |
| 88 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 89 | case DataType::F16: |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 90 | { |
Giorgio Arena | a8e2aeb | 2021-01-06 11:34:57 +0000 | [diff] [blame] | 91 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ float(min), float(max) }; |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 92 | library->fill(tensor, distribution, i); |
| 93 | break; |
| 94 | } |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 95 | case DataType::F32: |
| 96 | { |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 97 | std::uniform_real_distribution<float> distribution(min, max); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 98 | library->fill(tensor, distribution, i); |
| 99 | break; |
| 100 | } |
| 101 | default: |
| 102 | { |
| 103 | ARM_COMPUTE_ERROR("Not supported"); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 108 | TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, const PadStrideInfo &info, |
| 109 | DataType data_type, ActivationLayerInfo act_info, const DataLayout data_layout) |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 110 | { |
Pablo Tello | 7282d56 | 2018-06-14 15:35:49 +0100 | [diff] [blame] | 111 | if(data_layout == DataLayout::NHWC) |
| 112 | { |
| 113 | permute(input_shape, PermutationVector(2U, 0U, 1U)); |
| 114 | permute(weights_shape, PermutationVector(2U, 0U, 1U)); |
| 115 | permute(output_shape, PermutationVector(2U, 0U, 1U)); |
| 116 | } |
| 117 | |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 118 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 119 | TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 120 | TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 121 | TensorType bias = create_tensor<TensorType>(bias_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 122 | TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), data_layout); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 123 | |
| 124 | // Create and configure function |
| 125 | FunctionType conv; |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 126 | ARM_COMPUTE_EXPECT(static_cast<bool>(conv.validate(src.info(), weights.info(), (use_bias) ? bias.info() : nullptr, dst.info(), info, act_info, true /* Enable fast math */)), |
| 127 | framework::LogLevel::ERRORS); |
| 128 | conv.configure(&src, &weights, (use_bias) ? &bias : nullptr, &dst, info, act_info, true /* Enable fast math */); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 129 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 130 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 131 | ARM_COMPUTE_ASSERT(weights.info()->is_resizable()); |
| 132 | ARM_COMPUTE_ASSERT(bias.info()->is_resizable()); |
| 133 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 134 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 135 | add_padding_x({ &src, &weights, &bias, &dst }, data_layout); |
| 136 | |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 137 | // Allocate tensors |
| 138 | src.allocator()->allocate(); |
| 139 | weights.allocator()->allocate(); |
| 140 | dst.allocator()->allocate(); |
| 141 | bias.allocator()->allocate(); |
| 142 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 143 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 144 | ARM_COMPUTE_ASSERT(!weights.info()->is_resizable()); |
| 145 | ARM_COMPUTE_ASSERT(!bias.info()->is_resizable()); |
| 146 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 147 | |
| 148 | // Fill tensors |
Gian Marco Iodice | 6f688fd | 2019-08-19 11:45:26 +0100 | [diff] [blame] | 149 | fill(AccessorType(src), 0, -0.5f, 0.5f); |
| 150 | fill(AccessorType(weights), 1, -0.5f, 0.5f); |
| 151 | fill(AccessorType(bias), 2, -0.5f, 0.5f); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 152 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 153 | if(_mixed_layout) |
| 154 | { |
| 155 | mix_layout(conv, src, dst); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | // Compute function |
| 160 | conv.run(); |
| 161 | } |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 162 | return dst; |
| 163 | } |
| 164 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 165 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const PadStrideInfo &info, |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 166 | DataType data_type, ActivationLayerInfo act_info) |
| 167 | { |
| 168 | // Create reference |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 169 | SimpleTensor<T> src_t{ input_shape, data_type, 1 }; |
| 170 | SimpleTensor<T> weights_t{ weights_shape, data_type, 1 }; |
| 171 | SimpleTensor<T> bias_t{ bias_shape, data_type, 1 }; |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 172 | |
| 173 | // Fill reference |
Gian Marco Iodice | 6f688fd | 2019-08-19 11:45:26 +0100 | [diff] [blame] | 174 | fill(src_t, 0, -0.5f, 0.5f); |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 175 | SimpleTensor<T1> src_t1(copy_tensor<T1, T>(src_t)); |
| 176 | |
Gian Marco Iodice | 6f688fd | 2019-08-19 11:45:26 +0100 | [diff] [blame] | 177 | fill(weights_t, 1, -0.5f, 0.5f); |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 178 | SimpleTensor<T1> weights_t1(copy_tensor<T1, T>(weights_t)); |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 179 | if(use_bias) |
| 180 | { |
Gian Marco Iodice | 6f688fd | 2019-08-19 11:45:26 +0100 | [diff] [blame] | 181 | fill(bias_t, 2, -0.5f, 0.5f); |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 182 | } |
| 183 | else |
| 184 | { |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 185 | fill(bias_t, 2, 0.f, 0.f); |
Giorgio Arena | a3221e6 | 2018-05-03 15:57:48 +0100 | [diff] [blame] | 186 | } |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 187 | SimpleTensor<T1> bias_t1(copy_tensor<T1, T>(bias_t)); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 188 | |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 189 | // Set output tile |
| 190 | Size2D output_tile(4U, 4U); |
Pablo Tello | 96e922e | 2018-09-26 11:25:15 +0100 | [diff] [blame] | 191 | if(weights_shape[0] == 7 && weights_shape[1] == 1) |
| 192 | { |
| 193 | output_tile.width = 2; |
| 194 | output_tile.height = 1; |
| 195 | } |
| 196 | else if(weights_shape[0] == 1 && weights_shape[1] == 7) |
| 197 | { |
| 198 | output_tile.width = 1; |
| 199 | output_tile.height = 2; |
| 200 | } |
| 201 | else if(weights_shape[0] == 1) |
Gian Marco Iodice | f1c2bf0 | 2018-06-13 14:05:54 +0100 | [diff] [blame] | 202 | { |
| 203 | output_tile.width = 1; |
| 204 | } |
| 205 | else if(weights_shape[1] == 1) |
| 206 | { |
| 207 | output_tile.height = 1; |
| 208 | } |
| 209 | |
| 210 | WinogradInfo winograd_info(output_tile, |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 211 | Size2D(weights_shape[0], weights_shape[1]), |
| 212 | Size2D(input_shape[0], input_shape[1]), |
| 213 | info, |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 214 | src_t1.data_layout()); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 215 | |
| 216 | // Compute tensor shapes for input, filter and output transforms |
| 217 | TensorShape input_transform_shape = compute_winograd_input_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); |
| 218 | TensorShape filter_transform_shape = compute_winograd_filter_transform_shape(TensorInfo(weights_shape, 1, data_type), winograd_info); |
| 219 | TensorShape batched_gemm_shape = input_transform_shape; |
| 220 | batched_gemm_shape[0] = filter_transform_shape[0]; |
| 221 | TensorShape output_transform_shape = compute_winograd_output_transform_shape(TensorInfo(batched_gemm_shape, 1, data_type), winograd_info); |
| 222 | |
| 223 | // Dummy matrix C to perform matrix multiplication |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 224 | SimpleTensor<T1> dummy_c{ batched_gemm_shape, data_type, 1 }; |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 225 | |
| 226 | // Compute Winograd-based convolution |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 227 | SimpleTensor<T1> input_transform_out = reference::winograd_input_transform<T1>(src_t1, input_transform_shape, winograd_info); |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 228 | |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 229 | SimpleTensor<T1> filter_transform_out = reference::winograd_filter_transform<T1>(weights_t1, filter_transform_shape, winograd_info); |
| 230 | SimpleTensor<T1> batched_gemm = reference::gemm<T1>(input_transform_out, filter_transform_out, dummy_c, 1.0f, 0.0f); |
| 231 | SimpleTensor<T1> conv_out = reference::winograd_output_transform<T1>(batched_gemm, bias_t1, output_transform_shape, winograd_info); |
Jakub Sujak | c5df0c6 | 2024-01-11 10:02:01 +0000 | [diff] [blame] | 232 | SimpleTensor<T> conv_out_t(copy_tensor<T, T1>(conv_out)); |
Vidhya Sudhan Loganathan | a25d16c | 2018-11-16 11:33:12 +0000 | [diff] [blame] | 233 | return (act_info.enabled()) ? reference::activation_layer<T>(conv_out_t, act_info) : conv_out_t; |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | TensorType _target{}; |
| 237 | SimpleTensor<T> _reference{}; |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 238 | bool _mixed_layout{ false }; |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 239 | }; |
| 240 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 241 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool mixed_layout = false> |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 242 | class WinogradInputTransformValidationFixture : public framework::Fixture |
| 243 | { |
| 244 | public: |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 245 | void setup(TensorShape input_shape, WinogradInfo winograd_info, DataLayout data_layout, DataType data_type) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 246 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 247 | TensorShape output_shape = compute_winograd_input_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 248 | _mixed_layout = mixed_layout; |
| 249 | _target = compute_target(input_shape, output_shape, winograd_info, data_layout, data_type); |
| 250 | _reference = compute_reference(input_shape, output_shape, winograd_info, data_type); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | protected: |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 254 | void mix_layout(FunctionType &layer, TensorType &src, TensorType &dst) |
| 255 | { |
| 256 | const DataLayout data_layout_src = src.info()->data_layout(); |
| 257 | const DataLayout data_layout_dst = dst.info()->data_layout(); |
| 258 | |
| 259 | // Test Multi DataLayout graph cases, when the data layout changes after configure |
| 260 | src.info()->set_data_layout(data_layout_src == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 261 | dst.info()->set_data_layout(data_layout_dst == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 262 | |
| 263 | // Compute Convolution function |
| 264 | layer.run(); |
| 265 | |
| 266 | // Reinstating original data layout for the test suite to properly check the values |
| 267 | src.info()->set_data_layout(data_layout_src); |
| 268 | dst.info()->set_data_layout(data_layout_dst); |
| 269 | } |
| 270 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 271 | template <typename U> |
| 272 | void fill(U &&tensor, int i, float min, float max) |
| 273 | { |
| 274 | switch(tensor.data_type()) |
| 275 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 276 | case DataType::F16: |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 277 | { |
Giorgio Arena | 33b103b | 2021-01-08 10:37:15 +0000 | [diff] [blame] | 278 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ float(min), float(max) }; |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 279 | library->fill(tensor, distribution, i); |
| 280 | break; |
| 281 | } |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 282 | case DataType::F32: |
| 283 | { |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 284 | std::uniform_real_distribution<float> distribution(min, max); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 285 | library->fill(tensor, distribution, i); |
| 286 | break; |
| 287 | } |
| 288 | default: |
| 289 | { |
| 290 | ARM_COMPUTE_ERROR("Not supported"); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 295 | TensorType compute_target(TensorShape input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 296 | { |
Giorgio Arena | c42f28d | 2018-04-26 11:33:05 +0100 | [diff] [blame] | 297 | if(data_layout == DataLayout::NHWC) |
| 298 | { |
| 299 | permute(input_shape, PermutationVector(2U, 0U, 1U)); |
| 300 | } |
| 301 | |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 302 | TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 303 | TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo()); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 304 | |
| 305 | // Create and configure function |
| 306 | FunctionType transf; |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 307 | transf.configure(&src, &dst, winograd_info); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 308 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 309 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 310 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 311 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 312 | add_padding_x({ &src, &dst }, data_layout); |
| 313 | |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 314 | // Allocate tensors |
| 315 | src.allocator()->allocate(); |
| 316 | dst.allocator()->allocate(); |
| 317 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 318 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 319 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 320 | |
| 321 | // Fill tensors |
| 322 | fill(AccessorType(src), 0, -1.f, 1.f); |
| 323 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 324 | if(_mixed_layout) |
| 325 | { |
| 326 | mix_layout(transf, src, dst); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | // Compute Winograd input transform function |
| 331 | transf.run(); |
| 332 | } |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 333 | return dst; |
| 334 | } |
| 335 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 336 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataType data_type) |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 337 | { |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 338 | // Create reference |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 339 | SimpleTensor<T> src{ input_shape, data_type, 1, QuantizationInfo() }; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 340 | |
| 341 | // Fill reference |
| 342 | fill(src, 0, -1.f, 1.f); |
| 343 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 344 | return reference::winograd_input_transform<T>(src, output_shape, winograd_info); |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 347 | bool _mixed_layout{ false }; |
Giorgio Arena | 1f9ca1d | 2018-03-01 11:13:45 +0000 | [diff] [blame] | 348 | TensorType _target{}; |
| 349 | SimpleTensor<T> _reference{}; |
| 350 | }; |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 351 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 352 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool mixed_layout = false> |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 353 | class WinogradFilterTransformValidationFixture : public framework::Fixture |
| 354 | { |
| 355 | public: |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 356 | void setup(TensorShape input_shape, Size2D output_tile, DataLayout data_layout, DataType data_type) |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 357 | { |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 358 | WinogradInfo winograd_info(output_tile, Size2D(input_shape[0], input_shape[1]), Size2D() /* Not needed */, PadStrideInfo() /* Not needed */, DataLayout::NCHW /* Not needed */); |
| 359 | TensorShape output_shape = compute_winograd_filter_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 360 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 361 | _mixed_layout = mixed_layout; |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 362 | _target = compute_target(input_shape, output_shape, winograd_info, data_layout, data_type); |
| 363 | _reference = compute_reference(input_shape, output_shape, winograd_info, data_type); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | protected: |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 367 | void mix_layout(FunctionType &layer, TensorType &src, TensorType &dst) |
| 368 | { |
| 369 | const DataLayout data_layout_src = src.info()->data_layout(); |
| 370 | const DataLayout data_layout_dst = dst.info()->data_layout(); |
| 371 | |
| 372 | // Test Multi DataLayout graph cases, when the data layout changes after configure |
| 373 | src.info()->set_data_layout(data_layout_src == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 374 | dst.info()->set_data_layout(data_layout_dst == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 375 | |
| 376 | // Compute Convolution function |
| 377 | layer.run(); |
| 378 | |
| 379 | // Reinstating original data layout for the test suite to properly check the values |
| 380 | src.info()->set_data_layout(data_layout_src); |
| 381 | dst.info()->set_data_layout(data_layout_dst); |
| 382 | } |
| 383 | |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 384 | template <typename U> |
| 385 | void fill(U &&tensor, int i, float min, float max) |
| 386 | { |
| 387 | switch(tensor.data_type()) |
| 388 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 389 | case DataType::F16: |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 390 | { |
Giorgio Arena | 33b103b | 2021-01-08 10:37:15 +0000 | [diff] [blame] | 391 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ float(min), float(max) }; |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 392 | library->fill(tensor, distribution, i); |
| 393 | break; |
| 394 | } |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 395 | case DataType::F32: |
| 396 | { |
Giorgio Arena | 4bdd177 | 2020-12-17 16:47:07 +0000 | [diff] [blame] | 397 | std::uniform_real_distribution<float> distribution(min, max); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 398 | library->fill(tensor, distribution, i); |
| 399 | break; |
| 400 | } |
| 401 | default: |
| 402 | { |
| 403 | ARM_COMPUTE_ERROR("Not supported"); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
Giorgio Arena | dcb5b28 | 2018-04-25 12:07:29 +0100 | [diff] [blame] | 408 | TensorType compute_target(TensorShape input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type) |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 409 | { |
Giorgio Arena | dcb5b28 | 2018-04-25 12:07:29 +0100 | [diff] [blame] | 410 | if(data_layout == DataLayout::NHWC) |
| 411 | { |
| 412 | permute(input_shape, PermutationVector(2U, 0U, 1U)); |
| 413 | } |
| 414 | |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 415 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 416 | TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout); |
| 417 | TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo()); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 418 | |
| 419 | // Create and configure function |
| 420 | FunctionType filter_transform; |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 421 | filter_transform.configure(&src, &dst, winograd_info); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 422 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 423 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 424 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 425 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 426 | add_padding_x({ &src, &dst }, data_layout); |
| 427 | |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 428 | // Allocate tensors |
| 429 | src.allocator()->allocate(); |
| 430 | dst.allocator()->allocate(); |
| 431 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 432 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 433 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 434 | |
| 435 | // Fill tensors |
| 436 | fill(AccessorType(src), 0, -1.f, 1.f); |
| 437 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 438 | if(_mixed_layout) |
| 439 | { |
| 440 | mix_layout(filter_transform, src, dst); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | // Compute Winograd filter transform function |
| 445 | filter_transform.run(); |
| 446 | } |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 447 | return dst; |
| 448 | } |
| 449 | |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 450 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataType data_type) |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 451 | { |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 452 | // Create reference |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 453 | SimpleTensor<T> src{ input_shape, data_type, 1, QuantizationInfo() }; |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 454 | |
| 455 | // Fill reference |
| 456 | fill(src, 0, -1.f, 1.f); |
| 457 | |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 458 | return reference::winograd_filter_transform<T>(src, output_shape, winograd_info); |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 461 | bool _mixed_layout{ false }; |
Gian Marco Iodice | 7e4b239 | 2018-02-22 16:17:20 +0000 | [diff] [blame] | 462 | TensorType _target{}; |
| 463 | SimpleTensor<T> _reference{}; |
| 464 | }; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 465 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 466 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool mixed_layout = false> |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 467 | class WinogradOutputTransformValidationFixture : public framework::Fixture |
| 468 | { |
| 469 | public: |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 470 | void setup(TensorShape input_shape, WinogradInfo winograd_info, DataType data_type, ActivationLayerInfo act_info = ActivationLayerInfo()) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 471 | { |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 472 | _target = compute_target(input_shape, winograd_info, data_type, act_info); |
| 473 | _reference = compute_reference(input_shape, winograd_info, data_type, act_info); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | protected: |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 477 | void mix_layout(FunctionType &layer, TensorType &src, TensorType &dst) |
| 478 | { |
| 479 | const DataLayout data_layout_src = src.info()->data_layout(); |
| 480 | const DataLayout data_layout_dst = dst.info()->data_layout(); |
| 481 | |
| 482 | // Test Multi DataLayout graph cases, when the data layout changes after configure |
| 483 | src.info()->set_data_layout(data_layout_src == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 484 | dst.info()->set_data_layout(data_layout_dst == DataLayout::NCHW ? DataLayout::NHWC : DataLayout::NCHW); |
| 485 | |
| 486 | // Compute Convolution function |
| 487 | layer.run(); |
| 488 | |
| 489 | // Reinstating original data layout for the test suite to properly check the values |
| 490 | src.info()->set_data_layout(data_layout_src); |
| 491 | dst.info()->set_data_layout(data_layout_dst); |
| 492 | } |
| 493 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 494 | template <typename U> |
| 495 | void fill(U &&tensor, int i, float min, float max) |
| 496 | { |
| 497 | switch(tensor.data_type()) |
| 498 | { |
Vidhya Sudhan Loganathan | 71ecf39 | 2018-08-31 16:10:16 +0100 | [diff] [blame] | 499 | case DataType::F16: |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 500 | { |
Giorgio Arena | a8e2aeb | 2021-01-06 11:34:57 +0000 | [diff] [blame] | 501 | arm_compute::utils::uniform_real_distribution_16bit<half> distribution{ float(min), float(max) }; |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 502 | library->fill(tensor, distribution, i); |
| 503 | break; |
| 504 | } |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 505 | case DataType::F32: |
| 506 | { |
Giorgio Arena | 6aeb217 | 2020-12-15 15:45:43 +0000 | [diff] [blame] | 507 | std::uniform_real_distribution<float> distribution(min, max); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 508 | library->fill(tensor, distribution, i); |
| 509 | break; |
| 510 | } |
| 511 | default: |
| 512 | { |
| 513 | ARM_COMPUTE_ERROR("Not supported"); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 518 | TensorType compute_target(const TensorShape &input_shape, const WinogradInfo &winograd_info, DataType data_type, ActivationLayerInfo act_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 519 | { |
Giorgio Arena | 3695f9a | 2018-04-23 17:41:22 +0100 | [diff] [blame] | 520 | TensorShape output_shape = compute_winograd_output_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); |
| 521 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 522 | // Create tensors |
Giorgio Arena | ea55f91 | 2018-07-12 15:41:35 +0100 | [diff] [blame] | 523 | TensorType src = create_tensor<TensorType>(input_shape, data_type); |
| 524 | TensorType bias = create_tensor<TensorType>(output_shape[get_data_layout_dimension_index(winograd_info.output_data_layout, DataLayoutDimension::CHANNEL)], data_type); |
| 525 | TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, QuantizationInfo(), winograd_info.output_data_layout); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 526 | |
| 527 | // Create and configure function |
| 528 | FunctionType output_transform; |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 529 | output_transform.configure(&src, &bias, &dst, winograd_info, act_info); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 530 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 531 | ARM_COMPUTE_ASSERT(src.info()->is_resizable()); |
| 532 | ARM_COMPUTE_ASSERT(bias.info()->is_resizable()); |
| 533 | ARM_COMPUTE_ASSERT(dst.info()->is_resizable()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 534 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 535 | add_padding_x({ &src, &bias, &dst }, winograd_info.output_data_layout); |
| 536 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 537 | // Allocate tensors |
| 538 | src.allocator()->allocate(); |
Giorgio Arena | ea55f91 | 2018-07-12 15:41:35 +0100 | [diff] [blame] | 539 | bias.allocator()->allocate(); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 540 | dst.allocator()->allocate(); |
| 541 | |
Michele Di Giorgio | 4fc10b3 | 2021-04-30 18:30:41 +0100 | [diff] [blame] | 542 | ARM_COMPUTE_ASSERT(!src.info()->is_resizable()); |
| 543 | ARM_COMPUTE_ASSERT(!bias.info()->is_resizable()); |
| 544 | ARM_COMPUTE_ASSERT(!dst.info()->is_resizable()); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 545 | |
| 546 | // Fill tensors |
| 547 | fill(AccessorType(src), 0, -1.f, 1.f); |
Giorgio Arena | ea55f91 | 2018-07-12 15:41:35 +0100 | [diff] [blame] | 548 | fill(AccessorType(bias), 1, -1.f, 1.f); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 549 | |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 550 | if(_mixed_layout) |
| 551 | { |
| 552 | mix_layout(output_transform, src, dst); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | // Compute Winograd output transform function |
| 557 | output_transform.run(); |
| 558 | } |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 559 | return dst; |
| 560 | } |
| 561 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 562 | SimpleTensor<T> compute_reference(const TensorShape &input_shape, WinogradInfo winograd_info, DataType data_type, ActivationLayerInfo act_info) |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 563 | { |
Giorgio Arena | 3695f9a | 2018-04-23 17:41:22 +0100 | [diff] [blame] | 564 | winograd_info.output_data_layout = DataLayout::NCHW; |
| 565 | TensorShape output_shape = compute_winograd_output_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info); |
| 566 | |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 567 | // Create reference |
Gian Marco Iodice | 247f52c | 2018-03-22 11:24:56 +0000 | [diff] [blame] | 568 | SimpleTensor<T> src{ input_shape, data_type }; |
Gian Marco Iodice | 2213d4b | 2018-04-27 10:39:06 +0100 | [diff] [blame] | 569 | SimpleTensor<T> bias{ TensorShape(input_shape[0]), data_type }; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 570 | |
| 571 | // Fill reference |
| 572 | fill(src, 0, -1.f, 1.f); |
Giorgio Arena | ea55f91 | 2018-07-12 15:41:35 +0100 | [diff] [blame] | 573 | fill(bias, 1, -1.f, 1.f); |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 574 | |
Manuel Bottini | 0d0028c | 2018-10-02 16:41:52 +0100 | [diff] [blame] | 575 | const SimpleTensor<T> winograd_output = reference::winograd_output_transform<T>(src, bias, output_shape, winograd_info); |
| 576 | |
| 577 | return (act_info.enabled()) ? reference::activation_layer<T>(winograd_output, act_info) : winograd_output; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Giorgio Arena | 63825e8 | 2021-03-25 14:54:50 +0000 | [diff] [blame] | 580 | bool _mixed_layout{ false }; |
Gian Marco Iodice | d2fab73 | 2018-03-02 11:18:12 +0000 | [diff] [blame] | 581 | TensorType _target{}; |
| 582 | SimpleTensor<T> _reference{}; |
| 583 | }; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 584 | } // namespace validation |
| 585 | } // namespace test |
| 586 | } // namespace arm_compute |
Jakub Sujak | c5df0c6 | 2024-01-11 10:02:01 +0000 | [diff] [blame] | 587 | #endif // ACL_TESTS_VALIDATION_FIXTURES_WINOGRADCONVOLUTIONLAYERFIXTURE_H |