Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1 | /* |
Giorgio Arena | 9f7d55a | 2021-02-08 13:20:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [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 | */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 24 | #include "src/core/CL/kernels/CLDepthwiseConvolutionLayer3x3NHWCKernel.h" |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 25 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/CL/ICLTensor.h" |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/Helpers.h" |
| 30 | #include "arm_compute/core/TensorInfo.h" |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 31 | #include "arm_compute/core/Utils.h" |
| 32 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 33 | #include "src/core/AccessWindowStatic.h" |
| 34 | #include "src/core/CL/CLValidate.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 35 | #include "src/core/CL/ICLKernel.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 36 | #include "src/core/helpers/AutoConfiguration.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 38 | #include "support/StringSupport.h" |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 39 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 42 | namespace |
| 43 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 44 | Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 45 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, const ActivationLayerInfo &act_info, const Size2D &dilation) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 46 | { |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 47 | ARM_COMPUTE_UNUSED(act_info); |
Giorgio Arena | e6bb3c6 | 2018-08-23 11:19:11 +0100 | [diff] [blame] | 48 | ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input); |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 49 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32); |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 50 | ARM_COMPUTE_RETURN_ERROR_ON(depth_multiplier > 1); // COMPMID-1071 Add depth multiplier support for NHWC |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 51 | |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON(conv_info.stride().first < 1); |
Pablo Tello | e4cad15 | 2019-06-04 11:28:05 +0100 | [diff] [blame] | 53 | ARM_COMPUTE_RETURN_ERROR_ON(std::max(conv_info.pad_top(), conv_info.pad_bottom()) > 4); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 54 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 55 | ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1)); |
| 56 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 57 | const size_t weights_width = 3; |
| 58 | const size_t weights_height = 3; |
| 59 | |
Michalis Spyrou | 60c3b0e | 2021-04-08 12:02:58 +0100 | [diff] [blame] | 60 | const ConvolutionInfo info{ conv_info, depth_multiplier, ActivationLayerInfo(), dilation }; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 61 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 62 | const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape( |
| 63 | *input, TensorInfo(TensorShape(weights_width, weights_height), 1, weights->data_type()).set_data_layout(DataLayout::NCHW), info); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 64 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 65 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights); |
| 66 | ARM_COMPUTE_RETURN_ERROR_ON((weights->dimension(1) != weights_width) || (weights->dimension(2) != weights_height)); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 67 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 68 | if(biases != nullptr) |
| 69 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 70 | ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != output_shape[0]); |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 71 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(weights, biases); |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 72 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 73 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 74 | } |
| 75 | |
| 76 | if(output->total_size() != 0) |
| 77 | { |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 78 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); |
| 79 | } |
| 80 | |
| 81 | return Status{}; |
| 82 | } |
| 83 | |
Georgios Pinitas | b2d9ebb | 2018-05-14 12:21:51 +0100 | [diff] [blame] | 84 | std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *bias, ITensorInfo *output, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 85 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 86 | { |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 87 | ARM_COMPUTE_UNUSED(weights, bias); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 88 | ARM_COMPUTE_UNUSED(depth_multiplier); |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 89 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 90 | const bool is_stride_1_dilation_1 = ((conv_info.stride().first == conv_info.stride().second) && (conv_info.stride().first == 1) && dilation.x() == 1 && dilation.y() == 1); |
| 91 | unsigned int num_rows_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 92 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 93 | Window win{}; |
| 94 | Status err{}; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 95 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 96 | unsigned int num_elems_accessed_per_iteration = adjust_vec_size(4 / input->element_size(), input->dimension(0)); |
| 97 | win = calculate_max_window(*output, Steps(num_elems_accessed_per_iteration, num_rows_processed_per_iteration)); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 98 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 99 | return std::make_pair(err, win); |
| 100 | } |
| 101 | } // namespace |
| 102 | |
| 103 | CLDepthwiseConvolutionLayer3x3NHWCKernel::CLDepthwiseConvolutionLayer3x3NHWCKernel() |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 104 | : _input(), _output(), _weights(), _biases(), _num_planes_processed_per_iteration(1) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 105 | { |
| 106 | } |
| 107 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 108 | void CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 109 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 110 | { |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 111 | configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Manuel Bottini | 256c0b9 | 2020-04-21 13:29:30 +0100 | [diff] [blame] | 114 | void CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 115 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation) |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 116 | { |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 117 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 118 | ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 119 | conv_info, depth_multiplier, act_info, dilation)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 120 | |
| 121 | auto padding_info = get_padding_info({ input, weights, biases, output }); |
| 122 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 123 | auto win_config = validate_and_configure_window(input->info(), weights->info(), biases != nullptr ? biases->info() : nullptr, output->info(), |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 124 | conv_info, depth_multiplier, dilation); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 125 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 126 | const bool is_stride_1 = ((conv_info.stride().first == conv_info.stride().second) && (conv_info.stride().first == 1)); |
| 127 | const bool is_stride_1_dilation_1 = (is_stride_1 && dilation.x() == 1 && dilation.y() == 1); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 128 | |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 129 | _input = input; |
| 130 | _output = output; |
| 131 | _weights = weights; |
| 132 | _biases = biases; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 133 | _num_planes_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 134 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 135 | unsigned int num_elems_accessed_per_iteration = adjust_vec_size(4 / input->info()->element_size(), input->info()->dimension(0)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 136 | unsigned int num_rows_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1; |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 137 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 138 | CLBuildOptions build_opts; |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 139 | build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type())); |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 140 | build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_info.activation()))); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 141 | build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_accessed_per_iteration)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 142 | build_opts.add_option("-DSRC_DIM_1=" + support::cpp11::to_string(_input->info()->dimension(1))); |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 143 | build_opts.add_option("-DSRC_DIM_2=" + support::cpp11::to_string(_input->info()->dimension(2))); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 144 | build_opts.add_option("-DCONV_PAD_TOP=" + support::cpp11::to_string(conv_info.pad_top())); |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 145 | build_opts.add_option("-DCONV_PAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left())); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 146 | build_opts.add_option("-DPARTIAL_STORE_N0=" + support::cpp11::to_string(input->info()->dimension(0) % num_elems_accessed_per_iteration)); |
| 147 | build_opts.add_option_if(_biases != nullptr, "-DHAS_BIAS"); |
| 148 | build_opts.add_option_if(_input->info()->tensor_shape().total_size_upper(3) > 1, |
| 149 | "-DDST_DEPTH=" + support::cpp11::to_string(static_cast<int>(std::ceil(_output->info()->dimension(2) / static_cast<float>(_num_planes_processed_per_iteration))))); |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 150 | build_opts.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a())); |
| 151 | build_opts.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b())); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 152 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 153 | if(is_stride_1_dilation_1) |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 154 | { |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 155 | build_opts.add_option("-DNUM_ROWS_PROCESSED=" + support::cpp11::to_string(num_rows_processed_per_iteration)); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 156 | build_opts.add_option("-DNUM_PLANES_PROCESSED=" + support::cpp11::to_string(_num_planes_processed_per_iteration)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 157 | build_opts.add_option("-DDST_DIM_1=" + support::cpp11::to_string(_output->info()->dimension(1))); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 158 | build_opts.add_option("-DDST_DIM_2=" + support::cpp11::to_string(_output->info()->dimension(2))); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 159 | build_opts.add_option("-DPARTIAL_STORE_M0=" + support::cpp11::to_string((input->info()->dimension(1) + conv_info.pad_left() + conv_info.pad_right()) % num_rows_processed_per_iteration)); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 160 | } |
| 161 | else |
| 162 | { |
Georgios Pinitas | 3f8aac4 | 2018-12-24 13:09:02 +0000 | [diff] [blame] | 163 | build_opts.add_option("-DCONV_STRIDE_X=" + support::cpp11::to_string(conv_info.stride().first)); |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 164 | build_opts.add_option("-DCONV_STRIDE_Y=" + support::cpp11::to_string(conv_info.stride().second)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 165 | build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(dilation.x())); |
| 166 | build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(dilation.y())); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 167 | } |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 168 | |
| 169 | // Create kernel |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 170 | std::string kernel_name; |
| 171 | kernel_name = std::string("depthwise_convolution_3x3_nhwc"); |
| 172 | kernel_name += (is_stride_1_dilation_1 ? "_stride1" : ""); |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 173 | |
Anthony Barbier | b6eb353 | 2018-08-08 13:20:04 +0100 | [diff] [blame] | 174 | ICLKernel::configure_internal(win_config.second); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 175 | _kernel = create_kernel(compile_context, kernel_name, build_opts.options()); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 176 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 177 | ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info)); |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 178 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 179 | // Set config_id for enabling LWS tuning |
| 180 | _config_id = kernel_name; |
| 181 | _config_id += "_"; |
| 182 | _config_id += support::cpp11::to_string(input->info()->dimension(0)); |
| 183 | _config_id += "_"; |
| 184 | _config_id += support::cpp11::to_string(input->info()->dimension(1)); |
| 185 | _config_id += "_"; |
| 186 | _config_id += support::cpp11::to_string(input->info()->dimension(2)); |
| 187 | _config_id += "_"; |
| 188 | _config_id += support::cpp11::to_string(output->info()->dimension(0)); |
| 189 | _config_id += "_"; |
| 190 | _config_id += support::cpp11::to_string(output->info()->dimension(1)); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 191 | _config_id += "_"; |
| 192 | _config_id += string_from_data_type(input->info()->data_type()); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 195 | Status CLDepthwiseConvolutionLayer3x3NHWCKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 196 | const PadStrideInfo &conv_info, unsigned int depth_multiplier, ActivationLayerInfo act_info, const Size2D &dilation) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 197 | { |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 198 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation)); |
Georgios Pinitas | b2d9ebb | 2018-05-14 12:21:51 +0100 | [diff] [blame] | 199 | ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), weights->clone().get(), |
| 200 | biases != nullptr ? biases->clone().get() : nullptr, |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 201 | output->clone().get(), conv_info, depth_multiplier, dilation) |
Georgios Pinitas | b2d9ebb | 2018-05-14 12:21:51 +0100 | [diff] [blame] | 202 | .first); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 203 | return Status{}; |
| 204 | } |
| 205 | |
| 206 | void CLDepthwiseConvolutionLayer3x3NHWCKernel::run(const Window &window, cl::CommandQueue &queue) |
| 207 | { |
| 208 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 209 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 210 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 211 | const size_t total_batches = _input->info()->tensor_shape().total_size_upper(3); |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 212 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 213 | Window win = window.collapse_if_possible(ICLKernel::window(), Window::DimZ); |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 214 | win.set(Window::DimZ, Window::Dimension(0, std::ceil(_output->info()->dimension(2) / static_cast<float>(_num_planes_processed_per_iteration)) * total_batches, 1)); |
Giorgio Arena | d051e97 | 2018-06-20 11:46:42 +0100 | [diff] [blame] | 215 | |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 216 | unsigned int idx = 2 * num_arguments_per_4D_tensor() + num_arguments_per_3D_tensor(); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 217 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 218 | if(_biases != nullptr) |
| 219 | { |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 220 | Window win_biases; |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 221 | win_biases.use_tensor_dimensions(_biases->info()->tensor_shape()); |
| 222 | win_biases.set_dimension_step(Window::DimX, window.x().step()); |
| 223 | add_1D_tensor_argument(idx, _biases, win_biases); |
| 224 | } |
| 225 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 226 | Window slice = win.first_slice_window_4D(); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 227 | do |
| 228 | { |
| 229 | unsigned int idx = 0; |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 230 | add_4D_tensor_argument(idx, _input, slice); |
| 231 | add_4D_tensor_argument(idx, _output, slice); |
Giorgio Arena | dcf4c87 | 2021-04-16 12:41:45 +0100 | [diff] [blame] | 232 | add_3D_tensor_argument(idx, _weights, slice); |
| 233 | |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 234 | enqueue(queue, *this, slice, lws_hint()); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 235 | } |
Giorgio Arena | 1e2af2a | 2020-10-15 17:39:41 +0100 | [diff] [blame] | 236 | while(win.slide_window_slice_4D(slice)); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 237 | } |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 238 | } // namespace arm_compute |