giuros01 | 14c4e0f | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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/NEON/functions/NEFFT1D.h" |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEFFT2D.h" |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/NEON/functions/NEFFTConvolutionLayer.h" |
giuros01 | 14c4e0f | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/Tensor.h" |
| 29 | #include "tests/NEON/Accessor.h" |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 30 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
giuros01 | 14c4e0f | 2019-03-26 17:44:40 +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 }); |
| 46 | const auto shapes_1d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 2U, 3U), |
| 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 | }); |
| 54 | |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 55 | const auto shapes_2d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 6U, 3U), |
| 56 | TensorShape(4U, 5U, 3U), TensorShape(5U, 7U, 3U), |
| 57 | TensorShape(7U, 25U, 3U), TensorShape(8U, 2U, 3U), |
| 58 | TensorShape(9U, 16U, 3U), TensorShape(25U, 32U, 3U), |
| 59 | TensorShape(192U, 128U, 2U) |
| 60 | }); |
| 61 | |
giuros01 | 14c4e0f | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 62 | const auto ActivationFunctionsSmallDataset = framework::dataset::make("ActivationInfo", |
| 63 | { |
| 64 | ActivationLayerInfo(), |
| 65 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f) |
| 66 | }); |
| 67 | |
| 68 | RelativeTolerance<float> tolerance_f32(0.1f); /**< Relative tolerance value for FP32 */ |
| 69 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
| 70 | |
| 71 | } // namespace |
| 72 | TEST_SUITE(NEON) |
| 73 | TEST_SUITE(FFT1D) |
| 74 | |
| 75 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_1d, data_types), |
| 76 | shape, data_type) |
| 77 | { |
| 78 | // Create tensors |
| 79 | Tensor src = create_tensor<Tensor>(shape, data_type, 2); |
| 80 | Tensor dst = create_tensor<Tensor>(shape, data_type, 2); |
| 81 | |
| 82 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | |
| 85 | // Create and configure function |
| 86 | NEFFT1D fft1d; |
| 87 | fft1d.configure(&src, &dst, FFT1DInfo()); |
| 88 | |
| 89 | // Validate valid region |
| 90 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 91 | validate(src.info()->valid_region(), valid_region); |
| 92 | validate(dst.info()->valid_region(), valid_region); |
| 93 | |
| 94 | // Validate padding |
| 95 | validate(src.info()->padding(), PaddingSize()); |
| 96 | validate(dst.info()->padding(), PaddingSize()); |
| 97 | } |
| 98 | |
| 99 | // *INDENT-OFF* |
| 100 | // clang-format off |
| 101 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 102 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching data types |
| 103 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching shapes |
| 104 | TensorInfo(TensorShape(32U, 13U, 2U), 3, DataType::F32), // Invalid channels |
| 105 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Unsupported axis |
| 106 | TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT |
| 107 | TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32), |
| 108 | }), |
| 109 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F16), |
| 110 | TensorInfo(TensorShape(16U, 13U, 2U), 2, DataType::F32), |
| 111 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
| 112 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
| 113 | TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), |
| 114 | TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32), |
| 115 | })), |
| 116 | framework::dataset::make("Axis", { 0, 0, 0, 2, 0, 0 })), |
| 117 | framework::dataset::make("Expected", { false, false, false, false, false, true })), |
| 118 | input_info, output_info, axis, expected) |
| 119 | { |
| 120 | FFT1DInfo desc; |
| 121 | desc.axis = axis; |
| 122 | const Status s = NEFFT1D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), desc); |
| 123 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 124 | } |
| 125 | // clang-format on |
| 126 | // *INDENT-ON* |
| 127 | |
| 128 | template <typename T> |
| 129 | using NEFFT1DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT1D, FFT1DInfo, T>; |
| 130 | |
| 131 | TEST_SUITE(Float) |
| 132 | TEST_SUITE(FP32) |
| 133 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT1DFixture<float>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F32))) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(Accessor(_target), _reference, tolerance_f32, tolerance_num); |
| 137 | } |
| 138 | TEST_SUITE_END() // FP32 |
| 139 | TEST_SUITE_END() // Float |
giuros01 | 14c4e0f | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 140 | TEST_SUITE_END() // FFT1D |
giuros01 | 05fb448 | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 141 | |
| 142 | TEST_SUITE(FFT2D) |
| 143 | |
| 144 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_2d, data_types), |
| 145 | shape, data_type) |
| 146 | { |
| 147 | // Create tensors |
| 148 | Tensor src = create_tensor<Tensor>(shape, data_type, 2); |
| 149 | Tensor dst = create_tensor<Tensor>(shape, data_type, 2); |
| 150 | |
| 151 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 152 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 153 | |
| 154 | // Create and configure function |
| 155 | NEFFT2D fft2d; |
| 156 | fft2d.configure(&src, &dst, FFT2DInfo()); |
| 157 | |
| 158 | // Validate valid region |
| 159 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 160 | validate(src.info()->valid_region(), valid_region); |
| 161 | validate(dst.info()->valid_region(), valid_region); |
| 162 | |
| 163 | // Validate padding |
| 164 | validate(src.info()->padding(), PaddingSize()); |
| 165 | validate(dst.info()->padding(), PaddingSize()); |
| 166 | } |
| 167 | |
| 168 | // *INDENT-OFF* |
| 169 | // clang-format off |
| 170 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip( |
| 171 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching data types |
| 172 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching shapes |
| 173 | TensorInfo(TensorShape(32U, 25U, 2U), 3, DataType::F32), // Invalid channels |
| 174 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT |
| 175 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), |
| 176 | }), |
| 177 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F16), |
| 178 | TensorInfo(TensorShape(16U, 25U, 2U), 2, DataType::F32), |
| 179 | TensorInfo(TensorShape(32U, 25U, 2U), 1, DataType::F32), |
| 180 | TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), |
| 181 | TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), |
| 182 | })), |
| 183 | framework::dataset::make("Expected", { false, false, false, false, true })), |
| 184 | input_info, output_info, expected) |
| 185 | { |
| 186 | const Status s = NEFFT2D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), FFT2DInfo()); |
| 187 | ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS); |
| 188 | } |
| 189 | // clang-format on |
| 190 | // *INDENT-ON* |
| 191 | |
| 192 | template <typename T> |
| 193 | using NEFFT2DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT2D, FFT2DInfo, T>; |
| 194 | |
| 195 | TEST_SUITE(Float) |
| 196 | TEST_SUITE(FP32) |
| 197 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT2DFixture<float>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F32))) |
| 198 | { |
| 199 | // Validate output |
| 200 | validate(Accessor(_target), _reference, tolerance_f32, tolerance_num); |
| 201 | } |
| 202 | TEST_SUITE_END() // FP32 |
| 203 | TEST_SUITE_END() // Float |
| 204 | TEST_SUITE_END() // FFT2D |
| 205 | |
giuros01 | 154bc1c | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 206 | TEST_SUITE(FFTConvolutionLayer) |
| 207 | |
| 208 | template <typename T> |
| 209 | using NEFFTConvolutionLayerFixture = FFTConvolutionValidationFixture<Tensor, Accessor, NEFFTConvolutionLayer, T>; |
| 210 | |
| 211 | TEST_SUITE(Float) |
| 212 | TEST_SUITE(FP32) |
| 213 | FIXTURE_DATA_TEST_CASE(RunSmall, NEFFTConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFFTConvolutionLayerDataset(), |
| 214 | framework::dataset::make("DataType", DataType::F32)), |
| 215 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), |
| 216 | ActivationFunctionsSmallDataset)) |
| 217 | { |
| 218 | // Validate output |
| 219 | validate(Accessor(_target), _reference, tolerance_f32, tolerance_num); |
| 220 | } |
| 221 | TEST_SUITE_END() // FP32 |
| 222 | TEST_SUITE_END() // Float |
| 223 | TEST_SUITE_END() // FFTConvolutionLayer |
| 224 | |
giuros01 | 14c4e0f | 2019-03-26 17:44:40 +0000 | [diff] [blame] | 225 | TEST_SUITE_END() // NEON |
| 226 | } // namespace validation |
| 227 | } // namespace test |
| 228 | } // namespace arm_compute |