Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [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 | */ |
| 24 | #include "arm_compute/core/CL/kernels/CLScaleKernel.h" |
| 25 | |
| 26 | #include "arm_compute/core/AccessWindowStatic.h" |
| 27 | #include "arm_compute/core/CL/CLHelpers.h" |
| 28 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Vidhya Sudhan Loganathan | f1f4906 | 2018-05-25 13:21:26 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/CLValidate.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/CL/ICLKernel.h" |
| 31 | #include "arm_compute/core/CL/ICLTensor.h" |
| 32 | #include "arm_compute/core/CL/OpenCL.h" |
| 33 | #include "arm_compute/core/Error.h" |
| 34 | #include "arm_compute/core/Helpers.h" |
| 35 | #include "arm_compute/core/TensorInfo.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 36 | #include "support/StringSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 38 | #include "src/core/utils/ScaleUtils.h" |
| 39 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | #include <set> |
| 41 | #include <string> |
| 42 | |
| 43 | using namespace arm_compute; |
| 44 | |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 45 | namespace |
| 46 | { |
Sang-Hoon Park | 5b7fd87 | 2020-01-09 15:27:51 +0000 | [diff] [blame] | 47 | inline std::pair<float, float> calculate_scale_factors(const ITensorInfo &input, const ITensorInfo &output, bool align_corners) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 48 | { |
| 49 | DataLayout data_layout = input.data_layout(); |
| 50 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 51 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 52 | |
| 53 | // Compute the ratio between source width/height and destination width/height |
| 54 | const unsigned int input_width = input.dimension(idx_width); |
| 55 | const unsigned int input_height = input.dimension(idx_height); |
| 56 | const unsigned int output_width = output.dimension(idx_width); |
| 57 | const unsigned int output_height = output.dimension(idx_height); |
| 58 | |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 59 | float wr = arm_compute::scale_utils::calculate_resize_ratio(input_width, output_width, align_corners); |
| 60 | float hr = arm_compute::scale_utils::calculate_resize_ratio(input_height, output_height, align_corners); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 61 | |
| 62 | return std::make_pair(wr, hr); |
| 63 | } |
| 64 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 65 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 66 | { |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame] | 68 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::U8, DataType::S16, DataType::F16, DataType::F32); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 69 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output); |
| 70 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Isabella Gottardi | 0a1090a | 2019-02-14 18:07:36 +0000 | [diff] [blame] | 71 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(input, output); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_RETURN_ERROR_ON(output == input); |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON(info.align_corners && !arm_compute::scale_utils::is_align_corners_allowed_sampling_policy(info.sampling_policy)); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 74 | |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 75 | const bool will_use_align_corners = info.align_corners && arm_compute::scale_utils::is_align_corners_allowed_output_shape(output->tensor_shape(), output->data_layout()); |
Sang-Hoon Park | 5b7fd87 | 2020-01-09 15:27:51 +0000 | [diff] [blame] | 76 | |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 77 | float wr = 0.f; |
| 78 | float hr = 0.f; |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 79 | std::tie(wr, hr) = calculate_scale_factors(*input, *output, will_use_align_corners); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 80 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 81 | ARM_COMPUTE_RETURN_ERROR_ON(info.interpolation_policy == InterpolationPolicy::AREA && (wr > 1.f || hr > 1.f)); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 82 | |
| 83 | return Status{}; |
| 84 | } |
| 85 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 86 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output, const ScaleKernelInfo &info, BorderSize &border) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 87 | { |
| 88 | Window win{}; |
| 89 | bool window_changed{}; |
| 90 | unsigned int num_elems_processed_per_iteration = 0; |
| 91 | DataLayout data_layout = input->data_layout(); |
| 92 | |
| 93 | switch(data_layout) |
| 94 | { |
| 95 | case DataLayout::NCHW: |
| 96 | { |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 97 | if(info.border_mode == BorderMode::UNDEFINED) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 98 | { |
| 99 | border = BorderSize(0); |
| 100 | } |
| 101 | |
| 102 | num_elems_processed_per_iteration = 4; |
| 103 | // Configure kernel window |
Michele Di Giorgio | 17a01a3 | 2019-01-03 15:12:27 +0000 | [diff] [blame] | 104 | win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 105 | AccessWindowStatic input_access(input, |
Michele Di Giorgio | 17a01a3 | 2019-01-03 15:12:27 +0000 | [diff] [blame] | 106 | -border.left, -border.top, |
| 107 | input->dimension(0) + border.right, |
| 108 | input->dimension(1) + border.bottom); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 109 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 110 | |
| 111 | output_access.set_valid_region(win, calculate_valid_region_scale(*(input), |
| 112 | output->tensor_shape(), |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 113 | info.interpolation_policy, |
| 114 | info.sampling_policy, |
| 115 | info.border_mode == BorderMode::UNDEFINED)); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 116 | |
| 117 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 118 | } |
| 119 | break; |
| 120 | case DataLayout::NHWC: |
| 121 | { |
| 122 | num_elems_processed_per_iteration = 1; |
| 123 | // Configure kernel window |
| 124 | win = calculate_max_window(*output, Steps(num_elems_processed_per_iteration)); |
Michele Di Giorgio | 17a01a3 | 2019-01-03 15:12:27 +0000 | [diff] [blame] | 125 | AccessWindowStatic input_access(input, -border.left, -border.top, |
| 126 | input->dimension(0) + border.right, |
| 127 | input->dimension(1) + border.bottom); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 128 | AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration); |
| 129 | window_changed = update_window_and_padding(win, input_access, output_access); |
| 130 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape())); |
| 131 | } |
| 132 | break; |
| 133 | default: |
| 134 | ARM_COMPUTE_ERROR("Data layout not supported"); |
| 135 | } |
| 136 | |
| 137 | Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{}; |
| 138 | return std::make_pair(err, win); |
| 139 | } |
| 140 | } // namespace |
| 141 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 142 | BorderSize CLScaleKernel::border_size() const |
| 143 | { |
| 144 | return BorderSize(1); |
| 145 | } |
| 146 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 147 | Status CLScaleKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const ScaleKernelInfo &info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 148 | { |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 149 | BorderSize border = BorderSize(1); |
| 150 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 151 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, info)); |
| 152 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), info, border).first); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 153 | |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 154 | return Status{}; |
| 155 | } |
| 156 | |
Georgios Pinitas | 6c95c2d | 2018-08-20 16:06:58 +0100 | [diff] [blame] | 157 | const ICLTensor *CLScaleKernel::input() const |
| 158 | { |
| 159 | return _input; |
| 160 | } |
| 161 | |
| 162 | const ICLTensor *CLScaleKernel::output() const |
| 163 | { |
| 164 | return _output; |
| 165 | } |
| 166 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 167 | void CLScaleKernel::configure(const ICLTensor *input, ICLTensor *output, const ScaleKernelInfo &info) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 168 | { |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 169 | configure(CLKernelLibrary::get().get_compile_context(), input, output, info); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 172 | void CLScaleKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const ScaleKernelInfo &info) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 173 | { |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 174 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), info)); |
Georgios Pinitas | 14d9d98 | 2019-12-13 12:33:09 +0000 | [diff] [blame] | 175 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 176 | _input = input; |
| 177 | _output = output; |
| 178 | _interpolation_policy = info.interpolation_policy; |
| 179 | _data_layout = input->info()->data_layout(); |
Sang-Hoon Park | 3687ee1 | 2020-06-24 13:34:04 +0100 | [diff] [blame] | 180 | _align_corners = info.align_corners && arm_compute::scale_utils::is_align_corners_allowed_output_shape(output->info()->tensor_shape(), _data_layout); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 181 | |
| 182 | float wr = 0.f; |
| 183 | float hr = 0.f; |
Sang-Hoon Park | 5b7fd87 | 2020-01-09 15:27:51 +0000 | [diff] [blame] | 184 | std::tie(wr, hr) = calculate_scale_factors(*input->info(), *output->info(), _align_corners); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 185 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 186 | const bool call_quantized_kernel = is_data_type_quantized_asymmetric(input->info()->data_type()) && _interpolation_policy == InterpolationPolicy::BILINEAR; |
Michalis Spyrou | 17220e2 | 2018-09-12 13:35:38 +0100 | [diff] [blame] | 187 | |
Georgios Pinitas | 14d9d98 | 2019-12-13 12:33:09 +0000 | [diff] [blame] | 188 | const int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH); |
| 189 | const int idx_height = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT); |
| 190 | const bool is_nhwc = _data_layout == DataLayout::NHWC; |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 191 | |
Daniil Efremov | 7a49c79 | 2017-11-14 21:25:34 +0700 | [diff] [blame] | 192 | // Compute actual border size |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 193 | BorderSize border = border_size(); |
Daniil Efremov | 7a49c79 | 2017-11-14 21:25:34 +0700 | [diff] [blame] | 194 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 195 | auto interpolation_policy_to_use = _interpolation_policy; |
Daniil Efremov | 7a49c79 | 2017-11-14 21:25:34 +0700 | [diff] [blame] | 196 | // Area interpolation behaves as Nearest Neighbour in case of up-sampling |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 197 | if(_interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 198 | { |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 199 | interpolation_policy_to_use = InterpolationPolicy::NEAREST_NEIGHBOR; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 200 | } |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 201 | |
| 202 | // Configure kernel window |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 203 | auto win_config = validate_and_configure_window(input->info(), output->info(), info, border); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 204 | ARM_COMPUTE_ERROR_THROW_ON(win_config.first); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 205 | ICLKernel::configure_internal(win_config.second); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 206 | |
| 207 | // Create kernel |
Daniil Efremov | 7a49c79 | 2017-11-14 21:25:34 +0700 | [diff] [blame] | 208 | CLBuildOptions build_opts; |
| 209 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); |
| 210 | build_opts.add_option("-DBORDER_SIZE=" + support::cpp11::to_string(border.right)); |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 211 | build_opts.add_option_if(info.border_mode == BorderMode::REPLICATE, "-DBORDER_MODE_REPLICATE"); |
Michalis Spyrou | 1f8db2b | 2018-12-10 16:19:20 +0000 | [diff] [blame] | 212 | build_opts.add_option_if(is_nhwc, "-DDEPTH_OUT=" + support::cpp11::to_string(output->info()->dimension(2))); |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 213 | build_opts.add_option_if_else(info.sampling_policy == SamplingPolicy::CENTER, "-DSAMPLING_POLICY_CENTER", "-DSAMPLING_POLICY_TOP_LEFT"); |
Michalis Spyrou | 17220e2 | 2018-09-12 13:35:38 +0100 | [diff] [blame] | 214 | if(call_quantized_kernel) |
| 215 | { |
Georgios Pinitas | 4c5469b | 2019-05-21 13:32:43 +0100 | [diff] [blame] | 216 | const UniformQuantizationInfo qinfo = input->info()->quantization_info().uniform(); |
| 217 | build_opts.add_option("-DSCALE=" + support::cpp11::to_string(qinfo.scale)); |
| 218 | build_opts.add_option("-DOFFSET=" + support::cpp11::to_string(qinfo.offset)); |
Michalis Spyrou | 17220e2 | 2018-09-12 13:35:38 +0100 | [diff] [blame] | 219 | } |
Daniil Efremov | 7a49c79 | 2017-11-14 21:25:34 +0700 | [diff] [blame] | 220 | |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 221 | std::string interpolation_name = string_from_interpolation_policy(interpolation_policy_to_use); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 222 | std::transform(interpolation_name.begin(), interpolation_name.end(), interpolation_name.begin(), ::tolower); |
Michalis Spyrou | 17220e2 | 2018-09-12 13:35:38 +0100 | [diff] [blame] | 223 | std::string kernel_name = "scale_" + interpolation_name; |
| 224 | kernel_name += call_quantized_kernel ? "_quantized_" : "_"; |
Georgios Pinitas | 14d9d98 | 2019-12-13 12:33:09 +0000 | [diff] [blame] | 225 | kernel_name += lower_string(string_from_data_layout(_data_layout)); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 226 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 227 | |
Michalis Spyrou | 1f8db2b | 2018-12-10 16:19:20 +0000 | [diff] [blame] | 228 | unsigned int idx = is_nhwc ? 2 * num_arguments_per_4D_tensor() : 2 * num_arguments_per_2D_tensor(); //Skip the input and output parameters |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 229 | |
Sang-Hoon Park | 5b7fd87 | 2020-01-09 15:27:51 +0000 | [diff] [blame] | 230 | const unsigned int input_width = input->info()->dimension(idx_width); |
| 231 | const unsigned int input_height = input->info()->dimension(idx_height); |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 232 | |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 233 | _kernel.setArg<float>(idx++, input_width); |
| 234 | _kernel.setArg<float>(idx++, input_height); |
Sang-Hoon Park | 5b7fd87 | 2020-01-09 15:27:51 +0000 | [diff] [blame] | 235 | _kernel.setArg<float>(idx++, wr); |
| 236 | _kernel.setArg<float>(idx++, hr); |
Vidhya Sudhan Loganathan | 7a63e79 | 2019-01-14 16:29:20 +0000 | [diff] [blame] | 237 | |
| 238 | // Set config_id for enabling LWS tuning |
| 239 | _config_id = "scale_"; |
Sang-Hoon Park | ccd9496 | 2020-06-09 12:09:24 +0100 | [diff] [blame] | 240 | _config_id += (info.border_mode == BorderMode::REPLICATE ? "Bord_rep" : ""); |
| 241 | _config_id += (info.sampling_policy == SamplingPolicy::CENTER ? "center" : "topleft"); |
Michele Di Giorgio | 17a01a3 | 2019-01-03 15:12:27 +0000 | [diff] [blame] | 242 | _config_id += (is_nhwc ? "nhwc" : "nchw"); |
Vidhya Sudhan Loganathan | 7a63e79 | 2019-01-14 16:29:20 +0000 | [diff] [blame] | 243 | _config_id += "_"; |
| 244 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 245 | _config_id += "_"; |
| 246 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
| 247 | _config_id += "_"; |
| 248 | _config_id += support::cpp11::to_string(output->info()->dimension(2)); |
| 249 | _config_id += "_"; |
| 250 | _config_id += support::cpp11::to_string(output->info()->dimension(3)); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 251 | } |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 252 | |
| 253 | void CLScaleKernel::run(const Window &window, cl::CommandQueue &queue) |
| 254 | { |
| 255 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 256 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window); |
| 257 | |
Georgios Pinitas | 14d9d98 | 2019-12-13 12:33:09 +0000 | [diff] [blame] | 258 | switch(_data_layout) |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 259 | { |
| 260 | case DataLayout::NCHW: |
| 261 | { |
| 262 | Window slice = window.first_slice_window_2D(); |
| 263 | |
| 264 | do |
| 265 | { |
| 266 | unsigned int idx = 0; |
| 267 | add_2D_tensor_argument(idx, _input, slice); |
| 268 | add_2D_tensor_argument(idx, _output, slice); |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 269 | enqueue(queue, *this, slice, lws_hint()); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 270 | } |
| 271 | while(window.slide_window_slice_2D(slice)); |
| 272 | break; |
| 273 | } |
| 274 | case DataLayout::NHWC: |
| 275 | { |
Michalis Spyrou | 1f8db2b | 2018-12-10 16:19:20 +0000 | [diff] [blame] | 276 | Window collapsed = window.collapse(ICLKernel::window(), Window::DimZ); |
| 277 | Window slice = collapsed.first_slice_window_4D(); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 278 | |
Michalis Spyrou | 1f8db2b | 2018-12-10 16:19:20 +0000 | [diff] [blame] | 279 | unsigned int idx = 0; |
| 280 | add_4D_tensor_argument(idx, _input, slice); |
| 281 | add_4D_tensor_argument(idx, _output, slice); |
| 282 | enqueue(queue, *this, slice, lws_hint()); |
Michalis Spyrou | 46da23f | 2018-04-10 13:41:30 +0100 | [diff] [blame] | 283 | break; |
| 284 | } |
| 285 | default: |
| 286 | ARM_COMPUTE_ERROR("Data layout not supported"); |
| 287 | } |
| 288 | } |