blob: 598c8bb10d9829a093cd5611b84cdb8b3d38d6cb [file] [log] [blame]
giuros0114c4e0f2019-03-26 17:44:40 +00001/*
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"
giuros0105fb4482019-03-26 17:44:40 +000026#include "arm_compute/runtime/NEON/functions/NEFFT2D.h"
giuros0114c4e0f2019-03-26 17:44:40 +000027#include "arm_compute/runtime/Tensor.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/framework/Asserts.h"
30#include "tests/framework/Macros.h"
31#include "tests/framework/datasets/Datasets.h"
32#include "tests/validation/Validation.h"
33#include "tests/validation/fixtures/FFTFixture.h"
34
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
41namespace
42{
43const auto data_types = framework::dataset::make("DataType", { DataType::F32 });
44const auto shapes_1d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 2U, 3U),
45 TensorShape(4U, 2U, 3U), TensorShape(5U, 2U, 3U),
46 TensorShape(7U, 2U, 3U), TensorShape(8U, 2U, 3U),
47 TensorShape(9U, 2U, 3U), TensorShape(25U, 2U, 3U),
48 TensorShape(49U, 2U, 3U), TensorShape(64U, 2U, 3U),
49 TensorShape(16U, 2U, 3U), TensorShape(32U, 2U, 3U),
50 TensorShape(96U, 2U, 2U)
51 });
52
giuros0105fb4482019-03-26 17:44:40 +000053const auto shapes_2d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 6U, 3U),
54 TensorShape(4U, 5U, 3U), TensorShape(5U, 7U, 3U),
55 TensorShape(7U, 25U, 3U), TensorShape(8U, 2U, 3U),
56 TensorShape(9U, 16U, 3U), TensorShape(25U, 32U, 3U),
57 TensorShape(192U, 128U, 2U)
58 });
59
giuros0114c4e0f2019-03-26 17:44:40 +000060const auto ActivationFunctionsSmallDataset = framework::dataset::make("ActivationInfo",
61{
62 ActivationLayerInfo(),
63 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f)
64});
65
66RelativeTolerance<float> tolerance_f32(0.1f); /**< Relative tolerance value for FP32 */
67constexpr float tolerance_num = 0.07f; /**< Tolerance number */
68
69} // namespace
70TEST_SUITE(NEON)
71TEST_SUITE(FFT1D)
72
73DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_1d, data_types),
74 shape, data_type)
75{
76 // Create tensors
77 Tensor src = create_tensor<Tensor>(shape, data_type, 2);
78 Tensor dst = create_tensor<Tensor>(shape, data_type, 2);
79
80 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
82
83 // Create and configure function
84 NEFFT1D fft1d;
85 fft1d.configure(&src, &dst, FFT1DInfo());
86
87 // Validate valid region
88 const ValidRegion valid_region = shape_to_valid_region(shape);
89 validate(src.info()->valid_region(), valid_region);
90 validate(dst.info()->valid_region(), valid_region);
91
92 // Validate padding
93 validate(src.info()->padding(), PaddingSize());
94 validate(dst.info()->padding(), PaddingSize());
95}
96
97// *INDENT-OFF*
98// clang-format off
99DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
100 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching data types
101 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching shapes
102 TensorInfo(TensorShape(32U, 13U, 2U), 3, DataType::F32), // Invalid channels
103 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Unsupported axis
104 TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT
105 TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
106 }),
107 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F16),
108 TensorInfo(TensorShape(16U, 13U, 2U), 2, DataType::F32),
109 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
110 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
111 TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32),
112 TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
113 })),
114 framework::dataset::make("Axis", { 0, 0, 0, 2, 0, 0 })),
115 framework::dataset::make("Expected", { false, false, false, false, false, true })),
116 input_info, output_info, axis, expected)
117{
118 FFT1DInfo desc;
119 desc.axis = axis;
120 const Status s = NEFFT1D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), desc);
121 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
122}
123// clang-format on
124// *INDENT-ON*
125
126template <typename T>
127using NEFFT1DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT1D, FFT1DInfo, T>;
128
129TEST_SUITE(Float)
130TEST_SUITE(FP32)
131FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT1DFixture<float>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F32)))
132{
133 // Validate output
134 validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
135}
136TEST_SUITE_END() // FP32
137TEST_SUITE_END() // Float
giuros0114c4e0f2019-03-26 17:44:40 +0000138TEST_SUITE_END() // FFT1D
giuros0105fb4482019-03-26 17:44:40 +0000139
140TEST_SUITE(FFT2D)
141
142DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_2d, data_types),
143 shape, data_type)
144{
145 // Create tensors
146 Tensor src = create_tensor<Tensor>(shape, data_type, 2);
147 Tensor dst = create_tensor<Tensor>(shape, data_type, 2);
148
149 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
150 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
151
152 // Create and configure function
153 NEFFT2D fft2d;
154 fft2d.configure(&src, &dst, FFT2DInfo());
155
156 // Validate valid region
157 const ValidRegion valid_region = shape_to_valid_region(shape);
158 validate(src.info()->valid_region(), valid_region);
159 validate(dst.info()->valid_region(), valid_region);
160
161 // Validate padding
162 validate(src.info()->padding(), PaddingSize());
163 validate(dst.info()->padding(), PaddingSize());
164}
165
166// *INDENT-OFF*
167// clang-format off
168DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
169 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching data types
170 TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching shapes
171 TensorInfo(TensorShape(32U, 25U, 2U), 3, DataType::F32), // Invalid channels
172 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT
173 TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32),
174 }),
175 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F16),
176 TensorInfo(TensorShape(16U, 25U, 2U), 2, DataType::F32),
177 TensorInfo(TensorShape(32U, 25U, 2U), 1, DataType::F32),
178 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
179 TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32),
180 })),
181 framework::dataset::make("Expected", { false, false, false, false, true })),
182 input_info, output_info, expected)
183{
184 const Status s = NEFFT2D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), FFT2DInfo());
185 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
186}
187// clang-format on
188// *INDENT-ON*
189
190template <typename T>
191using NEFFT2DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT2D, FFT2DInfo, T>;
192
193TEST_SUITE(Float)
194TEST_SUITE(FP32)
195FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT2DFixture<float>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F32)))
196{
197 // Validate output
198 validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
199}
200TEST_SUITE_END() // FP32
201TEST_SUITE_END() // Float
202TEST_SUITE_END() // FFT2D
203
giuros0114c4e0f2019-03-26 17:44:40 +0000204TEST_SUITE_END() // NEON
205} // namespace validation
206} // namespace test
207} // namespace arm_compute