blob: 9cd60cc1fbe6fa78b5acdd4ceffa1d7cbbbe12dd [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Giorgio Arena93a690e2017-08-01 16:09:33 +01003 *
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_DEPTHWISE_CONVOLUTION_FIXTURE
25#define ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
Giorgio Arena76572242018-04-04 17:44:26 +010029#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010030#include "tests/AssetsLibrary.h"
31#include "tests/Globals.h"
32#include "tests/IAccessor.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/framework/Asserts.h"
34#include "tests/framework/Fixture.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010035#include "tests/validation/Helpers.h"
Manuel Bottinia788c2f2019-04-08 13:18:00 +010036#include "tests/validation/reference/ActivationLayer.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000037#include "tests/validation/reference/DepthwiseConvolutionLayer.h"
Giorgio Arena93a690e2017-08-01 16:09:33 +010038
Georgios Pinitasf72f9362018-01-12 16:29:45 +000039#include "utils/Utils.h"
40
Giorgio Arena93a690e2017-08-01 16:09:33 +010041#include <random>
42
43namespace arm_compute
44{
45namespace test
46{
47namespace validation
48{
Giorgio Arena76572242018-04-04 17:44:26 +010049using namespace arm_compute::misc::shape_calculator;
50
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010051template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000052class DepthwiseConvolutionLayerValidationGenericFixture : public framework::Fixture
Giorgio Arena93a690e2017-08-01 16:09:33 +010053{
54public:
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010055 using TBias = typename std::conditional < std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value, int32_t, T >::type;
Dmitry Savenkod7295b72017-11-20 22:00:08 +070056
57public:
Giorgio Arena93a690e2017-08-01 16:09:33 +010058 template <typename...>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010059 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation,
60 unsigned int depth_multiplier, DataType input_data_type, DataType weights_data_type,
61 QuantizationInfo input_quantization_info, QuantizationInfo weights_quantization_info, QuantizationInfo output_quantization_info,
62 DataLayout data_layout, ActivationLayerInfo act_info)
Giorgio Arena93a690e2017-08-01 16:09:33 +010063 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010064 const DataType bias_data_type = is_data_type_quantized(input_data_type) ? DataType::S32 : input_data_type;
Giorgio Arena76572242018-04-04 17:44:26 +010065
66 TensorShape weights_shape(kernel_size.width, kernel_size.height);
67
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010068 const TensorInfo in_info(in_shape, 1, input_data_type);
69 const TensorInfo we_info(weights_shape, 1, weights_data_type);
Manuel Bottinia788c2f2019-04-08 13:18:00 +010070 const TensorShape out_shape = compute_depthwise_convolution_shape(in_info, we_info, pad_stride_info, depth_multiplier, dilation);
Giorgio Arena76572242018-04-04 17:44:26 +010071
72 weights_shape.set(2, out_shape.z());
Pablo Tello941cd702017-12-12 14:35:00 +000073 const TensorShape biases_shape(weights_shape[2]);
Dmitry Savenkod7295b72017-11-20 22:00:08 +070074
Pablo Telloa28aebc2019-06-03 14:59:48 +010075 _target = compute_target(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010076 input_data_type, weights_data_type, bias_data_type, input_quantization_info, weights_quantization_info, output_quantization_info, data_layout, act_info);
Pablo Telloa28aebc2019-06-03 14:59:48 +010077 _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010078 input_data_type, weights_data_type, bias_data_type, input_quantization_info, weights_quantization_info, output_quantization_info, act_info);
Giorgio Arena93a690e2017-08-01 16:09:33 +010079 }
80
81protected:
82 template <typename U>
83 void fill(U &&tensor, int i)
84 {
85 switch(tensor.data_type())
86 {
Dmitry Savenkod7295b72017-11-20 22:00:08 +070087 case DataType::QASYMM8:
88 {
89 std::uniform_int_distribution<uint8_t> distribution(0, 10);
90 library->fill(tensor, distribution, i);
91 break;
92 }
Michele Di Giorgio4cd4cde2020-01-06 14:07:44 +000093 case DataType::QASYMM8_SIGNED:
Michele Di Giorgio633d30b2019-10-08 17:17:18 +010094 case DataType::QSYMM8_PER_CHANNEL:
95 {
96 std::uniform_int_distribution<int8_t> distribution(-10, 10);
97 library->fill(tensor, distribution, i);
98 break;
99 }
Frank Lei8cdfdb82018-01-02 16:49:33 +0800100 case DataType::F16:
Giorgio Arena93a690e2017-08-01 16:09:33 +0100101 {
Giorgio Arena6aeb2172020-12-15 15:45:43 +0000102 arm_compute::utils::uniform_real_distribution_fp16 distribution{ half(-1.0f), half(1.0f) };
103 library->fill(tensor, distribution, i);
104 break;
105 }
106 case DataType::F32:
107 {
108 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100109 library->fill(tensor, distribution, i);
110 break;
111 }
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700112 case DataType::S32:
113 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000114 std::uniform_int_distribution<int32_t> distribution(-100, 100);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700115 library->fill(tensor, distribution, i);
116 break;
117 }
Giorgio Arena93a690e2017-08-01 16:09:33 +0100118 default:
119 library->fill_tensor_uniform(tensor, i);
120 }
121 }
122
Usama Arife73686a2019-04-08 17:30:48 +0100123 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape output_shape, PadStrideInfo &pad_stride_info, Size2D dilation,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100124 unsigned int depth_multiplier, const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type,
125 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info,
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100126 const DataLayout data_layout, const ActivationLayerInfo &act_info)
Giorgio Arena93a690e2017-08-01 16:09:33 +0100127 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100128 if(data_layout == DataLayout::NHWC)
129 {
130 permute(input_shape, PermutationVector(2U, 0U, 1U));
131 permute(weights_shape, PermutationVector(2U, 0U, 1U));
132 permute(output_shape, PermutationVector(2U, 0U, 1U));
133 }
134
Giorgio Arena93a690e2017-08-01 16:09:33 +0100135 // Create tensors
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100136 TensorType src = create_tensor<TensorType>(input_shape, input_data_type, 1, input_quantization_info, data_layout);
137 TensorType weights = create_tensor<TensorType>(weights_shape, weights_data_type, 1, weights_quantization_info, data_layout);
Pablo Telloa28aebc2019-06-03 14:59:48 +0100138 TensorType biases = create_tensor<TensorType>(biases_shape, bias_data_type, 1, input_quantization_info, data_layout);
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100139 TensorType dst = create_tensor<TensorType>(output_shape, input_data_type, 1, output_quantization_info, data_layout);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100140
141 // Create Depthwise Convolution configure function
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700142 FunctionType dwc;
Manuel Bottinia788c2f2019-04-08 13:18:00 +0100143 dwc.configure(&src, &weights, &biases, &dst, pad_stride_info, depth_multiplier, act_info, dilation);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700144
145 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
146 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
147 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
148 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100149
150 // Allocate tensors
151 src.allocator()->allocate();
152 weights.allocator()->allocate();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100153 biases.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +0100154 dst.allocator()->allocate();
155
156 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
157 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100158 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100159 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
160
161 // Fill tensors
162 fill(AccessorType(src), 0);
163 fill(AccessorType(weights), 1);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100164 fill(AccessorType(biases), 2);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100165
166 // Compute function
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700167 dwc.run();
Giorgio Arena93a690e2017-08-01 16:09:33 +0100168
169 return dst;
170 }
171
Pablo Telloa28aebc2019-06-03 14:59:48 +0100172 SimpleTensor<T> compute_reference(const TensorShape &in_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &out_shape,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100173 const PadStrideInfo &pad_stride_info, const Size2D &dilation, unsigned int depth_multiplier,
174 const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type,
175 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info,
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100176 const ActivationLayerInfo &act_info)
Giorgio Arena93a690e2017-08-01 16:09:33 +0100177 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100178 SimpleTensor<T> src{ in_shape, input_data_type, 1, input_quantization_info };
179 SimpleTensor<TW> weights{ weights_shape, weights_data_type, 1, weights_quantization_info };
Pablo Telloa28aebc2019-06-03 14:59:48 +0100180 SimpleTensor<TBias> biases{ biases_shape, bias_data_type, 1, input_quantization_info };
Giorgio Arena93a690e2017-08-01 16:09:33 +0100181
182 fill(src, 0);
183 fill(weights, 1);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100184 fill(biases, 2);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100185
Pablo Telloa28aebc2019-06-03 14:59:48 +0100186 SimpleTensor<T> depth_out = reference::depthwise_convolution(src, weights, biases, out_shape, pad_stride_info, depth_multiplier, dilation, output_quantization_info);
Manuel Bottinia788c2f2019-04-08 13:18:00 +0100187 return (act_info.enabled()) ? reference::activation_layer<T>(depth_out, act_info) : depth_out;
Giorgio Arena93a690e2017-08-01 16:09:33 +0100188 }
189
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100190 TensorType _target{};
191 SimpleTensor<T> _reference{};
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700192};
193
194template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100195class DepthwiseConvolutionLayerValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700196{
197public:
198 template <typename...>
Manuel Bottinia788c2f2019-04-08 13:18:00 +0100199 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, DataLayout data_layout,
200 ActivationLayerInfo act_info)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700201 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100202 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier,
203 data_type, data_type, QuantizationInfo(), QuantizationInfo(), QuantizationInfo(),
204 data_layout, act_info);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700205 }
206};
207
208template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100209class DepthwiseConvolutionLayerNativeValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Giorgio Arena44f55722019-07-12 14:49:49 +0100210{
211public:
212 template <typename...>
213 void setup(size_t width, size_t height, size_t channel, size_t batch, Size2D kernel_size, size_t depth_multiplier, Size2D dilation, Size2D stride, bool padding_valid, DataType data_type,
214 DataLayout data_layout)
215 {
216 const TensorShape src_shape(width, height, channel, batch);
217 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier);
218 const TensorShape biases_shape(weights_shape.z());
219
220 PadStrideInfo conv_info;
221 if(padding_valid)
222 {
223 conv_info = PadStrideInfo();
224 }
225 else
226 {
227 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation);
228 }
229
230 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout);
231 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type);
232 }
233
234protected:
235 template <typename U>
236 void fill(U &&tensor, int i)
237 {
238 switch(tensor.data_type())
239 {
240 case DataType::F32:
241 {
242 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
243 library->fill(tensor, distribution, i);
244 break;
245 }
246 default:
247 library->fill_tensor_uniform(tensor, i);
248 }
249 }
250
251 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation,
252 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout)
253 {
254 if(data_layout == DataLayout::NHWC)
255 {
256 permute(input_shape, PermutationVector(2U, 0U, 1U));
257 permute(weights_shape, PermutationVector(2U, 0U, 1U));
258 }
259
260 // Create tensors
261 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
262 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout);
263 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout);
264 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout);
265
266 // Create Depthwise Convolution configure function
267 FunctionType dwc;
268 dwc.configure(&src, &weights, &biases, &dst, conv_info, depth_multiplier, dilation);
269
270 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
271 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
272 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
273 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
274
275 // Allocate tensors
276 src.allocator()->allocate();
277 weights.allocator()->allocate();
278 biases.allocator()->allocate();
279 dst.allocator()->allocate();
280
281 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
282 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
283 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
284 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
285
286 // Fill tensors
287 fill(AccessorType(src), 0);
288 fill(AccessorType(weights), 1);
289 fill(AccessorType(biases), 2);
290
291 // Compute function
292 dwc.run();
293
294 return dst;
295 }
296
297 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info,
298 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type)
299 {
300 SimpleTensor<T> src{ input_shape, data_type };
301 SimpleTensor<T> weights{ weights_shape, data_type };
302 SimpleTensor<T> biases{ biases_shape, data_type };
303
304 fill(src, 0);
305 fill(weights, 1);
306 fill(biases, 2);
307
308 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info,
309 depth_multiplier, dilation);
310 return reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation);
311 }
312
313 TensorType _target{};
314 SimpleTensor<T> _reference{};
315};
316
317template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100318class DepthwiseConvolutionLayerNativeConfigurableValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100319{
320public:
321 template <typename...>
322 void setup(size_t width, size_t height, size_t channel, size_t batch, Size2D kernel_size, size_t depth_multiplier, Size2D dilation, Size2D stride, bool padding_valid, DataType data_type,
323 DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0)
324 {
325 const TensorShape src_shape(width, height, channel, batch);
326 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier);
327 const TensorShape biases_shape(weights_shape.z());
328
329 PadStrideInfo conv_info;
330 if(padding_valid)
331 {
332 conv_info = PadStrideInfo();
333 }
334 else
335 {
336 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation);
337 }
338
339 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout, act_info, n0);
340 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, act_info);
341 }
342
343protected:
344 template <typename U>
345 void fill(U &&tensor, int i)
346 {
347 switch(tensor.data_type())
348 {
349 case DataType::F32:
350 {
Giorgio Arena6aeb2172020-12-15 15:45:43 +0000351 std::uniform_real_distribution<float> distribution(-1.0f, 1.0f);
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100352 library->fill(tensor, distribution, i);
353 break;
354 }
355 case DataType::F16:
356 {
Giorgio Arena6aeb2172020-12-15 15:45:43 +0000357 arm_compute::utils::uniform_real_distribution_fp16 distribution{ half(-1.0f), half(1.0f) };
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100358 library->fill(tensor, distribution, i);
359 break;
360 }
361 default:
362 library->fill_tensor_uniform(tensor, i);
363 }
364 }
365
366 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation,
367 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0)
368 {
369 if(data_layout == DataLayout::NHWC)
370 {
371 permute(input_shape, PermutationVector(2U, 0U, 1U));
372 permute(weights_shape, PermutationVector(2U, 0U, 1U));
373 }
374
375 // Create tensors
376 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
377 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout);
378 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout);
379 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout);
380
381 DWCWeightsKernelInfo dwc_weights_info;
382 dwc_weights_info.n0 = n0;
383
384 DWCKernelInfo dwc_info;
385 dwc_info.activation_info = act_info;
386
387 // Create Depthwise Convolution configure function
388 FunctionType dwc;
389 dwc.configure(&src, &weights, &biases, &dst, dwc_weights_info, dwc_info, conv_info, depth_multiplier, dilation);
390
391 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
392 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
393 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
394 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
395
396 // Allocate tensors
397 src.allocator()->allocate();
398 weights.allocator()->allocate();
399 biases.allocator()->allocate();
400 dst.allocator()->allocate();
401
402 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
403 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
404 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
405 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
406
407 // Fill tensors
408 fill(AccessorType(src), 0);
409 fill(AccessorType(weights), 1);
410 fill(AccessorType(biases), 2);
411
412 // Compute function
413 dwc.run();
414
415 return dst;
416 }
417
418 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info,
419 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type, const ActivationLayerInfo &act_info)
420 {
421 SimpleTensor<T> src{ input_shape, data_type };
422 SimpleTensor<T> weights{ weights_shape, data_type };
423 SimpleTensor<T> biases{ biases_shape, data_type };
424
425 fill(src, 0);
426 fill(weights, 1);
427 fill(biases, 2);
428
429 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info,
430 depth_multiplier, dilation);
431 return reference::activation_layer(reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation), act_info);
432 }
433
434 TensorType _target{};
435 SimpleTensor<T> _reference{};
436};
437
438template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100439class DepthwiseConvolutionLayerValidationQuantizedFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700440{
441public:
442 template <typename...>
Pablo Telloa28aebc2019-06-03 14:59:48 +0100443 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type,
444 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700445 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100446 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, data_type,
447 data_type, input_quantization_info, input_quantization_info, output_quantization_info,
448 data_layout, act_info);
449 }
450};
451
452template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW>
453class DepthwiseConvolutionLayerValidationQuantizedPerChannelFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>
454{
455public:
456 template <typename...>
457 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType input_data_type, DataType weights_data_type,
Giorgio Arenad93e2632019-10-15 11:09:33 +0100458 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info)
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100459 {
Giorgio Arenad93e2632019-10-15 11:09:33 +0100460 const float out_scale = output_quantization_info.uniform().scale;
461 const float in_scale = input_quantization_info.uniform().scale;
462
463 std::vector<float> weights_scales{};
464 std::mt19937 gen(library->seed());
465 std::uniform_real_distribution<> dis(0.01f, out_scale / in_scale);
466 for(size_t i = 0; i < in_shape.z() * depth_multiplier; ++i)
467 {
468 weights_scales.push_back(dis(gen));
469 }
470
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100471 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier,
472 input_data_type, weights_data_type,
Giorgio Arenad93e2632019-10-15 11:09:33 +0100473 input_quantization_info, QuantizationInfo(weights_scales), output_quantization_info,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100474 data_layout, act_info);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700475 }
Giorgio Arena93a690e2017-08-01 16:09:33 +0100476};
477} // namespace validation
478} // namespace test
479} // namespace arm_compute
480#endif /* ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE */