blob: b1cc491ac829f67fc912977600be16424f20debe [file] [log] [blame]
Anthony Barbier8140e1e2017-12-14 23:48:46 +00001/*
Anthony Barbierf45d5a92018-01-24 16:23:15 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier8140e1e2017-12-14 23:48:46 +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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
Jenkinsb3a371b2018-05-23 11:36:53 +010025#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Anthony Barbier8140e1e2017-12-14 23:48:46 +000026#include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/DepthwiseConvolutionLayerDataset.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
Jenkinsb3a371b2018-05-23 11:36:53 +010044using namespace arm_compute::misc::shape_calculator;
45
Anthony Barbier8140e1e2017-12-14 23:48:46 +000046namespace
47{
Anthony Barbierf45d5a92018-01-24 16:23:15 +000048constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
49constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for DataType::QASYMM8 */
Jenkinsb3a371b2018-05-23 11:36:53 +010050
51const auto depth_multipliers = framework::dataset::make("DepthMultiplier", { 1, 2, 3 });
Anthony Barbier8140e1e2017-12-14 23:48:46 +000052} // namespace
53
54TEST_SUITE(NEON)
Anthony Barbierf45d5a92018-01-24 16:23:15 +000055TEST_SUITE(DepthwiseConvLayer)
Anthony Barbier8140e1e2017-12-14 23:48:46 +000056
Jenkinsb3a371b2018-05-23 11:36:53 +010057DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
58 datasets::LargeDepthwiseConvolutionLayerDataset3x3()),
59 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +000060 framework::dataset::make("DataType", DataType::F32)),
Jenkinsb3a371b2018-05-23 11:36:53 +010061 input_shape, kernel_size, info, depth_multiplier, data_type)
Anthony Barbier8140e1e2017-12-14 23:48:46 +000062{
Jenkinsb3a371b2018-05-23 11:36:53 +010063 // Get shapes
64 TensorShape weights_shape(kernel_size.width, kernel_size.height);
65
66 const TensorInfo in_info(input_shape, 1, data_type);
67 const TensorInfo we_info(weights_shape, 1, data_type);
68 const TensorShape output_shape = compute_depthwise_convolution_shape(in_info, we_info, info, depth_multiplier);
69
70 weights_shape.set(2, output_shape.z());
71
Anthony Barbier8140e1e2017-12-14 23:48:46 +000072 // Create tensors
Anthony Barbierf45d5a92018-01-24 16:23:15 +000073 Tensor src = create_tensor<Tensor>(input_shape, data_type);
74 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
75 Tensor weights = create_tensor<Tensor>(weights_shape, data_type);
76 const TensorShape bias_shape(weights_shape[2]);
77 Tensor bias = create_tensor<Tensor>(bias_shape, data_type);
Anthony Barbier8140e1e2017-12-14 23:48:46 +000078
79 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
83
84 // Create and configure function
85 NEDepthwiseConvolutionLayer3x3 depthwise_layer;
Jenkinsb3a371b2018-05-23 11:36:53 +010086 depthwise_layer.configure(&src, &weights, &bias, &dst, info, depth_multiplier);
Anthony Barbier8140e1e2017-12-14 23:48:46 +000087
88 // Validate valid region
89 const ValidRegion input_valid_region = shape_to_valid_region(input_shape);
90 const ValidRegion output_valid_region = shape_to_valid_region(output_shape);
91 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
92 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
93
94 validate(src.info()->valid_region(), input_valid_region);
95 validate(dst.info()->valid_region(), output_valid_region);
96 validate(weights.info()->valid_region(), weights_valid_region);
97 validate(bias.info()->valid_region(), bias_valid_region);
98
99 // Validate padding
Jenkinsb3a371b2018-05-23 11:36:53 +0100100 bool is_optimized_run = NEDepthwiseConvolutionLayer3x3Kernel::is_optimized_execution_possible(input_shape, info, data_type, depth_multiplier, DataLayout::NCHW);
Anthony Barbier06ea0482018-02-22 15:45:35 +0000101 const int step_non_opt_dwc = 16 >> info.stride().first;
102 const int step_bias_add = 16 / src.info()->element_size();
103 const int step = is_optimized_run ? step_bias_add : std::max(step_non_opt_dwc, step_bias_add);
104 const PaddingSize padding = PaddingCalculator(output_shape.x(), step).required_padding();
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000105 validate(dst.info()->padding(), padding);
106}
107
108TEST_SUITE(Float)
109TEST_SUITE(F32)
110TEST_SUITE(Generic)
111template <typename T>
112using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Jenkinsb3a371b2018-05-23 11:36:53 +0100113FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
114 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000115 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100116 DataType::F32)),
117 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000118{
119 validate(Accessor(_target), _reference, tolerance_f32);
120}
Jenkinsb3a371b2018-05-23 11:36:53 +0100121FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset(),
122 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000123 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100124 DataType::F32)),
125 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000126{
127 validate(Accessor(_target), _reference, tolerance_f32);
128}
129TEST_SUITE_END()
130
131TEST_SUITE(W3x3)
132template <typename T>
133using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Jenkinsb3a371b2018-05-23 11:36:53 +0100134FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
135 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000136 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100137 DataType::F32)),
138 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000139{
140 validate(Accessor(_target), _reference, tolerance_f32);
141}
Jenkinsb3a371b2018-05-23 11:36:53 +0100142FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
143 depth_multipliers),
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000144 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100145 DataType::F32)),
146 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000147{
148 validate(Accessor(_target), _reference, tolerance_f32);
149}
Jenkinsb3a371b2018-05-23 11:36:53 +0100150FIXTURE_DATA_TEST_CASE(RunOptimized, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::OptimizedDepthwiseConvolutionLayerDataset3x3(),
151 framework::dataset::make("DepthMultiplier", 1)),
Anthony Barbier06ea0482018-02-22 15:45:35 +0000152 framework::dataset::make("DataType",
Jenkinsb3a371b2018-05-23 11:36:53 +0100153 DataType::F32)),
154 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Anthony Barbier06ea0482018-02-22 15:45:35 +0000155{
156 validate(Accessor(_target), _reference, tolerance_f32);
157}
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000158TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000159TEST_SUITE_END()
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000160
161TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000162
163template <typename T>
164using NEDepthwiseConvolutionLayerQuantizedFixture3x3 = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Anthony Barbier06ea0482018-02-22 15:45:35 +0000165template <typename T>
166using NEDepthwiseConvolutionLayerQuantizedFixture = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000167
168TEST_SUITE(Quantized)
169TEST_SUITE(QASYMM8)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000170TEST_SUITE(Generic)
Jenkinsb3a371b2018-05-23 11:36:53 +0100171FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
172 combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
173 depth_multipliers),
174 framework::dataset::make("DataType", DataType::QASYMM8)),
175 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
176 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbier06ea0482018-02-22 15:45:35 +0000177{
178 validate(Accessor(_target), _reference, tolerance_qasymm8);
179}
180TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000181TEST_SUITE(W3x3)
Jenkinsb3a371b2018-05-23 11:36:53 +0100182FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT,
183 combine(combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), depth_multipliers),
184 framework::dataset::make("DataType", DataType::QASYMM8)),
185 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
186 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000187{
188 validate(Accessor(_target), _reference, tolerance_qasymm8);
189}
Jenkinsb3a371b2018-05-23 11:36:53 +0100190FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY,
191 combine(combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
192 depth_multipliers),
193 framework::dataset::make("DataType", DataType::QASYMM8)),
194 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
195 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000196{
197 validate(Accessor(_target), _reference, tolerance_qasymm8);
198}
199TEST_SUITE_END()
200TEST_SUITE_END()
Anthony Barbier8140e1e2017-12-14 23:48:46 +0000201TEST_SUITE_END()
202
203TEST_SUITE_END()
204TEST_SUITE_END()
205} // namespace validation
206} // namespace test
207} // namespace arm_compute