blob: 12d53b522ed0ad595632e6bfc1d452d9ae74e352 [file] [log] [blame]
Georgios Pinitas0bc78492019-03-18 20:07:37 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019 Arm Limited.
Georgios Pinitas0bc78492019-03-18 20:07:37 +00003 *
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 Pinitas8be91482019-03-26 17:23:28 +000027#include "arm_compute/runtime/CL/functions/CLFFT2D.h"
28#include "arm_compute/runtime/CL/functions/CLFFTConvolutionLayer.h"
Georgios Pinitas0bc78492019-03-18 20:07:37 +000029#include "tests/CL/CLAccessor.h"
Georgios Pinitas8be91482019-03-26 17:23:28 +000030#include "tests/datasets/SmallConvolutionLayerDataset.h"
Georgios Pinitas0bc78492019-03-18 20:07:37 +000031#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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45const auto data_types = framework::dataset::make("DataType", { DataType::F32 });
Georgios Pinitas8be91482019-03-26 17:23:28 +000046const auto shapes_1d = framework::dataset::make("TensorShape", { TensorShape(2U, 2U, 3U), TensorShape(3U, 2U, 3U),
Georgios Pinitas0bc78492019-03-18 20:07:37 +000047 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 Pinitas8be91482019-03-26 17:23:28 +000054const 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
61const auto ActivationFunctionsSmallDataset = framework::dataset::make("ActivationInfo",
62{
63 ActivationLayerInfo(),
64 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 0.5f)
65});
66
67RelativeTolerance<float> tolerance_f32(0.1f); /**< Relative tolerance value for FP32 */
68constexpr float tolerance_num = 0.07f; /**< Tolerance number */
69
Georgios Pinitas0bc78492019-03-18 20:07:37 +000070} // namespace
71TEST_SUITE(CL)
72TEST_SUITE(FFT1D)
73
Georgios Pinitas8be91482019-03-26 17:23:28 +000074DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_1d, data_types),
Georgios Pinitas0bc78492019-03-18 20:07:37 +000075 shape, data_type)
76{
77 // Create tensors
78 CLTensor src = create_tensor<CLTensor>(shape, data_type, 2);
79 CLTensor dst = create_tensor<CLTensor>(shape, data_type, 2);
80
81 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
83
84 // Create and configure function
85 CLFFT1D fft1d;
86 fft1d.configure(&src, &dst, FFT1DInfo());
87
88 // Validate valid region
89 const ValidRegion valid_region = shape_to_valid_region(shape);
90 validate(src.info()->valid_region(), valid_region);
91 validate(dst.info()->valid_region(), valid_region);
92
93 // Validate padding
94 validate(src.info()->padding(), PaddingSize());
95 validate(dst.info()->padding(), PaddingSize());
96}
97
98// *INDENT-OFF*
99// clang-format off
100DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
101 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching data types
102 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching shapes
Georgios Pinitas8be91482019-03-26 17:23:28 +0000103 TensorInfo(TensorShape(32U, 13U, 2U), 3, DataType::F32), // Invalid channels
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000104 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Unsupported axis
105 TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT
106 TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
107 }),
108 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F16),
109 TensorInfo(TensorShape(16U, 13U, 2U), 2, DataType::F32),
Georgios Pinitas8be91482019-03-26 17:23:28 +0000110 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000111 TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
112 TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32),
113 TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
114 })),
Georgios Pinitas8be91482019-03-26 17:23:28 +0000115 framework::dataset::make("Axis", { 0, 0, 0, 2, 0, 0 })),
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000116 framework::dataset::make("Expected", { false, false, false, false, false, true })),
117 input_info, output_info, axis, expected)
118{
119 FFT1DInfo desc;
120 desc.axis = axis;
121 const Status s = CLFFT1D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), desc);
122 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
123}
124// clang-format on
125// *INDENT-ON*
126
127template <typename T>
Georgios Pinitas8be91482019-03-26 17:23:28 +0000128using CLFFT1DFixture = FFTValidationFixture<CLTensor, CLAccessor, CLFFT1D, FFT1DInfo, T>;
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000129
130TEST_SUITE(Float)
131TEST_SUITE(FP32)
Georgios Pinitas8be91482019-03-26 17:23:28 +0000132FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT1DFixture<float>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F32)))
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000133{
134 // Validate output
Georgios Pinitas8be91482019-03-26 17:23:28 +0000135 validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num);
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000136}
137TEST_SUITE_END() // FP32
138TEST_SUITE_END() // Float
139
140TEST_SUITE_END() // FFT1D
Georgios Pinitas8be91482019-03-26 17:23:28 +0000141
142TEST_SUITE(FFT2D)
143
144DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(shapes_2d, data_types),
145 shape, data_type)
146{
147 // Create tensors
148 CLTensor src = create_tensor<CLTensor>(shape, data_type, 2);
149 CLTensor dst = create_tensor<CLTensor>(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 CLFFT2D 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
170DATA_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 = CLFFT2D::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
192template <typename T>
193using CLFFT2DFixture = FFTValidationFixture<CLTensor, CLAccessor, CLFFT2D, FFT2DInfo, T>;
194
195TEST_SUITE(Float)
196TEST_SUITE(FP32)
197FIXTURE_DATA_TEST_CASE(RunSmall, CLFFT2DFixture<float>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F32)))
198{
199 // Validate output
200 validate(CLAccessor(_target), _reference, tolerance_f32, tolerance_num);
201}
202TEST_SUITE_END() // FP32
203TEST_SUITE_END() // Float
204TEST_SUITE_END() // FFT2D
205
206TEST_SUITE(FFTConvolutionLayer)
207
208template <typename T>
209using CLFFTConvolutionLayerFixture = FFTConvolutionValidationFixture<CLTensor, CLAccessor, CLFFTConvolutionLayer, T>;
210
211TEST_SUITE(Float)
212TEST_SUITE(FP32)
213FIXTURE_DATA_TEST_CASE(RunSmall, CLFFTConvolutionLayerFixture<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(CLAccessor(_target), _reference, tolerance_f32, tolerance_num);
220}
221TEST_SUITE_END() // FP32
222TEST_SUITE_END() // Float
223TEST_SUITE_END() // FFTConvolutionLayer
224
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000225TEST_SUITE_END() // CL
226} // namespace validation
227} // namespace test
228} // namespace arm_compute