Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 4cd4cde | 2020-01-06 14:07:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [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 | |
| 25 | #include "helpers_asymm.h" |
| 26 | |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 27 | #ifndef VEC_SIZE |
| 28 | #if defined(N0) |
| 29 | #define VEC_SIZE N0 |
| 30 | #else /* defined(N0) */ |
| 31 | #define VEC_SIZE 8 |
| 32 | #endif /* defined(N0) */ |
| 33 | #endif /* VEC_SIZE */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 34 | |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 35 | #if defined(ACTIVATION_TYPE) && defined(CONST_0) |
Manuel Bottini | 30dbeef | 2019-06-26 16:23:03 +0100 | [diff] [blame] | 36 | #include "activation_layer_quant.cl" |
| 37 | #define ACTIVATION_FUNC(x) PERFORM_ACTIVATION_QUANT(ACTIVATION_TYPE, x) |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 38 | #else /* defined(ACTIVATION_TYPE) && defined(CONST_0) */ |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 39 | #define ACTIVATION_FUNC(x) (x) |
Usama Arif | 6a98a6e | 2019-05-10 17:07:27 +0100 | [diff] [blame] | 40 | #endif /* defined(ACTIVATION_TYPE) && defined(CONST_0) */ |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 41 | |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 42 | #define VEC_INT VEC_DATA_TYPE(int, VEC_SIZE) |
| 43 | #define VEC_FLOAT VEC_DATA_TYPE(float, VEC_SIZE) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 44 | #define VEC_SHORT VEC_DATA_TYPE(short, VEC_SIZE) |
| 45 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 46 | #if defined(DATA_TYPE) && defined(WEIGHTS_TYPE) |
| 47 | |
| 48 | #define VEC_TYPE(size) VEC_DATA_TYPE(DATA_TYPE, size) |
| 49 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 50 | #if defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && ((defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)) || defined(REAL_MULTIPLIER)) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 51 | |
| 52 | #if defined(WEIGHTS_PROMOTED_TYPE) |
| 53 | #define VEC_WEIGHTS_PROMOTED_TYPE(size) VEC_DATA_TYPE(WEIGHTS_PROMOTED_TYPE, size) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 54 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 55 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
| 56 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 57 | #define ARM_DOT(x, y, val) val = arm_dot_acc((x), (y), val); |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 58 | #else // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 59 | #define ARM_DOT(x, y, val) val += arm_dot((x), (y)); |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 60 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8) |
| 61 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 62 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 63 | #if defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X) && defined(DEPTH_MULTIPLIER) && defined(DST_CHANNELS) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 64 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 65 | #if CONV_STRIDE_X > 3 |
| 66 | #error "Stride X not supported" |
| 67 | #endif /* CONV_STRIDE_X > 3 */ |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 68 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 69 | #if !defined(IS_DOT8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 70 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 71 | #if DILATION_X == 1 |
| 72 | |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 73 | #if CONV_STRIDE_X == 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 74 | #define GET_VALUES(first_value, left, middle, right) \ |
| 75 | ({ \ |
| 76 | int8 temp0 = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value)), int8); \ |
| 77 | int2 temp1 = CONVERT(vload2(0, (__global DATA_TYPE *)(first_value + 8 * sizeof(DATA_TYPE))), int2); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 78 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 79 | left = CONVERT(temp0.s01234567, int8); \ |
| 80 | middle = CONVERT((int8)(temp0.s1234, temp0.s567, temp1.s0), int8); \ |
| 81 | right = CONVERT((int8)(temp0.s2345, temp0.s67, temp1.s01), int8); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 82 | }) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 83 | #elif CONV_STRIDE_X == 2 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 84 | #define GET_VALUES(first_value, left, middle, right) \ |
| 85 | ({ \ |
| 86 | int16 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value)), int16); \ |
| 87 | int temp1 = CONVERT(*((__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))), int); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 88 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 89 | left = CONVERT(temp0.s02468ace, int8); \ |
| 90 | middle = CONVERT(temp0.s13579bdf, int8); \ |
| 91 | right = CONVERT((int8)(temp0.s2468, temp0.sace, temp1), int8); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 92 | }) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 93 | #else /* CONV_STRIDE_X */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 94 | #define GET_VALUES(first_value, left, middle, right) \ |
| 95 | ({ \ |
| 96 | int16 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value)), int16); \ |
| 97 | int8 temp1 = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))), int8); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 98 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 99 | left = CONVERT((int8)(temp0.s0369, temp0.scf, temp1.s25), int8); \ |
| 100 | middle = CONVERT((int8)(temp0.s147a, temp0.sd, temp1.s036), int8); \ |
| 101 | right = CONVERT((int8)(temp0.s258b, temp0.se, temp1.s147), int8); \ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 102 | }) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 103 | #endif /* CONV_STRIDE_X */ |
| 104 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 105 | #else /* DILATION_X == 1 */ |
| 106 | |
| 107 | #if CONV_STRIDE_X == 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 108 | #define GET_VALUES(first_value, left, middle, right) \ |
| 109 | ({ \ |
| 110 | left = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value)), int8); \ |
| 111 | middle = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))), int8); \ |
| 112 | right = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))), int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 113 | }) |
| 114 | #elif CONV_STRIDE_X == 2 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 115 | #define GET_VALUES(first_value, left, middle, right) \ |
| 116 | ({ \ |
| 117 | int16 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value)), int16); \ |
| 118 | left = CONVERT(temp0.s02468ace, int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 119 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 120 | temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))), int16); \ |
| 121 | middle = CONVERT(temp0.s02468ace, int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 122 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 123 | temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))), int16); \ |
| 124 | right = CONVERT(temp0.s02468ace, int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 125 | }) |
| 126 | #else /* CONV_STRIDE_X */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 127 | #define GET_VALUES(first_value, left, middle, right) \ |
| 128 | ({ \ |
| 129 | int16 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value)), int16); \ |
| 130 | int8 temp1 = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))), int8); \ |
| 131 | left = CONVERT((int8)(temp0.s0369, temp0.scf, temp1.s25), int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 132 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 133 | temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))), int16); \ |
| 134 | temp1 = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + (16 + DILATION_X) * sizeof(DATA_TYPE))), int8); \ |
| 135 | middle = CONVERT((int8)(temp0.s0369, temp0.scf, temp1.s25), int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 136 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 137 | temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))), int16); \ |
| 138 | temp1 = CONVERT(vload8(0, (__global DATA_TYPE *)(first_value + (16 + 2 * DILATION_X) * sizeof(DATA_TYPE))), int8); \ |
| 139 | right = CONVERT((int8)(temp0.s0369, temp0.scf, temp1.s25), int8); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 140 | }) |
| 141 | |
| 142 | #endif /* CONV_STRIDE_X */ |
| 143 | #endif /* DILATION_X==1 */ |
| 144 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 145 | /** This function computes the depthwise convolution quantized. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 146 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 147 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8 |
| 148 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 149 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 150 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 151 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 152 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 153 | * @param[in] src_step_z src_stride_z * number of elements along Y processed per workitem(in bytes) |
| 154 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 155 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: QASYMM8 |
| 156 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 157 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 158 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 159 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 160 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 161 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 162 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 163 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QSYMM8_PER_CHANNEL |
| 164 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 165 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 166 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 167 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 168 | * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 169 | * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes) |
| 170 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 171 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 172 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 173 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 174 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 175 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 176 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 177 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 178 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 179 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 180 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 181 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 182 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 183 | */ |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 184 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 185 | __kernel void dwc_3x3_native_quantized8_nchw( |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 186 | TENSOR3D_DECLARATION(src), |
| 187 | TENSOR3D_DECLARATION(dst), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 188 | TENSOR3D_DECLARATION(weights), |
| 189 | VECTOR_DECLARATION(output_multipliers), |
| 190 | VECTOR_DECLARATION(output_shifts) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 191 | #if defined(HAS_BIAS) |
Georgios Pinitas | 5b2191e | 2018-02-22 12:56:51 +0000 | [diff] [blame] | 192 | , |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 193 | VECTOR_DECLARATION(biases) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 194 | #endif //defined(HAS_BIAS) |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 195 | ) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 196 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 197 | Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src); |
| 198 | Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst); |
| 199 | Tensor3D weights = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(weights); |
| 200 | Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_multipliers); |
| 201 | Vector output_shifts = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_shifts); |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 202 | |
| 203 | // Extract channel and linearized batch indices |
| 204 | const int channel = get_global_id(2) % DST_CHANNELS; |
| 205 | const int batch = get_global_id(2) / DST_CHANNELS; |
| 206 | |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 207 | #if defined(HAS_BIAS) |
| 208 | Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 209 | |
Georgios Pinitas | 728d3cf | 2018-09-21 13:41:35 +0100 | [diff] [blame] | 210 | int bias_value = *((__global int *)(vector_offset(&biases, channel))); |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 211 | #endif //defined(HAS_BIAS) |
| 212 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 213 | // Load relevant input and weights data (Accounts depth multiplier when indexing input, OFM = IFM * DEPTH_MULTIPLIER) |
| 214 | src.ptr -= batch * (DST_CHANNELS / DEPTH_MULTIPLIER) * (DEPTH_MULTIPLIER - 1) * src_step_z + (channel - (channel / DEPTH_MULTIPLIER)) * src_step_z; |
| 215 | __global uchar *weights_addr = weights.ptr + get_global_id(0) * weights_step_x + get_global_id(1) * weights_step_y + channel * weights_step_z; |
Giorgio Arena | 7657224 | 2018-04-04 17:44:26 +0100 | [diff] [blame] | 216 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 217 | VEC_DATA_TYPE(WEIGHTS_TYPE, 3) |
| 218 | w0 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 0 * weights_stride_y)); |
| 219 | VEC_DATA_TYPE(WEIGHTS_TYPE, 3) |
| 220 | w1 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 1 * weights_stride_y)); |
| 221 | VEC_DATA_TYPE(WEIGHTS_TYPE, 3) |
| 222 | w2 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * weights_stride_y)); |
| 223 | |
| 224 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 225 | const int output_multiplier = *((__global int *)vector_offset(&output_multipliers, channel)); |
| 226 | const int output_shift = *((__global int *)vector_offset(&output_shifts, channel)); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 227 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 228 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 229 | int8 values0 = 0; |
| 230 | int8 sum0 = 0; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 231 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 232 | int8 values1 = 0; |
| 233 | int8 sum1 = 0; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 234 | #endif /* CONV_STRIDE_Y &&DILATION_Y==1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 235 | |
| 236 | // Row0 |
| 237 | int8 left, middle, right; |
| 238 | GET_VALUES(src.ptr + 0 * src_stride_y, left, middle, right); |
| 239 | values0 += left * (int8)(w0.s0); |
| 240 | values0 += middle * (int8)(w0.s1); |
| 241 | values0 += right * (int8)(w0.s2); |
| 242 | |
| 243 | #if WEIGHTS_OFFSET != 0 |
| 244 | sum0 += left + middle + right; |
| 245 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 246 | |
| 247 | // Row1 |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 248 | GET_VALUES(src.ptr + DILATION_Y * src_stride_y, left, middle, right); |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 249 | values0 += left * (int8)(w1.s0); |
| 250 | values0 += middle * (int8)(w1.s1); |
| 251 | values0 += right * (int8)(w1.s2); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 252 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 253 | values1 += left * (int8)(w0.s0); |
| 254 | values1 += middle * (int8)(w0.s1); |
| 255 | values1 += right * (int8)(w0.s2); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 256 | #endif /* CONV_STRIDE_Y && DILATION_Y== 1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 257 | |
| 258 | #if WEIGHTS_OFFSET != 0 |
| 259 | int8 tmp = left + middle + right; |
| 260 | sum0 += tmp; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 261 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 262 | sum1 += tmp; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 263 | #endif /* CONV_STRIDE_Y &&DILATION_Y== 1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 264 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 265 | |
| 266 | // Row2 |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 267 | GET_VALUES(src.ptr + 2 * DILATION_Y * src_stride_y, left, middle, right); |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 268 | values0 += left * (int8)(w2.s0); |
| 269 | values0 += middle * (int8)(w2.s1); |
| 270 | values0 += right * (int8)(w2.s2); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 271 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 272 | values1 += left * (int8)(w1.s0); |
| 273 | values1 += middle * (int8)(w1.s1); |
| 274 | values1 += right * (int8)(w1.s2); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 275 | #endif /* CONV_STRIDE_Y &&DILATION_Y == 1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 276 | |
| 277 | #if WEIGHTS_OFFSET != 0 |
| 278 | tmp = left + middle + right; |
| 279 | sum0 += tmp; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 280 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 281 | sum1 += tmp; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 282 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 283 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 284 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 285 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 286 | // Row3 |
| 287 | GET_VALUES(src.ptr + 3 * src_stride_y, left, middle, right); |
| 288 | values1 += left * (int8)(w2.s0); |
| 289 | values1 += middle * (int8)(w2.s1); |
| 290 | values1 += right * (int8)(w2.s2); |
| 291 | |
| 292 | #if WEIGHTS_OFFSET != 0 |
| 293 | sum1 += left + middle + right; |
| 294 | #endif /* WEIGHTS_OFFSET != 0 */ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 295 | #endif /* CONV_STRIDE_Y && DILATION_Y == 1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 296 | |
| 297 | #if defined(HAS_BIAS) |
| 298 | values0 += (int8)(bias_value); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 299 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 300 | values1 += (int8)(bias_value); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 301 | #endif /* CONV_STRIDE_Y & &DILATION_Y == 1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 302 | #endif //defined(HAS_BIAS) |
| 303 | |
| 304 | #if WEIGHTS_OFFSET != 0 |
| 305 | values0 += sum0 * (int8)(WEIGHTS_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 306 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 307 | values1 += sum1 * (int8)(WEIGHTS_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 308 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 309 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 310 | |
| 311 | #if INPUT_OFFSET != 0 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 312 | VEC_WEIGHTS_PROMOTED_TYPE(3) |
| 313 | tmp_we = CONVERT(w0, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w1, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w2, VEC_WEIGHTS_PROMOTED_TYPE(3)); |
| 314 | |
| 315 | WEIGHTS_PROMOTED_TYPE sum_weights = tmp_we.s0 + tmp_we.s1 + tmp_we.s2; |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 316 | values0 += sum_weights * (int8)(INPUT_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 317 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 318 | values1 += sum_weights * (int8)(INPUT_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 319 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 320 | #endif /* INPUT_OFFSET != 0 */ |
| 321 | |
| 322 | #if K_OFFSET != 0 |
| 323 | values0 += (int8)(K_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 324 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 325 | values1 += (int8)(K_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 326 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/ |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 327 | #endif /* K_OFFSET != 0 */ |
| 328 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 329 | #if defined(REAL_MULTIPLIER) |
| 330 | |
| 331 | values0 = CONVERT(round(CONVERT(values0, float8) * (float8)REAL_MULTIPLIER), int8); |
| 332 | |
| 333 | #else // defined(REAL_MULTIPLIER) |
| 334 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 335 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 336 | int8 res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, output_multiplier, output_shift, 8); |
| 337 | int8 res0_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, output_multiplier, output_shift, 8); |
| 338 | values0 = select(res0_shift_lt0, res0_shift_gt0, (int8)(output_shift) >= 0); |
| 339 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 340 | #if OUTPUT_SHIFT < 0 |
| 341 | values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 342 | #else // OUTPUT_SHIFT < 0 |
| 343 | values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 344 | #endif // OUTPUT_OFFSET < 0 |
| 345 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 346 | |
| 347 | #endif // defined(REAL_MULTIPLIER) |
| 348 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 349 | values0 += (int8)OUTPUT_OFFSET; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 350 | VEC_TYPE(8) |
| 351 | res0 = CONVERT_SAT(values0, VEC_TYPE(8)); |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 352 | |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 353 | vstore8(ACTIVATION_FUNC(res0), 0, dst.ptr); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 354 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 355 | #if defined(REAL_MULTIPLIER) |
| 356 | |
| 357 | values1 = CONVERT(round(CONVERT(values1, float8) * (float8)REAL_MULTIPLIER), int8); |
| 358 | |
| 359 | #else // defined(REAL_MULTIPLIER) |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 360 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 361 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 362 | int8 res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, output_multiplier, output_shift, 8); |
| 363 | int8 res1_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, output_multiplier, output_shift, 8); |
| 364 | values1 = select(res1_shift_lt0, res1_shift_gt0, (int8)(output_shift) >= 0); |
| 365 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 366 | #if OUTPUT_SHIFT < 0 |
| 367 | values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 368 | #else // OUTPUT_SHIFT < 0 |
| 369 | values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 370 | #endif // OUTPUT_OFFSET < 0 |
| 371 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 372 | |
| 373 | #endif // defined(REAL_MULTIPLIER) |
| 374 | |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 375 | values1 += (int8)OUTPUT_OFFSET; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 376 | VEC_TYPE(8) |
| 377 | res1 = CONVERT_SAT(values1, VEC_TYPE(8)); |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 378 | |
Giorgio Arena | 99ac60b | 2018-02-16 15:17:23 +0000 | [diff] [blame] | 379 | vstore8(ACTIVATION_FUNC(res1), 0, dst.ptr + dst_stride_y); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 380 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/ |
Dmitry Savenko | d7295b7 | 2017-11-20 22:00:08 +0700 | [diff] [blame] | 381 | } |
Giorgio Arena | 287b570 | 2018-02-16 11:01:04 +0000 | [diff] [blame] | 382 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 383 | #else // !defined(IS_DOT8) |
| 384 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 385 | #if DILATION_X == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 386 | #if CONV_STRIDE_X == 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 387 | #define GET_VALUES(first_value, left, middle, right) \ |
| 388 | ({ \ |
| 389 | VEC_TYPE(8) \ |
| 390 | temp0 = vload8(0, (__global DATA_TYPE *)(first_value)); \ |
| 391 | VEC_TYPE(2) \ |
| 392 | temp1 = vload2(0, (__global DATA_TYPE *)(first_value + 8 * sizeof(DATA_TYPE))); \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 393 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 394 | left = temp0.s01234567; \ |
| 395 | middle = (VEC_TYPE(8))(temp0.s1234, temp0.s567, temp1.s0); \ |
| 396 | right = (VEC_TYPE(8))(temp0.s2345, temp0.s67, temp1.s01); \ |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 397 | }) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 398 | #elif CONV_STRIDE_X == 2 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 399 | #define GET_VALUES(first_value, left, middle, right) \ |
| 400 | ({ \ |
| 401 | VEC_TYPE(16) \ |
| 402 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \ |
| 403 | DATA_TYPE temp1 = *((__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))); \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 404 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 405 | left = temp0.s02468ace; \ |
| 406 | middle = temp0.s13579bdf; \ |
| 407 | right = (VEC_TYPE(8))(temp0.s2468, temp0.sace, temp1); \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 408 | }) |
| 409 | #else /* CONV_STRIDE_X */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 410 | #define GET_VALUES(first_value, left, middle, right) \ |
| 411 | ({ \ |
| 412 | VEC_TYPE(16) \ |
| 413 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \ |
| 414 | VEC_TYPE(8) \ |
| 415 | temp1 = vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))); \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 416 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 417 | left = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \ |
| 418 | middle = (VEC_TYPE(8))(temp0.s147a, temp0.sd, temp1.s036); \ |
| 419 | right = (VEC_TYPE(8))(temp0.s258b, temp0.se, temp1.s147); \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 420 | }) |
| 421 | #endif /* CONV_STRIDE_X */ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 422 | #else /*DILATION_X==1*/ |
| 423 | |
| 424 | #if CONV_STRIDE_X == 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 425 | #define GET_VALUES(first_value, left, middle, right) \ |
| 426 | ({ \ |
| 427 | left = vload8(0, (__global DATA_TYPE *)(first_value)); \ |
| 428 | middle = vload8(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \ |
| 429 | right = vload8(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 430 | }) |
| 431 | #elif CONV_STRIDE_X == 2 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 432 | #define GET_VALUES(first_value, left, middle, right) \ |
| 433 | ({ \ |
| 434 | VEC_TYPE(16) \ |
| 435 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \ |
| 436 | left = temp0.s02468ace; \ |
| 437 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \ |
| 438 | middle = temp0.s02468ace; \ |
| 439 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \ |
| 440 | right = temp0.s02468ace; \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 441 | }) |
| 442 | #else /* CONV_STRIDE_X */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 443 | #define GET_VALUES(first_value, left, middle, right) \ |
| 444 | ({ \ |
| 445 | VEC_TYPE(16) \ |
| 446 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \ |
| 447 | VEC_TYPE(8) \ |
| 448 | temp1 = vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE)))); \ |
| 449 | left = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 450 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 451 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \ |
| 452 | temp1 = vload8(0, (__global DATA_TYPE *)(first_value + (16 + DILATION_X) * sizeof(DATA_TYPE))); \ |
| 453 | middle = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 454 | \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 455 | temp0 = vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \ |
| 456 | temp1 = vload8(0, (__global DATA_TYPE *)(first_value + (16 + 2 * DILATION_X) * sizeof(DATA_TYPE))); \ |
| 457 | right = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 458 | }) |
| 459 | |
| 460 | #endif /* CONV_STRIDE_X */ |
| 461 | #endif /*DILATION_X==1*/ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 462 | /** This function computes the depthwise convolution quantized using dot product when the data layout is NCHW. |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 463 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 464 | * @note Per-channel quantization is not supported by this kernel. |
| 465 | * |
| 466 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8 |
| 467 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 468 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 469 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 470 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 471 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 472 | * @param[in] src_step_z src_stride_z * number of elements along Y processed per workitem(in bytes) |
| 473 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 474 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: QASYMM8 |
| 475 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 476 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 477 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 478 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 479 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 480 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 481 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 482 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QSYMM8_PER_CHANNEL |
| 483 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 484 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 485 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 486 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 487 | * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 488 | * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes) |
| 489 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 490 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 491 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 492 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 493 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 494 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 495 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 496 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 497 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 498 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 499 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 500 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 501 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 502 | */ |
| 503 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 504 | __kernel void dwc_3x3_native_quantized8_dot8_nchw( |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 505 | TENSOR3D_DECLARATION(src), |
| 506 | TENSOR3D_DECLARATION(dst), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 507 | TENSOR3D_DECLARATION(weights), |
| 508 | VECTOR_DECLARATION(output_multipliers), |
| 509 | VECTOR_DECLARATION(output_shifts) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 510 | #if defined(HAS_BIAS) |
| 511 | , |
| 512 | VECTOR_DECLARATION(biases) |
| 513 | #endif //defined(HAS_BIAS) |
| 514 | ) |
| 515 | { |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 516 | Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src); |
| 517 | Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst); |
| 518 | Tensor3D weights = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(weights); |
| 519 | Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_multipliers); |
| 520 | Vector output_shifts = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_shifts); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 521 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 522 | // Extract channel and linearized batch indices |
| 523 | const int channel = get_global_id(2) % DST_CHANNELS; |
| 524 | const int batch = get_global_id(2) / DST_CHANNELS; |
| 525 | |
| 526 | #if defined(HAS_BIAS) |
| 527 | Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases); |
| 528 | |
| 529 | const int bias_value = *((__global int *)(vector_offset(&biases, channel))); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 530 | #endif //defined(HAS_BIAS) |
| 531 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 532 | // Load relevant input and weights data (Accounts depth multiplier when indexing input, OFM = IFM * DEPTH_MULTIPLIER) |
| 533 | src.ptr -= batch * (DST_CHANNELS / DEPTH_MULTIPLIER) * (DEPTH_MULTIPLIER - 1) * src_step_z + (channel - (channel / DEPTH_MULTIPLIER)) * src_step_z; |
| 534 | __global uchar *weights_addr = weights.ptr + get_global_id(0) * weights_step_x + get_global_id(1) * weights_step_y + channel * weights_step_z; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 535 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 536 | VEC_TYPE(3) |
| 537 | w0 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 0 * weights_stride_y)); |
| 538 | VEC_TYPE(3) |
| 539 | w1 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 1 * weights_stride_y)); |
| 540 | VEC_TYPE(3) |
| 541 | w2 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * weights_stride_y)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 542 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 543 | const int output_multiplier = *((__global int *)vector_offset(&output_multipliers, 0)); |
| 544 | const int output_shift = *((__global int *)vector_offset(&output_shifts, 0)); |
| 545 | |
| 546 | VEC_TYPE(8) |
| 547 | left0, middle0, right0; |
| 548 | VEC_TYPE(8) |
| 549 | left1, middle1, right1; |
| 550 | VEC_TYPE(8) |
| 551 | left2, middle2, right2; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 552 | |
| 553 | int8 values0 = 0; |
| 554 | int8 sum0 = 0; |
| 555 | |
| 556 | GET_VALUES(src.ptr + 0 * src_stride_y, left0, middle0, right0); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 557 | GET_VALUES(src.ptr + DILATION_Y * src_stride_y, left1, middle1, right1); |
| 558 | GET_VALUES(src.ptr + 2 * DILATION_Y * src_stride_y, left2, middle2, right2); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 559 | |
| 560 | #if WEIGHTS_OFFSET != 0 |
| 561 | sum0 += convert_int8(left0) + convert_int8(middle0) + convert_int8(right0); |
| 562 | sum0 += convert_int8(left1) + convert_int8(middle1) + convert_int8(right1); |
| 563 | sum0 += convert_int8(left2) + convert_int8(middle2) + convert_int8(right2); |
| 564 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 565 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 566 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 567 | // If conv_stride_y is equals to 1, we compute two output rows |
| 568 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 569 | VEC_TYPE(8) |
| 570 | left3, middle3, right3; |
| 571 | int8 values1 = 0; |
| 572 | int8 sum1 = 0; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 573 | |
| 574 | GET_VALUES(src.ptr + 3 * src_stride_y, left3, middle3, right3); |
| 575 | |
| 576 | #if WEIGHTS_OFFSET != 0 |
| 577 | sum1 += convert_int8(left1) + convert_int8(middle1) + convert_int8(right1); |
| 578 | sum1 += convert_int8(left2) + convert_int8(middle2) + convert_int8(right2); |
| 579 | sum1 += convert_int8(left3) + convert_int8(middle3) + convert_int8(right3); |
| 580 | #endif /* WEIGHTS_OFFSET != 0 */ |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 581 | #endif // CONV_STRIDE_Y == 1 && DILATION_Y==1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 582 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 583 | ARM_DOT((VEC_TYPE(4))(left0.s0, middle0.s0, right0.s0, left1.s0), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s0); |
| 584 | ARM_DOT((VEC_TYPE(4))(middle1.s0, right1.s0, left2.s0, middle2.s0), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s0); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 585 | values0.s0 += right2.s0 * w2.s2; |
| 586 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 587 | ARM_DOT((VEC_TYPE(4))(left0.s1, middle0.s1, right0.s1, left1.s1), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s1); |
| 588 | ARM_DOT((VEC_TYPE(4))(middle1.s1, right1.s1, left2.s1, middle2.s1), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s1); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 589 | values0.s1 += right2.s1 * w2.s2; |
| 590 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 591 | ARM_DOT((VEC_TYPE(4))(left0.s2, middle0.s2, right0.s2, left1.s2), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s2); |
| 592 | ARM_DOT((VEC_TYPE(4))(middle1.s2, right1.s2, left2.s2, middle2.s2), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s2); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 593 | values0.s2 += right2.s2 * w2.s2; |
| 594 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 595 | ARM_DOT((VEC_TYPE(4))(left0.s3, middle0.s3, right0.s3, left1.s3), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s3); |
| 596 | ARM_DOT((VEC_TYPE(4))(middle1.s3, right1.s3, left2.s3, middle2.s3), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s3); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 597 | values0.s3 += right2.s3 * w2.s2; |
| 598 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 599 | ARM_DOT((VEC_TYPE(4))(left0.s4, middle0.s4, right0.s4, left1.s4), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s4); |
| 600 | ARM_DOT((VEC_TYPE(4))(middle1.s4, right1.s4, left2.s4, middle2.s4), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s4); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 601 | values0.s4 += right2.s4 * w2.s2; |
| 602 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 603 | ARM_DOT((VEC_TYPE(4))(left0.s5, middle0.s5, right0.s5, left1.s5), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s5); |
| 604 | ARM_DOT((VEC_TYPE(4))(middle1.s5, right1.s5, left2.s5, middle2.s5), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s5); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 605 | values0.s5 += right2.s5 * w2.s2; |
| 606 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 607 | ARM_DOT((VEC_TYPE(4))(left0.s6, middle0.s6, right0.s6, left1.s6), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s6); |
| 608 | ARM_DOT((VEC_TYPE(4))(middle1.s6, right1.s6, left2.s6, middle2.s6), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s6); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 609 | values0.s6 += right2.s6 * w2.s2; |
| 610 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 611 | ARM_DOT((VEC_TYPE(4))(left0.s7, middle0.s7, right0.s7, left1.s7), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values0.s7); |
| 612 | ARM_DOT((VEC_TYPE(4))(middle1.s7, right1.s7, left2.s7, middle2.s7), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values0.s7); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 613 | values0.s7 += right2.s7 * w2.s2; |
| 614 | |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 615 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 616 | ARM_DOT((VEC_TYPE(4))(left1.s0, middle1.s0, right1.s0, left2.s0), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s0); |
| 617 | ARM_DOT((VEC_TYPE(4))(middle2.s0, right2.s0, left3.s0, middle3.s0), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s0); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 618 | values1.s0 += right3.s0 * w2.s2; |
| 619 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 620 | ARM_DOT((VEC_TYPE(4))(left1.s1, middle1.s1, right1.s1, left2.s1), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s1); |
| 621 | ARM_DOT((VEC_TYPE(4))(middle2.s1, right2.s1, left3.s1, middle3.s1), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s1); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 622 | values1.s1 += right3.s1 * w2.s2; |
| 623 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 624 | ARM_DOT((VEC_TYPE(4))(left1.s2, middle1.s2, right1.s2, left2.s2), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s2); |
| 625 | ARM_DOT((VEC_TYPE(4))(middle2.s2, right2.s2, left3.s2, middle3.s2), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s2); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 626 | values1.s2 += right3.s2 * w2.s2; |
| 627 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 628 | ARM_DOT((VEC_TYPE(4))(left1.s3, middle1.s3, right1.s3, left2.s3), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s3); |
| 629 | ARM_DOT((VEC_TYPE(4))(middle2.s3, right2.s3, left3.s3, middle3.s3), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s3); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 630 | values1.s3 += right3.s3 * w2.s2; |
| 631 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 632 | ARM_DOT((VEC_TYPE(4))(left1.s4, middle1.s4, right1.s4, left2.s4), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s4); |
| 633 | ARM_DOT((VEC_TYPE(4))(middle2.s4, right2.s4, left3.s4, middle3.s4), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s4); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 634 | values1.s4 += right3.s4 * w2.s2; |
| 635 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 636 | ARM_DOT((VEC_TYPE(4))(left1.s5, middle1.s5, right1.s5, left2.s5), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s5); |
| 637 | ARM_DOT((VEC_TYPE(4))(middle2.s5, right2.s5, left3.s5, middle3.s5), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s5); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 638 | values1.s5 += right3.s5 * w2.s2; |
| 639 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 640 | ARM_DOT((VEC_TYPE(4))(left1.s6, middle1.s6, right1.s6, left2.s6), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s6); |
| 641 | ARM_DOT((VEC_TYPE(4))(middle2.s6, right2.s6, left3.s6, middle3.s6), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s6); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 642 | values1.s6 += right3.s6 * w2.s2; |
| 643 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 644 | ARM_DOT((VEC_TYPE(4))(left1.s7, middle1.s7, right1.s7, left2.s7), (VEC_TYPE(4))(w0.s0, w0.s1, w0.s2, w1.s0), values1.s7); |
| 645 | ARM_DOT((VEC_TYPE(4))(middle2.s7, right2.s7, left3.s7, middle3.s7), (VEC_TYPE(4))(w1.s1, w1.s2, w2.s0, w2.s1), values1.s7); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 646 | values1.s7 += right3.s7 * w2.s2; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 647 | #endif // CONV_STRIDE_Y == 1 && DILATION_Y==1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 648 | |
| 649 | #if defined(HAS_BIAS) |
| 650 | values0 += (int8)(bias_value); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 651 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 652 | values1 += (int8)(bias_value); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 653 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 654 | #endif //defined(HAS_BIAS) |
| 655 | |
| 656 | #if WEIGHTS_OFFSET != 0 |
| 657 | values0 += sum0 * (int8)(WEIGHTS_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 658 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 659 | values1 += sum1 * (int8)(WEIGHTS_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 660 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 661 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 662 | |
| 663 | #if INPUT_OFFSET != 0 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 664 | WEIGHTS_PROMOTED_TYPE sum_weights = 0; |
| 665 | VEC_WEIGHTS_PROMOTED_TYPE(3) |
| 666 | tmp_we = CONVERT(w0, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w1, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w2, VEC_WEIGHTS_PROMOTED_TYPE(3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 667 | sum_weights += tmp_we.s0 + tmp_we.s1 + tmp_we.s2; |
| 668 | values0 += sum_weights * (int8)(INPUT_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 669 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 670 | values1 += sum_weights * (int8)(INPUT_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 671 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 672 | #endif /* INPUT_OFFSET != 0 */ |
| 673 | |
| 674 | #if K_OFFSET != 0 |
| 675 | values0 += (int8)(K_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 676 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 677 | values1 += (int8)(K_OFFSET); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 678 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 679 | #endif /* K_OFFSET != 0 */ |
| 680 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 681 | #if defined(REAL_MULTIPLIER) |
| 682 | |
| 683 | values0 = CONVERT(round(CONVERT(values0, float8) * (float8)REAL_MULTIPLIER), int8); |
| 684 | |
| 685 | #else // defined(REAL_MULTIPLIER) |
| 686 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 687 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 688 | int8 res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, output_multiplier, output_shift, 8); |
| 689 | int8 res0_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, output_multiplier, output_shift, 8); |
| 690 | values0 = select(res0_shift_lt0, res0_shift_gt0, (int8)(output_shift) >= 0); |
| 691 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 692 | #if OUTPUT_SHIFT < 0 |
| 693 | values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 694 | #else // OUTPUT_SHIFT < 0 |
| 695 | values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 696 | #endif // OUTPUT_OFFSET < 0 |
| 697 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 698 | |
| 699 | #endif // defined(REAL_MULTIPLIER) |
| 700 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 701 | values0 += (int8)OUTPUT_OFFSET; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 702 | VEC_TYPE(8) |
| 703 | res0 = CONVERT_SAT(values0, VEC_TYPE(8)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 704 | |
| 705 | vstore8(ACTIVATION_FUNC(res0), 0, dst.ptr); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 706 | #if CONV_STRIDE_Y == 1 && DILATION_Y == 1 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 707 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 708 | #if defined(REAL_MULTIPLIER) |
| 709 | |
| 710 | values1 = CONVERT(round(CONVERT(values1, float8) * (float8)REAL_MULTIPLIER), int8); |
| 711 | |
| 712 | #else // defined(REAL_MULTIPLIER) |
| 713 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 714 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 715 | int8 res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, output_multiplier, output_shift, 8); |
| 716 | int8 res1_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, output_multiplier, output_shift, 8); |
| 717 | values1 = select(res1_shift_lt0, res1_shift_gt0, (int8)(output_shift) >= 0); |
| 718 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 719 | #if OUTPUT_SHIFT < 0 |
| 720 | values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 721 | #else // OUTPUT_SHIFT < 0 |
| 722 | values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8); |
| 723 | #endif // OUTPUT_OFFSET < 0 |
| 724 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 725 | |
| 726 | #endif // defined(REAL_MULTIPLIER) |
| 727 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 728 | values1 += (int8)OUTPUT_OFFSET; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 729 | VEC_TYPE(8) |
| 730 | res1 = CONVERT_SAT(values1, VEC_TYPE(8)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 731 | |
| 732 | vstore8(ACTIVATION_FUNC(res1), 0, dst.ptr + dst_stride_y); |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 733 | #endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 734 | } |
| 735 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 736 | #endif // !defined(IS_DOT8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 737 | |
Georgios Pinitas | e55b40a | 2018-09-13 17:20:04 +0100 | [diff] [blame] | 738 | #endif /* defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X) && defined(DEPTH_MULTIPLIER) && defined(DST_CHANNELS) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 739 | |
| 740 | #if defined(VEC_SIZE) && defined(SRC_DIM_1) && defined(SRC_DIM_2) && defined(CONV_PAD_TOP) && defined(CONV_PAD_LEFT) |
| 741 | |
| 742 | #define asymm_mult_by_quant_multiplier_less_than_one(x, y, z) ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(x, y, z, VEC_SIZE) |
| 743 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 744 | #define MULTIPLY_ADD(x, y, acc) acc += CONVERT(CONVERT(x, VEC_WEIGHTS_PROMOTED_TYPE(VEC_SIZE)) * CONVERT(y, VEC_WEIGHTS_PROMOTED_TYPE(VEC_SIZE)), VEC_INT) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 745 | |
| 746 | #if WEIGHTS_OFFSET != 0 |
| 747 | #define MULTIPLY_ADD_ACCUMULATE(x, y, acc, sum) \ |
| 748 | ({ \ |
| 749 | sum += CONVERT(x, VEC_INT); \ |
| 750 | MULTIPLY_ADD(x, y, acc); \ |
| 751 | }) |
| 752 | #else /* WEIGHTS_OFFSET != 0 */ |
| 753 | #define MULTIPLY_ADD_ACCUMULATE(x, y, acc, sum) MULTIPLY_ADD(x, y, acc) |
| 754 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 755 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 756 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 757 | #define DOT_PRODUCT(acc, val0, val1, val2, val3, val4, val5, val6, val7, val8, w0, w1) \ |
| 758 | ({ \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 759 | ARM_DOT((VEC_TYPE(4))(val0, val1, val2, val3), w0.s0123, acc); \ |
| 760 | ARM_DOT((VEC_TYPE(4))(val4, val5, val6, val7), w0.s4567, acc); \ |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 761 | acc += val8 * w1; \ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 762 | }) |
| 763 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 764 | #define DOT_PRODUCT_REDUCTION(sum, val0, val1, val2, val3, val4, val5, val6, val7, val8) \ |
| 765 | ({ \ |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 766 | sum = val0; \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 767 | ARM_DOT((VEC_TYPE(4))(val1, val2, val3, val4), (VEC_TYPE(4))1, sum); \ |
| 768 | ARM_DOT((VEC_TYPE(4))(val5, val6, val7, val8), (VEC_TYPE(4))1, sum); \ |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 769 | }) |
| 770 | |
| 771 | #define DOT_PRODUCT_REDUCTION_WEIGHTS(sum, w0, w1) \ |
| 772 | ({ \ |
| 773 | sum = w1; \ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 774 | ARM_DOT(w0.s0123, (VEC_TYPE(4))1, sum); \ |
| 775 | ARM_DOT(w0.s4567, (VEC_TYPE(4))1, sum); \ |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 776 | }) |
| 777 | |
Georgios Pinitas | daa3855 | 2018-08-28 17:43:18 +0100 | [diff] [blame] | 778 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 779 | |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 780 | #if defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && VEC_SIZE == 4 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 781 | /** This function computes the depthwise convolution quantized for NHWC data layout when the stride along the width or height is not 1. |
| 782 | * |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 783 | * @note This kernel assumes VEC_SIZE is 4. |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 784 | * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel. |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 785 | * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2) |
| 786 | * @note Dimension two of the input tensor (height for NHWC data layout) must be passed at compile time using -DSRC_DIM2 (e.g. -DSRC_DIM_2=112) |
| 787 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1) |
| 788 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1) |
| 789 | * @note The convolution stride along the width must be passed at compile time using -DCONV_STRIDE_X (e.g. -DCONV_STRIDE_Y=X) |
| 790 | * @note The convolution stride along the height must be passed at compile time using -DCONV_STRIDE_Y (e.g. -DCONV_STRIDE_Y=1) |
| 791 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 792 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8 |
| 793 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 794 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 795 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 796 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 797 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 798 | * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes) |
| 799 | * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes) |
| 800 | * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes) |
| 801 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 802 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 803 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 804 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 805 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 806 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 807 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 808 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 809 | * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes) |
| 810 | * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes) |
| 811 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 812 | * @param[in] weights_ptr Pointer to the weights tensor reshaped. Supported data types: QASYMM8/QSYMM8_PER_CHANNEL |
| 813 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 814 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 815 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 816 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 817 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 818 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 819 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 820 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 821 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 822 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 823 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 824 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 825 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 826 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 827 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 828 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 829 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
| 830 | * @param[in] max_offset Max offset for the input tensor |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 831 | */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 832 | __kernel void dwc_3x3_reshaped_quantized8_nhwc( |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 833 | TENSOR4D_DECLARATION(src), |
| 834 | TENSOR4D_DECLARATION(dst), |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 835 | IMAGE_DECLARATION(weights), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 836 | VECTOR_DECLARATION(output_multipliers), |
| 837 | VECTOR_DECLARATION(output_shifts), |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 838 | #if defined(HAS_BIAS) |
| 839 | VECTOR_DECLARATION(biases), |
| 840 | #endif /* defined(HAS_BIAS) */ |
| 841 | int max_offset) |
| 842 | { |
| 843 | const int x = get_global_id(0); // channels |
| 844 | const int y = get_global_id(1); // spatial coordinate x |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 845 | #if defined(DST_DEPTH) |
| 846 | int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y |
| 847 | int b = get_global_id(2) / (int)DST_DEPTH; // batch |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 848 | #else // defined(DST_DEPTH) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 849 | int z = get_global_id(2); // spatial coordinate y |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 850 | #endif // defined(DST_DEPTH) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 851 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 852 | __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 853 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 854 | #if defined(DST_DEPTH) |
| 855 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w; |
| 856 | #else /* defined(DST_DEPTH) */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 857 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 858 | #endif /* defined(DST_DEPTH) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 859 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 860 | int z_coord = 0; |
| 861 | int4 offset = 0; |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 862 | int4 y_coord = ((int4)(y * CONV_STRIDE_X) + (int4)(0, DILATION_X * 1, DILATION_X * 2, DILATION_X * 3)) - (int)CONV_PAD_LEFT; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 863 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 864 | // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1 |
| 865 | y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1); |
| 866 | y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1); |
| 867 | y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1); |
| 868 | y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1); |
| 869 | |
| 870 | int4 y_offset = convert_int4(y_coord * (int)src_stride_y); |
| 871 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 872 | // We compute VEC_SIZEx1x1 [C,W,H] elements |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 873 | VEC_INT acc = 0, sum = 0; |
| 874 | |
| 875 | // Load weights |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 876 | VEC_DATA_TYPE(WEIGHTS_TYPE, 16) |
| 877 | w0_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr)); |
| 878 | VEC_DATA_TYPE(WEIGHTS_TYPE, 16) |
| 879 | w1_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16)); |
| 880 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 881 | w8 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * 16)); |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 882 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 883 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 884 | w0 = w0_tmp.s0123; |
| 885 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 886 | w1 = w0_tmp.s4567; |
| 887 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 888 | w2 = w0_tmp.s89AB; |
| 889 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 890 | w3 = w0_tmp.sCDEF; |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 891 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 892 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 893 | w4 = w1_tmp.s0123; |
| 894 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 895 | w5 = w1_tmp.s4567; |
| 896 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 897 | w6 = w1_tmp.s89AB; |
| 898 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 899 | w7 = w1_tmp.sCDEF; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 900 | |
| 901 | #if INPUT_OFFSET != 0 |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 902 | VEC_INT sum_we = CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT) |
| 903 | + CONVERT(w3, VEC_INT) + CONVERT(w4, VEC_INT) + CONVERT(w5, VEC_INT) |
| 904 | + CONVERT(w6, VEC_INT) + CONVERT(w7, VEC_INT) + CONVERT(w8, VEC_INT); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 905 | #endif /* INPUT_OFFSET != 0 */ |
| 906 | |
| 907 | // Load input values |
| 908 | // z == 0 |
| 909 | // Clamp z_coord as for z = 0, it can be negative |
| 910 | // z_coord is casted to unsigned int in order to use just a min() operation |
| 911 | // A "-1" 32 bit signed variable converted to unsigned gives 4294967295 |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 912 | z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 913 | z_coord = min((uint)z_coord, (uint)SRC_DIM_2); |
| 914 | offset = y_offset + (int4)(z_coord * src_stride_z); |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 915 | offset = min(offset, (int4)max_offset); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 916 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 917 | VEC_TYPE(VEC_SIZE) |
| 918 | values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 919 | VEC_TYPE(VEC_SIZE) |
| 920 | values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 921 | VEC_TYPE(VEC_SIZE) |
| 922 | values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 923 | |
| 924 | // z == 1 |
| 925 | // z_coord can be only negative for z = 0 so we do not need to clamp it |
| 926 | // Moreover z_coord cannot be out-of-bound for z = 1 so we do not need to clamp the offset |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 927 | z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP + DILATION_Y; |
| 928 | offset = y_offset + (int4)(z_coord * src_stride_z); |
| 929 | VEC_TYPE(VEC_SIZE) |
| 930 | values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 931 | VEC_TYPE(VEC_SIZE) |
| 932 | values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 933 | VEC_TYPE(VEC_SIZE) |
| 934 | values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 935 | |
| 936 | // z == 2 |
Usama Arif | e73686a | 2019-04-08 17:30:48 +0100 | [diff] [blame] | 937 | // Offset can be out-of-bound so we need to check if it is greater than max_offset |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 938 | z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP + DILATION_Y * 2; |
| 939 | offset = y_offset + (int4)(z_coord * src_stride_z); |
| 940 | offset = min(offset, (int4)max_offset); |
| 941 | VEC_TYPE(VEC_SIZE) |
| 942 | values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 943 | VEC_TYPE(VEC_SIZE) |
| 944 | values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 945 | VEC_TYPE(VEC_SIZE) |
| 946 | values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 947 | |
| 948 | MULTIPLY_ADD_ACCUMULATE(values0, w0, acc, sum); |
| 949 | MULTIPLY_ADD_ACCUMULATE(values1, w1, acc, sum); |
| 950 | MULTIPLY_ADD_ACCUMULATE(values2, w2, acc, sum); |
| 951 | |
| 952 | MULTIPLY_ADD_ACCUMULATE(values3, w3, acc, sum); |
| 953 | MULTIPLY_ADD_ACCUMULATE(values4, w4, acc, sum); |
| 954 | MULTIPLY_ADD_ACCUMULATE(values5, w5, acc, sum); |
| 955 | |
| 956 | MULTIPLY_ADD_ACCUMULATE(values6, w6, acc, sum); |
| 957 | MULTIPLY_ADD_ACCUMULATE(values7, w7, acc, sum); |
| 958 | MULTIPLY_ADD_ACCUMULATE(values8, w8, acc, sum); |
| 959 | |
| 960 | #if defined(HAS_BIAS) |
| 961 | Vector biases = CONVERT_TO_VECTOR_STRUCT(biases); |
| 962 | VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr); |
| 963 | acc += bias_values; |
| 964 | #endif // defined(HAS_BIAS) |
| 965 | |
| 966 | #if WEIGHTS_OFFSET != 0 |
| 967 | acc += WEIGHTS_OFFSET * sum; |
| 968 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 969 | |
| 970 | #if INPUT_OFFSET != 0 |
| 971 | acc += INPUT_OFFSET * sum_we; |
| 972 | #endif /* INPUT_OFFSET != 0 */ |
| 973 | |
| 974 | #if K_OFFSET != 0 |
| 975 | acc += (VEC_INT)K_OFFSET; |
| 976 | #endif /* K_OFFSET != 0 */ |
| 977 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 978 | #if defined(REAL_MULTIPLIER) |
| 979 | |
| 980 | acc = CONVERT(round(CONVERT(acc, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 981 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 982 | #else // defined(REAL_MULTIPLIER) |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 983 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 984 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 985 | Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT(output_multipliers); |
| 986 | Vector output_shifts = CONVERT_TO_VECTOR_STRUCT(output_shifts); |
| 987 | VEC_INT output_multiplier = VLOAD(VEC_SIZE)(0, (__global int *)output_multipliers.ptr); |
| 988 | VEC_INT output_shift = VLOAD(VEC_SIZE)(0, (__global int *)output_shifts.ptr); |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 989 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 990 | VEC_INT res_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc, output_multiplier, output_shift, VEC_SIZE); |
| 991 | VEC_INT res_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc, output_multiplier, output_shift); |
| 992 | acc = select(res_shift_lt0, res_shift_gt0, output_shift >= 0); |
| 993 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 994 | #if OUTPUT_SHIFT < 0 |
| 995 | acc = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 996 | #else // OUTPUT_SHIFT < 0 |
| 997 | acc = asymm_mult_by_quant_multiplier_less_than_one(acc, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 998 | #endif // OUTPUT_SHIFT < 0 |
| 999 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1000 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1001 | #endif // defined(REAL_MULTIPLIER) |
| 1002 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1003 | acc += (VEC_INT)OUTPUT_OFFSET; |
| 1004 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1005 | VEC_TYPE(VEC_SIZE) |
| 1006 | res = CONVERT_SAT(acc, VEC_TYPE(VEC_SIZE)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1007 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1008 | #if defined(DST_DEPTH) |
| 1009 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + z * dst_step_z + b * dst_stride_w; |
| 1010 | #else /* defined(DST_DEPTH) */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1011 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + z * dst_step_z; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1012 | #endif /* defined(DST_DEPTH) */ |
| 1013 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1014 | VSTORE(VEC_SIZE) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1015 | (ACTIVATION_FUNC(res), 0, (__global DATA_TYPE *)(dst_addr)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1016 | } |
| 1017 | #endif // defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) |
| 1018 | |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1019 | #if defined(NUM_ROWS_PROCESSED) && defined(NUM_PLANES_PROCESSED) && VEC_SIZE == 4 |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1020 | /** This function computes the depthwise convolution quantized for NHWC data layout when the stride along the width and height is 1. |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1021 | * |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1022 | * @note This kernel assumes VEC_SIZE is 4. |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1023 | * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel. |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1024 | * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2) |
| 1025 | * @note Dimension two of the input tensor (height for NHWC data layout) must be passed at compile time using -DSRC_DIM2 (e.g. -DSRC_DIM_2=112) |
| 1026 | * @note The number of rows processed per thread must be passed at compile time using -DNUM_ROWS_PROCESSED (i.e. -DNUM_ROWS_PROCESSED=2) |
| 1027 | * @note The number of planes processed per thread must be passed at compile time using -DNUM_PLANES_PROCESSED (i.e. -DNUM_PLANES_PROCESSED=2) |
| 1028 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1) |
| 1029 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1). |
| 1030 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1031 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8 |
| 1032 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 1033 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 1034 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 1035 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1036 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 1037 | * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes) |
| 1038 | * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes) |
| 1039 | * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes) |
| 1040 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 1041 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 1042 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 1043 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 1044 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 1045 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1046 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 1047 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 1048 | * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes) |
| 1049 | * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes) |
| 1050 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 1051 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QSYMM8_PER_CHANNEL |
| 1052 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 1053 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 1054 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 1055 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1056 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 1057 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 1058 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 1059 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 1060 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 1061 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 1062 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 1063 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 1064 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 1065 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 1066 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 1067 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 1068 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
| 1069 | * @param[in] max_offset Max offset for the input tensor |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1070 | */ |
| 1071 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1072 | __kernel void dwc_3x3_reshaped_quantized8_stride1_nhwc( |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1073 | TENSOR4D_DECLARATION(src), |
| 1074 | TENSOR4D_DECLARATION(dst), |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1075 | IMAGE_DECLARATION(weights), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1076 | VECTOR_DECLARATION(output_multipliers), |
| 1077 | VECTOR_DECLARATION(output_shifts), |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1078 | #if defined(HAS_BIAS) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1079 | VECTOR_DECLARATION(biases), |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1080 | #endif /* defined(HAS_BIAS) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1081 | int max_offset) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1082 | { |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 1083 | int x = get_global_id(0); |
| 1084 | int y = get_global_id(1); |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1085 | #if defined(DST_DEPTH) |
| 1086 | int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y |
| 1087 | int b = get_global_id(2) / (int)DST_DEPTH; // batch |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1088 | #else // defined(DST_DEPTH) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1089 | int z = get_global_id(2); // spatial coordinate y |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1090 | #endif // defined(DST_DEPTH) |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 1091 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1092 | __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1093 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1094 | #if defined(DST_DEPTH) |
| 1095 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w; |
| 1096 | #else /* defined(DST_DEPTH) */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1097 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1098 | #endif /* defined(DST_DEPTH) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1099 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1100 | int z_coord = 0; |
| 1101 | int4 offset = 0; |
| 1102 | int4 y_coord = ((int4)(y * NUM_ROWS_PROCESSED) + (int4)(0, 1, 2, 3)) - (int)CONV_PAD_LEFT; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1103 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1104 | // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1 |
| 1105 | y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1); |
| 1106 | y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1); |
| 1107 | y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1); |
| 1108 | y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1); |
| 1109 | |
| 1110 | int4 y_offset = convert_int4(y_coord * (int)src_stride_y); |
| 1111 | |
| 1112 | // We compute 4x2x2 [C,W,H] elements |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1113 | VEC_INT acc0 = 0, sum0 = 0; |
| 1114 | VEC_INT acc1 = 0, sum1 = 0; |
| 1115 | VEC_INT acc2 = 0, sum2 = 0; |
| 1116 | VEC_INT acc3 = 0, sum3 = 0; |
| 1117 | |
| 1118 | // Load weights |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1119 | VEC_DATA_TYPE(WEIGHTS_TYPE, 16) |
| 1120 | w0_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr)); |
| 1121 | VEC_DATA_TYPE(WEIGHTS_TYPE, 16) |
| 1122 | w1_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16)); |
| 1123 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1124 | w8 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * 16)); |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1125 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1126 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1127 | w0 = w0_tmp.s0123; |
| 1128 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1129 | w1 = w0_tmp.s4567; |
| 1130 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1131 | w2 = w0_tmp.s89AB; |
| 1132 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1133 | w3 = w0_tmp.sCDEF; |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1134 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1135 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1136 | w4 = w1_tmp.s0123; |
| 1137 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1138 | w5 = w1_tmp.s4567; |
| 1139 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1140 | w6 = w1_tmp.s89AB; |
| 1141 | VEC_DATA_TYPE(WEIGHTS_TYPE, 4) |
| 1142 | w7 = w1_tmp.sCDEF; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1143 | |
| 1144 | #if INPUT_OFFSET != 0 |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 1145 | VEC_INT sum_we = CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT) |
| 1146 | + CONVERT(w3, VEC_INT) + CONVERT(w4, VEC_INT) + CONVERT(w5, VEC_INT) |
| 1147 | + CONVERT(w6, VEC_INT) + CONVERT(w7, VEC_INT) + CONVERT(w8, VEC_INT); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1148 | #endif /* INPUT_OFFSET != 0 */ |
| 1149 | |
| 1150 | // Load input values |
| 1151 | // z == 0 |
| 1152 | // Clamp z_coord as for z = 0, it can be negative |
| 1153 | // z_coord is casted to unsigned int in order to use just a min() operation |
| 1154 | // A "-1" 32 bit signed variable converted to unsigned gives 4294967295 |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 1155 | z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1156 | z_coord = min((uint)z_coord, (uint)SRC_DIM_2); |
| 1157 | offset = y_offset + (int4)(z_coord * src_stride_z); |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 1158 | offset = min(offset, (int4)max_offset); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1159 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1160 | VEC_TYPE(VEC_SIZE) |
| 1161 | values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1162 | VEC_TYPE(VEC_SIZE) |
| 1163 | values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1164 | VEC_TYPE(VEC_SIZE) |
| 1165 | values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1166 | VEC_TYPE(VEC_SIZE) |
| 1167 | values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1168 | |
| 1169 | // z == 1 |
| 1170 | // z_coord can be only negative for z = 0 so we do not need to clamp it |
| 1171 | // Moreover z_coord cannot be out-of-bound for z = 1 so we do not need to clamp the offset |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1172 | z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP + 1; |
| 1173 | offset = y_offset + (int4)(z_coord * src_stride_z); |
| 1174 | VEC_TYPE(VEC_SIZE) |
| 1175 | values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1176 | VEC_TYPE(VEC_SIZE) |
| 1177 | values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1178 | VEC_TYPE(VEC_SIZE) |
| 1179 | values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1180 | VEC_TYPE(VEC_SIZE) |
| 1181 | values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1182 | |
| 1183 | // z == 2 |
| 1184 | // After z = 1 we can simply add src_stride_z to offset without updating z_coord |
| 1185 | // However offset can be out-of-bound so we need to check if it is greater than max_offset |
| 1186 | offset += (int4)src_stride_z; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1187 | offset = min(offset, (int4)max_offset); |
| 1188 | VEC_TYPE(VEC_SIZE) |
| 1189 | values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1190 | VEC_TYPE(VEC_SIZE) |
| 1191 | values9 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1192 | VEC_TYPE(VEC_SIZE) |
| 1193 | values10 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1194 | VEC_TYPE(VEC_SIZE) |
| 1195 | values11 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1196 | |
| 1197 | // z == 3 |
| 1198 | // After z = 1 we can simply add src_stride_z to offset without updating z_coord |
| 1199 | // However offset can be out-of-bound so we need to check if it is greater than max_offset |
| 1200 | offset += (int4)(src_stride_z); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1201 | offset = min(offset, (int4)max_offset); |
| 1202 | VEC_TYPE(VEC_SIZE) |
| 1203 | values12 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1204 | VEC_TYPE(VEC_SIZE) |
| 1205 | values13 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1206 | VEC_TYPE(VEC_SIZE) |
| 1207 | values14 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1208 | VEC_TYPE(VEC_SIZE) |
| 1209 | values15 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1210 | |
| 1211 | MULTIPLY_ADD_ACCUMULATE(values0, w0, acc0, sum0); |
| 1212 | MULTIPLY_ADD_ACCUMULATE(values1, w1, acc0, sum0); |
| 1213 | MULTIPLY_ADD_ACCUMULATE(values2, w2, acc0, sum0); |
| 1214 | MULTIPLY_ADD_ACCUMULATE(values1, w0, acc1, sum1); |
| 1215 | MULTIPLY_ADD_ACCUMULATE(values2, w1, acc1, sum1); |
| 1216 | MULTIPLY_ADD_ACCUMULATE(values3, w2, acc1, sum1); |
| 1217 | |
| 1218 | MULTIPLY_ADD_ACCUMULATE(values4, w3, acc0, sum0); |
| 1219 | MULTIPLY_ADD_ACCUMULATE(values5, w4, acc0, sum0); |
| 1220 | MULTIPLY_ADD_ACCUMULATE(values6, w5, acc0, sum0); |
| 1221 | MULTIPLY_ADD_ACCUMULATE(values5, w3, acc1, sum1); |
| 1222 | MULTIPLY_ADD_ACCUMULATE(values6, w4, acc1, sum1); |
| 1223 | MULTIPLY_ADD_ACCUMULATE(values7, w5, acc1, sum1); |
| 1224 | |
| 1225 | MULTIPLY_ADD_ACCUMULATE(values8, w6, acc0, sum0); |
| 1226 | MULTIPLY_ADD_ACCUMULATE(values9, w7, acc0, sum0); |
| 1227 | MULTIPLY_ADD_ACCUMULATE(values10, w8, acc0, sum0); |
| 1228 | MULTIPLY_ADD_ACCUMULATE(values9, w6, acc1, sum1); |
| 1229 | MULTIPLY_ADD_ACCUMULATE(values10, w7, acc1, sum1); |
| 1230 | MULTIPLY_ADD_ACCUMULATE(values11, w8, acc1, sum1); |
| 1231 | |
| 1232 | MULTIPLY_ADD_ACCUMULATE(values4, w0, acc2, sum2); |
| 1233 | MULTIPLY_ADD_ACCUMULATE(values5, w1, acc2, sum2); |
| 1234 | MULTIPLY_ADD_ACCUMULATE(values6, w2, acc2, sum2); |
| 1235 | MULTIPLY_ADD_ACCUMULATE(values5, w0, acc3, sum3); |
| 1236 | MULTIPLY_ADD_ACCUMULATE(values6, w1, acc3, sum3); |
| 1237 | MULTIPLY_ADD_ACCUMULATE(values7, w2, acc3, sum3); |
| 1238 | |
| 1239 | MULTIPLY_ADD_ACCUMULATE(values8, w3, acc2, sum2); |
| 1240 | MULTIPLY_ADD_ACCUMULATE(values9, w4, acc2, sum2); |
| 1241 | MULTIPLY_ADD_ACCUMULATE(values10, w5, acc2, sum2); |
| 1242 | MULTIPLY_ADD_ACCUMULATE(values9, w3, acc3, sum3); |
| 1243 | MULTIPLY_ADD_ACCUMULATE(values10, w4, acc3, sum3); |
| 1244 | MULTIPLY_ADD_ACCUMULATE(values11, w5, acc3, sum3); |
| 1245 | |
| 1246 | MULTIPLY_ADD_ACCUMULATE(values12, w6, acc2, sum2); |
| 1247 | MULTIPLY_ADD_ACCUMULATE(values13, w7, acc2, sum2); |
| 1248 | MULTIPLY_ADD_ACCUMULATE(values14, w8, acc2, sum2); |
| 1249 | MULTIPLY_ADD_ACCUMULATE(values13, w6, acc3, sum3); |
| 1250 | MULTIPLY_ADD_ACCUMULATE(values14, w7, acc3, sum3); |
| 1251 | MULTIPLY_ADD_ACCUMULATE(values15, w8, acc3, sum3); |
| 1252 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1253 | #if defined(HAS_BIAS) |
| 1254 | Vector biases = CONVERT_TO_VECTOR_STRUCT(biases); |
| 1255 | |
| 1256 | VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1257 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1258 | acc0 += bias_values; |
| 1259 | acc1 += bias_values; |
| 1260 | acc2 += bias_values; |
| 1261 | acc3 += bias_values; |
| 1262 | #endif /* defined(HAS_BIAS) */ |
| 1263 | |
| 1264 | #if WEIGHTS_OFFSET != 0 |
| 1265 | acc0 += WEIGHTS_OFFSET * sum0; |
| 1266 | acc1 += WEIGHTS_OFFSET * sum1; |
| 1267 | acc2 += WEIGHTS_OFFSET * sum2; |
| 1268 | acc3 += WEIGHTS_OFFSET * sum3; |
| 1269 | #endif /* WEIGHTS_OFFSET != 0 */ |
| 1270 | |
| 1271 | #if INPUT_OFFSET != 0 |
| 1272 | VEC_INT offs = INPUT_OFFSET * sum_we; |
| 1273 | |
| 1274 | acc0 += offs; |
| 1275 | acc1 += offs; |
| 1276 | acc2 += offs; |
| 1277 | acc3 += offs; |
| 1278 | #endif /* INPUT_OFFSET != 0 */ |
| 1279 | |
| 1280 | #if K_OFFSET != 0 |
| 1281 | acc0 += (VEC_INT)K_OFFSET; |
| 1282 | acc1 += (VEC_INT)K_OFFSET; |
| 1283 | acc2 += (VEC_INT)K_OFFSET; |
| 1284 | acc3 += (VEC_INT)K_OFFSET; |
| 1285 | #endif /* K_OFFSET != 0 */ |
| 1286 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1287 | #if defined(REAL_MULTIPLIER) |
| 1288 | |
| 1289 | acc0 = CONVERT(round(CONVERT(acc0, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1290 | acc1 = CONVERT(round(CONVERT(acc1, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1291 | acc2 = CONVERT(round(CONVERT(acc2, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1292 | acc3 = CONVERT(round(CONVERT(acc3, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1293 | |
| 1294 | #else // defined(REAL_MULTIPLIER) |
| 1295 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1296 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 1297 | Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT(output_multipliers); |
| 1298 | Vector output_shifts = CONVERT_TO_VECTOR_STRUCT(output_shifts); |
| 1299 | VEC_INT output_multiplier = VLOAD(VEC_SIZE)(0, (__global int *)output_multipliers.ptr); |
| 1300 | VEC_INT output_shift = VLOAD(VEC_SIZE)(0, (__global int *)output_shifts.ptr); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1301 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1302 | res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, output_multiplier, output_shift, VEC_SIZE); |
| 1303 | res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, output_multiplier, output_shift, VEC_SIZE); |
| 1304 | res2_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc2, output_multiplier, output_shift, VEC_SIZE); |
| 1305 | res3_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc3, output_multiplier, output_shift, VEC_SIZE); |
| 1306 | res0_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, output_multiplier, output_shift); |
| 1307 | res1_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc1, output_multiplier, output_shift); |
| 1308 | res2_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc2, output_multiplier, output_shift); |
| 1309 | res3_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc3, output_multiplier, output_shift); |
| 1310 | acc0 = select(res0_shift_lt0, res0_shift_gt0, output_shift >= 0); |
| 1311 | acc1 = select(res1_shift_lt0, res1_shift_gt0, output_shift >= 0); |
| 1312 | acc2 = select(res2_shift_lt0, res2_shift_gt0, output_shift >= 0); |
| 1313 | acc3 = select(res3_shift_lt0, res3_shift_gt0, output_shift >= 0); |
| 1314 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 1315 | #if OUTPUT_SHIFT < 0 |
Michele Di Giorgio | b598afa | 2019-12-20 16:22:20 +0000 | [diff] [blame] | 1316 | acc0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 1317 | acc1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 1318 | acc2 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 1319 | acc3 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc3, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1320 | #else // OUTPUT_SHIFT < 0 |
Michele Di Giorgio | b598afa | 2019-12-20 16:22:20 +0000 | [diff] [blame] | 1321 | acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 1322 | acc1 = asymm_mult_by_quant_multiplier_less_than_one(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 1323 | acc2 = asymm_mult_by_quant_multiplier_less_than_one(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 1324 | acc3 = asymm_mult_by_quant_multiplier_less_than_one(acc3, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1325 | #endif // OUTPUT_SHIFT < 0 |
| 1326 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1327 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1328 | #endif // defined(REAL_MULTIPLIER) |
| 1329 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1330 | acc0 += (VEC_INT)OUTPUT_OFFSET; |
| 1331 | acc1 += (VEC_INT)OUTPUT_OFFSET; |
| 1332 | acc2 += (VEC_INT)OUTPUT_OFFSET; |
| 1333 | acc3 += (VEC_INT)OUTPUT_OFFSET; |
| 1334 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1335 | VEC_TYPE(VEC_SIZE) |
| 1336 | res0 = CONVERT_SAT(acc0, VEC_TYPE(VEC_SIZE)); |
| 1337 | VEC_TYPE(VEC_SIZE) |
| 1338 | res1 = CONVERT_SAT(acc1, VEC_TYPE(VEC_SIZE)); |
| 1339 | VEC_TYPE(VEC_SIZE) |
| 1340 | res2 = CONVERT_SAT(acc2, VEC_TYPE(VEC_SIZE)); |
| 1341 | VEC_TYPE(VEC_SIZE) |
| 1342 | res3 = CONVERT_SAT(acc3, VEC_TYPE(VEC_SIZE)); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1343 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1344 | #if defined(DST_DEPTH) |
| 1345 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + (z * NUM_PLANES_PROCESSED) * dst_step_z + b * dst_stride_w; |
| 1346 | #else /* defined(DST_DEPTH) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1347 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + (z * NUM_PLANES_PROCESSED) * dst_step_z; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1348 | #endif /* defined(DST_DEPTH) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1349 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1350 | VSTORE(VEC_SIZE) |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 1351 | (ACTIVATION_FUNC(res0), 0, dst_addr + 0 * dst_stride_y); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1352 | VSTORE(VEC_SIZE) |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 1353 | (ACTIVATION_FUNC(res1), 0, dst_addr + 1 * dst_stride_y); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1354 | |
| 1355 | #if((DST_DIM_2 % NUM_PLANES_PROCESSED) != 0) |
| 1356 | if((z * NUM_PLANES_PROCESSED + 1) < DST_DIM_2) |
| 1357 | #endif // ((DST_DIM_2 % NUM_PLANES_PROCESSED) != 0) |
| 1358 | { |
| 1359 | VSTORE(VEC_SIZE) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1360 | (ACTIVATION_FUNC(res2), 0, (__global DATA_TYPE *)(dst_addr + 0 * dst_stride_y + 1 * dst_stride_z)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1361 | VSTORE(VEC_SIZE) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1362 | (ACTIVATION_FUNC(res3), 0, (__global DATA_TYPE *)(dst_addr + 1 * dst_stride_y + 1 * dst_stride_z)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1363 | } |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1366 | #if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) && VEC_SIZE == 4 |
| 1367 | /** This function computes the depthwise convolution quantized for NHWC data layout when the stride along the width and height is 1 using dot product. |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1368 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1369 | * @note Per-channel quantization is not supported by this kernel. |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1370 | * @note This kernel assumes VEC_SIZE is 4. |
| 1371 | * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel. |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1372 | * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2) |
| 1373 | * @note Dimension two of the input tensor (height for NHWC data layout) must be passed at compile time using -DSRC_DIM2 (e.g. -DSRC_DIM_2=112) |
| 1374 | * @note The number of rows processed per thread must be passed at compile time using -DNUM_ROWS_PROCESSED (i.e. -DNUM_ROWS_PROCESSED=2) |
| 1375 | * @note The number of planes processed per thread must be passed at compile time using -DNUM_PLANES_PROCESSED (i.e. -DNUM_PLANES_PROCESSED=2) |
| 1376 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1) |
| 1377 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1). |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1378 | * @note If REAL_MULTIPLIER is passed at compile time (i.e. -DREAL_MULTIPLIER=1.355f), the final quantization is performed using a floating point multiplication. |
| 1379 | * If not, the quantization will be performed using a fixed point multiplication |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1380 | * |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1381 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8 |
| 1382 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 1383 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 1384 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 1385 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1386 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 1387 | * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes) |
| 1388 | * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes) |
| 1389 | * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes) |
| 1390 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 1391 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 1392 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 1393 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 1394 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 1395 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1396 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 1397 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 1398 | * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes) |
| 1399 | * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes) |
| 1400 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 1401 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: same as @p src_ptr |
| 1402 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 1403 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 1404 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 1405 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1406 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 1407 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 1408 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 1409 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 1410 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 1411 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 1412 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 1413 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 1414 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 1415 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 1416 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 1417 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 1418 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
| 1419 | * @param[in] max_offset The maximum allowed offset for the input tensor |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1420 | */ |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1421 | __kernel void dwc_3x3_reshaped_quantized8_dot8_stride1_nhwc( |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1422 | TENSOR4D_DECLARATION(src), |
| 1423 | TENSOR4D_DECLARATION(dst), |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1424 | IMAGE_DECLARATION(weights), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1425 | VECTOR_DECLARATION(output_multipliers), |
| 1426 | VECTOR_DECLARATION(output_shifts), |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1427 | #if defined(HAS_BIAS) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1428 | VECTOR_DECLARATION(biases), |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1429 | #endif // defined(HAS_BIAS) |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1430 | int max_offset) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1431 | { |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 1432 | int x = get_global_id(0); |
| 1433 | int y = get_global_id(1); |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1434 | #if defined(DST_DEPTH) |
| 1435 | int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y |
| 1436 | int b = get_global_id(2) / (int)DST_DEPTH; // batch |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1437 | #else // defined(DST_DEPTH) |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1438 | int z = get_global_id(2); // spatial coordinate y |
Pablo Tello | 4710436 | 2019-02-27 13:32:51 +0000 | [diff] [blame] | 1439 | #endif // defined(DST_DEPTH) |
Giorgio Arena | fa23f11 | 2018-06-19 11:27:38 +0100 | [diff] [blame] | 1440 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1441 | __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1442 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1443 | #if defined(DST_DEPTH) |
| 1444 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w; |
| 1445 | #else /* defined(DST_DEPTH) */ |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1446 | __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1447 | #endif /* defined(DST_DEPTH) */ |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1448 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1449 | int z_coord = 0; |
| 1450 | int4 offset = 0; |
| 1451 | int4 y_coord = ((int4)(y * NUM_ROWS_PROCESSED) + (int4)(0, 1, 2, 3)) - (int)CONV_PAD_LEFT; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1452 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1453 | // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1 |
| 1454 | y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1); |
| 1455 | y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1); |
| 1456 | y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1); |
| 1457 | y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1); |
| 1458 | |
| 1459 | int4 y_offset = convert_int4(y_coord * (int)src_stride_y); |
| 1460 | |
| 1461 | // We compute 4x2x1 [C,W,H] elements |
| 1462 | VEC_INT acc0 = 0; |
| 1463 | VEC_INT acc1 = 0; |
| 1464 | VEC_INT sum0 = 0; |
| 1465 | VEC_INT sum1 = 0; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1466 | |
| 1467 | // Load weights |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1468 | VEC_TYPE(16) |
| 1469 | w0 = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr)); |
| 1470 | VEC_TYPE(16) |
| 1471 | w1 = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16)); |
| 1472 | VEC_TYPE(4) |
| 1473 | w2 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 32)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1474 | |
| 1475 | #if INPUT_OFFSET != 0 |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1476 | // Initilize the final result with the weights reduction multiplied by INPUT_OFFSET |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1477 | DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s0, w0.s01234567, w0.s8); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1478 | DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s1, (VEC_TYPE(8))((w0.s9ABC), (w0.sDEF), w1.s0), w1.s1); |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1479 | DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s2, w1.s23456789, w1.sA); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1480 | DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s3, (VEC_TYPE(8))((w1.sBCD), (w1.sEF), (w2.s012)), w2.s3); |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1481 | |
| 1482 | // Multiply the weights reduction with INPUT_OFFSET |
| 1483 | acc0 = INPUT_OFFSET * acc0; |
| 1484 | |
| 1485 | acc1 = acc0; |
| 1486 | #endif // INPUT_OFFSET != 0 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1487 | |
| 1488 | // Load input values |
| 1489 | // z == 0 |
| 1490 | // Clamp z_coord as for z = 0, it can be negative |
| 1491 | // z_coord is casted to unsigned int in order to use just a min() operation |
| 1492 | // A "-1" 32 bit signed variable converted to unsigned gives 4294967295 |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1493 | z_coord = z - (int)CONV_PAD_TOP; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1494 | z_coord = min((uint)z_coord, (uint)SRC_DIM_2); |
| 1495 | offset = y_offset + (int4)(z_coord * src_stride_z); |
Georgios Pinitas | 4e0d381 | 2018-08-01 20:16:34 +0100 | [diff] [blame] | 1496 | offset = min(offset, (int4)max_offset); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1497 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1498 | VEC_TYPE(VEC_SIZE) |
| 1499 | values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1500 | VEC_TYPE(VEC_SIZE) |
| 1501 | values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1502 | VEC_TYPE(VEC_SIZE) |
| 1503 | values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1504 | VEC_TYPE(VEC_SIZE) |
| 1505 | values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1506 | |
| 1507 | // z == 1 |
| 1508 | // z_coord can be only negative for z = 0 so we do not need to clamp it |
| 1509 | // Moreover z_coord cannot be out-of-bound for z = 1 so we do not need to clamp the offset |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1510 | z_coord = z - (int)CONV_PAD_TOP + 1; |
| 1511 | offset = y_offset + (int4)(z_coord * src_stride_z); |
| 1512 | VEC_TYPE(VEC_SIZE) |
| 1513 | values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1514 | VEC_TYPE(VEC_SIZE) |
| 1515 | values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1516 | VEC_TYPE(VEC_SIZE) |
| 1517 | values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1518 | VEC_TYPE(VEC_SIZE) |
| 1519 | values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1520 | |
| 1521 | // z == 2 |
| 1522 | // After z = 1 we can simply add src_stride_z to offset without updating z_coord |
| 1523 | // However offset can be out-of-bound so we need to check if it is greater than max_offset |
| 1524 | offset += (int4)src_stride_z; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1525 | offset = min(offset, (int4)max_offset); |
| 1526 | VEC_TYPE(VEC_SIZE) |
| 1527 | values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0)); |
| 1528 | VEC_TYPE(VEC_SIZE) |
| 1529 | values9 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1)); |
| 1530 | VEC_TYPE(VEC_SIZE) |
| 1531 | values10 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2)); |
| 1532 | VEC_TYPE(VEC_SIZE) |
| 1533 | values11 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1534 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1535 | DOT_PRODUCT_REDUCTION(sum0.s0, values0.s0, values1.s0, values2.s0, values4.s0, values5.s0, values6.s0, values8.s0, values9.s0, values10.s0); |
| 1536 | DOT_PRODUCT_REDUCTION(sum1.s0, values1.s0, values2.s0, values3.s0, values5.s0, values6.s0, values7.s0, values9.s0, values10.s0, values11.s0); |
| 1537 | DOT_PRODUCT(acc0.s0, values0.s0, values1.s0, values2.s0, values4.s0, values5.s0, values6.s0, values8.s0, values9.s0, values10.s0, w0.s01234567, w0.s8); |
| 1538 | DOT_PRODUCT(acc1.s0, values1.s0, values2.s0, values3.s0, values5.s0, values6.s0, values7.s0, values9.s0, values10.s0, values11.s0, w0.s01234567, w0.s8); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1539 | |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1540 | DOT_PRODUCT_REDUCTION(sum0.s1, values0.s1, values1.s1, values2.s1, values4.s1, values5.s1, values6.s1, values8.s1, values9.s1, values10.s1); |
| 1541 | DOT_PRODUCT_REDUCTION(sum1.s1, values1.s1, values2.s1, values3.s1, values5.s1, values6.s1, values7.s1, values9.s1, values10.s1, values11.s1); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1542 | DOT_PRODUCT(acc0.s1, values0.s1, values1.s1, values2.s1, values4.s1, values5.s1, values6.s1, values8.s1, values9.s1, values10.s1, (VEC_TYPE(8))((w0.s9ABC), (w0.sDEF), w1.s0), w1.s1); |
| 1543 | DOT_PRODUCT(acc1.s1, values1.s1, values2.s1, values3.s1, values5.s1, values6.s1, values7.s1, values9.s1, values10.s1, values11.s1, (VEC_TYPE(8))((w0.s9ABC), (w0.sDEF), w1.s0), w1.s1); |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1544 | |
| 1545 | DOT_PRODUCT_REDUCTION(sum0.s2, values0.s2, values1.s2, values2.s2, values4.s2, values5.s2, values6.s2, values8.s2, values9.s2, values10.s2); |
| 1546 | DOT_PRODUCT_REDUCTION(sum1.s2, values1.s2, values2.s2, values3.s2, values5.s2, values6.s2, values7.s2, values9.s2, values10.s2, values11.s2); |
| 1547 | DOT_PRODUCT(acc0.s2, values0.s2, values1.s2, values2.s2, values4.s2, values5.s2, values6.s2, values8.s2, values9.s2, values10.s2, w1.s23456789, w1.sA); |
| 1548 | DOT_PRODUCT(acc1.s2, values1.s2, values2.s2, values3.s2, values5.s2, values6.s2, values7.s2, values9.s2, values10.s2, values11.s2, w1.s23456789, w1.sA); |
| 1549 | |
| 1550 | DOT_PRODUCT_REDUCTION(sum0.s3, values0.s3, values1.s3, values2.s3, values4.s3, values5.s3, values6.s3, values8.s3, values9.s3, values10.s3); |
| 1551 | DOT_PRODUCT_REDUCTION(sum1.s3, values1.s3, values2.s3, values3.s3, values5.s3, values6.s3, values7.s3, values9.s3, values10.s3, values11.s3); |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1552 | DOT_PRODUCT(acc0.s3, values0.s3, values1.s3, values2.s3, values4.s3, values5.s3, values6.s3, values8.s3, values9.s3, values10.s3, (VEC_TYPE(8))((w1.sBCD), (w1.sEF), (w2.s012)), w2.s3); |
| 1553 | DOT_PRODUCT(acc1.s3, values1.s3, values2.s3, values3.s3, values5.s3, values6.s3, values7.s3, values9.s3, values10.s3, values11.s3, (VEC_TYPE(8))((w1.sBCD), (w1.sEF), (w2.s012)), w2.s3); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1554 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1555 | #if defined(HAS_BIAS) |
| 1556 | Vector biases = CONVERT_TO_VECTOR_STRUCT(biases); |
| 1557 | |
| 1558 | VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1559 | |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1560 | acc0 += bias_values; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1561 | acc1 += bias_values; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1562 | |
| 1563 | #endif // defined(HAS_BIAS) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1564 | |
| 1565 | #if WEIGHTS_OFFSET != 0 |
| 1566 | acc0 += WEIGHTS_OFFSET * sum0; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1567 | acc1 += WEIGHTS_OFFSET * sum1; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1568 | #endif // WEIGHTS_OFFSET != 0 |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1569 | |
| 1570 | #if K_OFFSET != 0 |
| 1571 | acc0 += (VEC_INT)K_OFFSET; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1572 | acc1 += (VEC_INT)K_OFFSET; |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1573 | |
| 1574 | #endif // K_OFFSET != 0 |
| 1575 | |
| 1576 | #if defined(REAL_MULTIPLIER) |
| 1577 | |
| 1578 | acc0 = CONVERT(round(CONVERT(acc0, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1579 | acc1 = CONVERT(round(CONVERT(acc1, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT); |
| 1580 | |
| 1581 | #else // defined(REAL_MULTIPLIER) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1582 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1583 | #if OUTPUT_SHIFT < 0 |
| 1584 | acc0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 1585 | acc1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE); |
| 1586 | #else // OUTPUT_SHIFT < 0 |
| 1587 | acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 1588 | acc1 = asymm_mult_by_quant_multiplier_less_than_one(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT); |
| 1589 | #endif // OUTPUT_SHIFT < 0 |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1590 | |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1591 | #endif // defined(REAL_MULTIPLIER) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1592 | acc0 += (VEC_INT)OUTPUT_OFFSET; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1593 | acc1 += (VEC_INT)OUTPUT_OFFSET; |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1594 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1595 | VEC_TYPE(VEC_SIZE) |
| 1596 | res0 = CONVERT_SAT(acc0, VEC_TYPE(VEC_SIZE)); |
| 1597 | VEC_TYPE(VEC_SIZE) |
| 1598 | res1 = CONVERT_SAT(acc1, VEC_TYPE(VEC_SIZE)); |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1599 | |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1600 | #if defined(DST_DEPTH) |
| 1601 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + z * dst_step_z + b * dst_stride_w; |
| 1602 | #else /* defined(DST_DEPTH) */ |
Gian Marco Iodice | 4b90865 | 2018-10-18 10:21:02 +0100 | [diff] [blame] | 1603 | __global uchar *dst_addr = dst_ptr + dst_offset_first_element_in_bytes + x * dst_step_x + y * dst_step_y + z * dst_step_z; |
Georgios Pinitas | 3704464 | 2018-10-30 14:53:25 +0000 | [diff] [blame] | 1604 | #endif /* defined(DST_DEPTH) */ |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1605 | |
| 1606 | VSTORE(VEC_SIZE) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1607 | (ACTIVATION_FUNC(res0), 0, (__global DATA_TYPE *)(dst_addr + 0 * dst_stride_y)); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1608 | VSTORE(VEC_SIZE) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1609 | (ACTIVATION_FUNC(res1), 0, (__global DATA_TYPE *)(dst_addr + 1 * dst_stride_y)); |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1610 | } |
giuros01 | 6d10996 | 2019-01-07 17:47:19 +0000 | [diff] [blame] | 1611 | #endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) && VEC_SIZE==4 |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1612 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1613 | #endif // defined(NUM_ROWS_PROCESSED) && defined(NUM_PLANES_PROCESSED) |
Giorgio Arena | dfca60b | 2018-01-31 10:30:59 +0000 | [diff] [blame] | 1614 | |
Giorgio Arena | eff8d95 | 2018-07-02 15:29:57 +0100 | [diff] [blame] | 1615 | #endif // defined(VEC_SIZE) && defined(SRC_DIM_1) && defined(SRC_DIM_2) && defined(CONV_PAD_TOP) && defined(CONV_PAD_LEFT) |
| 1616 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1617 | #endif // defined(WEIGHTS_PROMOTED_TYPE) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1618 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1619 | #endif // defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && ((defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)) || defined(REAL_MULTIPLIER)) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1620 | |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1621 | #if defined(SRC_DIM1) && defined(SRC_DIM2) && defined(KERNEL_WIDTH) && defined(KERNEL_HEIGHT) && defined(N0) && defined(DILATION_X) && defined(DILATION_Y) && defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && defined(CONV_PAD_LEFT) && defined(CONV_PAD_TOP) && defined(INPUT_OFFSET) && defined(WEIGHTS_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_SHIFT) && defined(OUTPUT_MULTIPLIER) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1622 | /** This function computes the depthwise convolution for NHWC data layout. This kernel assumes that the weights tensor is NOT reshaped |
| 1623 | * |
| 1624 | * @note The number of elements processed must be passed at compile time using -DN0 (e.g. -DN0=2) |
| 1625 | * @note The depth multiplier must be passed at compile time using -DDEPTH_MULTIPLIER (e.g. -DDEPTH_MULTIPLIER=1) |
| 1626 | * @note The first dimension of the input tensor must be passed at compile time using -DSRC_DIM1 (e.g. -DSRC_DIM1=112) |
| 1627 | * @note The second dimension of the input tensor must be passed at compile time using -DSRC_DIM2 (e.g. -DSRC_DIM2=80) |
| 1628 | * @note The kernel width must be passed at compile time using -DKERNEL_WIDTH (e.g. -DKERNEL_WIDTH=5) |
| 1629 | * @note The kernel height must be passed at compile time using -DKERNEL_HEIGHT (e.g. -DKERNEL_HEIGHT=5) |
| 1630 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1) |
| 1631 | * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1) |
| 1632 | * @note The convolution stride along the width must be passed at compile time using -DCONV_STRIDE_X (e.g. -DCONV_STRIDE_Y=X) |
| 1633 | * @note The convolution stride along the height must be passed at compile time using -DCONV_STRIDE_Y (e.g. -DCONV_STRIDE_Y=1) |
| 1634 | * @note It is possible to select the activation function to apply using -DACTIVATION_TYPE e.g. -DACTIVATION_TYPE=relu |
| 1635 | * @note A, B variables required by some activation functions are set using -DA_VAL= and -DB_VAL= respectively |
| 1636 | * |
Michele Di Giorgio | 4cd4cde | 2020-01-06 14:07:44 +0000 | [diff] [blame] | 1637 | * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1638 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 1639 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 1640 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 1641 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1642 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 1643 | * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes) |
| 1644 | * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes) |
| 1645 | * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes) |
| 1646 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 1647 | * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr |
| 1648 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 1649 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 1650 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 1651 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1652 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 1653 | * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes) |
| 1654 | * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes) |
| 1655 | * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes) |
| 1656 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
Michele Di Giorgio | 4cd4cde | 2020-01-06 14:07:44 +0000 | [diff] [blame] | 1657 | * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1658 | * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 1659 | * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes) |
| 1660 | * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 1661 | * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes) |
| 1662 | * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 1663 | * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes) |
| 1664 | * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 1665 | * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32 |
| 1666 | * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes) |
| 1667 | * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 1668 | * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector |
| 1669 | * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32 |
| 1670 | * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes) |
| 1671 | * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 1672 | * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector |
| 1673 | * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32 |
| 1674 | * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes) |
| 1675 | * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes) |
| 1676 | * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1677 | */ |
| 1678 | __kernel void dwc_MxN_native_quantized8_nhwc( |
| 1679 | TENSOR4D_DECLARATION(src), |
| 1680 | TENSOR4D_DECLARATION(dst), |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1681 | TENSOR3D_DECLARATION(weights), |
| 1682 | VECTOR_DECLARATION(output_multipliers), |
| 1683 | VECTOR_DECLARATION(output_shifts) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1684 | #if defined(HAS_BIAS) |
Michele Di Giorgio | 1dce310 | 2019-10-22 10:29:03 +0100 | [diff] [blame] | 1685 | , |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1686 | VECTOR_DECLARATION(biases) |
| 1687 | #endif // defined(HAS_BIAS) |
| 1688 | ) |
| 1689 | { |
| 1690 | int x = get_global_id(0); // channels |
| 1691 | int y = get_global_id(1); // spatial coordinate x |
| 1692 | #if defined(DST_DEPTH) |
| 1693 | int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y |
| 1694 | int b = get_global_id(2) / (int)DST_DEPTH; // batch |
| 1695 | #else // defined(DST_DEPTH) |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1696 | int z = get_global_id(2); // spatial coordinate y |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1697 | #endif // defined(DST_DEPTH) |
| 1698 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1699 | __global uchar *s_addr = src_ptr + src_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) * (int)N0; |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1700 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1701 | __global uchar *d_addr = dst_ptr + dst_offset_first_element_in_bytes + x * sizeof(DATA_TYPE) * (int)DEPTH_MULTIPLIER * (int)N0 + y * dst_stride_y + z * dst_stride_z; |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1702 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1703 | __global uchar *w_addr = weights_ptr + weights_offset_first_element_in_bytes + x * sizeof(WEIGHTS_TYPE) * (int)DEPTH_MULTIPLIER * (int)N0; |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1704 | |
| 1705 | #if defined(HAS_BIAS) |
| 1706 | __global uchar *b_addr = biases_ptr + biases_offset_first_element_in_bytes + x * sizeof(int) * (int)DEPTH_MULTIPLIER * (int)N0; |
| 1707 | #endif // defined(HAS_BIAS) |
| 1708 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1709 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 1710 | __global uchar *out_mul_addr = output_multipliers_ptr + output_multipliers_offset_first_element_in_bytes + x * sizeof(int) * (int)DEPTH_MULTIPLIER * (int)N0; |
| 1711 | __global uchar *out_shift_addr = output_shifts_ptr + output_shifts_offset_first_element_in_bytes + x * sizeof(int) * (int)DEPTH_MULTIPLIER * (int)N0; |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1712 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
| 1713 | |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1714 | #if defined(DST_DEPTH) |
| 1715 | s_addr += b * src_stride_w; |
| 1716 | d_addr += b * dst_stride_w; |
| 1717 | #endif // defined(DST_DEPTH) |
| 1718 | |
| 1719 | #if DEPTH_MULTIPLIER > 1 |
| 1720 | for(int d = 0; d < (int)DEPTH_MULTIPLIER; ++d) |
| 1721 | { |
| 1722 | #endif // DEPTH_MULTIPLIER > 1 |
| 1723 | // Each work-item computes N0x1x1 elements |
Sang-Hoon Park | 15396ff | 2019-11-07 09:37:29 +0000 | [diff] [blame] | 1724 | VEC_INT res = 0; |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1725 | |
| 1726 | int x_coord = y * CONV_STRIDE_X - (int)CONV_PAD_LEFT; |
| 1727 | int y_coord = z * CONV_STRIDE_Y - (int)CONV_PAD_TOP; |
| 1728 | |
| 1729 | for(int yk = 0; yk < KERNEL_HEIGHT; ++yk) |
| 1730 | { |
| 1731 | if(y_coord >= 0 && y_coord < SRC_DIM2) |
| 1732 | { |
| 1733 | int x_coord_tmp = x_coord; |
| 1734 | |
| 1735 | for(int xk = 0; xk < KERNEL_WIDTH; ++xk) |
| 1736 | { |
| 1737 | if(x_coord_tmp >= 0 && x_coord_tmp < SRC_DIM1) |
| 1738 | { |
| 1739 | int s_offset = x_coord_tmp * (int)src_stride_y + y_coord * (int)src_stride_z; |
| 1740 | int w_offset = xk * weights_stride_y + yk * weights_stride_z; |
| 1741 | |
| 1742 | // Load input and weights values |
Sang-Hoon Park | 15396ff | 2019-11-07 09:37:29 +0000 | [diff] [blame] | 1743 | VEC_INT i = CONVERT(VLOAD(N0)(0, (__global DATA_TYPE *)(s_addr + s_offset)), VEC_INT); |
| 1744 | VEC_INT w = CONVERT(VLOAD(N0)(0, (__global WEIGHTS_TYPE *)(w_addr + w_offset)), VEC_INT); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1745 | |
Sang-Hoon Park | 15396ff | 2019-11-07 09:37:29 +0000 | [diff] [blame] | 1746 | res += (i + (VEC_INT)INPUT_OFFSET) * (w + (VEC_INT)WEIGHTS_OFFSET); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1747 | } |
| 1748 | x_coord_tmp += DILATION_X; |
| 1749 | } |
| 1750 | } |
| 1751 | y_coord += DILATION_Y; |
| 1752 | } |
| 1753 | |
| 1754 | #if defined(HAS_BIAS) |
Sang-Hoon Park | 15396ff | 2019-11-07 09:37:29 +0000 | [diff] [blame] | 1755 | VEC_INT bias = VLOAD(N0)(0, (__global int *)(b_addr)); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1756 | res += bias; |
| 1757 | #endif // defined(HAS_BIAS) |
| 1758 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1759 | #if defined(PER_CHANNEL_QUANTIZATION) |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1760 | VEC_INT output_multiplier = VLOAD(N0)(0, (__global int *)(out_mul_addr)); |
| 1761 | VEC_INT output_shift = VLOAD(N0)(0, (__global int *)(out_shift_addr)); |
| 1762 | |
| 1763 | VEC_INT res_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(res, output_multiplier, output_shift, N0); |
| 1764 | VEC_INT res_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(res, output_multiplier, output_shift, N0); |
| 1765 | res = select(res_shift_lt0, res_shift_gt0, (VEC_INT)(output_shift) >= 0); |
| 1766 | #else // defined(PER_CHANNEL_QUANTIZATION) |
| 1767 | #if OUTPUT_SHIFT < 0 |
| 1768 | res = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(res, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, N0); |
| 1769 | #else // OUTPUT_SHIFT < 0 |
| 1770 | res = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(res, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, N0); |
| 1771 | #endif // OUTPUT_OFFSET < 0 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1772 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
| 1773 | |
Sang-Hoon Park | 15396ff | 2019-11-07 09:37:29 +0000 | [diff] [blame] | 1774 | res += (VEC_INT)OUTPUT_OFFSET; |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1775 | |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1776 | VEC_TYPE(VEC_SIZE) |
| 1777 | res1 = CONVERT_SAT(res, VEC_TYPE(VEC_SIZE)); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1778 | |
| 1779 | VSTORE(N0) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1780 | (ACTIVATION_FUNC(res1), 0, (__global DATA_TYPE *)(d_addr)); |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1781 | |
| 1782 | #if DEPTH_MULTIPLIER > 1 |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1783 | w_addr += sizeof(WEIGHTS_TYPE); |
| 1784 | d_addr += sizeof(DATA_TYPE); |
| 1785 | #if defined(PER_CHANNEL_QUANTIZATION) |
| 1786 | out_mul_addr += sizeof(int); |
| 1787 | out_shift_addr += sizeof(int); |
| 1788 | #endif // defined(PER_CHANNEL_QUANTIZATION) |
Michele Di Giorgio | a046e16 | 2019-10-08 09:36:26 +0100 | [diff] [blame] | 1789 | #if defined(HAS_BIAS) |
| 1790 | b_addr += sizeof(int); |
| 1791 | #endif // defined(HAS_BIAS) |
| 1792 | } |
| 1793 | #endif // DEPTH_MULTIPLIER > 1 |
| 1794 | } |
Michele Di Giorgio | 14cbfb2 | 2019-10-23 10:53:10 +0100 | [diff] [blame] | 1795 | #endif // defined(SRC_DIM1) && defined(SRC_DIM2) && defined(KERNEL_WIDTH) && defined(KERNEL_HEIGHT) && defiend(N0) && defined(DILATION_X) && defined(DILATION_Y) && defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && defined(CONV_PAD_LEFT) && defined(CONV_PAD_TOP) && defined(INPUT_OFFSET) && defined(WEIGHTS_OFFSET) && defined(OUTPUT_OFFSET) && defined(OUTPUT_SHIFT) && defined(OUTPUT_MULTIPLIER) |
Michele Di Giorgio | df4cf57 | 2019-10-09 15:32:39 +0100 | [diff] [blame] | 1796 | #endif // defined(DATA_TYPE) && defined(WEIGHTS_TYPE) |