Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 1 | /* |
| 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 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/datasets/ShapeDatasets.h" |
| 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" |
| 35 | #include "tests/validation/fixtures/DirectConvolutionLayerFixture.h" |
| 36 | #include "tests/validation/half.h" |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
Moritz Pflanzer | 6106a4d | 2017-08-02 09:42:27 +0100 | [diff] [blame] | 46 | constexpr AbsoluteTolerance<float> tolerance_fp16(0.1f); /**< Tolerance for floating point tests */ |
| 47 | constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */ |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 48 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 49 | constexpr AbsoluteTolerance<int8_t> tolerance_qs8(0); /**< Tolerance for fixed point tests */ |
| 50 | constexpr AbsoluteTolerance<int16_t> tolerance_qs16(0); /**< Tolerance for fixed point tests */ |
| 51 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 52 | /** Direct convolution data set. */ |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 53 | const auto data_quantized = combine(datasets::SmallDirectConvolutionShapes(), |
| 54 | combine(framework::dataset::make("StrideX", 1, 3), |
| 55 | combine(framework::dataset::make("StrideY", 1, 3), |
| 56 | combine(concat(combine(framework::dataset::make("PadX", 0), |
| 57 | combine(framework::dataset::make("PadY", 0), |
| 58 | framework::dataset::make("KernelSize", 1))), |
| 59 | combine(framework::dataset::make("PadX", 0, 2), |
| 60 | combine(framework::dataset::make("PadY", 0, 2), |
| 61 | framework::dataset::make("KernelSize", { 3 })))), |
| 62 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
| 63 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 64 | const auto data = combine(datasets::SmallDirectConvolutionShapes(), |
| 65 | combine(framework::dataset::make("StrideX", 1, 3), |
| 66 | combine(framework::dataset::make("StrideY", 1, 3), |
| 67 | combine(concat(combine(framework::dataset::make("PadX", 0), |
| 68 | combine(framework::dataset::make("PadY", 0), |
| 69 | framework::dataset::make("KernelSize", 1))), |
| 70 | combine(framework::dataset::make("PadX", 0, 2), |
| 71 | combine(framework::dataset::make("PadY", 0, 2), |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 72 | framework::dataset::make("KernelSize", { 3, 5 })))), |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 73 | framework::dataset::make("NumKernels", { 1, 4, 8, 16 }))))); |
| 74 | } // namespace |
| 75 | |
| 76 | TEST_SUITE(CL) |
| 77 | TEST_SUITE(DirectConvolutionLayer) |
| 78 | |
| 79 | //TODO(COMPMID-415): Configuration tests? |
| 80 | |
| 81 | template <typename T> |
| 82 | using CLDirectConvolutionLayerFixture = DirectConvolutionValidationFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
| 83 | |
| 84 | TEST_SUITE(Float) |
| 85 | TEST_SUITE(FP16) |
| 86 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<half_float::half>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F16))) |
| 87 | { |
| 88 | // Validate output |
| 89 | validate(CLAccessor(_target), _reference, tolerance_fp16); |
| 90 | } |
| 91 | TEST_SUITE_END() |
| 92 | |
| 93 | TEST_SUITE(FP32) |
| 94 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixture<float>, framework::DatasetMode::ALL, combine(data, framework::dataset::make("DataType", DataType::F32))) |
| 95 | { |
| 96 | // Validate output |
| 97 | validate(CLAccessor(_target), _reference, tolerance_fp32); |
| 98 | } |
| 99 | TEST_SUITE_END() |
| 100 | TEST_SUITE_END() |
| 101 | |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 102 | template <typename T> |
| 103 | using CLDirectConvolutionLayerFixedPointFixture = DirectConvolutionValidationFixedPointFixture<CLTensor, CLAccessor, CLDirectConvolutionLayer, T>; |
| 104 | |
| 105 | TEST_SUITE(Quantized) |
| 106 | TEST_SUITE(QS8) |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 107 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(data_quantized, framework::dataset::make("DataType", DataType::QS8)), |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 108 | framework::dataset::make("FractionalBits", 2, 7))) |
| 109 | { |
| 110 | // Validate output |
| 111 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 112 | } |
| 113 | TEST_SUITE_END() |
| 114 | |
| 115 | TEST_SUITE(QS16) |
steniu01 | db00668 | 2017-08-09 16:26:22 +0100 | [diff] [blame] | 116 | FIXTURE_DATA_TEST_CASE(Run, CLDirectConvolutionLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(data_quantized, framework::dataset::make("DataType", DataType::QS16)), |
Michalis Spyrou | def665a | 2017-08-14 11:26:37 +0100 | [diff] [blame] | 117 | framework::dataset::make("FractionalBits", 2, 15))) |
| 118 | { |
| 119 | // Validate output |
| 120 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 121 | } |
| 122 | TEST_SUITE_END() |
| 123 | TEST_SUITE_END() |
| 124 | |
Moritz Pflanzer | b3d2579 | 2017-07-26 11:49:37 +0100 | [diff] [blame] | 125 | TEST_SUITE_END() |
| 126 | TEST_SUITE_END() |
| 127 | } // namespace validation |
| 128 | } // namespace test |
| 129 | } // namespace arm_compute |