blob: 420c9744d8aab5982d2483e37eceefe2dee26cd5 [file] [log] [blame]
Michalis Spyrou7362f0d2017-10-18 17:58:22 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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{
45constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
46} // namespace
47
48TEST_SUITE(NEON)
Pablo Tello941cd702017-12-12 14:35:00 +000049TEST_SUITE(DepthwiseConvLayer)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010050
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000051DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
52 datasets::LargeDepthwiseConvolutionLayerDataset3x3()),
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010053 framework::dataset::make("DataType", DataType::F32)),
Pablo Tello941cd702017-12-12 14:35:00 +000054 input_shape, weights_shape, output_shape, info, data_type)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010055{
56 // Create tensors
Pablo Tello941cd702017-12-12 14:35:00 +000057 Tensor src = create_tensor<Tensor>(input_shape, data_type);
58 Tensor dst = create_tensor<Tensor>(output_shape, data_type);
59 Tensor weights = create_tensor<Tensor>(weights_shape, data_type);
60 const TensorShape bias_shape(weights_shape[2]);
61 Tensor bias = create_tensor<Tensor>(bias_shape, data_type);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010062
63 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
64 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
65 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
66 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
67
68 // Create and configure function
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000069 NEDepthwiseConvolutionLayer3x3 depthwise_layer;
Giorgio Arena82afedf2017-11-15 13:36:15 +000070 depthwise_layer.configure(&src, &weights, &bias, &dst, info);
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010071
72 // Validate valid region
73 const ValidRegion input_valid_region = shape_to_valid_region(input_shape);
74 const ValidRegion output_valid_region = shape_to_valid_region(output_shape);
75 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
76 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
77
78 validate(src.info()->valid_region(), input_valid_region);
79 validate(dst.info()->valid_region(), output_valid_region);
80 validate(weights.info()->valid_region(), weights_valid_region);
81 validate(bias.info()->valid_region(), bias_valid_region);
82
83 // Validate padding
84 const int step = 16 >> info.stride().first;
85 const PaddingSize padding = PaddingCalculator(output_shape.x(), step).required_padding();
86 validate(dst.info()->padding(), padding);
87}
88
Dmitry Savenkod7295b72017-11-20 22:00:08 +070089TEST_SUITE(Float)
Michalis Spyrou7362f0d2017-10-18 17:58:22 +010090TEST_SUITE(F32)
Michalis Spyroub7b31532017-11-23 12:10:21 +000091TEST_SUITE(Generic)
92template <typename T>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000093using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>;
94FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallDepthwiseConvolutionLayerDataset(),
95 framework::dataset::make("DataType",
96 DataType::F32)))
Michalis Spyroub7b31532017-11-23 12:10:21 +000097{
98 validate(Accessor(_target), _reference, tolerance_f32);
99}
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000100FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeDepthwiseConvolutionLayerDataset(),
101 framework::dataset::make("DataType",
102 DataType::F32)))
Michalis Spyroub7b31532017-11-23 12:10:21 +0000103{
104 validate(Accessor(_target), _reference, tolerance_f32);
105}
106TEST_SUITE_END()
107
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100108TEST_SUITE(W3x3)
Michalis Spyroub7b31532017-11-23 12:10:21 +0000109template <typename T>
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000110using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>;
111FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(),
112 framework::dataset::make("DataType",
113 DataType::F32)))
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100114{
115 validate(Accessor(_target), _reference, tolerance_f32);
116}
Giorgio Arena04a8f8c2017-11-23 11:45:24 +0000117FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(),
118 framework::dataset::make("DataType",
119 DataType::F32)))
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100120{
121 validate(Accessor(_target), _reference, tolerance_f32);
122}
123TEST_SUITE_END()
124TEST_SUITE_END()
Pablo Tello941cd702017-12-12 14:35:00 +0000125
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700126TEST_SUITE_END()
Michalis Spyrou7362f0d2017-10-18 17:58:22 +0100127
128TEST_SUITE_END()
129TEST_SUITE_END()
130} // namespace validation
131} // namespace test
132} // namespace arm_compute