Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 1 | /* |
Michalis Spyrou | d175ece | 2020-07-30 23:39:32 +0100 | [diff] [blame] | 2 | * Copyright (c) 2019-2020 Arm Limited. |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [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 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/functions/CLFFT1D.h" |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/CL/functions/CLFFT2D.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLFFTConvolutionLayer.h" |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 29 | #include "tests/CL/CLAccessor.h" |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 30 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [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" |
| 35 | #include "tests/validation/fixtures/FFTFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | const auto data_types = framework::dataset::make("DataType", { DataType::F32 }); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 46 | const auto shapes_1d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 2U, 3U), |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 47 | TensorShape(4U, 2U, 3U), TensorShape(5U, 2U, 3U), |
| 48 | TensorShape(7U, 2U, 3U), TensorShape(8U, 2U, 3U), |
| 49 | TensorShape(9U, 2U, 3U), TensorShape(25U, 2U, 3U), |
| 50 | TensorShape(49U, 2U, 3U), TensorShape(64U, 2U, 3U), |
| 51 | TensorShape(16U, 2U, 3U), TensorShape(32U, 2U, 3U), |
| 52 | TensorShape(96U, 2U, 2U) |
| 53 | }); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 54 | const auto shapes_2d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 6U, 3U), |
| 55 | TensorShape(4U, 5U, 3U), TensorShape(5U, 7U, 3U), |
| 56 | TensorShape(7U, 25U, 3U), TensorShape(8U, 2U, 3U), |
| 57 | TensorShape(9U, 16U, 3U), TensorShape(25U, 32U, 3U), |
| 58 | TensorShape(192U, 128U, 2U) |
| 59 | }); |
| 60 | |
| 61 | const auto ActivationFunctionsSmallDataset = framework::dataset::make("ActivationInfo", |
| 62 | { |
| 63 | ActivationLayerInfo(), |
| 64 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f) |
| 65 | }); |
| 66 | |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 67 | RelativeTolerance<float> tolerance_f32(0.1f); /**< Relative tolerance value for FP32 */ |
| 68 | RelativeTolerance<half> tolerance_f16(half(0.1f)); /**< Relative tolerance value for FP16 */ |
| 69 | constexpr float tolerance_num_f32 = 0.07f; /**< Tolerance number for FP32*/ |
| 70 | constexpr float tolerance_num_f16 = 0.15f; /**< Tolerance number for FP32*/ |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 71 | |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 72 | } // namespace |
| 73 | TEST_SUITE(CL) |
| 74 | TEST_SUITE(FFT1D) |
| 75 | |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 76 | // *INDENT-OFF* |
| 77 | // clang-format off |
| 78 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 79 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching data types |
| 80 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching shapes |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 81 | TensorInfo(TensorShape(32U, 13U, 2U), 3, DataType::F32), // Invalid channels |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 82 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Unsupported axis |
| 83 | TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT |
| 84 | TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32), |
| 85 | }), |
| 86 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F16), |
| 87 | TensorInfo(TensorShape(16U, 13U, 2U), 2, DataType::F32), |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 88 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 89 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
| 90 | TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), |
| 91 | TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32), |
| 92 | })), |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 93 | framework::dataset::make("Axis", { 0, 0, 0, 2, 0, 0 })), |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 94 | framework::dataset::make("Expected", { false, false, false, false, false, true })), |
| 95 | input_info, output_info, axis, expected) |
| 96 | { |
| 97 | FFT1DInfo desc; |
| 98 | desc.axis = axis; |
| 99 | const Status s = CLFFT1D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), desc); |
| 100 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 101 | } |
| 102 | // clang-format on |
| 103 | // *INDENT-ON* |
| 104 | |
| 105 | template <typename T> |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 106 | using CLFFT1DFixture = FFTValidationFixture<CLTensor, CLAccessor, CLFFT1D, FFT1DInfo, T>; |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 107 | |
| 108 | TEST_SUITE(Float) |
| 109 | TEST_SUITE(FP32) |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 110 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT1DFixture<float>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F32))) |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 111 | { |
| 112 | // Validate output |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 113 | validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 114 | } |
| 115 | TEST_SUITE_END() // FP32 |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 116 | TEST_SUITE(FP16) |
| 117 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT1DFixture<half>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F16))) |
| 118 | { |
| 119 | // Validate output |
| 120 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num_f16); |
| 121 | } |
| 122 | TEST_SUITE_END() // FP16 |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 123 | TEST_SUITE_END() // Float |
| 124 | |
| 125 | TEST_SUITE_END() // FFT1D |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 126 | |
| 127 | TEST_SUITE(FFT2D) |
| 128 | |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 129 | // *INDENT-OFF* |
| 130 | // clang-format off |
| 131 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip( |
| 132 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching data types |
| 133 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching shapes |
| 134 | TensorInfo(TensorShape(32U, 25U, 2U), 3, DataType::F32), // Invalid channels |
| 135 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT |
| 136 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), |
| 137 | }), |
| 138 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F16), |
| 139 | TensorInfo(TensorShape(16U, 25U, 2U), 2, DataType::F32), |
| 140 | TensorInfo(TensorShape(32U, 25U, 2U), 1, DataType::F32), |
| 141 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
| 142 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), |
| 143 | })), |
| 144 | framework::dataset::make("Expected", { false, false, false, false, true })), |
| 145 | input_info, output_info, expected) |
| 146 | { |
| 147 | const Status s = CLFFT2D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), FFT2DInfo()); |
| 148 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 149 | } |
| 150 | // clang-format on |
| 151 | // *INDENT-ON* |
| 152 | |
| 153 | template <typename T> |
| 154 | using CLFFT2DFixture = FFTValidationFixture<CLTensor, CLAccessor, CLFFT2D, FFT2DInfo, T>; |
| 155 | |
| 156 | TEST_SUITE(Float) |
| 157 | TEST_SUITE(FP32) |
| 158 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT2DFixture<float>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F32))) |
| 159 | { |
| 160 | // Validate output |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 161 | validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 162 | } |
| 163 | TEST_SUITE_END() // FP32 |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 164 | TEST_SUITE(FP16) |
| 165 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT2DFixture<half>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F16))) |
| 166 | { |
| 167 | // Validate output |
| 168 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num_f16); |
| 169 | } |
| 170 | TEST_SUITE_END() // FP16 |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 171 | TEST_SUITE_END() // Float |
| 172 | TEST_SUITE_END() // FFT2D |
| 173 | |
| 174 | TEST_SUITE(FFTConvolutionLayer) |
| 175 | |
| 176 | template <typename T> |
| 177 | using CLFFTConvolutionLayerFixture = FFTConvolutionValidationFixture<CLTensor, CLAccessor, CLFFTConvolutionLayer, T>; |
| 178 | |
| 179 | TEST_SUITE(Float) |
| 180 | TEST_SUITE(FP32) |
| 181 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFTConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFFTConvolutionLayerDataset(), |
| 182 | framework::dataset::make("DataType", DataType::F32)), |
| 183 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 184 | ActivationFunctionsSmallDataset)) |
| 185 | { |
| 186 | // Validate output |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 187 | validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 188 | } |
| 189 | TEST_SUITE_END() // FP32 |
Giorgio Arena | ea7de7b | 2020-12-10 16:49:39 +0000 | [diff] [blame] | 190 | TEST_SUITE(FP16) |
| 191 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFFTConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFFTConvolutionLayerDataset(), |
| 192 | framework::dataset::make("DataType", DataType::F16)), |
| 193 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 194 | ActivationFunctionsSmallDataset)) |
| 195 | { |
| 196 | // Validate output |
| 197 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num_f16); |
| 198 | } |
| 199 | TEST_SUITE_END() // FP16 |
Georgios Pinitas | 8be9148 | 2019-03-26 17:23:28 +0000 | [diff] [blame] | 200 | TEST_SUITE_END() // Float |
| 201 | TEST_SUITE_END() // FFTConvolutionLayer |
| 202 | |
Georgios Pinitas | 0bc7849 | 2019-03-18 20:07:37 +0000 | [diff] [blame] | 203 | TEST_SUITE_END() // CL |
| 204 | } // namespace validation |
| 205 | } // namespace test |
| 206 | } // namespace arm_compute |