blob: e15931eafb53a3d237db3b538f8dde4f0d33bcee [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
Georgios Pinitas9fb11592018-04-26 20:34:58 +01002 * Copyright (c) 2018 ARM Limited.
Pablo Tello89519332017-11-17 11:52:36 +00003 *
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_WINOGRAD_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_WINOGRAD_LAYER_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +000029#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Pablo Tello89519332017-11-17 11:52:36 +000030#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 Tello89519332017-11-17 11:52:36 +000035#include "tests/validation/Helpers.h"
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000036#include "tests/validation/reference/ActivationLayer.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000037#include "tests/validation/reference/ConvolutionLayer.h"
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +010038#include "tests/validation/reference/GEMM.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000039#include "tests/validation/reference/Utils.h"
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +000040#include "tests/validation/reference/Winograd.h"
Pablo Tello89519332017-11-17 11:52:36 +000041
42#include <random>
43
44namespace arm_compute
45{
Pablo Tello89519332017-11-17 11:52:36 +000046namespace test
47{
48namespace validation
49{
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +000050using namespace arm_compute::misc::shape_calculator;
51
Andrew Mundy4d9379a2018-03-15 16:47:03 +000052template <typename TensorType, typename AccessorType, typename FunctionType, typename T, bool use_bias = true>
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000053class WinogradConvolutionLayerValidationFixture : public framework::Fixture
Pablo Tello89519332017-11-17 11:52:36 +000054{
55public:
56 template <typename...>
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000057 void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, DataType data_type, ActivationLayerInfo act_info)
Pablo Tello89519332017-11-17 11:52:36 +000058 {
Alex Gilday7da29b62018-03-23 14:16:00 +000059 ARM_COMPUTE_UNUSED(dilation);
60
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000061 _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info);
62 _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info);
Pablo Tello89519332017-11-17 11:52:36 +000063 }
64
65protected:
66 template <typename U>
67 void fill(U &&tensor, int i, float min, float max)
68 {
69 switch(tensor.data_type())
70 {
71 case DataType::F32:
72 {
73 std::uniform_real_distribution<> distribution(min, max);
74 library->fill(tensor, distribution, i);
75 break;
76 }
77 default:
78 {
79 ARM_COMPUTE_ERROR("Not supported");
80 library->fill_tensor_uniform(tensor, i);
81 break;
82 }
83 }
84 }
85
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000086 TensorType compute_target(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info,
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000087 DataType data_type, ActivationLayerInfo act_info)
Pablo Tello89519332017-11-17 11:52:36 +000088 {
89 // Create tensors
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000090 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1);
91 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1);
92 TensorType bias = create_tensor<TensorType>(bias_shape, data_type, 1);
93 TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1);
Pablo Tello89519332017-11-17 11:52:36 +000094
95 // Create and configure function
96 FunctionType conv;
Vidhya Sudhan Loganathan84ce1f92018-04-25 13:00:09 +010097 ARM_COMPUTE_EXPECT(static_cast<bool>(conv.validate(src.info(), weights.info(), (use_bias) ? bias.info() : nullptr, dst.info(), info, act_info)), framework::LogLevel::ERRORS);
Andrew Mundy4d9379a2018-03-15 16:47:03 +000098 conv.configure(&src, &weights, (use_bias) ? &bias : nullptr, &dst, info, act_info);
Pablo Tello89519332017-11-17 11:52:36 +000099
100 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
101 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
102 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
103 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
104
105 // Allocate tensors
106 src.allocator()->allocate();
107 weights.allocator()->allocate();
Pablo Tello89519332017-11-17 11:52:36 +0000108 dst.allocator()->allocate();
Pablo Tellod6ca4782018-01-23 09:36:04 +0000109 bias.allocator()->allocate();
Pablo Tello89519332017-11-17 11:52:36 +0000110
111 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
112 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
113 ARM_COMPUTE_EXPECT(!bias.info()->is_resizable(), framework::LogLevel::ERRORS);
114 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
115
116 // Fill tensors
117 fill(AccessorType(src), 0, -1.f, 1.f);
118 fill(AccessorType(weights), 1, -1.f, 1.f);
Pablo Tellod6ca4782018-01-23 09:36:04 +0000119 fill(AccessorType(bias), 2, -1.f, 1.f);
Pablo Tello89519332017-11-17 11:52:36 +0000120
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000121 // Compute Winograd Convolution function
Pablo Tello89519332017-11-17 11:52:36 +0000122 conv.run();
123
124 return dst;
125 }
126
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000127 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info,
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000128 DataType data_type, ActivationLayerInfo act_info)
Pablo Tello89519332017-11-17 11:52:36 +0000129 {
130 // Create reference
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000131 SimpleTensor<T> src{ input_shape, data_type, 1 };
132 SimpleTensor<T> weights{ weights_shape, data_type, 1 };
133 SimpleTensor<T> bias{ bias_shape, data_type, 1 };
Pablo Tello89519332017-11-17 11:52:36 +0000134
135 // Fill reference
136 fill(src, 0, -1.f, 1.f);
137 fill(weights, 1, -1.f, 1.f);
Andrew Mundy4d9379a2018-03-15 16:47:03 +0000138 if(use_bias)
139 {
140 fill(bias, 2, -1.f, 1.f);
141 }
142 else
143 {
144 fill(bias, 2, 0.f, 0.f);
145 }
Pablo Tello89519332017-11-17 11:52:36 +0000146
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000147 SimpleTensor<T> conv_out = reference::convolution_layer<T>(src, weights, bias, output_shape, info);
148
149 return (act_info.enabled()) ? reference::activation_layer<T>(conv_out, act_info) : conv_out;
Pablo Tello89519332017-11-17 11:52:36 +0000150 }
151
152 TensorType _target{};
153 SimpleTensor<T> _reference{};
Pablo Tello89519332017-11-17 11:52:36 +0000154};
155
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000156template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100157class WinogradConvolutionLayerFastMathValidationFixture : public framework::Fixture
158{
159public:
160 template <typename...>
161 void setup(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info, Size2D dilation, DataType data_type, ActivationLayerInfo act_info)
162 {
163 ARM_COMPUTE_UNUSED(dilation);
164
165 _target = compute_target(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info);
166 _reference = compute_reference(input_shape, weights_shape, bias_shape, output_shape, info, data_type, act_info);
167 }
168
169protected:
170 template <typename U>
171 void fill(U &&tensor, int i, float min, float max)
172 {
173 switch(tensor.data_type())
174 {
175 case DataType::F32:
176 {
177 std::uniform_real_distribution<> distribution(min, max);
178 library->fill(tensor, distribution, i);
179 break;
180 }
181 default:
182 {
183 ARM_COMPUTE_ERROR("Not supported");
184 library->fill_tensor_uniform(tensor, i);
185 break;
186 }
187 }
188 }
189
190 TensorType compute_target(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info,
191 DataType data_type, ActivationLayerInfo act_info)
192 {
193 // Create tensors
194 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1);
195 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1);
196 TensorType bias = create_tensor<TensorType>(bias_shape, data_type, 1);
197 TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1);
198
199 // Create and configure function
200 FunctionType conv;
201 ARM_COMPUTE_EXPECT(static_cast<bool>(conv.validate(src.info(), weights.info(), bias.info(), dst.info(), info, act_info, true /* Enable fast math */)), framework::LogLevel::ERRORS);
202 conv.configure(&src, &weights, &bias, &dst, info, act_info, true /* Enable fast math */);
203
204 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
205 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
206 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
207 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
208
209 // Allocate tensors
210 src.allocator()->allocate();
211 weights.allocator()->allocate();
212 dst.allocator()->allocate();
213 bias.allocator()->allocate();
214
215 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
216 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
217 ARM_COMPUTE_EXPECT(!bias.info()->is_resizable(), framework::LogLevel::ERRORS);
218 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
219
220 // Fill tensors
221 fill(AccessorType(src), 0, -1.f, 1.f);
222 fill(AccessorType(weights), 1, -1.f, 1.f);
223 fill(AccessorType(bias), 2, -1.f, 1.f);
224
225 // Compute Winograd Convolution function
226 conv.run();
227
228 return dst;
229 }
230
231 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, const PadStrideInfo &info,
232 DataType data_type, ActivationLayerInfo act_info)
233 {
234 // Create reference
235 SimpleTensor<T> src{ input_shape, data_type, 1 };
236 SimpleTensor<T> weights{ weights_shape, data_type, 1 };
237 SimpleTensor<T> bias{ bias_shape, data_type, 1 };
238
239 // Fill reference
240 fill(src, 0, -1.f, 1.f);
241 fill(weights, 1, -1.f, 1.f);
242 fill(bias, 2, -1.f, 1.f);
243
244 WinogradInfo winograd_info(Size2D(4U, 4U),
245 Size2D(weights_shape[0], weights_shape[1]),
246 Size2D(input_shape[0], input_shape[1]),
247 info,
248 src.data_layout());
249
250 // Compute tensor shapes for input, filter and output transforms
251 TensorShape input_transform_shape = compute_winograd_input_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info);
252 TensorShape filter_transform_shape = compute_winograd_filter_transform_shape(TensorInfo(weights_shape, 1, data_type), winograd_info);
253 TensorShape batched_gemm_shape = input_transform_shape;
254 batched_gemm_shape[0] = filter_transform_shape[0];
255 TensorShape output_transform_shape = compute_winograd_output_transform_shape(TensorInfo(batched_gemm_shape, 1, data_type), winograd_info);
256
257 // Dummy matrix C to perform matrix multiplication
258 SimpleTensor<T> dummy_c{ batched_gemm_shape, data_type, 1 };
259
260 // Compute Winograd-based convolution
261 SimpleTensor<T> input_transform_out = reference::winograd_input_transform<T>(src, input_transform_shape, winograd_info);
262 SimpleTensor<T> filter_transform_out = reference::winograd_filter_transform<T>(weights, filter_transform_shape, winograd_info);
263 SimpleTensor<T> batched_gemm = reference::gemm<T>(input_transform_out, filter_transform_out, dummy_c, 1.0f, 0.0f);
264 SimpleTensor<T> conv_out = reference::winograd_output_transform<T>(batched_gemm, bias, output_transform_shape, winograd_info);
265
266 return (act_info.enabled()) ? reference::activation_layer<T>(conv_out, act_info) : conv_out;
267 }
268
269 TensorType _target{};
270 SimpleTensor<T> _reference{};
271};
272
273template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000274class WinogradInputTransformValidationFixture : public framework::Fixture
275{
276public:
277 template <typename...>
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000278 void setup(TensorShape input_shape, WinogradInfo winograd_info, DataLayout data_layout, DataType data_type)
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000279 {
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000280 TensorShape output_shape = compute_winograd_input_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000281
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000282 _target = compute_target(input_shape, output_shape, winograd_info, data_layout, data_type);
283 _reference = compute_reference(input_shape, output_shape, winograd_info, data_layout, data_type);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000284 }
285
286protected:
287 template <typename U>
288 void fill(U &&tensor, int i, float min, float max)
289 {
290 switch(tensor.data_type())
291 {
292 case DataType::F32:
293 {
294 std::uniform_real_distribution<> distribution(min, max);
295 library->fill(tensor, distribution, i);
296 break;
297 }
298 default:
299 {
300 ARM_COMPUTE_ERROR("Not supported");
301 library->fill_tensor_uniform(tensor, i);
302 break;
303 }
304 }
305 }
306
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000307 TensorType compute_target(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type)
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000308 {
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000309 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, 0, QuantizationInfo(), data_layout);
310 TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, 0, QuantizationInfo(), data_layout);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000311
312 // Create and configure function
313 FunctionType transf;
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000314 transf.configure(&src, &dst, winograd_info);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000315
316 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
317 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
318
319 // Allocate tensors
320 src.allocator()->allocate();
321 dst.allocator()->allocate();
322
323 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
324 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
325
326 // Fill tensors
327 fill(AccessorType(src), 0, -1.f, 1.f);
328
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000329 // Compute Winograd input transform function
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000330 transf.run();
331
332 return dst;
333 }
334
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000335 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type)
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000336 {
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000337 // Create reference
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000338 SimpleTensor<T> src{ input_shape, data_type, 1, 0, QuantizationInfo(), data_layout };
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000339
340 // Fill reference
341 fill(src, 0, -1.f, 1.f);
342
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000343 return reference::winograd_input_transform<T>(src, output_shape, winograd_info);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000344 }
345
346 TensorType _target{};
347 SimpleTensor<T> _reference{};
348};
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000349
350template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
351class WinogradFilterTransformValidationFixture : public framework::Fixture
352{
353public:
354 template <typename...>
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000355 void setup(TensorShape input_shape, Size2D output_tile, DataLayout data_layout, DataType data_type)
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000356 {
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000357 WinogradInfo winograd_info(output_tile, Size2D(input_shape[0], input_shape[1]), Size2D() /* Not needed */, PadStrideInfo() /* Not needed */, DataLayout::NCHW /* Not needed */);
358 TensorShape output_shape = compute_winograd_filter_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info);
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000359
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000360 _target = compute_target(input_shape, output_shape, winograd_info, data_layout, data_type);
361 _reference = compute_reference(input_shape, output_shape, winograd_info, data_layout, data_type);
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000362 }
363
364protected:
365 template <typename U>
366 void fill(U &&tensor, int i, float min, float max)
367 {
368 switch(tensor.data_type())
369 {
370 case DataType::F32:
371 {
372 std::uniform_real_distribution<> distribution(min, max);
373 library->fill(tensor, distribution, i);
374 break;
375 }
376 default:
377 {
378 ARM_COMPUTE_ERROR("Not supported");
379 library->fill_tensor_uniform(tensor, i);
380 break;
381 }
382 }
383 }
384
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000385 TensorType compute_target(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type)
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000386 {
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000387 // Create tensors
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000388 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, 0, QuantizationInfo(), data_layout);
389 TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, 0, QuantizationInfo(), data_layout);
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000390
391 // Create and configure function
392 FunctionType filter_transform;
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000393 filter_transform.configure(&src, &dst, winograd_info);
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000394
395 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
396 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
397
398 // Allocate tensors
399 src.allocator()->allocate();
400 dst.allocator()->allocate();
401
402 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
403 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
404
405 // Fill tensors
406 fill(AccessorType(src), 0, -1.f, 1.f);
407
408 filter_transform.run();
409
410 return dst;
411 }
412
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000413 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataLayout data_layout, DataType data_type)
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000414 {
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000415 // Create reference
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000416 SimpleTensor<T> src{ input_shape, data_type, 1, 0, QuantizationInfo(), data_layout };
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000417
418 // Fill reference
419 fill(src, 0, -1.f, 1.f);
420
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000421 return reference::winograd_filter_transform<T>(src, output_shape, winograd_info);
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000422 }
423
424 TensorType _target{};
425 SimpleTensor<T> _reference{};
426};
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000427
428template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
429class WinogradOutputTransformValidationFixture : public framework::Fixture
430{
431public:
432 template <typename...>
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000433 void setup(TensorShape input_shape, WinogradInfo winograd_info, DataType data_type)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000434 {
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000435 TensorShape output_shape = compute_winograd_output_transform_shape(TensorInfo(input_shape, 1, data_type), winograd_info);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000436
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000437 _target = compute_target(input_shape, output_shape, winograd_info, data_type);
438 _reference = compute_reference(input_shape, output_shape, winograd_info, data_type);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000439 }
440
441protected:
442 template <typename U>
443 void fill(U &&tensor, int i, float min, float max)
444 {
445 switch(tensor.data_type())
446 {
447 case DataType::F32:
448 {
449 std::uniform_real_distribution<> distribution(min, max);
450 library->fill(tensor, distribution, i);
451 break;
452 }
453 default:
454 {
455 ARM_COMPUTE_ERROR("Not supported");
456 library->fill_tensor_uniform(tensor, i);
457 break;
458 }
459 }
460 }
461
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000462 TensorType compute_target(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataType data_type)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000463 {
464 // Create tensors
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000465 TensorType src = create_tensor<TensorType>(input_shape, data_type);
466 TensorType dst = create_tensor<TensorType>(output_shape, data_type, 1, 0, QuantizationInfo(), winograd_info.output_data_layout);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000467
468 // Create and configure function
469 FunctionType output_transform;
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000470 output_transform.configure(&src, nullptr, &dst, winograd_info);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000471
472 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
473 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
474
475 // Allocate tensors
476 src.allocator()->allocate();
477 dst.allocator()->allocate();
478
479 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
480 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
481
482 // Fill tensors
483 fill(AccessorType(src), 0, -1.f, 1.f);
484
485 output_transform.run();
486
487 return dst;
488 }
489
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000490 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &output_shape, const WinogradInfo &winograd_info, DataType data_type)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000491 {
492 // Create reference
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000493 SimpleTensor<T> src{ input_shape, data_type };
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100494 SimpleTensor<T> bias{ TensorShape(input_shape[0]), data_type };
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000495
496 // Fill reference
497 fill(src, 0, -1.f, 1.f);
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100498 fill(bias, 1, 0.0f, 0.0f); // Fill with zeros as we validate just the output transform without bias contribution
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000499
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100500 return reference::winograd_output_transform<T>(src, bias, output_shape, winograd_info);
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000501 }
502
503 TensorType _target{};
504 SimpleTensor<T> _reference{};
505};
Pablo Tello89519332017-11-17 11:52:36 +0000506} // namespace validation
507} // namespace test
508} // namespace arm_compute
509#endif /* ARM_COMPUTE_TEST_WINOGRAD_LAYER_FIXTURE */