Compute Library
 23.05
DFT.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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  */
25 #include "arm_compute/core/Types.h"
26 #include "tests/AssetsLibrary.h"
27 #include "tests/Globals.h"
28 #include "tests/SimpleTensor.h"
31 #include "tests/framework/Macros.h"
33 
37 
38 #include <random>
39 
40 namespace arm_compute
41 {
42 namespace test
43 {
44 namespace validation
45 {
46 namespace
47 {
48 auto shapes_1d_dft = framework::dataset::make("TensorShape", { TensorShape(33U),
49  TensorShape(8U),
50  TensorShape(23U, 7U),
51  TensorShape(16U, 8U, 4U)
52  });
53 
54 auto shapes_2d_dft = framework::dataset::make("TensorShape", { TensorShape(33U, 14U),
55  TensorShape(8U, 9U),
56  TensorShape(23U, 7U, 3U),
57  TensorShape(16U, 8U, 4U)
58  });
59 
60 auto conv_dataset_dft = framework::dataset::zip(framework::dataset::zip(framework::dataset::make("InputShape", { TensorShape(8U, 7U, 3U, 2U),
61  TensorShape(18U, 22U, 4U),
62  TensorShape(32U, 48U, 8U)
63  }),
64  framework::dataset::make("WeightShape", { TensorShape(3U, 3U, 3U, 6U),
65  TensorShape(5U, 5U, 4U, 3U),
66  TensorShape(9U, 9U, 8U, 3U)
67  })),
68  framework::dataset::make("ConvInfo", { PadStrideInfo(1, 1, 1, 1),
69  PadStrideInfo(1, 1, 2, 2),
70  PadStrideInfo(1, 1, 4, 4)
71  }));
72 } // namespace
73 TEST_SUITE(CPP)
74 TEST_SUITE(DFT)
75 
76 TEST_SUITE(DFT1D)
77 DATA_TEST_CASE(Real, framework::DatasetMode::ALL, shapes_1d_dft,
78  shape)
79 {
81  std::uniform_real_distribution<float> distribution(-5.f, 5.f);
82  library->fill(src, distribution, 0);
83 
84  const bool is_odd = shape.x() % 2;
85 
86  // Forward pass
88  // Backward pass
89  auto backward = reference::ridft_1d(forward, is_odd);
90 
91  // Validate with input
93 }
94 
96  shape)
97 {
99  std::uniform_real_distribution<float> distribution(-5.f, 5.f);
100  library->fill(src, distribution, 0);
101 
102  // Forward pass
104  // Backward pass
106 
107  // Validate with input
109 }
110 TEST_SUITE_END() // DFT1D
111 
112 TEST_SUITE(DFT2D)
113 DATA_TEST_CASE(Real, framework::DatasetMode::ALL, shapes_2d_dft,
114  shape)
115 {
117  std::uniform_real_distribution<float> distribution(-5.f, 5.f);
118  library->fill(src, distribution, 0);
119 
120  const bool is_odd = shape.x() % 2;
121 
122  // Forward pass
124  // Backward pass
126 
127  // Validate with input
129 }
130 
132  shape)
133 {
135  std::uniform_real_distribution<float> distribution(-5.f, 5.f);
136  library->fill(src, distribution, 0);
137 
138  // Forward pass
140  // Backward pass
142 
143  // Validate with input
145 }
146 TEST_SUITE_END() // DFT2D
147 
148 TEST_SUITE(Conv)
149 DATA_TEST_CASE(Real2Real, framework::DatasetMode::ALL, conv_dataset_dft,
151 {
152  std::uniform_real_distribution<float> distribution(-1.f, 1.f);
153  std::uniform_real_distribution<float> distribution_b(0.f, 0.f);
154 
158 
159  library->fill(src, distribution, 0);
160  library->fill(w, distribution, 1);
161  library->fill(b, distribution_b, 2);
162 
163  const auto output_wh = arm_compute::scaled_dimensions(shape_in.x(), shape_in.y(), shape_w.x(), shape_w.y(), conv_info);
165  dst_shape.set(0, output_wh.first);
166  dst_shape.set(1, output_wh.second);
167  dst_shape.set(2, shape_w[3]);
168 
169  // FFT based convolution
170  auto dst = reference::conv2d_dft(src, w, conv_info);
171  // Reference convolution
172  auto dst_ref = reference::convolution_layer(src, w, b, dst_shape, conv_info);
173 
174  // Validate with input
176 }
177 TEST_SUITE_END() // Conv
178 
179 TEST_SUITE_END() // DFT
180 TEST_SUITE_END() // CPP
181 } // namespace validation
182 } // namespace test
183 } // namespace arm_compute
SimpleTensor< float > w
Definition: DFT.cpp:156
Shape of a tensor.
Definition: TensorShape.h:39
Class reprensenting an absolute tolerance value.
Definition: Validation.h:61
SimpleTensor< T > dft_2d(const SimpleTensor< T > &src, FFTDirection direction)
Performs a two dimensional DFT on a complex input.
Definition: DFT.cpp:370
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
SimpleTensor< float > b
Definition: DFT.cpp:157
SimpleTensor< T > ridft_1d(const SimpleTensor< T > &src, bool is_odd)
Performs an one dimensional inverse DFT on a real input.
Definition: DFT.cpp:319
Accessor implementation for SimpleTensor objects.
1 channel, 1 F32 per channel
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2023 Arm Limited.
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:429
SimpleTensor< T > dft_1d(const SimpleTensor< T > &src, FFTDirection direction)
Performs an one dimensional DFT on a complex input.
Definition: DFT.cpp:330
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)
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:76
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
validate(CLAccessor(output_state), expected_output)
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
SimpleTensor< T > ridft_2d(const SimpleTensor< T > &src, bool is_odd)
Performs a two dimensional inverse DFT on a real input.
Definition: DFT.cpp:354
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
SimpleTensor< T > rdft_2d(const SimpleTensor< T > &src)
Performs a two dimensional DFT on a real input.
Definition: DFT.cpp:342
SimpleTensor< T > convolution_layer(const SimpleTensor< T > &src, const SimpleTensor< TW > &weights, const SimpleTensor< TB > &bias, const TensorShape &output_shape, const PadStrideInfo &info, const Size2D &dilation, unsigned int num_groups, QuantizationInfo out_quant_info)
Class reprensenting a relative tolerance value.
Definition: Validation.h:97
std::uniform_real_distribution< float > distribution_b(0.f, 0.f)
SimpleTensor< T > conv2d_dft(const SimpleTensor< T > &src, const SimpleTensor< T > &w, const PadStrideInfo &conv_info)
Performs and DFT based convolution on a real input.
Definition: DFT.cpp:396
SimpleTensor< T > rdft_1d(const SimpleTensor< T > &src)
Performs an one dimensional DFT on a real input.
Definition: DFT.cpp:313
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79
ZipDataset< T, U > zip(T &&dataset1, U &&dataset2)
Helper function to create a ZipDataset.
Definition: ZipDataset.h:149