Compute Library
 21.05
NEFFTScaleKernel.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  */
25 
28 #include "arm_compute/core/Types.h"
34 
35 #include <arm_neon.h>
36 
37 namespace arm_compute
38 {
39 namespace
40 {
41 void scale_complex(float *c_in, float *c_out, bool is_conjugate, float scale)
42 {
43  const auto a = wrapper::vload(c_in);
44  auto b = wrapper::vdiv(a, float32x2_t{ scale, scale });
45  if(is_conjugate)
46  {
47  const float img_part = wrapper::vgetlane(b, 1);
48  b = wrapper::vsetlane(-img_part, b, 1);
49  }
50 
51  wrapper::vstore(c_out, b);
52 }
53 
54 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output)
55 {
57 
58  // Checks performed when output is configured
59  if((output != nullptr) && (output->total_size() != 0))
60  {
61  ARM_COMPUTE_RETURN_ERROR_ON(output->num_channels() != 1 && output->num_channels() != 2);
64  }
65 
66  return Status{};
67 }
68 
69 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
70 {
71  // Configure kernel window
72  Window win = calculate_max_window(*input, Steps());
73 
74  if(output != nullptr)
75  {
76  // Output auto inizialitation if not yet initialized
77  auto_init_if_empty(*output, *input->clone());
78 
79  // NEFFTScaleKernel doesn't need padding so update_window_and_padding() can be skipped
80  }
81 
82  return std::make_pair(Status{}, win);
83 }
84 } // namespace
85 
87  : _input(nullptr), _output(nullptr), _scale(), _run_in_place(false), _is_conj(false)
88 {
89 }
90 
92 {
94  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), (output != nullptr) ? output->info() : nullptr));
95 
96  _input = input;
97  _output = output;
98  _run_in_place = (output == nullptr) || (output == input);
99  _is_conj = config.conjugate;
100  _scale = config.scale;
101 
102  // Configure kernel window
103  auto win_config = validate_and_configure_window(input->info(), _run_in_place ? nullptr : output->info());
104  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
105  INEKernel::configure(win_config.second);
106 }
107 
109 {
110  ARM_COMPUTE_UNUSED(config);
112  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
113 
114  return Status{};
115 }
116 
117 void NEFFTScaleKernel::run(const Window &window, const ThreadInfo &info)
118 {
122 
123  Window input_window = window;
124  input_window.set(Window::DimX, 0);
125 
126  Iterator in(_input, input_window);
127  Iterator out(_run_in_place ? _input : _output, input_window);
128 
130  {
131  scale_complex(reinterpret_cast<float *>(in.ptr()), reinterpret_cast<float *>(out.ptr()), _is_conj, _scale);
132  },
133  in, out);
134 }
135 } // namespace arm_compute
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
float32x2_t vdiv(const float32x2_t &a, const float32x2_t &b)
Definition: div.h:58
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
SimpleTensor< float > b
Definition: DFT.cpp:157
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const FFTScaleKernelInfo &config)
Static function to check if given info will lead to a valid configuration of NEFFTScaleKernel.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
1 channel, 1 F32 per channel
Store the tensor's metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
uint8_t vgetlane(const uint8x8_t vector, const unsigned int lane)
Definition: getlane.h:91
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Coordinates of an item.
Definition: Coordinates.h:37
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Descriptor for FFT scale kernels.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
Definition: Helpers.inl:139
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
uint8x8_t vsetlane(const uint8_t value, const uint8x8_t vector, const unsigned int lane)
Definition: setlane.h:91
void configure(ITensor *input, ITensor *output, const FFTScaleKernelInfo &config)
Set the input and output tensors.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:252
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
uint8x8_t vload(const uint8_t *ptr)
Definition: load.h:39
void vstore(uint8_t *ptr, uint8x8_t val)
Definition: store.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77
Includes all wrapper headers at once.
float scale
Axis to perform the kernel on.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:46
Describe a multidimensional execution window.
Definition: Window.h:39
bool conjugate
Flag to conjugate the output/.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201