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