Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NESCALEKERNEL_H |
| 25 | #define ARM_COMPUTE_NESCALEKERNEL_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/KernelDescriptors.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/NEON/INEKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 38 | const char *name() const override |
| 39 | { |
| 40 | return "NEScaleKernel"; |
| 41 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 58 | * @note Using @p policy Area only supports data layout NCHW and input data type U8. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | * |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 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 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | */ |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 67 | void configure(const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 68 | const ScaleKernelInfo &info); |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 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 |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 72 | * @note Using @p policy Area only supports data layout NCHW and input data type U8. |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 73 | * |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 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 |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 80 | */ |
| 81 | static Status validate(const ITensorInfo *input, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 82 | const ScaleKernelInfo &info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | |
| 84 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 85 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | BorderSize border_size() const override; |
| 87 | |
| 88 | private: |
| 89 | /** function to perform scale using nearest interpolation on the given window */ |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 90 | void scale_nearest_nchw(const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 91 | /** function to perform scale using bilinear interpolation on the given window */ |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 92 | void scale_bilinear_nchw(const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | /** function to perform scale using area interpolation on the given window |
| 94 | * |
| 95 | * @note Used only in case down-sampling. |
| 96 | */ |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 97 | void scale_area_nchw(const Window &window); |
| 98 | /** function to perform scale on the given window */ |
| 99 | void scale_nhwc(const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | /** Scale function to use for the particular interpolation type passed to configure() */ |
| 101 | void (NEScaleKernel::*_func)(const Window &window); |
| 102 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 103 | const ITensor *_offsets; |
| 104 | const ITensor *_dx; |
| 105 | const ITensor *_dy; |
| 106 | const ITensor *_input; |
| 107 | ITensor *_output; |
| 108 | InterpolationPolicy _policy; |
| 109 | BorderSize _border_size; |
| 110 | BorderMode _border_mode; |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 111 | PixelValue _constant_border_value; |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 112 | float _sampling_offset; |
George Wort | 05398a9 | 2019-01-25 15:38:33 +0000 | [diff] [blame] | 113 | bool _use_padding; |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 114 | bool _align_corners; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 115 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 116 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 117 | #endif /*ARM_COMPUTE_NESCALEKERNEL_H */ |