Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. |
| 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.h" |
| 26 | #include "tile_helpers.h" |
| 27 | |
| 28 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION(A_DATA_TYPE, B_DATA_TYPE) CALCULATE_WEIGHTS_OFFSET_CORRECTION_STR(A_DATA_TYPE, B_DATA_TYPE) |
| 29 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION_STR(A_DATA_TYPE, B_DATA_TYPE) CALCULATE_WEIGHTS_OFFSET_CORRECTION_##A_DATA_TYPE##_##B_DATA_TYPE |
| 30 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION_char_char (0) |
| 31 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION_uchar_uchar (0) |
| 32 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION_uchar_char (128) |
| 33 | #define CALCULATE_WEIGHTS_OFFSET_CORRECTION_char_uchar (-128) |
| 34 | |
| 35 | #define T_LOAD_MULTIPLIERS_SHIFT_PER_TENSOR() \ |
| 36 | ({}) |
| 37 | |
| 38 | #define T_LOAD_MULTIPLIERS_SHIFT_PER_CHANNEL() \ |
| 39 | TILE(DST_MULTIPLIERS_DATA_TYPE, 1, N0, multipliers); \ |
| 40 | TILE(DST_SHIFTS_DATA_TYPE, 1, N0, shifts); \ |
| 41 | T_LOAD(DST_MULTIPLIERS_DATA_TYPE, 1, N0, BUFFER, dst_multipliers, cout *DEPTH_MULTIPLIER + d, 0, 0, 0, multipliers); \ |
| 42 | T_LOAD(DST_SHIFTS_DATA_TYPE, 1, N0, BUFFER, dst_shifts, cout *DEPTH_MULTIPLIER + d, 0, 0, 0, shifts); |
| 43 | |
| 44 | #define T_LOAD_MULTIPLIERS_SHIFT(QUANTIZATION_TYPE) T_LOAD_MULTIPLIERS_SHIFT_STR(QUANTIZATION_TYPE) |
| 45 | #define T_LOAD_MULTIPLIERS_SHIFT_STR(QUANTIZATION_TYPE) T_LOAD_MULTIPLIERS_SHIFT_##QUANTIZATION_TYPE() |
| 46 | |
| 47 | #if defined(SRC_WIDTH) && defined(SRC_HEIGHT) && defined(DST_WIDTH) && defined(DST_HEIGHT) && defined(WEI_WIDTH) && defined(WEI_HEIGHT) && defined(N0) && defined(M0) && defined(DILATION_X) && defined(DILATION_Y) && defined(STRIDE_X) && defined(STRIDE_Y) && defined(PAD_LEFT) && defined(PAD_TOP) |
| 48 | //! @cond Doxygen_Suppress |
| 49 | /** OpenCL kernel to compute the depthwise convolution for quantized data types |
| 50 | * |
| 51 | * @note Data layout supported: NHWC |
| 52 | * @note Data type supported: QSYMM8/QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL |
| 53 | * @note The convolution padding (left and top) must be passed at compile time using -DPAD_LEFT and -DPAD_TOP (e.g. -DPAD_LEFT=2, -DPAD_TOP=2) |
| 54 | * @note The convolution strides must be passed at compile time using -DSTRIDE_X and -DSTRIDE_Y (e.g. -DSTRIDE_X=2, -DSTRIDE_Y=2) |
| 55 | * @note The convolution dilations must be passed at compile time using -DDILATION_X and -DDILATION_Y (e.g. -DDILATION_X=2, -DDILATION_Y=2) |
| 56 | * @note The spatial dimensions of the weights must be passed at compile time using -DWEI_WIDTH and -DWEI_HEIGHT (e.g. -DWEI_WIDTH=9, -DWEI_HEIGHT=9) |
| 57 | * @note The spatial dimensions of the source tensor must be passed at compile time using -DSRC_WIDTH and -DSRC_HEIGHT (e.g. -DSRC_WIDTH=96, -DSRC_HEIGHT=64) |
| 58 | * @note The spatial dimensions of the destination tensor must be passed at compile time using -DDST_WIDTH and -DDST_HEIGHT (e.g. -DDST_WIDTH=96, -DDST_HEIGHT=64) |
| 59 | * @note The channels of the source tensor must be passed at compile time using -DSRC_CHANNELS (e.g. -DSRC_CHANNELS=64) |
| 60 | * @note The channels of the destination tensor must be passed at compile time using -DDST_CHANNELS (e.g. -DDDST_CHANNELS=64) |
| 61 | * @note The tensor type ("BUFFER" or "IMAGE") of the source tensor must be passed at compile time using -DSRC_TENSOR_TYPE (e.g. -DSRC_TENSOR_TYPE=BUFFER) |
| 62 | * @note The tensor type ("BUFFER" or "IMAGE") of the weights tensor must be passed at compile time using -DWEI_TENSOR_TYPE (e.g. -DWEI_TENSOR_TYPE=BUFFER) |
| 63 | * @note The tensor type ("BUFFER" or "IMAGE") of the destination tensor must be passed at compile time using -DDST_TENSOR_TYPE (e.g. -DDST_TENSOR_TYPE=BUFFER) |
| 64 | * @note The data type of the source tensor must be passed at compile time using -DSRC_DATA_TYPE (e.g. -DSRC_DATA_TYPE=int8) |
| 65 | * @note The data type of the weights tensor must be passed at compile time using -DWEI_DATA_TYPE (e.g. -DWEI_DATA_TYPE=int8) |
| 66 | * @note The data type of the destination tensor must be passed at compile time using -DDST_DATA_TYPE (e.g. -DDST_DATA_TYPE=int8) |
| 67 | * @note The data type of the accumulators must be passed at compile time using -DACC_DATA_TYPE (e.g. -DACC_DATA_TYPE=int) |
| 68 | * @note The number of M0 rows (width) to process must be passed at compile time using -DM0 (e.g. -DM0=2) |
| 69 | * @note The number of N0 output channels to process must be passed at compile time using -DN0 (e.g. -DN0=2) |
| 70 | * @note The size of the partial store block in the first dimension must be passed at compile time using -DPARTIAL_N0 (e.g. -DPARTIAL_N0=1) |
| 71 | * @note The activation type must be passed at compile using -DACTIVATION_TYPE e.g. -DACTIVATION_TYPE=relu |
| 72 | * @note The A and B variables required by some activation functions must be passed at compile time using -DA_VAL= and -DB_VAL= respectively |
| 73 | * @note The quantization offset used for both the per-tensor and per-channel quantization must be passed at compile using -DDST_OFFSET (e.g., -DDST_OFFSET=3) |
| 74 | * @note The quantization shift for the per-tensor quantization must be passed at compile time using -DDST_SHIFT (e.g., -DDST_SHIFT=1) |
| 75 | * @note The quantization multiplier for the per-tensor quantization must be passed at compile using -DDST_MULTIPLIER (e.g., -DDST_MULTIPLER=121432) |
| 76 | * @note Only the following configurations of M0 and N0 are currently supported: |
| 77 | * - M0 = 1, 2, 3, 4, 5, .... n (M0 != 1 with STRIDE_X == 1 && DILATION_X == 1 only) |
| 78 | * - N0 = 2, 3, 4, 8, 16 |
| 79 | * @note The number of rows to read from the src tensor must be passed at compile time using -DM0_A (e.g., -DM0_A=3). M0_A must be equal to WEI_WIDTH + (M0 - 1) |
| 80 | * |
| 81 | * @param[in] src_ptr Pointer to the source tensor. Supported data type: QSYMM8/QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL |
| 82 | * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) |
| 83 | * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) |
| 84 | * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) |
| 85 | * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) |
| 86 | * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) |
| 87 | * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) |
| 88 | * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes) |
| 89 | * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes) |
| 90 | * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor |
| 91 | * @param[out] dst_ptr Pointer to the destination tensor. Supported data type: same as @p src_ptr |
| 92 | * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) |
| 93 | * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) |
| 94 | * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) |
| 95 | * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) |
| 96 | * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) |
| 97 | * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) |
| 98 | * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes) |
| 99 | * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes) |
| 100 | * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor |
| 101 | * @param[in] wei_ptr Pointer to the weights tensor. Supported data type: same as @p src_ptr |
| 102 | * @param[in] wei_stride_x Stride of the weights tensor in X dimension (in bytes) |
| 103 | * @param[in] wei_step_x wei_stride_x * number of elements along X processed per workitem(in bytes) |
| 104 | * @param[in] wei_stride_y Stride of the weights tensor in Y dimension (in bytes) |
| 105 | * @param[in] wei_step_y wei_stride_y * number of elements along Y processed per workitem(in bytes) |
| 106 | * @param[in] wei_stride_z Stride of the weights tensor in Z dimension (in bytes) |
| 107 | * @param[in] wei_step_z wei_stride_z * number of elements along Z processed per workitem(in bytes) |
| 108 | * @param[in] wei_stride_w Stride of the weights tensor in W dimension (in bytes) |
| 109 | * @param[in] wei_step_w wei_stride_w * number of elements along W processed per workitem(in bytes) |
| 110 | * @param[in] wei_offset_first_element_in_bytes The offset of the first element in the weights tensor |
| 111 | * @param[in] dst_multipliers_ptr Pointer to the destination multipliers tensor for the per-channel quantization. Supported data type: S32 |
| 112 | * @param[in] dst_multipliers_stride_x Stride of the destination multipliers tensor in X dimension (in bytes) |
| 113 | * @param[in] dst_multipliers_step_x dst_multipliers_stride_x * number of elements along X processed per workitem(in bytes) |
| 114 | * @param[in] dst_multipliers_offset_first_element_in_bytes The offset of the first element in the destination multipliers tensor |
| 115 | * @param[in] dst_shifts_ptr Pointer to the destination shifts tensor for the per-channel quantization. Supported data type: S32 |
| 116 | * @param[in] dst_shifts_stride_x Stride of the destination shifts tensor in X dimension (in bytes) |
| 117 | * @param[in] dst_shifts_step_x dst_shifts_stride_x * number of elements along X processed per workitem(in bytes) |
| 118 | * @param[in] dst_shifts_offset_first_element_in_bytes The offset of the first element in the destination shifts tensor |
| 119 | * @param[in] bia_ptr (Optional) Pointer to the bias tensor Supported data type: S32 |
| 120 | * @param[in] bia_stride_x (Optional) Stride of the bias tensor in X dimension (in bytes) |
| 121 | * @param[in] bia_step_x (Optional) bia_stride_x * number of elements along X processed per workitem(in bytes) |
| 122 | * @param[in] bia_offset_first_element_in_bytes (Optional) The offset of the first element in the bias tensor |
| 123 | */ |
| 124 | //! @endcond |
| 125 | __kernel void dwc_native_quantized_nhwc( |
| 126 | TENSOR4D(src, SRC_TENSOR_TYPE), |
| 127 | TENSOR4D(dst, DST_TENSOR_TYPE), |
| 128 | TENSOR4D(wei, WEI_TENSOR_TYPE), |
| 129 | VECTOR_DECLARATION(dst_multipliers), |
| 130 | VECTOR_DECLARATION(dst_shifts) |
| 131 | #if defined(HAS_BIAS) |
| 132 | , |
| 133 | VECTOR_DECLARATION(bia) |
| 134 | #endif // defined(HAS_BIAS) |
| 135 | ) |
| 136 | { |
| 137 | // All the tensor dimensions are passed at compile time. |
| 138 | // In case of dynamic tensor support, the following dimensions should be passed as function argument. |
| 139 | #define _IWEI_WIDTH WEI_WIDTH |
| 140 | #define _IWEI_HEIGHT WEI_HEIGHT |
| 141 | #define _ISRC_WIDTH SRC_WIDTH |
| 142 | #define _ISRC_HEIGHT SRC_HEIGHT |
| 143 | #define _IDST_WIDTH DST_WIDTH |
| 144 | #define _IDST_HEIGHT DST_HEIGHT |
| 145 | #define _IDST_CHANNELS DST_CHANNELS |
| 146 | #define _IM0_A M0_A // _IWEI_WIDTH + (M0 - 1) Rows tile A (If M0 != 1, the tiles overlap of 1 element on the X dimension) |
| 147 | #define _IN0_A N0 // Cols tile A |
| 148 | #define _IM0_B _IWEI_WIDTH // Rows tile B |
| 149 | #define _IN0_B N0 // Cols tile B |
| 150 | #define _IBOUNDARY_CHECK (!((WEI_WIDTH == 1 && WEI_HEIGHT == 1 && PAD_LEFT == 0 && PAD_TOP == 0 && M0 == 1))) |
| 151 | |
| 152 | const int cout = GET_SPATIAL_IDX(0, N0, PARTIAL_N0); // OFM |
| 153 | const int xo = GET_SPATIAL_IDX(1, M0, 0); // WIDTH |
| 154 | #if defined(BATCHED_EXECUTION) |
| 155 | const int yo = GET_SPATIAL_IDX(2, 1, 0) % _IDST_HEIGHT; // HEIGHT |
| 156 | const int bout = GET_SPATIAL_IDX(2, 1, 0) / _IDST_HEIGHT; // BATCH SIZE IDX |
| 157 | #else // defined(BATCHED_EXECUTION) |
| 158 | const int yo = GET_SPATIAL_IDX(2, 1, 0); // HEIGHT |
| 159 | const int bout = 0; // BATCH SIZE IDX |
| 160 | #endif // defined(BATCHED_EXECUTION) |
| 161 | |
| 162 | int xi = xo * STRIDE_X; |
| 163 | int yi = yo * STRIDE_Y; |
| 164 | xi -= PAD_LEFT; |
| 165 | yi -= PAD_TOP; |
| 166 | |
| 167 | int d = 0; |
| 168 | #if DEPTH_MULTIPLIER != 1 |
| 169 | for(; d < DEPTH_MULTIPLIER; d++) |
| 170 | #endif // DEPTH_MULTIPLIER != 1 |
| 171 | { |
| 172 | TILE(ACC_DATA_TYPE, M0, N0, c); |
| 173 | |
| 174 | // Reset accumulators |
| 175 | LOOP_UNROLLING(int, i, 0, 1, M0, |
| 176 | { |
| 177 | c[i].v = 0; |
| 178 | }) |
| 179 | |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 180 | #if _IWEI_HEIGHT <= 5 |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 181 | LOOP_UNROLLING(int, yk, 0, 1, _IWEI_HEIGHT, |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 182 | #else // _IWEI_HEIGHT <= 5 |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 183 | for(int yk = 0; yk < _IWEI_HEIGHT; yk++) |
| 184 | #endif // _IWEI_HEIGHT <= 5 |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 185 | { |
| 186 | TILE(SRC_DATA_TYPE, _IM0_A, _IN0_A, a); |
| 187 | |
| 188 | LOOP_UNROLLING(int, i, 0, 1, _IM0_A, |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 189 | { |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 190 | a[i].v = ZERO_VALUE; |
| 191 | }) |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 192 | |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 193 | // Load tile from the src tensor (TILE A) |
| 194 | T_LOAD_NHWC_WITH_DILATION(SRC_DATA_TYPE, 1, _IM0_A, _IN0_A, SRC_TENSOR_TYPE, src, bout, yi + yk * DILATION_Y, xi, cout, _ISRC_WIDTH, _ISRC_HEIGHT, DILATION_X, 1, _IBOUNDARY_CHECK, a); |
| 195 | |
| 196 | TILE(WEI_DATA_TYPE, _IM0_B, _IN0_B, b); |
| 197 | |
| 198 | // Load tile from the weights tensor (TILE B) |
| 199 | T_LOAD(WEI_DATA_TYPE, _IM0_B, _IN0_B, WEI_TENSOR_TYPE, wei, cout * DEPTH_MULTIPLIER + d, yk * _IM0_B, 1, wei_stride_y, b); |
| 200 | |
| 201 | // Optimized path for STRIDE_X == 1 |
| 202 | // If M0 != 1, we can skip the common loads between the two applied kernels on the X (WIDTH) dimension |
| 203 | LOOP_UNROLLING(int, m0, 0, 1, M0, |
| 204 | { |
| 205 | LOOP_UNROLLING(int, n0, 0, 1, N0, |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 206 | { |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 207 | #if _IWEI_WIDTH <= 16 |
| 208 | #define DOT_DATA_TYPE SRC_DATA_TYPE |
| 209 | #define WEI_OFFSET_CORRECTION (CALCULATE_WEIGHTS_OFFSET_CORRECTION(SRC_DATA_TYPE, WEI_DATA_TYPE)) |
| 210 | |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 211 | // Optimized path for the dot instruction |
| 212 | TILE(DOT_DATA_TYPE, 1, _IWEI_WIDTH, x0); |
| 213 | TILE(DOT_DATA_TYPE, 1, _IWEI_WIDTH, y0); |
| 214 | ACC_DATA_TYPE offset_a = 0; |
| 215 | ACC_DATA_TYPE offset_b = 0; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 216 | |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 217 | LOOP_UNROLLING(int, xk, 0, 1, _IWEI_WIDTH, |
| 218 | { |
| 219 | x0[0].s[xk] = a[xk + m0].s[n0]; |
| 220 | y0[0].s[xk] = b[xk].s[n0] + (int)WEI_OFFSET_CORRECTION; |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 221 | }) |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 222 | DOT_PRODUCT_INTEGER8(DOT_DATA_TYPE, DOT_DATA_TYPE, ACC_DATA_TYPE, _IWEI_WIDTH, x0[0].v, y0[0].v, c[m0].s[n0]); |
| 223 | REDUCE_INTEGER8(DOT_DATA_TYPE, DOT_DATA_TYPE, ACC_DATA_TYPE, _IWEI_WIDTH, x0[0].v, offset_a); |
| 224 | REDUCE_INTEGER8(DOT_DATA_TYPE, DOT_DATA_TYPE, ACC_DATA_TYPE, _IWEI_WIDTH, y0[0].v, offset_b); |
| 225 | c[m0].s[n0] += offset_a * (ACC_DATA_TYPE)(WEI_OFFSET - (ACC_DATA_TYPE)WEI_OFFSET_CORRECTION) + offset_b * (ACC_DATA_TYPE)SRC_OFFSET; |
| 226 | #else // _IWEI_WIDTH <= 16 |
| 227 | LOOP_UNROLLING(int, xk, 0, 1, _IWEI_WIDTH, |
| 228 | { |
| 229 | c[m0].s[n0] += ((ACC_DATA_TYPE)a[xk + m0].s[n0] + (ACC_DATA_TYPE)(SRC_OFFSET)) * ((ACC_DATA_TYPE)b[xk].s[n0] + (ACC_DATA_TYPE)(WEI_OFFSET)); |
| 230 | }) |
| 231 | #endif // _IWEI_WIDTH <= 16 |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 232 | }) |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 233 | }) |
| 234 | } |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 235 | #if _IWEI_HEIGHT <= 5 |
Adnan AlSinan | 7075fe2 | 2021-07-05 13:12:52 +0100 | [diff] [blame] | 236 | ) |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 237 | #endif // _IWEI_HEIGHT <= 5 |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 238 | |
| 239 | #if _IWEI_WIDTH <= 16 |
| 240 | T_ADD_CONSTANT(ACC_DATA_TYPE, M0, N0, c, (_IWEI_WIDTH * _IWEI_HEIGHT * SRC_OFFSET * (ACC_DATA_TYPE)(WEI_OFFSET - (ACC_DATA_TYPE)WEI_OFFSET_CORRECTION)), c); |
| 241 | #endif // _IWEI_WIDTH <= 16 |
| 242 | |
| 243 | #if defined(HAS_BIAS) |
| 244 | TILE(BIA_DATA_TYPE, 1, N0, bias0); |
| 245 | |
| 246 | // Load bias |
| 247 | T_LOAD(BIA_DATA_TYPE, 1, N0, BUFFER, bia, cout * DEPTH_MULTIPLIER + d, 0, 0, 0, bias0); |
| 248 | |
| 249 | // c = c + bias[broadcasted] |
| 250 | T_ADD_BROADCAST_X(ACC_DATA_TYPE, M0, N0, c, bias0, c); |
| 251 | #endif // HAS_BIAS |
| 252 | |
| 253 | T_LOAD_MULTIPLIERS_SHIFT(QUANTIZATION_TYPE); |
| 254 | |
| 255 | // Quantize the tile |
| 256 | TILE(DST_DATA_TYPE, M0, N0, cq); |
| 257 | T_QUANTIZE8(ACC_DATA_TYPE, DST_DATA_TYPE, QUANTIZATION_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, c, multipliers, shifts, cq); |
| 258 | |
| 259 | // Perform activation |
| 260 | T_ACTIVATION_QUANTIZED(DST_DATA_TYPE, M0, N0, ACTIVATION_TYPE, DST_OFFSET, A_VAL, B_VAL, cq, cq); |
| 261 | |
| 262 | bool x_cond = PARTIAL_N0 != 0 && get_global_id(0) == 0; |
| 263 | |
| 264 | if(x_cond) |
| 265 | { |
| 266 | LOOP_UNROLLING(int, m0, 0, 1, M0, |
| 267 | { |
| 268 | int xi_out = min(xo + M0 - 1 - m0, (int)(_IDST_WIDTH) - 1); |
| 269 | VSTORE_PARTIAL(N0, PARTIAL_N0) |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 270 | (cq[M0 - 1 - m0].v, 0, (__global DST_DATA_TYPE *)(dst_ptr + dst_offset_first_element_in_bytes + (uint)((cout * DEPTH_MULTIPLIER) + d) * sizeof(DST_DATA_TYPE) + (uint)xi_out * dst_stride_y + (uint)yo * dst_stride_z + (uint)bout * dst_stride_w)); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 271 | }) |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | LOOP_UNROLLING(int, m0, 0, 1, M0, |
| 276 | { |
| 277 | int xi_out = min(xo + M0 - 1 - m0, (int)(_IDST_WIDTH) - 1); |
| 278 | VSTORE(N0) |
Gian Marco Iodice | 04b39e8 | 2021-07-07 10:25:41 +0100 | [diff] [blame] | 279 | (cq[M0 - 1 - m0].v, 0, (__global DST_DATA_TYPE *)(dst_ptr + dst_offset_first_element_in_bytes + (uint)((cout * DEPTH_MULTIPLIER) + d) * sizeof(DST_DATA_TYPE) + (uint)xi_out * dst_stride_y + (uint)yo * dst_stride_z + (uint)bout * dst_stride_w)); |
Gian Marco Iodice | 8155c02 | 2021-04-16 15:08:59 +0100 | [diff] [blame] | 280 | }) |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | #endif // defined(SRC_WIDTH) && defined(SRC_HEIGHT) && defined(DST_WIDTH) && defined(DST_HEIGHT) && defined(WEI_WIDTH) && defined(WEI_HEIGHT) && defined(N0) && defined(M0) && defined(DILATION_X) && defined(DILATION_Y) && defined(STRIDE_X) && defined(STRIDE_Y) && defined(PAD_LEFT) && defined(PAD_TOP) |