blob: 236d4bd653b7037c2adb024c49ae805de6ba3846 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
Georgios Pinitasf72f9362018-01-12 16:29:45 +00002 * Copyright (c) 2017-2018 ARM Limited.
Michalis Spyrou7362f0d2017-10-18 17:58:22 +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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/core/Types.h"
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000025#include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010026#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/PaddingCalculator.h"
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000030#include "tests/datasets/DepthwiseConvolutionLayerDataset.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010031#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000035#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010036
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Georgios Pinitasf72f9362018-01-12 16:29:45 +000045constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
46constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for DataType::QASYMM8 */
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010047} // namespace
48
49TEST_SUITE(NEON)
Pablo Tello941cd702017-12-12 14:35:00 +000050TEST_SUITE(DepthwiseConvLayer)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010051
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000052DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
53 datasets::LargeDepthwiseConvolutionLayerDataset3x3()),
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010054 framework::dataset::make("DataType", DataType::F32)),
Pablo Tello941cd702017-12-12 14:35:00 +000055 input_shape, weights_shape, output_shape, info, data_type)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010056{
57 // Create tensors
Pablo Tello941cd702017-12-12 14:35:00 +000058 Tensor src = create_tensor<Tensor>(input_shape, data_type);
59 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
60 Tensor weights = create_tensor<Tensor>(weights_shape, data_type);
61 const TensorShape bias_shape(weights_shape[2]);
62 Tensor bias = create_tensor<Tensor>(bias_shape, data_type);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010063
64 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
65 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
66 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
67 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
68
69 // Create and configure function
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000070 NEDepthwiseConvolutionLayer3x3 depthwise_layer;
Giorgio Arena82afedf2017-11-15 13:36:15 +000071 depthwise_layer.configure(&src, &weights, &bias, &dst, info);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010072
73 // Validate valid region
74 const ValidRegion input_valid_region = shape_to_valid_region(input_shape);
75 const ValidRegion output_valid_region = shape_to_valid_region(output_shape);
76 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
77 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
78
79 validate(src.info()->valid_region(), input_valid_region);
80 validate(dst.info()->valid_region(), output_valid_region);
81 validate(weights.info()->valid_region(), weights_valid_region);
82 validate(bias.info()->valid_region(), bias_valid_region);
83
84 // Validate padding
Georgios Pinitas69af6cf2018-02-14 19:23:44 +000085 bool is_optimized_run = NEDepthwiseConvolutionLayer3x3Kernel::is_optimized_execution_possible(input_shape, info, data_type, DataLayout::NCHW);
86 const int step_non_opt_dwc = 16 >> info.stride().first;
87 const int step_bias_add = 16 / src.info()->element_size();
88 const int step = is_optimized_run ? step_bias_add : std::max(step_non_opt_dwc, step_bias_add);
89 const PaddingSize padding = PaddingCalculator(output_shape.x(), step).required_padding();
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010090 validate(dst.info()->padding(), padding);
91}
92
Dmitry Savenkod7295b72017-11-20 22:00:08 +070093TEST_SUITE(Float)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010094TEST_SUITE(F32)
Michalis Spyroub7b31532017-11-23 12:10:21 +000095TEST_SUITE(Generic)
96template <typename T>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000097using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Giorgio Arena1ed1fc62018-03-26 16:20:05 +010098FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000099 framework::dataset::make("DataType",
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100100 DataType::F32)),
101 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Michalis Spyroub7b31532017-11-23 12:10:21 +0000102{
103 validate(Accessor(_target), _reference, tolerance_f32);
104}
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100105FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset(),
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000106 framework::dataset::make("DataType",
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100107 DataType::F32)),
108 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Michalis Spyroub7b31532017-11-23 12:10:21 +0000109{
110 validate(Accessor(_target), _reference, tolerance_f32);
111}
112TEST_SUITE_END()
113
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100114TEST_SUITE(W3x3)
Michalis Spyroub7b31532017-11-23 12:10:21 +0000115template <typename T>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000116using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100117FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000118 framework::dataset::make("DataType",
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100119 DataType::F32)),
120 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100121{
122 validate(Accessor(_target), _reference, tolerance_f32);
123}
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100124FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000125 framework::dataset::make("DataType",
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100126 DataType::F32)),
127 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100128{
129 validate(Accessor(_target), _reference, tolerance_f32);
130}
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100131FIXTURE_DATA_TEST_CASE(RunOptimized, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(combine(datasets::OptimizedDepthwiseConvolutionLayerDataset3x3(),
Georgios Pinitas4074c992018-01-30 18:13:46 +0000132 framework::dataset::make("DataType",
Giorgio Arena1ed1fc62018-03-26 16:20:05 +0100133 DataType::F32)),
134 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })))
Georgios Pinitas4074c992018-01-30 18:13:46 +0000135{
136 validate(Accessor(_target), _reference, tolerance_f32);
137}
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100138TEST_SUITE_END()
139TEST_SUITE_END()
Pablo Tello941cd702017-12-12 14:35:00 +0000140
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700141TEST_SUITE_END()
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100142
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000143template <typename T>
144using NEDepthwiseConvolutionLayerQuantizedFixture3x3 = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000145template <typename T>
146using NEDepthwiseConvolutionLayerQuantizedFixture = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000147
148TEST_SUITE(Quantized)
149TEST_SUITE(QASYMM8)
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000150TEST_SUITE(Generic)
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000151FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000152 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000153 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
154 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000155{
156 validate(Accessor(_target), _reference, tolerance_qasymm8);
157}
158TEST_SUITE_END()
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000159TEST_SUITE(W3x3)
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000160FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT,
161 combine(combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
162 framework::dataset::make("DataType", DataType::QASYMM8)),
163 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
164 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000165{
166 validate(Accessor(_target), _reference, tolerance_qasymm8);
167}
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000168FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000169 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000170 framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) })),
171 framework::dataset::make("DataLayout", DataLayout::NCHW)))
Georgios Pinitasf72f9362018-01-12 16:29:45 +0000172{
173 validate(Accessor(_target), _reference, tolerance_qasymm8);
174}
175TEST_SUITE_END()
176TEST_SUITE_END()
177TEST_SUITE_END()
178
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100179TEST_SUITE_END()
180TEST_SUITE_END()
181} // namespace validation
182} // namespace test
183} // namespace arm_compute