Compute Library
 22.11
FFT.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 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"
29 #include "tests/NEON/Accessor.h"
30 #include "tests/datasets/SmallConvolutionLayerDataset.h"
32 #include "tests/framework/Macros.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 
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 
62 const auto ActivationFunctionsSmallDataset = framework::dataset::make("ActivationInfo",
63 {
64  ActivationLayerInfo(),
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 // *INDENT-OFF*
76 // clang-format off
78  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching data types
79  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Mismatching shapes
80  TensorInfo(TensorShape(32U, 13U, 2U), 3, DataType::F32), // Invalid channels
81  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Unsupported axis
82  TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT
83  TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
84  }),
85  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F16),
86  TensorInfo(TensorShape(16U, 13U, 2U), 2, DataType::F32),
87  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
88  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
89  TensorInfo(TensorShape(11U, 13U, 2U), 2, DataType::F32),
90  TensorInfo(TensorShape(25U, 13U, 2U), 2, DataType::F32),
91  })),
92  framework::dataset::make("Axis", { 0, 0, 0, 2, 0, 0 })),
93  framework::dataset::make("Expected", { false, false, false, false, false, true })),
95 {
96  FFT1DInfo desc;
97  desc.axis = axis;
98  const Status s = NEFFT1D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), desc);
100 }
101 // clang-format on
102 // *INDENT-ON*
103 
104 template <typename T>
105 using NEFFT1DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT1D, FFT1DInfo, T>;
106 
107 TEST_SUITE(Float)
108 TEST_SUITE(FP32)
109 FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT1DFixture<float>, framework::DatasetMode::ALL, combine(shapes_1d, framework::dataset::make("DataType", DataType::F32)))
110 {
111  // Validate output
112  validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
113 }
114 TEST_SUITE_END() // FP32
115 TEST_SUITE_END() // Float
116 TEST_SUITE_END() // FFT1D
117 
118 TEST_SUITE(FFT2D)
119 // *INDENT-OFF*
120 // clang-format off
122  framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching data types
123  TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32), // Mismatching shapes
124  TensorInfo(TensorShape(32U, 25U, 2U), 3, DataType::F32), // Invalid channels
125  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32), // Undecomposable FFT
126  TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32),
127  }),
128  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F16),
129  TensorInfo(TensorShape(16U, 25U, 2U), 2, DataType::F32),
130  TensorInfo(TensorShape(32U, 25U, 2U), 1, DataType::F32),
131  TensorInfo(TensorShape(32U, 13U, 2U), 2, DataType::F32),
132  TensorInfo(TensorShape(32U, 25U, 2U), 2, DataType::F32),
133  })),
134  framework::dataset::make("Expected", { false, false, false, false, true })),
136 {
137  const Status s = NEFFT2D::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), FFT2DInfo());
139 }
140 // clang-format on
141 // *INDENT-ON*
142 
143 template <typename T>
144 using NEFFT2DFixture = FFTValidationFixture<Tensor, Accessor, NEFFT2D, FFT2DInfo, T>;
145 
146 TEST_SUITE(Float)
147 TEST_SUITE(FP32)
148 FIXTURE_DATA_TEST_CASE(RunSmall, NEFFT2DFixture<float>, framework::DatasetMode::ALL, combine(shapes_2d, framework::dataset::make("DataType", DataType::F32)))
149 {
150  // Validate output
151  validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
152 }
153 TEST_SUITE_END() // FP32
154 TEST_SUITE_END() // Float
155 TEST_SUITE_END() // FFT2D
156 
157 TEST_SUITE(FFTConvolutionLayer)
158 
159 template <typename T>
160 using NEFFTConvolutionLayerFixture = FFTConvolutionValidationFixture<Tensor, Accessor, NEFFTConvolutionLayer, T>;
161 template <typename T>
162 using NEFFTConvolutionLayerMixedDataLayoutFixture = FFTConvolutionValidationFixture<Tensor, Accessor, NEFFTConvolutionLayer, T, true>;
163 
164 TEST_SUITE(Float)
165 TEST_SUITE(FP32)
166 FIXTURE_DATA_TEST_CASE(RunSmall, NEFFTConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFFTConvolutionLayerDataset(),
167  framework::dataset::make("DataType", DataType::F32)),
168  framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
169  ActivationFunctionsSmallDataset))
170 {
171  // Validate output
172  validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
173 }
177  ActivationFunctionsSmallDataset))
178 {
179  // Validate output
180  validate(Accessor(_target), _reference, tolerance_f32, tolerance_num);
181 }
182 TEST_SUITE_END() // FP32
183 TEST_SUITE_END() // Float
184 TEST_SUITE_END() // FFTConvolutionLayer
185 TEST_SUITE_END() // Neon
186 } // namespace validation
187 } // namespace test
188 } // namespace arm_compute
FFTConvolutionValidationFixture< Tensor, Accessor, NEFFTConvolutionLayer, T, true > NEFFTConvolutionLayerMixedDataLayoutFixture
Definition: FFT.cpp:162
FFTValidationFixture< Tensor, Accessor, NEFFT1D, FFT1DInfo, T > NEFFT1DFixture
Definition: FFT.cpp:105
Shape of a tensor.
Definition: TensorShape.h:39
Descriptor used by the FFT2D function.
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
FFTValidationFixture< Tensor, Accessor, NEFFT2D, FFT2DInfo, T > NEFFT2DFixture
Definition: FFT.cpp:144
Status class.
Definition: Error.h:52
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const FFT2DInfo &config)
Static function to check if given info will lead to a valid configuration of NEFFT2D.
Definition: NEFFT2D.cpp:61
RelativeTolerance< float > tolerance_f32(0.01f)
Tolerance value for comparing reference&#39;s output against implementation&#39;s output for DataType::F32...
validate(CLAccessor(output_state), expected_output)
Num samples, channels, height, width.
constexpr float tolerance_num
Tolerance number.
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Num samples, height, width, channels.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const FFT1DInfo &config)
Static function to check if given info will lead to a valid configuration of NEFFT1D.
Definition: NEFFT1D.cpp:111
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65