Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 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 Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 25 | #include "arm_compute/runtime/NEON/functions/NEDepthwiseConvolutionLayer.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 26 | #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 Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 30 | #include "tests/datasets/DepthwiseConvolutionLayerDataset.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 31 | #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 Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 35 | #include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h" |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 45 | constexpr RelativeTolerance<float> tolerance_f32(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 46 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for DataType::QASYMM8 */ |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 47 | } // namespace |
| 48 | |
| 49 | TEST_SUITE(NEON) |
Pablo Tello | 941cd70 | 2017-12-12 14:35:00 +0000 | [diff] [blame] | 50 | TEST_SUITE(DepthwiseConvLayer) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 51 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 52 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), |
| 53 | datasets::LargeDepthwiseConvolutionLayerDataset3x3()), |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 54 | framework::dataset::make("DataType", DataType::F32)), |
Pablo Tello | 941cd70 | 2017-12-12 14:35:00 +0000 | [diff] [blame] | 55 | input_shape, weights_shape, output_shape, info, data_type) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 56 | { |
| 57 | // Create tensors |
Pablo Tello | 941cd70 | 2017-12-12 14:35:00 +0000 | [diff] [blame] | 58 | 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 Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 63 | |
| 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 Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 70 | NEDepthwiseConvolutionLayer3x3 depthwise_layer; |
Giorgio Arena | 82afedf | 2017-11-15 13:36:15 +0000 | [diff] [blame] | 71 | depthwise_layer.configure(&src, &weights, &bias, &dst, info); |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 72 | |
| 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 |
| 85 | const int step = 16 >> info.stride().first; |
| 86 | const PaddingSize padding = PaddingCalculator(output_shape.x(), step).required_padding(); |
| 87 | validate(dst.info()->padding(), padding); |
| 88 | } |
| 89 | |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 90 | TEST_SUITE(Float) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 91 | TEST_SUITE(F32) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 92 | TEST_SUITE(Generic) |
| 93 | template <typename T> |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 94 | using NEDepthwiseConvolutionLayerFixture = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer, T>; |
| 95 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallDepthwiseConvolutionLayerDataset(), |
| 96 | framework::dataset::make("DataType", |
| 97 | DataType::F32))) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 98 | { |
| 99 | validate(Accessor(_target), _reference, tolerance_f32); |
| 100 | } |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 101 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeDepthwiseConvolutionLayerDataset(), |
| 102 | framework::dataset::make("DataType", |
| 103 | DataType::F32))) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 104 | { |
| 105 | validate(Accessor(_target), _reference, tolerance_f32); |
| 106 | } |
| 107 | TEST_SUITE_END() |
| 108 | |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 109 | TEST_SUITE(W3x3) |
Michalis Spyrou | b7b3153 | 2017-11-23 12:10:21 +0000 | [diff] [blame] | 110 | template <typename T> |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 111 | using NEDepthwiseConvolutionLayerFixture3x3 = DepthwiseConvolutionLayerValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>; |
| 112 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), |
| 113 | framework::dataset::make("DataType", |
| 114 | DataType::F32))) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 115 | { |
| 116 | validate(Accessor(_target), _reference, tolerance_f32); |
| 117 | } |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 118 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerFixture3x3<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(), |
| 119 | framework::dataset::make("DataType", |
| 120 | DataType::F32))) |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 121 | { |
| 122 | validate(Accessor(_target), _reference, tolerance_f32); |
| 123 | } |
| 124 | TEST_SUITE_END() |
| 125 | TEST_SUITE_END() |
Pablo Tello | 941cd70 | 2017-12-12 14:35:00 +0000 | [diff] [blame] | 126 | |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 127 | TEST_SUITE_END() |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 128 | |
Georgios Pinitas | f72f936 | 2018-01-12 16:29:45 +0000 | [diff] [blame^] | 129 | template <typename T> |
| 130 | using NEDepthwiseConvolutionLayerQuantizedFixture3x3 = DepthwiseConvolutionLayerValidationQuantizedFixture<Tensor, Accessor, NEDepthwiseConvolutionLayer3x3, T>; |
| 131 | |
| 132 | TEST_SUITE(Quantized) |
| 133 | TEST_SUITE(QASYMM8) |
| 134 | TEST_SUITE(W3x3) |
| 135 | FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallDepthwiseConvolutionLayerDataset3x3(), |
| 136 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 137 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) |
| 138 | { |
| 139 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 140 | } |
| 141 | FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerQuantizedFixture3x3<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeDepthwiseConvolutionLayerDataset3x3(), |
| 142 | framework::dataset::make("DataType", DataType::QASYMM8)), |
| 143 | framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.5f, 10) }))) |
| 144 | { |
| 145 | validate(Accessor(_target), _reference, tolerance_qasymm8); |
| 146 | } |
| 147 | TEST_SUITE_END() |
| 148 | TEST_SUITE_END() |
| 149 | TEST_SUITE_END() |
| 150 | |
Michalis Spyrou | 7362f0d | 2017-10-18 17:58:22 +0100 | [diff] [blame] | 151 | TEST_SUITE_END() |
| 152 | TEST_SUITE_END() |
| 153 | } // namespace validation |
| 154 | } // namespace test |
| 155 | } // namespace arm_compute |