blob: b720288c5ca63330b217a5e79274e4d1d1f22245 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +00002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NESCALEKERNEL_H
25#define ARM_COMPUTE_NESCALEKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/core/Types.h"
29
30namespace arm_compute
31{
32class ITensor;
33
34/** NEON kernel to perform scaling on a tensor */
35class NEScaleKernel : public INEKernel
36{
37public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000038 const char *name() const override
39 {
40 return "NEScaleKernel";
41 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 /** 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
George Wort05398a92019-01-25 15:38:33 +000058 * @note Using @p policy Area only supports data layout NCHW and input data type U8.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 *
George Wort05398a92019-01-25 15:38:33 +000060 * @param[in] input Source tensor. Data types supported: 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] policy Interpolation type to use
66 * @param[in] border_mode Border mode policy
67 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false.
68 * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
69 * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +010071 void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output,
George Wort05398a92019-01-25 15:38:33 +000072 InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(),
73 SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true);
Georgios Pinitas20b43132018-05-14 16:05:23 +010074 /** Static function to check if given info will lead to a valid configuration of @ref NEScaleKernel
75 *
76 * @note dx, dy and offsets have the same dimensions (width and height) of the output tensor
George Wort05398a92019-01-25 15:38:33 +000077 * @note Using @p policy Area only supports data layout NCHW and input data type U8.
Georgios Pinitas20b43132018-05-14 16:05:23 +010078 *
George Wort05398a92019-01-25 15:38:33 +000079 * @param[in] input Source tensor. Data types supported: U8/S16/F16/F32.
80 * @param[in] dx Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
81 * @param[in] dy Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
82 * @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.
83 * @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.
84 * @param[in] policy Interpolation type to use
85 * @param[in] border_mode Border mode policy
86 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false.
87 * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
88 * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
Georgios Pinitas20b43132018-05-14 16:05:23 +010089 */
90 static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output,
George Wort05398a92019-01-25 15:38:33 +000091 InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value = PixelValue(),
92 SamplingPolicy sampling_policy = SamplingPolicy::CENTER, bool use_padding = true);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093
94 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010095 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096 BorderSize border_size() const override;
97
98private:
99 /** function to perform scale using nearest interpolation on the given window */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100100 void scale_nearest_nchw(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101 /** function to perform scale using bilinear interpolation on the given window */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100102 void scale_bilinear_nchw(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103 /** function to perform scale using area interpolation on the given window
104 *
105 * @note Used only in case down-sampling.
106 */
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100107 void scale_area_nchw(const Window &window);
108 /** function to perform scale on the given window */
109 void scale_nhwc(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110 /** Scale function to use for the particular interpolation type passed to configure() */
111 void (NEScaleKernel::*_func)(const Window &window);
112
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100113 const ITensor *_offsets;
114 const ITensor *_dx;
115 const ITensor *_dy;
116 const ITensor *_input;
117 ITensor *_output;
118 InterpolationPolicy _policy;
119 BorderSize _border_size;
120 BorderMode _border_mode;
George Wort05398a92019-01-25 15:38:33 +0000121 PixelValue _constant_border_value;
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000122 float _sampling_offset;
George Wort05398a92019-01-25 15:38:33 +0000123 bool _use_padding;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100125} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000126#endif /*ARM_COMPUTE_NESCALEKERNEL_H */