blob: 7016e9fb6802147fe801983406bf0e25c477811c [file] [log] [blame]
Giorgio Arena93a690e2017-08-01 16:09:33 +01001/*
Michele Di Giorgio4cd4cde2020-01-06 14:07:44 +00002 * 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 }
Giorgio Arena93a690e2017-08-01 16:09:33 +0100100 case DataType::F32:
Frank Lei8cdfdb82018-01-02 16:49:33 +0800101 case DataType::F16:
Giorgio Arena93a690e2017-08-01 16:09:33 +0100102 {
103 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
104 library->fill(tensor, distribution, i);
105 break;
106 }
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700107 case DataType::S32:
108 {
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000109 std::uniform_int_distribution<int32_t> distribution(-100, 100);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700110 library->fill(tensor, distribution, i);
111 break;
112 }
Giorgio Arena93a690e2017-08-01 16:09:33 +0100113 default:
114 library->fill_tensor_uniform(tensor, i);
115 }
116 }
117
Usama Arife73686a2019-04-08 17:30:48 +0100118 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 +0100119 unsigned int depth_multiplier, const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type,
120 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info,
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100121 const DataLayout data_layout, const ActivationLayerInfo &act_info)
Giorgio Arena93a690e2017-08-01 16:09:33 +0100122 {
Giorgio Arena563494c2018-04-30 17:29:41 +0100123 if(data_layout == DataLayout::NHWC)
124 {
125 permute(input_shape, PermutationVector(2U, 0U, 1U));
126 permute(weights_shape, PermutationVector(2U, 0U, 1U));
127 permute(output_shape, PermutationVector(2U, 0U, 1U));
128 }
129
Giorgio Arena93a690e2017-08-01 16:09:33 +0100130 // Create tensors
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100131 TensorType src = create_tensor<TensorType>(input_shape, input_data_type, 1, input_quantization_info, data_layout);
132 TensorType weights = create_tensor<TensorType>(weights_shape, weights_data_type, 1, weights_quantization_info, data_layout);
Pablo Telloa28aebc2019-06-03 14:59:48 +0100133 TensorType biases = create_tensor<TensorType>(biases_shape, bias_data_type, 1, input_quantization_info, data_layout);
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100134 TensorType dst = create_tensor<TensorType>(output_shape, input_data_type, 1, output_quantization_info, data_layout);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100135
136 // Create Depthwise Convolution configure function
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700137 FunctionType dwc;
Manuel Bottinia788c2f2019-04-08 13:18:00 +0100138 dwc.configure(&src, &weights, &biases, &dst, pad_stride_info, depth_multiplier, act_info, dilation);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700139
140 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
141 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
142 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
143 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100144
145 // Allocate tensors
146 src.allocator()->allocate();
147 weights.allocator()->allocate();
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100148 biases.allocator()->allocate();
Giorgio Arena93a690e2017-08-01 16:09:33 +0100149 dst.allocator()->allocate();
150
151 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
152 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100153 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100154 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
155
156 // Fill tensors
157 fill(AccessorType(src), 0);
158 fill(AccessorType(weights), 1);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100159 fill(AccessorType(biases), 2);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100160
161 // Compute function
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700162 dwc.run();
Giorgio Arena93a690e2017-08-01 16:09:33 +0100163
164 return dst;
165 }
166
Pablo Telloa28aebc2019-06-03 14:59:48 +0100167 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 +0100168 const PadStrideInfo &pad_stride_info, const Size2D &dilation, unsigned int depth_multiplier,
169 const DataType input_data_type, const DataType weights_data_type, const DataType bias_data_type,
170 const QuantizationInfo &input_quantization_info, const QuantizationInfo &weights_quantization_info, const QuantizationInfo &output_quantization_info,
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100171 const ActivationLayerInfo &act_info)
Giorgio Arena93a690e2017-08-01 16:09:33 +0100172 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100173 SimpleTensor<T> src{ in_shape, input_data_type, 1, input_quantization_info };
174 SimpleTensor<TW> weights{ weights_shape, weights_data_type, 1, weights_quantization_info };
Pablo Telloa28aebc2019-06-03 14:59:48 +0100175 SimpleTensor<TBias> biases{ biases_shape, bias_data_type, 1, input_quantization_info };
Giorgio Arena93a690e2017-08-01 16:09:33 +0100176
177 fill(src, 0);
178 fill(weights, 1);
Georgios Pinitas81a26ad2017-10-23 20:29:30 +0100179 fill(biases, 2);
Giorgio Arena93a690e2017-08-01 16:09:33 +0100180
Pablo Telloa28aebc2019-06-03 14:59:48 +0100181 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 +0100182 return (act_info.enabled()) ? reference::activation_layer<T>(depth_out, act_info) : depth_out;
Giorgio Arena93a690e2017-08-01 16:09:33 +0100183 }
184
Georgios Pinitasddec4d62019-07-10 19:23:02 +0100185 TensorType _target{};
186 SimpleTensor<T> _reference{};
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700187};
188
189template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100190class DepthwiseConvolutionLayerValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700191{
192public:
193 template <typename...>
Manuel Bottinia788c2f2019-04-08 13:18:00 +0100194 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, DataLayout data_layout,
195 ActivationLayerInfo act_info)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700196 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100197 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier,
198 data_type, data_type, QuantizationInfo(), QuantizationInfo(), QuantizationInfo(),
199 data_layout, act_info);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700200 }
201};
202
203template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100204class DepthwiseConvolutionLayerNativeValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Giorgio Arena44f55722019-07-12 14:49:49 +0100205{
206public:
207 template <typename...>
208 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,
209 DataLayout data_layout)
210 {
211 const TensorShape src_shape(width, height, channel, batch);
212 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier);
213 const TensorShape biases_shape(weights_shape.z());
214
215 PadStrideInfo conv_info;
216 if(padding_valid)
217 {
218 conv_info = PadStrideInfo();
219 }
220 else
221 {
222 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation);
223 }
224
225 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout);
226 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type);
227 }
228
229protected:
230 template <typename U>
231 void fill(U &&tensor, int i)
232 {
233 switch(tensor.data_type())
234 {
235 case DataType::F32:
236 {
237 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
238 library->fill(tensor, distribution, i);
239 break;
240 }
241 default:
242 library->fill_tensor_uniform(tensor, i);
243 }
244 }
245
246 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation,
247 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout)
248 {
249 if(data_layout == DataLayout::NHWC)
250 {
251 permute(input_shape, PermutationVector(2U, 0U, 1U));
252 permute(weights_shape, PermutationVector(2U, 0U, 1U));
253 }
254
255 // Create tensors
256 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
257 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout);
258 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout);
259 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout);
260
261 // Create Depthwise Convolution configure function
262 FunctionType dwc;
263 dwc.configure(&src, &weights, &biases, &dst, conv_info, depth_multiplier, dilation);
264
265 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
266 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
267 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
268 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
269
270 // Allocate tensors
271 src.allocator()->allocate();
272 weights.allocator()->allocate();
273 biases.allocator()->allocate();
274 dst.allocator()->allocate();
275
276 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
277 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
278 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
279 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
280
281 // Fill tensors
282 fill(AccessorType(src), 0);
283 fill(AccessorType(weights), 1);
284 fill(AccessorType(biases), 2);
285
286 // Compute function
287 dwc.run();
288
289 return dst;
290 }
291
292 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info,
293 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type)
294 {
295 SimpleTensor<T> src{ input_shape, data_type };
296 SimpleTensor<T> weights{ weights_shape, data_type };
297 SimpleTensor<T> biases{ biases_shape, data_type };
298
299 fill(src, 0);
300 fill(weights, 1);
301 fill(biases, 2);
302
303 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info,
304 depth_multiplier, dilation);
305 return reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation);
306 }
307
308 TensorType _target{};
309 SimpleTensor<T> _reference{};
310};
311
312template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100313class DepthwiseConvolutionLayerNativeConfigurableValidationFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100314{
315public:
316 template <typename...>
317 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,
318 DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0)
319 {
320 const TensorShape src_shape(width, height, channel, batch);
321 const TensorShape weights_shape(kernel_size.width, kernel_size.height, channel * depth_multiplier);
322 const TensorShape biases_shape(weights_shape.z());
323
324 PadStrideInfo conv_info;
325 if(padding_valid)
326 {
327 conv_info = PadStrideInfo();
328 }
329 else
330 {
331 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride.width, stride.height), DataLayout::NCHW, dilation);
332 }
333
334 _target = compute_target(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, data_layout, act_info, n0);
335 _reference = compute_reference(src_shape, weights_shape, biases_shape, conv_info, dilation, depth_multiplier, data_type, act_info);
336 }
337
338protected:
339 template <typename U>
340 void fill(U &&tensor, int i)
341 {
342 switch(tensor.data_type())
343 {
344 case DataType::F32:
345 {
346 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
347 library->fill(tensor, distribution, i);
348 break;
349 }
350 case DataType::F16:
351 {
352 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
353 library->fill(tensor, distribution, i);
354 break;
355 }
356 default:
357 library->fill_tensor_uniform(tensor, i);
358 }
359 }
360
361 TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, PadStrideInfo &conv_info, Size2D dilation,
362 unsigned int depth_multiplier, const DataType data_type, const DataLayout data_layout, const ActivationLayerInfo &act_info, unsigned int n0)
363 {
364 if(data_layout == DataLayout::NHWC)
365 {
366 permute(input_shape, PermutationVector(2U, 0U, 1U));
367 permute(weights_shape, PermutationVector(2U, 0U, 1U));
368 }
369
370 // Create tensors
371 TensorType src = create_tensor<TensorType>(input_shape, data_type, 1, QuantizationInfo(), data_layout);
372 TensorType weights = create_tensor<TensorType>(weights_shape, data_type, 1, QuantizationInfo(), data_layout);
373 TensorType biases = create_tensor<TensorType>(biases_shape, data_type, 1, QuantizationInfo(), data_layout);
374 TensorType dst = create_tensor<TensorType>(TensorShape(), data_type, 1, QuantizationInfo(), data_layout);
375
376 DWCWeightsKernelInfo dwc_weights_info;
377 dwc_weights_info.n0 = n0;
378
379 DWCKernelInfo dwc_info;
380 dwc_info.activation_info = act_info;
381
382 // Create Depthwise Convolution configure function
383 FunctionType dwc;
384 dwc.configure(&src, &weights, &biases, &dst, dwc_weights_info, dwc_info, conv_info, depth_multiplier, dilation);
385
386 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
387 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
388 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
389 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
390
391 // Allocate tensors
392 src.allocator()->allocate();
393 weights.allocator()->allocate();
394 biases.allocator()->allocate();
395 dst.allocator()->allocate();
396
397 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
398 ARM_COMPUTE_EXPECT(!weights.info()->is_resizable(), framework::LogLevel::ERRORS);
399 ARM_COMPUTE_EXPECT(!biases.info()->is_resizable(), framework::LogLevel::ERRORS);
400 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
401
402 // Fill tensors
403 fill(AccessorType(src), 0);
404 fill(AccessorType(weights), 1);
405 fill(AccessorType(biases), 2);
406
407 // Compute function
408 dwc.run();
409
410 return dst;
411 }
412
413 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const PadStrideInfo &conv_info,
414 const Size2D &dilation, unsigned int depth_multiplier, const DataType data_type, const ActivationLayerInfo &act_info)
415 {
416 SimpleTensor<T> src{ input_shape, data_type };
417 SimpleTensor<T> weights{ weights_shape, data_type };
418 SimpleTensor<T> biases{ biases_shape, data_type };
419
420 fill(src, 0);
421 fill(weights, 1);
422 fill(biases, 2);
423
424 const TensorShape dst_shape = compute_depthwise_convolution_shape(TensorInfo(input_shape, 1, data_type), TensorInfo(weights_shape, 1, data_type), conv_info,
425 depth_multiplier, dilation);
426 return reference::activation_layer(reference::depthwise_convolution(src, weights, biases, dst_shape, conv_info, depth_multiplier, dilation), act_info);
427 }
428
429 TensorType _target{};
430 SimpleTensor<T> _reference{};
431};
432
433template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100434class DepthwiseConvolutionLayerValidationQuantizedFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700435{
436public:
437 template <typename...>
Pablo Telloa28aebc2019-06-03 14:59:48 +0100438 void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type,
439 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700440 {
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100441 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, T>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, data_type,
442 data_type, input_quantization_info, input_quantization_info, output_quantization_info,
443 data_layout, act_info);
444 }
445};
446
447template <typename TensorType, typename AccessorType, typename FunctionType, typename T, typename TW>
448class DepthwiseConvolutionLayerValidationQuantizedPerChannelFixture : public DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>
449{
450public:
451 template <typename...>
452 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 +0100453 QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info)
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100454 {
Giorgio Arenad93e2632019-10-15 11:09:33 +0100455 const float out_scale = output_quantization_info.uniform().scale;
456 const float in_scale = input_quantization_info.uniform().scale;
457
458 std::vector<float> weights_scales{};
459 std::mt19937 gen(library->seed());
460 std::uniform_real_distribution<> dis(0.01f, out_scale / in_scale);
461 for(size_t i = 0; i < in_shape.z() * depth_multiplier; ++i)
462 {
463 weights_scales.push_back(dis(gen));
464 }
465
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100466 DepthwiseConvolutionLayerValidationGenericFixture<TensorType, AccessorType, FunctionType, T, TW>::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier,
467 input_data_type, weights_data_type,
Giorgio Arenad93e2632019-10-15 11:09:33 +0100468 input_quantization_info, QuantizationInfo(weights_scales), output_quantization_info,
Michele Di Giorgio633d30b2019-10-08 17:17:18 +0100469 data_layout, act_info);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700470 }
Giorgio Arena93a690e2017-08-01 16:09:33 +0100471};
472} // namespace validation
473} // namespace test
474} // namespace arm_compute
475#endif /* ARM_COMPUTE_TEST_DEPTHWISE_CONVOLUTION_FIXTURE */