Compute Library
 21.02
NEScaleKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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 #ifndef ARM_COMPUTE_NESCALEKERNEL_H
25 #define ARM_COMPUTE_NESCALEKERNEL_H
26 
29 
30 namespace arm_compute
31 {
32 class ITensor;
33 
34 /** Neon kernel to perform scaling on a tensor */
35 class NEScaleKernel : public INEKernel
36 {
37 public:
38  const char *name() const override
39  {
40  return "NEScaleKernel";
41  }
42  /** Default constructor */
43  NEScaleKernel();
44  /** Prevent instances of this class from being copied (As this class contains pointers) */
45  NEScaleKernel(const NEScaleKernel &) = delete;
46  /** Prevent instances of this class from being copied (As this class contains pointers) */
47  NEScaleKernel &operator=(const NEScaleKernel &) = delete;
48  /** Allow instances of this class to be moved */
49  NEScaleKernel(NEScaleKernel &&) = default;
50  /** Allow instances of this class to be moved */
51  NEScaleKernel &operator=(NEScaleKernel &&) = default;
52  /** Default destructor */
53  ~NEScaleKernel() = default;
54 
55  /** Initialise the kernel's inputs, output and interpolation policy
56  *
57  * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
58  * @note Using @p policy Area only supports data layout NCHW and input data type U8.
59  *
60  * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
61  * @param[in] dx Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
62  * @param[in] dy Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
63  * @param[in] offsets Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
64  * @param[out] output Destination tensor. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
65  * @param[in] info @ref ScaleKernelInfo to use for configuration
66  */
67  void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output,
68  const ScaleKernelInfo &info);
69  /** Static function to check if given info will lead to a valid configuration of @ref NEScaleKernel
70  *
71  * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
72  * @note Using @p policy Area only supports data layout NCHW and input data type U8.
73  *
74  * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
75  * @param[in] dx Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
76  * @param[in] dy Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
77  * @param[in] offsets Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
78  * @param[in] output Destination tensor. Data types supported: Same as @p input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
79  * @param[in] info @ref ScaleKernelInfo to use for validation
80  */
81  static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output,
82  const ScaleKernelInfo &info);
83 
84  // Inherited methods overridden:
85  void run(const Window &window, const ThreadInfo &info) override;
86 
87 private:
88  /** function to perform scale using area interpolation on the given window
89  *
90  * @note Used only in case down-sampling.
91  */
92  void scale_area_nchw_u8(const Window &window);
93 
94  /** function to perform scale using bilinear interpolation on the given window */
95  template <typename T>
96  void scale_bilinear_nchw(const Window &window);
97  /** function to perform scale using bilinear interpolation on the given window */
98  template <typename T>
99  void scale_bilinear_qasymm(const Window &window);
100 
101  /** function to perform scale using nearest neighbour on the given window */
102  template <typename T>
103  void scale_nearest_nchw(const Window &window);
104 
105  /** Scale function to use for the particular function to use */
106  using ScaleFunctionPtr = void (NEScaleKernel::*)(const Window &window);
107 
108  ScaleFunctionPtr _func;
109  const ITensor *_offsets;
110  const ITensor *_dx;
111  const ITensor *_dy;
112  const ITensor *_input;
113  ITensor *_output;
114  InterpolationPolicy _policy;
115  BorderMode _border_mode;
116  PixelValue _constant_border_value;
117  float _sampling_offset;
118  bool _align_corners;
119  DataLayout _data_layout;
120 };
121 } // namespace arm_compute
122 #endif /*ARM_COMPUTE_NESCALEKERNEL_H */
BorderMode
Methods available to handle borders.
Definition: Types.h:265
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
InterpolationPolicy
Interpolation method.
Definition: Types.h:392
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for Neon tensor.
Definition: ITensor.h:36
NEScaleKernel & operator=(const NEScaleKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Copyright (c) 2017-2021 Arm Limited.
static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration of NEScaleKernel.
void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, const ScaleKernelInfo &info)
Initialise the kernel&#39;s inputs, output and interpolation policy.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:235
~NEScaleKernel()=default
Default destructor.
const char * name() const override
Name of the kernel.
Definition: NEScaleKernel.h:38
DataLayout
[DataLayout enum definition]
Definition: Types.h:120
Describe a multidimensional execution window.
Definition: Window.h:39
NEScaleKernel()
Default constructor.
Neon kernel to perform scaling on a tensor.
Definition: NEScaleKernel.h:35