blob: 285c00a713bdc7b627a89bc9e473b82991801f4f [file] [log] [blame]
Dmitry Savenkod7295b72017-11-20 22:00:08 +07001/*
Giorgio Arena8bcb65f2021-01-12 11:29:18 +00002 * Copyright (c) 2017-2021 Arm Limited.
Dmitry Savenkod7295b72017-11-20 22:00:08 +07003 *
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 Giorgioa046e162019-10-08 09:36:26 +010027#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 Arena287b5702018-02-16 11:01:04 +000034
Usama Arif6a98a6e2019-05-10 17:07:27 +010035#if defined(ACTIVATION_TYPE) && defined(CONST_0)
Manuel Bottini30dbeef2019-06-26 16:23:03 +010036#include "activation_layer_quant.cl"
37#define ACTIVATION_FUNC(x) PERFORM_ACTIVATION_QUANT(ACTIVATION_TYPE, x)
Usama Arif6a98a6e2019-05-10 17:07:27 +010038#else /* defined(ACTIVATION_TYPE) && defined(CONST_0) */
Giorgio Arena99ac60b2018-02-16 15:17:23 +000039#define ACTIVATION_FUNC(x) (x)
Usama Arif6a98a6e2019-05-10 17:07:27 +010040#endif /* defined(ACTIVATION_TYPE) && defined(CONST_0) */
Giorgio Arena99ac60b2018-02-16 15:17:23 +000041
Michele Di Giorgioa046e162019-10-08 09:36:26 +010042#define VEC_INT VEC_DATA_TYPE(int, VEC_SIZE)
43#define VEC_FLOAT VEC_DATA_TYPE(float, VEC_SIZE)
Michele Di Giorgioa046e162019-10-08 09:36:26 +010044#define VEC_SHORT VEC_DATA_TYPE(short, VEC_SIZE)
45
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010046#if defined(DATA_TYPE) && defined(WEIGHTS_TYPE)
47
48#define VEC_TYPE(size) VEC_DATA_TYPE(DATA_TYPE, size)
49
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +010050#if defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && ((defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)) || defined(REAL_MULTIPLIER))
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010051
52#if defined(WEIGHTS_PROMOTED_TYPE)
53#define VEC_WEIGHTS_PROMOTED_TYPE(size) VEC_DATA_TYPE(WEIGHTS_PROMOTED_TYPE, size)
Michele Di Giorgioa046e162019-10-08 09:36:26 +010054
Georgios Pinitasdaa38552018-08-28 17:43:18 +010055#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 Iodice4b908652018-10-18 10:21:02 +010057#define ARM_DOT(x, y, val) val = arm_dot_acc((x), (y), val);
Georgios Pinitasdaa38552018-08-28 17:43:18 +010058#else // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
Gian Marco Iodice4b908652018-10-18 10:21:02 +010059#define ARM_DOT(x, y, val) val += arm_dot((x), (y));
Georgios Pinitasdaa38552018-08-28 17:43:18 +010060#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 Arenaeff8d952018-07-02 15:29:57 +010062
Georgios Pinitase55b40a2018-09-13 17:20:04 +010063#if defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X) && defined(DEPTH_MULTIPLIER) && defined(DST_CHANNELS)
Giorgio Arenadfca60b2018-01-31 10:30:59 +000064
Giorgio Arena287b5702018-02-16 11:01:04 +000065#if CONV_STRIDE_X > 3
66#error "Stride X not supported"
67#endif /* CONV_STRIDE_X > 3 */
Dmitry Savenkod7295b72017-11-20 22:00:08 +070068
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010069#if !defined(IS_DOT8)
Giorgio Arenaeff8d952018-07-02 15:29:57 +010070
Usama Arife73686a2019-04-08 17:30:48 +010071#if DILATION_X == 1
72
Dmitry Savenkod7295b72017-11-20 22:00:08 +070073#if CONV_STRIDE_X == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010074#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 Arena287b5702018-02-16 11:01:04 +000078 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010079 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 Arena287b5702018-02-16 11:01:04 +000082 })
Dmitry Savenkod7295b72017-11-20 22:00:08 +070083#elif CONV_STRIDE_X == 2
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010084#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 Arena287b5702018-02-16 11:01:04 +000088 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010089 left = CONVERT(temp0.s02468ace, int8); \
90 middle = CONVERT(temp0.s13579bdf, int8); \
91 right = CONVERT((int8)(temp0.s2468, temp0.sace, temp1), int8); \
Giorgio Arena287b5702018-02-16 11:01:04 +000092 })
Dmitry Savenkod7295b72017-11-20 22:00:08 +070093#else /* CONV_STRIDE_X */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010094#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 Arena287b5702018-02-16 11:01:04 +000098 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010099 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 Arena287b5702018-02-16 11:01:04 +0000102 })
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700103#endif /* CONV_STRIDE_X */
104
Usama Arife73686a2019-04-08 17:30:48 +0100105#else /* DILATION_X == 1 */
106
107#if CONV_STRIDE_X == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100108#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 Arife73686a2019-04-08 17:30:48 +0100113 })
114#elif CONV_STRIDE_X == 2
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100115#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 Arife73686a2019-04-08 17:30:48 +0100119 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100120 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))), int16); \
121 middle = CONVERT(temp0.s02468ace, int8); \
Usama Arife73686a2019-04-08 17:30:48 +0100122 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100123 temp0 = CONVERT(vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))), int16); \
124 right = CONVERT(temp0.s02468ace, int8); \
Usama Arife73686a2019-04-08 17:30:48 +0100125 })
126#else /* CONV_STRIDE_X */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100127#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 Arife73686a2019-04-08 17:30:48 +0100132 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100133 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 Arife73686a2019-04-08 17:30:48 +0100136 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100137 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 Arife73686a2019-04-08 17:30:48 +0100140 })
141
142#endif /* CONV_STRIDE_X */
143#endif /* DILATION_X==1 */
144
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000145/** This function computes the depthwise convolution quantized.
Anthony Barbierf202e502017-11-23 18:02:04 +0000146 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100147 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100148 * @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
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100155 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100156 * @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
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100163 * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100164 * @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 Barbierf202e502017-11-23 18:02:04 +0000183 */
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700184
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100185__kernel void dwc_3x3_native_quantized8_nchw(
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700186 TENSOR3D_DECLARATION(src),
187 TENSOR3D_DECLARATION(dst),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100188 TENSOR3D_DECLARATION(weights),
189 VECTOR_DECLARATION(output_multipliers),
190 VECTOR_DECLARATION(output_shifts)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700191#if defined(HAS_BIAS)
Georgios Pinitas5b2191e2018-02-22 12:56:51 +0000192 ,
Giorgio Arena287b5702018-02-16 11:01:04 +0000193 VECTOR_DECLARATION(biases)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700194#endif //defined(HAS_BIAS)
Giorgio Arena287b5702018-02-16 11:01:04 +0000195)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700196{
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000197 __global uchar *src_addr = src_ptr + get_global_id(0) * src_step_x + get_global_id(1) * src_step_y + get_global_id(2) * src_step_z;
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 Pinitase55b40a2018-09-13 17:20:04 +0100202
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 Savenkod7295b72017-11-20 22:00:08 +0700207#if defined(HAS_BIAS)
208 Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases);
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700209
Georgios Pinitas728d3cf2018-09-21 13:41:35 +0100210 int bias_value = *((__global int *)(vector_offset(&biases, channel)));
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700211#endif //defined(HAS_BIAS)
212
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100213 // Load relevant input and weights data (Accounts depth multiplier when indexing input, OFM = IFM * DEPTH_MULTIPLIER)
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000214 src_addr -= batch * (DST_CHANNELS / DEPTH_MULTIPLIER) * (DEPTH_MULTIPLIER - 1) * src_step_z + (channel - (channel / DEPTH_MULTIPLIER)) * src_step_z;
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100215 __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 Arena76572242018-04-04 17:44:26 +0100216
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100217 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 Giorgiodf4cf572019-10-09 15:32:39 +0100227#endif // defined(PER_CHANNEL_QUANTIZATION)
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700228
Giorgio Arena287b5702018-02-16 11:01:04 +0000229 int8 values0 = 0;
230 int8 sum0 = 0;
Usama Arife73686a2019-04-08 17:30:48 +0100231#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000232 int8 values1 = 0;
233 int8 sum1 = 0;
Usama Arife73686a2019-04-08 17:30:48 +0100234#endif /* CONV_STRIDE_Y &&DILATION_Y==1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000235
236 // Row0
237 int8 left, middle, right;
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000238 GET_VALUES(src_addr + 0 * src_stride_y, left, middle, right);
Giorgio Arena287b5702018-02-16 11:01:04 +0000239 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
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000248 GET_VALUES(src_addr + DILATION_Y * src_stride_y, left, middle, right);
Giorgio Arena287b5702018-02-16 11:01:04 +0000249 values0 += left * (int8)(w1.s0);
250 values0 += middle * (int8)(w1.s1);
251 values0 += right * (int8)(w1.s2);
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000252
Usama Arife73686a2019-04-08 17:30:48 +0100253#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000254 values1 += left * (int8)(w0.s0);
255 values1 += middle * (int8)(w0.s1);
256 values1 += right * (int8)(w0.s2);
Usama Arife73686a2019-04-08 17:30:48 +0100257#endif /* CONV_STRIDE_Y && DILATION_Y== 1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000258
259#if WEIGHTS_OFFSET != 0
260 int8 tmp = left + middle + right;
261 sum0 += tmp;
Usama Arife73686a2019-04-08 17:30:48 +0100262#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000263 sum1 += tmp;
Usama Arife73686a2019-04-08 17:30:48 +0100264#endif /* CONV_STRIDE_Y &&DILATION_Y== 1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000265#endif /* WEIGHTS_OFFSET != 0 */
266
267 // Row2
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000268 GET_VALUES(src_addr + 2 * DILATION_Y * src_stride_y, left, middle, right);
Giorgio Arena287b5702018-02-16 11:01:04 +0000269 values0 += left * (int8)(w2.s0);
270 values0 += middle * (int8)(w2.s1);
271 values0 += right * (int8)(w2.s2);
Usama Arife73686a2019-04-08 17:30:48 +0100272#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000273 values1 += left * (int8)(w1.s0);
274 values1 += middle * (int8)(w1.s1);
275 values1 += right * (int8)(w1.s2);
Usama Arife73686a2019-04-08 17:30:48 +0100276#endif /* CONV_STRIDE_Y &&DILATION_Y == 1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000277
278#if WEIGHTS_OFFSET != 0
279 tmp = left + middle + right;
280 sum0 += tmp;
Usama Arife73686a2019-04-08 17:30:48 +0100281#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000282 sum1 += tmp;
Usama Arife73686a2019-04-08 17:30:48 +0100283#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000284#endif /* WEIGHTS_OFFSET != 0 */
285
Usama Arife73686a2019-04-08 17:30:48 +0100286#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000287 // Row3
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000288 GET_VALUES(src_addr + 3 * src_stride_y, left, middle, right);
Giorgio Arena287b5702018-02-16 11:01:04 +0000289 values1 += left * (int8)(w2.s0);
290 values1 += middle * (int8)(w2.s1);
291 values1 += right * (int8)(w2.s2);
292
293#if WEIGHTS_OFFSET != 0
294 sum1 += left + middle + right;
295#endif /* WEIGHTS_OFFSET != 0 */
Usama Arife73686a2019-04-08 17:30:48 +0100296#endif /* CONV_STRIDE_Y && DILATION_Y == 1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000297
298#if defined(HAS_BIAS)
299 values0 += (int8)(bias_value);
Usama Arife73686a2019-04-08 17:30:48 +0100300#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000301 values1 += (int8)(bias_value);
Usama Arife73686a2019-04-08 17:30:48 +0100302#endif /* CONV_STRIDE_Y & &DILATION_Y == 1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000303#endif //defined(HAS_BIAS)
304
305#if WEIGHTS_OFFSET != 0
306 values0 += sum0 * (int8)(WEIGHTS_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100307#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000308 values1 += sum1 * (int8)(WEIGHTS_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100309#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000310#endif /* WEIGHTS_OFFSET != 0 */
311
312#if INPUT_OFFSET != 0
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100313 VEC_WEIGHTS_PROMOTED_TYPE(3)
314 tmp_we = CONVERT(w0, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w1, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w2, VEC_WEIGHTS_PROMOTED_TYPE(3));
315
316 WEIGHTS_PROMOTED_TYPE sum_weights = tmp_we.s0 + tmp_we.s1 + tmp_we.s2;
Giorgio Arena287b5702018-02-16 11:01:04 +0000317 values0 += sum_weights * (int8)(INPUT_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100318#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000319 values1 += sum_weights * (int8)(INPUT_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100320#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */
Giorgio Arena287b5702018-02-16 11:01:04 +0000321#endif /* INPUT_OFFSET != 0 */
322
323#if K_OFFSET != 0
324 values0 += (int8)(K_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100325#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arena287b5702018-02-16 11:01:04 +0000326 values1 += (int8)(K_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100327#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/
Giorgio Arena287b5702018-02-16 11:01:04 +0000328#endif /* K_OFFSET != 0 */
329
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100330#if defined(REAL_MULTIPLIER)
331
332 values0 = CONVERT(round(CONVERT(values0, float8) * (float8)REAL_MULTIPLIER), int8);
333
334#else // defined(REAL_MULTIPLIER)
335
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100336#if defined(PER_CHANNEL_QUANTIZATION)
337 int8 res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, output_multiplier, output_shift, 8);
338 int8 res0_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, output_multiplier, output_shift, 8);
339 values0 = select(res0_shift_lt0, res0_shift_gt0, (int8)(output_shift) >= 0);
340#else // defined(PER_CHANNEL_QUANTIZATION)
341#if OUTPUT_SHIFT < 0
342 values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
343#else // OUTPUT_SHIFT < 0
344 values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
345#endif // OUTPUT_OFFSET < 0
346#endif // defined(PER_CHANNEL_QUANTIZATION)
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100347
348#endif // defined(REAL_MULTIPLIER)
349
Giorgio Arena287b5702018-02-16 11:01:04 +0000350 values0 += (int8)OUTPUT_OFFSET;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100351 VEC_TYPE(8)
352 res0 = CONVERT_SAT(values0, VEC_TYPE(8));
Giorgio Arena287b5702018-02-16 11:01:04 +0000353
Giorgio Arena99ac60b2018-02-16 15:17:23 +0000354 vstore8(ACTIVATION_FUNC(res0), 0, dst.ptr);
Usama Arife73686a2019-04-08 17:30:48 +0100355#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100356#if defined(REAL_MULTIPLIER)
357
358 values1 = CONVERT(round(CONVERT(values1, float8) * (float8)REAL_MULTIPLIER), int8);
359
360#else // defined(REAL_MULTIPLIER)
Giorgio Arena287b5702018-02-16 11:01:04 +0000361
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100362#if defined(PER_CHANNEL_QUANTIZATION)
363 int8 res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, output_multiplier, output_shift, 8);
364 int8 res1_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, output_multiplier, output_shift, 8);
365 values1 = select(res1_shift_lt0, res1_shift_gt0, (int8)(output_shift) >= 0);
366#else // defined(PER_CHANNEL_QUANTIZATION)
367#if OUTPUT_SHIFT < 0
368 values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
369#else // OUTPUT_SHIFT < 0
370 values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
371#endif // OUTPUT_OFFSET < 0
372#endif // defined(PER_CHANNEL_QUANTIZATION)
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100373
374#endif // defined(REAL_MULTIPLIER)
375
Giorgio Arena287b5702018-02-16 11:01:04 +0000376 values1 += (int8)OUTPUT_OFFSET;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100377 VEC_TYPE(8)
378 res1 = CONVERT_SAT(values1, VEC_TYPE(8));
Giorgio Arena287b5702018-02-16 11:01:04 +0000379
Giorgio Arena99ac60b2018-02-16 15:17:23 +0000380 vstore8(ACTIVATION_FUNC(res1), 0, dst.ptr + dst_stride_y);
Usama Arife73686a2019-04-08 17:30:48 +0100381#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/
Dmitry Savenkod7295b72017-11-20 22:00:08 +0700382}
Giorgio Arena287b5702018-02-16 11:01:04 +0000383
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100384#else // !defined(IS_DOT8)
385
Usama Arife73686a2019-04-08 17:30:48 +0100386#if DILATION_X == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100387#if CONV_STRIDE_X == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100388#define GET_VALUES(first_value, left, middle, right) \
389 ({ \
390 VEC_TYPE(8) \
391 temp0 = vload8(0, (__global DATA_TYPE *)(first_value)); \
392 VEC_TYPE(2) \
393 temp1 = vload2(0, (__global DATA_TYPE *)(first_value + 8 * sizeof(DATA_TYPE))); \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100394 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100395 left = temp0.s01234567; \
396 middle = (VEC_TYPE(8))(temp0.s1234, temp0.s567, temp1.s0); \
397 right = (VEC_TYPE(8))(temp0.s2345, temp0.s67, temp1.s01); \
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000398 })
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100399#elif CONV_STRIDE_X == 2
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100400#define GET_VALUES(first_value, left, middle, right) \
401 ({ \
402 VEC_TYPE(16) \
403 temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \
404 DATA_TYPE temp1 = *((__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))); \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100405 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100406 left = temp0.s02468ace; \
407 middle = temp0.s13579bdf; \
408 right = (VEC_TYPE(8))(temp0.s2468, temp0.sace, temp1); \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100409 })
410#else /* CONV_STRIDE_X */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100411#define GET_VALUES(first_value, left, middle, right) \
412 ({ \
413 VEC_TYPE(16) \
414 temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \
415 VEC_TYPE(8) \
416 temp1 = vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE))); \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100417 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100418 left = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \
419 middle = (VEC_TYPE(8))(temp0.s147a, temp0.sd, temp1.s036); \
420 right = (VEC_TYPE(8))(temp0.s258b, temp0.se, temp1.s147); \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100421 })
422#endif /* CONV_STRIDE_X */
Usama Arife73686a2019-04-08 17:30:48 +0100423#else /*DILATION_X==1*/
424
425#if CONV_STRIDE_X == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100426#define GET_VALUES(first_value, left, middle, right) \
427 ({ \
428 left = vload8(0, (__global DATA_TYPE *)(first_value)); \
429 middle = vload8(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \
430 right = vload8(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \
Usama Arife73686a2019-04-08 17:30:48 +0100431 })
432#elif CONV_STRIDE_X == 2
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100433#define GET_VALUES(first_value, left, middle, right) \
434 ({ \
435 VEC_TYPE(16) \
436 temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \
437 left = temp0.s02468ace; \
438 temp0 = vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \
439 middle = temp0.s02468ace; \
440 temp0 = vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \
441 right = temp0.s02468ace; \
Usama Arife73686a2019-04-08 17:30:48 +0100442 })
443#else /* CONV_STRIDE_X */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100444#define GET_VALUES(first_value, left, middle, right) \
445 ({ \
446 VEC_TYPE(16) \
447 temp0 = vload16(0, (__global DATA_TYPE *)(first_value)); \
448 VEC_TYPE(8) \
449 temp1 = vload8(0, (__global DATA_TYPE *)(first_value + 16 * sizeof(DATA_TYPE)))); \
450 left = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \
Usama Arife73686a2019-04-08 17:30:48 +0100451 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100452 temp0 = vload16(0, (__global DATA_TYPE *)(first_value + DILATION_X * sizeof(DATA_TYPE))); \
453 temp1 = vload8(0, (__global DATA_TYPE *)(first_value + (16 + DILATION_X) * sizeof(DATA_TYPE))); \
454 middle = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \
Usama Arife73686a2019-04-08 17:30:48 +0100455 \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100456 temp0 = vload16(0, (__global DATA_TYPE *)(first_value + 2 * DILATION_X * sizeof(DATA_TYPE))); \
457 temp1 = vload8(0, (__global DATA_TYPE *)(first_value + (16 + 2 * DILATION_X) * sizeof(DATA_TYPE))); \
458 right = (VEC_TYPE(8))(temp0.s0369, temp0.scf, temp1.s25); \
Usama Arife73686a2019-04-08 17:30:48 +0100459 })
460
461#endif /* CONV_STRIDE_X */
462#endif /*DILATION_X==1*/
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100463/** This function computes the depthwise convolution quantized using dot product when the data layout is NCHW.
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000464 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100465 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100466 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
467 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
468 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
469 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
470 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
471 * @param[in] src_step_z src_stride_z * number of elements along Y processed per workitem(in bytes)
472 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100473 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100474 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
475 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
476 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
477 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
478 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
479 * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
480 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100481 * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100482 * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
483 * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
484 * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
485 * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
486 * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes)
487 * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes)
488 * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
489 * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32
490 * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes)
491 * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes)
492 * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector
493 * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32
494 * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes)
495 * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes)
496 * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector
497 * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32
498 * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
499 * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
500 * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000501 */
502
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100503__kernel void dwc_3x3_native_quantized8_dot8_nchw(
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100504 TENSOR3D_DECLARATION(src),
505 TENSOR3D_DECLARATION(dst),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100506 TENSOR3D_DECLARATION(weights),
507 VECTOR_DECLARATION(output_multipliers),
508 VECTOR_DECLARATION(output_shifts)
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100509#if defined(HAS_BIAS)
510 ,
511 VECTOR_DECLARATION(biases)
512#endif //defined(HAS_BIAS)
513)
514{
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000515 __global uchar *src_addr = src_ptr + get_global_id(0) * src_step_x + get_global_id(1) * src_step_y + get_global_id(2) * src_step_z;
516 Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst);
517 Tensor3D weights = CONVERT_TO_TENSOR3D_STRUCT_NO_STEP(weights);
518 Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_multipliers);
519 Vector output_shifts = CONVERT_TO_VECTOR_STRUCT_NO_STEP(output_shifts);
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100520
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100521 // Extract channel and linearized batch indices
522 const int channel = get_global_id(2) % DST_CHANNELS;
523 const int batch = get_global_id(2) / DST_CHANNELS;
524
525#if defined(HAS_BIAS)
526 Vector biases = CONVERT_TO_VECTOR_STRUCT_NO_STEP(biases);
527
528 const int bias_value = *((__global int *)(vector_offset(&biases, channel)));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100529#endif //defined(HAS_BIAS)
530
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100531 // Load relevant input and weights data (Accounts depth multiplier when indexing input, OFM = IFM * DEPTH_MULTIPLIER)
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000532 src_addr -= batch * (DST_CHANNELS / DEPTH_MULTIPLIER) * (DEPTH_MULTIPLIER - 1) * src_step_z + (channel - (channel / DEPTH_MULTIPLIER)) * src_step_z;
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100533 __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 Arenaeff8d952018-07-02 15:29:57 +0100534
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100535 VEC_TYPE(3)
536 w0 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 0 * weights_stride_y));
537 VEC_TYPE(3)
538 w1 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 1 * weights_stride_y));
539 VEC_TYPE(3)
540 w2 = vload3(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * weights_stride_y));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100541
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100542 const int output_multiplier = *((__global int *)vector_offset(&output_multipliers, 0));
543 const int output_shift = *((__global int *)vector_offset(&output_shifts, 0));
544
545 VEC_TYPE(8)
546 left0, middle0, right0;
547 VEC_TYPE(8)
548 left1, middle1, right1;
549 VEC_TYPE(8)
550 left2, middle2, right2;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100551
552 int8 values0 = 0;
553 int8 sum0 = 0;
554
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000555 GET_VALUES(src_addr + 0 * src_stride_y, left0, middle0, right0);
556 GET_VALUES(src_addr + DILATION_Y * src_stride_y, left1, middle1, right1);
557 GET_VALUES(src_addr + 2 * DILATION_Y * src_stride_y, left2, middle2, right2);
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100558
559#if WEIGHTS_OFFSET != 0
560 sum0 += convert_int8(left0) + convert_int8(middle0) + convert_int8(right0);
561 sum0 += convert_int8(left1) + convert_int8(middle1) + convert_int8(right1);
562 sum0 += convert_int8(left2) + convert_int8(middle2) + convert_int8(right2);
563#endif /* WEIGHTS_OFFSET != 0 */
564
Usama Arife73686a2019-04-08 17:30:48 +0100565#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100566 // If conv_stride_y is equals to 1, we compute two output rows
567
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100568 VEC_TYPE(8)
569 left3, middle3, right3;
570 int8 values1 = 0;
571 int8 sum1 = 0;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100572
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000573 GET_VALUES(src_addr + 3 * src_stride_y, left3, middle3, right3);
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100574
575#if WEIGHTS_OFFSET != 0
576 sum1 += convert_int8(left1) + convert_int8(middle1) + convert_int8(right1);
577 sum1 += convert_int8(left2) + convert_int8(middle2) + convert_int8(right2);
578 sum1 += convert_int8(left3) + convert_int8(middle3) + convert_int8(right3);
579#endif /* WEIGHTS_OFFSET != 0 */
Usama Arife73686a2019-04-08 17:30:48 +0100580#endif // CONV_STRIDE_Y == 1 && DILATION_Y==1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100581
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100582 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);
583 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 Arenaeff8d952018-07-02 15:29:57 +0100584 values0.s0 += right2.s0 * w2.s2;
585
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100586 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);
587 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 Arenaeff8d952018-07-02 15:29:57 +0100588 values0.s1 += right2.s1 * w2.s2;
589
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100590 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);
591 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 Arenaeff8d952018-07-02 15:29:57 +0100592 values0.s2 += right2.s2 * w2.s2;
593
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100594 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);
595 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 Arenaeff8d952018-07-02 15:29:57 +0100596 values0.s3 += right2.s3 * w2.s2;
597
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100598 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);
599 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 Arenaeff8d952018-07-02 15:29:57 +0100600 values0.s4 += right2.s4 * w2.s2;
601
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100602 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);
603 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 Arenaeff8d952018-07-02 15:29:57 +0100604 values0.s5 += right2.s5 * w2.s2;
605
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100606 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);
607 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 Arenaeff8d952018-07-02 15:29:57 +0100608 values0.s6 += right2.s6 * w2.s2;
609
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100610 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);
611 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 Arenaeff8d952018-07-02 15:29:57 +0100612 values0.s7 += right2.s7 * w2.s2;
613
Usama Arife73686a2019-04-08 17:30:48 +0100614#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100615 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);
616 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 Arenaeff8d952018-07-02 15:29:57 +0100617 values1.s0 += right3.s0 * w2.s2;
618
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100619 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);
620 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 Arenaeff8d952018-07-02 15:29:57 +0100621 values1.s1 += right3.s1 * w2.s2;
622
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100623 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);
624 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 Arenaeff8d952018-07-02 15:29:57 +0100625 values1.s2 += right3.s2 * w2.s2;
626
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100627 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);
628 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 Arenaeff8d952018-07-02 15:29:57 +0100629 values1.s3 += right3.s3 * w2.s2;
630
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100631 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);
632 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 Arenaeff8d952018-07-02 15:29:57 +0100633 values1.s4 += right3.s4 * w2.s2;
634
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100635 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);
636 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 Arenaeff8d952018-07-02 15:29:57 +0100637 values1.s5 += right3.s5 * w2.s2;
638
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100639 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);
640 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 Arenaeff8d952018-07-02 15:29:57 +0100641 values1.s6 += right3.s6 * w2.s2;
642
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100643 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);
644 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 Arenaeff8d952018-07-02 15:29:57 +0100645 values1.s7 += right3.s7 * w2.s2;
Usama Arife73686a2019-04-08 17:30:48 +0100646#endif // CONV_STRIDE_Y == 1 && DILATION_Y==1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100647
648#if defined(HAS_BIAS)
649 values0 += (int8)(bias_value);
Usama Arife73686a2019-04-08 17:30:48 +0100650#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100651 values1 += (int8)(bias_value);
Usama Arife73686a2019-04-08 17:30:48 +0100652#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100653#endif //defined(HAS_BIAS)
654
655#if WEIGHTS_OFFSET != 0
656 values0 += sum0 * (int8)(WEIGHTS_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100657#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100658 values1 += sum1 * (int8)(WEIGHTS_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100659#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1 */
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100660#endif /* WEIGHTS_OFFSET != 0 */
661
662#if INPUT_OFFSET != 0
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100663 WEIGHTS_PROMOTED_TYPE sum_weights = 0;
664 VEC_WEIGHTS_PROMOTED_TYPE(3)
665 tmp_we = CONVERT(w0, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w1, VEC_WEIGHTS_PROMOTED_TYPE(3)) + CONVERT(w2, VEC_WEIGHTS_PROMOTED_TYPE(3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100666 sum_weights += tmp_we.s0 + tmp_we.s1 + tmp_we.s2;
667 values0 += sum_weights * (int8)(INPUT_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100668#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100669 values1 += sum_weights * (int8)(INPUT_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100670#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100671#endif /* INPUT_OFFSET != 0 */
672
673#if K_OFFSET != 0
674 values0 += (int8)(K_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100675#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100676 values1 += (int8)(K_OFFSET);
Usama Arife73686a2019-04-08 17:30:48 +0100677#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100678#endif /* K_OFFSET != 0 */
679
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100680#if defined(REAL_MULTIPLIER)
681
682 values0 = CONVERT(round(CONVERT(values0, float8) * (float8)REAL_MULTIPLIER), int8);
683
684#else // defined(REAL_MULTIPLIER)
685
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100686#if defined(PER_CHANNEL_QUANTIZATION)
687 int8 res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, output_multiplier, output_shift, 8);
688 int8 res0_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, output_multiplier, output_shift, 8);
689 values0 = select(res0_shift_lt0, res0_shift_gt0, (int8)(output_shift) >= 0);
690#else // defined(PER_CHANNEL_QUANTIZATION)
691#if OUTPUT_SHIFT < 0
692 values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
693#else // OUTPUT_SHIFT < 0
694 values0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
695#endif // OUTPUT_OFFSET < 0
696#endif // defined(PER_CHANNEL_QUANTIZATION)
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100697
698#endif // defined(REAL_MULTIPLIER)
699
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100700 values0 += (int8)OUTPUT_OFFSET;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100701 VEC_TYPE(8)
702 res0 = CONVERT_SAT(values0, VEC_TYPE(8));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100703
704 vstore8(ACTIVATION_FUNC(res0), 0, dst.ptr);
Usama Arife73686a2019-04-08 17:30:48 +0100705#if CONV_STRIDE_Y == 1 && DILATION_Y == 1
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100706
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100707#if defined(REAL_MULTIPLIER)
708
709 values1 = CONVERT(round(CONVERT(values1, float8) * (float8)REAL_MULTIPLIER), int8);
710
711#else // defined(REAL_MULTIPLIER)
712
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100713#if defined(PER_CHANNEL_QUANTIZATION)
714 int8 res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, output_multiplier, output_shift, 8);
715 int8 res1_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, output_multiplier, output_shift, 8);
716 values1 = select(res1_shift_lt0, res1_shift_gt0, (int8)(output_shift) >= 0);
717#else // defined(PER_CHANNEL_QUANTIZATION)
718#if OUTPUT_SHIFT < 0
719 values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
720#else // OUTPUT_SHIFT < 0
721 values1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(values1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, 8);
722#endif // OUTPUT_OFFSET < 0
723#endif // defined(PER_CHANNEL_QUANTIZATION)
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100724
725#endif // defined(REAL_MULTIPLIER)
726
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100727 values1 += (int8)OUTPUT_OFFSET;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100728 VEC_TYPE(8)
729 res1 = CONVERT_SAT(values1, VEC_TYPE(8));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100730
731 vstore8(ACTIVATION_FUNC(res1), 0, dst.ptr + dst_stride_y);
Usama Arife73686a2019-04-08 17:30:48 +0100732#endif /* CONV_STRIDE_Y == 1 && DILATION_Y==1*/
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100733}
734
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100735#endif // !defined(IS_DOT8)
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100736
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100737#endif /* defined(CONV_STRIDE_Y) && defined(CONV_STRIDE_X) && defined(DEPTH_MULTIPLIER) && defined(DST_CHANNELS) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100738
739#if defined(VEC_SIZE) && defined(SRC_DIM_1) && defined(SRC_DIM_2) && defined(CONV_PAD_TOP) && defined(CONV_PAD_LEFT)
740
741#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)
742
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100743#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 Arenaeff8d952018-07-02 15:29:57 +0100744
745#if WEIGHTS_OFFSET != 0
746#define MULTIPLY_ADD_ACCUMULATE(x, y, acc, sum) \
747 ({ \
748 sum += CONVERT(x, VEC_INT); \
749 MULTIPLY_ADD(x, y, acc); \
750 })
751#else /* WEIGHTS_OFFSET != 0 */
752#define MULTIPLY_ADD_ACCUMULATE(x, y, acc, sum) MULTIPLY_ADD(x, y, acc)
753#endif /* WEIGHTS_OFFSET != 0 */
754
Georgios Pinitasdaa38552018-08-28 17:43:18 +0100755#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8)
giuros016d109962019-01-07 17:47:19 +0000756#define DOT_PRODUCT(acc, val0, val1, val2, val3, val4, val5, val6, val7, val8, w0, w1) \
757 ({ \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100758 ARM_DOT((VEC_TYPE(4))(val0, val1, val2, val3), w0.s0123, acc); \
759 ARM_DOT((VEC_TYPE(4))(val4, val5, val6, val7), w0.s4567, acc); \
giuros016d109962019-01-07 17:47:19 +0000760 acc += val8 * w1; \
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100761 })
762
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100763#define DOT_PRODUCT_REDUCTION(sum, val0, val1, val2, val3, val4, val5, val6, val7, val8) \
764 ({ \
giuros016d109962019-01-07 17:47:19 +0000765 sum = val0; \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100766 ARM_DOT((VEC_TYPE(4))(val1, val2, val3, val4), (VEC_TYPE(4))1, sum); \
767 ARM_DOT((VEC_TYPE(4))(val5, val6, val7, val8), (VEC_TYPE(4))1, sum); \
giuros016d109962019-01-07 17:47:19 +0000768 })
769
770#define DOT_PRODUCT_REDUCTION_WEIGHTS(sum, w0, w1) \
771 ({ \
772 sum = w1; \
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100773 ARM_DOT(w0.s0123, (VEC_TYPE(4))1, sum); \
774 ARM_DOT(w0.s4567, (VEC_TYPE(4))1, sum); \
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100775 })
776
Georgios Pinitasdaa38552018-08-28 17:43:18 +0100777#endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8)
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100778
Pablo Tello47104362019-02-27 13:32:51 +0000779#if defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y) && VEC_SIZE == 4
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100780/** This function computes the depthwise convolution quantized for NHWC data layout when the stride along the width or height is not 1.
781 *
Pablo Tello47104362019-02-27 13:32:51 +0000782 * @note This kernel assumes VEC_SIZE is 4.
giuros016d109962019-01-07 17:47:19 +0000783 * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel.
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100784 * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2)
785 * @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)
786 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1)
787 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1)
788 * @note The convolution stride along the width must be passed at compile time using -DCONV_STRIDE_X (e.g. -DCONV_STRIDE_Y=X)
789 * @note The convolution stride along the height must be passed at compile time using -DCONV_STRIDE_Y (e.g. -DCONV_STRIDE_Y=1)
790 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100791 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100792 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
793 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
794 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
795 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
796 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
797 * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes)
798 * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes)
799 * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes)
800 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
801 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
802 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
803 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
804 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
805 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
806 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
807 * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
808 * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes)
809 * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes)
810 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100811 * @param[in] weights_ptr Pointer to the weights tensor reshaped. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100812 * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
813 * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
814 * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
815 * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
816 * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
817 * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32
818 * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes)
819 * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes)
820 * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector
821 * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32
822 * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes)
823 * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes)
824 * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector
825 * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32
826 * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
827 * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
828 * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
829 * @param[in] max_offset Max offset for the input tensor
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100830 */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100831__kernel void dwc_3x3_reshaped_quantized8_nhwc(
Georgios Pinitas37044642018-10-30 14:53:25 +0000832 TENSOR4D_DECLARATION(src),
833 TENSOR4D_DECLARATION(dst),
giuros016d109962019-01-07 17:47:19 +0000834 IMAGE_DECLARATION(weights),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100835 VECTOR_DECLARATION(output_multipliers),
836 VECTOR_DECLARATION(output_shifts),
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100837#if defined(HAS_BIAS)
838 VECTOR_DECLARATION(biases),
839#endif /* defined(HAS_BIAS) */
840 int max_offset)
841{
842 const int x = get_global_id(0); // channels
843 const int y = get_global_id(1); // spatial coordinate x
Georgios Pinitas37044642018-10-30 14:53:25 +0000844#if defined(DST_DEPTH)
845 int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y
846 int b = get_global_id(2) / (int)DST_DEPTH; // batch
Pablo Tello47104362019-02-27 13:32:51 +0000847#else // defined(DST_DEPTH)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100848 int z = get_global_id(2); // spatial coordinate y
Pablo Tello47104362019-02-27 13:32:51 +0000849#endif // defined(DST_DEPTH)
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100850
giuros016d109962019-01-07 17:47:19 +0000851 __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100852
Georgios Pinitas37044642018-10-30 14:53:25 +0000853#if defined(DST_DEPTH)
854 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w;
855#else /* defined(DST_DEPTH) */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100856 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE;
Georgios Pinitas37044642018-10-30 14:53:25 +0000857#endif /* defined(DST_DEPTH) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100858
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100859 int z_coord = 0;
860 int4 offset = 0;
Usama Arife73686a2019-04-08 17:30:48 +0100861 int4 y_coord = ((int4)(y * CONV_STRIDE_X) + (int4)(0, DILATION_X * 1, DILATION_X * 2, DILATION_X * 3)) - (int)CONV_PAD_LEFT;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100862
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100863 // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1
864 y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1);
865 y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1);
866 y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1);
867 y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1);
868
869 int4 y_offset = convert_int4(y_coord * (int)src_stride_y);
870
giuros016d109962019-01-07 17:47:19 +0000871 // We compute VEC_SIZEx1x1 [C,W,H] elements
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100872 VEC_INT acc = 0, sum = 0;
873
874 // Load weights
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100875 VEC_DATA_TYPE(WEIGHTS_TYPE, 16)
876 w0_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr));
877 VEC_DATA_TYPE(WEIGHTS_TYPE, 16)
878 w1_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16));
879 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
880 w8 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * 16));
Pablo Tello47104362019-02-27 13:32:51 +0000881
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100882 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
883 w0 = w0_tmp.s0123;
884 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
885 w1 = w0_tmp.s4567;
886 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
887 w2 = w0_tmp.s89AB;
888 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
889 w3 = w0_tmp.sCDEF;
Pablo Tello47104362019-02-27 13:32:51 +0000890
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100891 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
892 w4 = w1_tmp.s0123;
893 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
894 w5 = w1_tmp.s4567;
895 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
896 w6 = w1_tmp.s89AB;
897 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
898 w7 = w1_tmp.sCDEF;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100899
900#if INPUT_OFFSET != 0
Georgios Pinitas4e0d3812018-08-01 20:16:34 +0100901 VEC_INT sum_we = CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT)
902 + CONVERT(w3, VEC_INT) + CONVERT(w4, VEC_INT) + CONVERT(w5, VEC_INT)
903 + CONVERT(w6, VEC_INT) + CONVERT(w7, VEC_INT) + CONVERT(w8, VEC_INT);
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100904#endif /* INPUT_OFFSET != 0 */
905
906 // Load input values
907 // z == 0
908 // Clamp z_coord as for z = 0, it can be negative
909 // z_coord is casted to unsigned int in order to use just a min() operation
910 // A "-1" 32 bit signed variable converted to unsigned gives 4294967295
Georgios Pinitas4e0d3812018-08-01 20:16:34 +0100911 z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP;
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100912 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
913 offset = y_offset + (int4)(z_coord * src_stride_z);
Georgios Pinitas4e0d3812018-08-01 20:16:34 +0100914 offset = min(offset, (int4)max_offset);
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100915
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100916 VEC_TYPE(VEC_SIZE)
917 values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
918 VEC_TYPE(VEC_SIZE)
919 values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
920 VEC_TYPE(VEC_SIZE)
921 values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100922
923 // z == 1
924 // z_coord can be only negative for z = 0 so we do not need to clamp it
925 // Moreover z_coord cannot be out-of-bound for z = 1 so we do not need to clamp the offset
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100926 z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP + DILATION_Y;
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000927 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100928 offset = y_offset + (int4)(z_coord * src_stride_z);
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000929 offset = min(offset, (int4)max_offset);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100930 VEC_TYPE(VEC_SIZE)
931 values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
932 VEC_TYPE(VEC_SIZE)
933 values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
934 VEC_TYPE(VEC_SIZE)
935 values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100936
937 // z == 2
Usama Arife73686a2019-04-08 17:30:48 +0100938 // Offset can be out-of-bound so we need to check if it is greater than max_offset
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100939 z_coord = z * (int)CONV_STRIDE_Y - (int)CONV_PAD_TOP + DILATION_Y * 2;
Giorgio Arena9f7d55a2021-02-08 13:20:24 +0000940 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100941 offset = y_offset + (int4)(z_coord * src_stride_z);
942 offset = min(offset, (int4)max_offset);
943 VEC_TYPE(VEC_SIZE)
944 values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
945 VEC_TYPE(VEC_SIZE)
946 values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
947 VEC_TYPE(VEC_SIZE)
948 values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
Giorgio Arenaeff8d952018-07-02 15:29:57 +0100949
950 MULTIPLY_ADD_ACCUMULATE(values0, w0, acc, sum);
951 MULTIPLY_ADD_ACCUMULATE(values1, w1, acc, sum);
952 MULTIPLY_ADD_ACCUMULATE(values2, w2, acc, sum);
953
954 MULTIPLY_ADD_ACCUMULATE(values3, w3, acc, sum);
955 MULTIPLY_ADD_ACCUMULATE(values4, w4, acc, sum);
956 MULTIPLY_ADD_ACCUMULATE(values5, w5, acc, sum);
957
958 MULTIPLY_ADD_ACCUMULATE(values6, w6, acc, sum);
959 MULTIPLY_ADD_ACCUMULATE(values7, w7, acc, sum);
960 MULTIPLY_ADD_ACCUMULATE(values8, w8, acc, sum);
961
962#if defined(HAS_BIAS)
963 Vector biases = CONVERT_TO_VECTOR_STRUCT(biases);
964 VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr);
965 acc += bias_values;
966#endif // defined(HAS_BIAS)
967
968#if WEIGHTS_OFFSET != 0
969 acc += WEIGHTS_OFFSET * sum;
970#endif /* WEIGHTS_OFFSET != 0 */
971
972#if INPUT_OFFSET != 0
973 acc += INPUT_OFFSET * sum_we;
974#endif /* INPUT_OFFSET != 0 */
975
976#if K_OFFSET != 0
977 acc += (VEC_INT)K_OFFSET;
978#endif /* K_OFFSET != 0 */
979
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100980#if defined(REAL_MULTIPLIER)
981
982 acc = CONVERT(round(CONVERT(acc, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
983
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100984#else // defined(REAL_MULTIPLIER)
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100985
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100986#if defined(PER_CHANNEL_QUANTIZATION)
987 Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT(output_multipliers);
988 Vector output_shifts = CONVERT_TO_VECTOR_STRUCT(output_shifts);
989 VEC_INT output_multiplier = VLOAD(VEC_SIZE)(0, (__global int *)output_multipliers.ptr);
990 VEC_INT output_shift = VLOAD(VEC_SIZE)(0, (__global int *)output_shifts.ptr);
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100991
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100992 VEC_INT res_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc, output_multiplier, output_shift, VEC_SIZE);
993 VEC_INT res_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc, output_multiplier, output_shift);
994 acc = select(res_shift_lt0, res_shift_gt0, output_shift >= 0);
995#else // defined(PER_CHANNEL_QUANTIZATION)
996#if OUTPUT_SHIFT < 0
997 acc = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
998#else // OUTPUT_SHIFT < 0
999 acc = asymm_mult_by_quant_multiplier_less_than_one(acc, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1000#endif // OUTPUT_SHIFT < 0
1001#endif // defined(PER_CHANNEL_QUANTIZATION)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001002
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001003#endif // defined(REAL_MULTIPLIER)
1004
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001005 acc += (VEC_INT)OUTPUT_OFFSET;
1006
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001007 VEC_TYPE(VEC_SIZE)
1008 res = CONVERT_SAT(acc, VEC_TYPE(VEC_SIZE));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001009
Georgios Pinitas37044642018-10-30 14:53:25 +00001010#if defined(DST_DEPTH)
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 + b * dst_stride_w;
1012#else /* defined(DST_DEPTH) */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001013 __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 Pinitas37044642018-10-30 14:53:25 +00001014#endif /* defined(DST_DEPTH) */
1015
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001016 VSTORE(VEC_SIZE)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001017 (ACTIVATION_FUNC(res), 0, (__global DATA_TYPE *)(dst_addr));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001018}
1019#endif // defined(CONV_STRIDE_X) && defined(CONV_STRIDE_Y)
1020
Pablo Tello47104362019-02-27 13:32:51 +00001021#if defined(NUM_ROWS_PROCESSED) && defined(NUM_PLANES_PROCESSED) && VEC_SIZE == 4
giuros016d109962019-01-07 17:47:19 +00001022/** This function computes the depthwise convolution quantized for NHWC data layout when the stride along the width and height is 1.
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001023 *
Pablo Tello47104362019-02-27 13:32:51 +00001024 * @note This kernel assumes VEC_SIZE is 4.
giuros016d109962019-01-07 17:47:19 +00001025 * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel.
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001026 * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2)
1027 * @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)
1028 * @note The number of rows processed per thread must be passed at compile time using -DNUM_ROWS_PROCESSED (i.e. -DNUM_ROWS_PROCESSED=2)
1029 * @note The number of planes processed per thread must be passed at compile time using -DNUM_PLANES_PROCESSED (i.e. -DNUM_PLANES_PROCESSED=2)
1030 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1)
1031 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1).
1032 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +01001033 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001034 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
1035 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
1036 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
1037 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
1038 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
1039 * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes)
1040 * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes)
1041 * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes)
1042 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
1043 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
1044 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
1045 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
1046 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
1047 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
1048 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
1049 * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
1050 * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes)
1051 * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes)
1052 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgiof6f78762020-07-06 11:27:21 +01001053 * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001054 * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
1055 * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
1056 * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
1057 * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
1058 * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
1059 * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32
1060 * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes)
1061 * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes)
1062 * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector
1063 * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32
1064 * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes)
1065 * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes)
1066 * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector
1067 * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32
1068 * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
1069 * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
1070 * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
1071 * @param[in] max_offset Max offset for the input tensor
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001072 */
1073
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001074__kernel void dwc_3x3_reshaped_quantized8_stride1_nhwc(
Georgios Pinitas37044642018-10-30 14:53:25 +00001075 TENSOR4D_DECLARATION(src),
1076 TENSOR4D_DECLARATION(dst),
giuros016d109962019-01-07 17:47:19 +00001077 IMAGE_DECLARATION(weights),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001078 VECTOR_DECLARATION(output_multipliers),
1079 VECTOR_DECLARATION(output_shifts),
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001080#if defined(HAS_BIAS)
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001081 VECTOR_DECLARATION(biases),
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001082#endif /* defined(HAS_BIAS) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001083 int max_offset)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001084{
Giorgio Arenafa23f112018-06-19 11:27:38 +01001085 int x = get_global_id(0);
1086 int y = get_global_id(1);
Georgios Pinitas37044642018-10-30 14:53:25 +00001087#if defined(DST_DEPTH)
1088 int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y
1089 int b = get_global_id(2) / (int)DST_DEPTH; // batch
Pablo Tello47104362019-02-27 13:32:51 +00001090#else // defined(DST_DEPTH)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001091 int z = get_global_id(2); // spatial coordinate y
Pablo Tello47104362019-02-27 13:32:51 +00001092#endif // defined(DST_DEPTH)
Giorgio Arenafa23f112018-06-19 11:27:38 +01001093
giuros016d109962019-01-07 17:47:19 +00001094 __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001095
Georgios Pinitas37044642018-10-30 14:53:25 +00001096#if defined(DST_DEPTH)
1097 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w;
1098#else /* defined(DST_DEPTH) */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001099 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE;
Georgios Pinitas37044642018-10-30 14:53:25 +00001100#endif /* defined(DST_DEPTH) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001101
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001102 int z_coord = 0;
1103 int4 offset = 0;
1104 int4 y_coord = ((int4)(y * NUM_ROWS_PROCESSED) + (int4)(0, 1, 2, 3)) - (int)CONV_PAD_LEFT;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001105
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001106 // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1
1107 y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1);
1108 y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1);
1109 y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1);
1110 y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1);
1111
1112 int4 y_offset = convert_int4(y_coord * (int)src_stride_y);
1113
1114 // We compute 4x2x2 [C,W,H] elements
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001115 VEC_INT acc0 = 0, sum0 = 0;
1116 VEC_INT acc1 = 0, sum1 = 0;
1117 VEC_INT acc2 = 0, sum2 = 0;
1118 VEC_INT acc3 = 0, sum3 = 0;
1119
1120 // Load weights
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001121 VEC_DATA_TYPE(WEIGHTS_TYPE, 16)
1122 w0_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr));
1123 VEC_DATA_TYPE(WEIGHTS_TYPE, 16)
1124 w1_tmp = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16));
1125 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1126 w8 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 2 * 16));
Pablo Tello47104362019-02-27 13:32:51 +00001127
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001128 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1129 w0 = w0_tmp.s0123;
1130 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1131 w1 = w0_tmp.s4567;
1132 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1133 w2 = w0_tmp.s89AB;
1134 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1135 w3 = w0_tmp.sCDEF;
Pablo Tello47104362019-02-27 13:32:51 +00001136
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001137 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1138 w4 = w1_tmp.s0123;
1139 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1140 w5 = w1_tmp.s4567;
1141 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1142 w6 = w1_tmp.s89AB;
1143 VEC_DATA_TYPE(WEIGHTS_TYPE, 4)
1144 w7 = w1_tmp.sCDEF;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001145
1146#if INPUT_OFFSET != 0
Georgios Pinitas4e0d3812018-08-01 20:16:34 +01001147 VEC_INT sum_we = CONVERT(w0, VEC_INT) + CONVERT(w1, VEC_INT) + CONVERT(w2, VEC_INT)
1148 + CONVERT(w3, VEC_INT) + CONVERT(w4, VEC_INT) + CONVERT(w5, VEC_INT)
1149 + CONVERT(w6, VEC_INT) + CONVERT(w7, VEC_INT) + CONVERT(w8, VEC_INT);
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001150#endif /* INPUT_OFFSET != 0 */
1151
1152 // Load input values
1153 // z == 0
1154 // Clamp z_coord as for z = 0, it can be negative
1155 // z_coord is casted to unsigned int in order to use just a min() operation
1156 // A "-1" 32 bit signed variable converted to unsigned gives 4294967295
Georgios Pinitas4e0d3812018-08-01 20:16:34 +01001157 z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001158 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
1159 offset = y_offset + (int4)(z_coord * src_stride_z);
Georgios Pinitas4e0d3812018-08-01 20:16:34 +01001160 offset = min(offset, (int4)max_offset);
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001161
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001162 VEC_TYPE(VEC_SIZE)
1163 values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1164 VEC_TYPE(VEC_SIZE)
1165 values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1166 VEC_TYPE(VEC_SIZE)
1167 values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1168 VEC_TYPE(VEC_SIZE)
1169 values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001170
1171 // z == 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001172 z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP + 1;
Giorgio Arena8bcb65f2021-01-12 11:29:18 +00001173 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001174 offset = y_offset + (int4)(z_coord * src_stride_z);
Giorgio Arena8bcb65f2021-01-12 11:29:18 +00001175 offset = min(offset, (int4)max_offset);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001176 VEC_TYPE(VEC_SIZE)
1177 values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1178 VEC_TYPE(VEC_SIZE)
1179 values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1180 VEC_TYPE(VEC_SIZE)
1181 values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1182 VEC_TYPE(VEC_SIZE)
1183 values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001184
1185 // z == 2
Giorgio Arena8bcb65f2021-01-12 11:29:18 +00001186 z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP + 2;
1187 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
1188 offset = y_offset + (int4)(z_coord * src_stride_z);
1189 offset = min(offset, (int4)max_offset);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001190 VEC_TYPE(VEC_SIZE)
1191 values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1192 VEC_TYPE(VEC_SIZE)
1193 values9 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1194 VEC_TYPE(VEC_SIZE)
1195 values10 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1196 VEC_TYPE(VEC_SIZE)
1197 values11 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001198
1199 // z == 3
Giorgio Arena8bcb65f2021-01-12 11:29:18 +00001200 z_coord = z * (int)NUM_PLANES_PROCESSED - (int)CONV_PAD_TOP + 3;
1201 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
1202 offset = y_offset + (int4)(z_coord * src_stride_z);
1203 offset = min(offset, (int4)max_offset);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001204 VEC_TYPE(VEC_SIZE)
1205 values12 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1206 VEC_TYPE(VEC_SIZE)
1207 values13 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1208 VEC_TYPE(VEC_SIZE)
1209 values14 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1210 VEC_TYPE(VEC_SIZE)
1211 values15 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001212
1213 MULTIPLY_ADD_ACCUMULATE(values0, w0, acc0, sum0);
1214 MULTIPLY_ADD_ACCUMULATE(values1, w1, acc0, sum0);
1215 MULTIPLY_ADD_ACCUMULATE(values2, w2, acc0, sum0);
1216 MULTIPLY_ADD_ACCUMULATE(values1, w0, acc1, sum1);
1217 MULTIPLY_ADD_ACCUMULATE(values2, w1, acc1, sum1);
1218 MULTIPLY_ADD_ACCUMULATE(values3, w2, acc1, sum1);
1219
1220 MULTIPLY_ADD_ACCUMULATE(values4, w3, acc0, sum0);
1221 MULTIPLY_ADD_ACCUMULATE(values5, w4, acc0, sum0);
1222 MULTIPLY_ADD_ACCUMULATE(values6, w5, acc0, sum0);
1223 MULTIPLY_ADD_ACCUMULATE(values5, w3, acc1, sum1);
1224 MULTIPLY_ADD_ACCUMULATE(values6, w4, acc1, sum1);
1225 MULTIPLY_ADD_ACCUMULATE(values7, w5, acc1, sum1);
1226
1227 MULTIPLY_ADD_ACCUMULATE(values8, w6, acc0, sum0);
1228 MULTIPLY_ADD_ACCUMULATE(values9, w7, acc0, sum0);
1229 MULTIPLY_ADD_ACCUMULATE(values10, w8, acc0, sum0);
1230 MULTIPLY_ADD_ACCUMULATE(values9, w6, acc1, sum1);
1231 MULTIPLY_ADD_ACCUMULATE(values10, w7, acc1, sum1);
1232 MULTIPLY_ADD_ACCUMULATE(values11, w8, acc1, sum1);
1233
1234 MULTIPLY_ADD_ACCUMULATE(values4, w0, acc2, sum2);
1235 MULTIPLY_ADD_ACCUMULATE(values5, w1, acc2, sum2);
1236 MULTIPLY_ADD_ACCUMULATE(values6, w2, acc2, sum2);
1237 MULTIPLY_ADD_ACCUMULATE(values5, w0, acc3, sum3);
1238 MULTIPLY_ADD_ACCUMULATE(values6, w1, acc3, sum3);
1239 MULTIPLY_ADD_ACCUMULATE(values7, w2, acc3, sum3);
1240
1241 MULTIPLY_ADD_ACCUMULATE(values8, w3, acc2, sum2);
1242 MULTIPLY_ADD_ACCUMULATE(values9, w4, acc2, sum2);
1243 MULTIPLY_ADD_ACCUMULATE(values10, w5, acc2, sum2);
1244 MULTIPLY_ADD_ACCUMULATE(values9, w3, acc3, sum3);
1245 MULTIPLY_ADD_ACCUMULATE(values10, w4, acc3, sum3);
1246 MULTIPLY_ADD_ACCUMULATE(values11, w5, acc3, sum3);
1247
1248 MULTIPLY_ADD_ACCUMULATE(values12, w6, acc2, sum2);
1249 MULTIPLY_ADD_ACCUMULATE(values13, w7, acc2, sum2);
1250 MULTIPLY_ADD_ACCUMULATE(values14, w8, acc2, sum2);
1251 MULTIPLY_ADD_ACCUMULATE(values13, w6, acc3, sum3);
1252 MULTIPLY_ADD_ACCUMULATE(values14, w7, acc3, sum3);
1253 MULTIPLY_ADD_ACCUMULATE(values15, w8, acc3, sum3);
1254
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001255#if defined(HAS_BIAS)
1256 Vector biases = CONVERT_TO_VECTOR_STRUCT(biases);
1257
1258 VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr);
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001259
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001260 acc0 += bias_values;
1261 acc1 += bias_values;
1262 acc2 += bias_values;
1263 acc3 += bias_values;
1264#endif /* defined(HAS_BIAS) */
1265
1266#if WEIGHTS_OFFSET != 0
1267 acc0 += WEIGHTS_OFFSET * sum0;
1268 acc1 += WEIGHTS_OFFSET * sum1;
1269 acc2 += WEIGHTS_OFFSET * sum2;
1270 acc3 += WEIGHTS_OFFSET * sum3;
1271#endif /* WEIGHTS_OFFSET != 0 */
1272
1273#if INPUT_OFFSET != 0
1274 VEC_INT offs = INPUT_OFFSET * sum_we;
1275
1276 acc0 += offs;
1277 acc1 += offs;
1278 acc2 += offs;
1279 acc3 += offs;
1280#endif /* INPUT_OFFSET != 0 */
1281
1282#if K_OFFSET != 0
1283 acc0 += (VEC_INT)K_OFFSET;
1284 acc1 += (VEC_INT)K_OFFSET;
1285 acc2 += (VEC_INT)K_OFFSET;
1286 acc3 += (VEC_INT)K_OFFSET;
1287#endif /* K_OFFSET != 0 */
1288
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001289#if defined(REAL_MULTIPLIER)
1290
1291 acc0 = CONVERT(round(CONVERT(acc0, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1292 acc1 = CONVERT(round(CONVERT(acc1, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1293 acc2 = CONVERT(round(CONVERT(acc2, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1294 acc3 = CONVERT(round(CONVERT(acc3, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1295
1296#else // defined(REAL_MULTIPLIER)
1297
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001298#if defined(PER_CHANNEL_QUANTIZATION)
1299 Vector output_multipliers = CONVERT_TO_VECTOR_STRUCT(output_multipliers);
1300 Vector output_shifts = CONVERT_TO_VECTOR_STRUCT(output_shifts);
1301 VEC_INT output_multiplier = VLOAD(VEC_SIZE)(0, (__global int *)output_multipliers.ptr);
1302 VEC_INT output_shift = VLOAD(VEC_SIZE)(0, (__global int *)output_shifts.ptr);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001303
Sang-Hoon Park4d79d4b2020-01-30 14:38:37 +00001304 VEC_INT res0_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, output_multiplier, output_shift, VEC_SIZE);
1305 VEC_INT res1_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, output_multiplier, output_shift, VEC_SIZE);
1306 VEC_INT res2_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc2, output_multiplier, output_shift, VEC_SIZE);
1307 VEC_INT res3_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc3, output_multiplier, output_shift, VEC_SIZE);
1308 VEC_INT res0_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, output_multiplier, output_shift);
1309 VEC_INT res1_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc1, output_multiplier, output_shift);
1310 VEC_INT res2_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc2, output_multiplier, output_shift);
1311 VEC_INT res3_shift_gt0 = asymm_mult_by_quant_multiplier_less_than_one(acc3, output_multiplier, output_shift);
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001312 acc0 = select(res0_shift_lt0, res0_shift_gt0, output_shift >= 0);
1313 acc1 = select(res1_shift_lt0, res1_shift_gt0, output_shift >= 0);
1314 acc2 = select(res2_shift_lt0, res2_shift_gt0, output_shift >= 0);
1315 acc3 = select(res3_shift_lt0, res3_shift_gt0, output_shift >= 0);
1316#else // defined(PER_CHANNEL_QUANTIZATION)
1317#if OUTPUT_SHIFT < 0
Michele Di Giorgiob598afa2019-12-20 16:22:20 +00001318 acc0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
1319 acc1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
1320 acc2 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
1321 acc3 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc3, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001322#else // OUTPUT_SHIFT < 0
Michele Di Giorgiob598afa2019-12-20 16:22:20 +00001323 acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1324 acc1 = asymm_mult_by_quant_multiplier_less_than_one(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1325 acc2 = asymm_mult_by_quant_multiplier_less_than_one(acc2, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1326 acc3 = asymm_mult_by_quant_multiplier_less_than_one(acc3, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001327#endif // OUTPUT_SHIFT < 0
1328#endif // defined(PER_CHANNEL_QUANTIZATION)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001329
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001330#endif // defined(REAL_MULTIPLIER)
1331
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001332 acc0 += (VEC_INT)OUTPUT_OFFSET;
1333 acc1 += (VEC_INT)OUTPUT_OFFSET;
1334 acc2 += (VEC_INT)OUTPUT_OFFSET;
1335 acc3 += (VEC_INT)OUTPUT_OFFSET;
1336
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001337 VEC_TYPE(VEC_SIZE)
1338 res0 = CONVERT_SAT(acc0, VEC_TYPE(VEC_SIZE));
1339 VEC_TYPE(VEC_SIZE)
1340 res1 = CONVERT_SAT(acc1, VEC_TYPE(VEC_SIZE));
1341 VEC_TYPE(VEC_SIZE)
1342 res2 = CONVERT_SAT(acc2, VEC_TYPE(VEC_SIZE));
1343 VEC_TYPE(VEC_SIZE)
1344 res3 = CONVERT_SAT(acc3, VEC_TYPE(VEC_SIZE));
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001345
Georgios Pinitas37044642018-10-30 14:53:25 +00001346#if defined(DST_DEPTH)
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 + b * dst_stride_w;
1348#else /* defined(DST_DEPTH) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001349 __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 Pinitas37044642018-10-30 14:53:25 +00001350#endif /* defined(DST_DEPTH) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001351
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001352 VSTORE(VEC_SIZE)
Georgios Pinitas60e98252018-10-22 16:17:20 +01001353 (ACTIVATION_FUNC(res0), 0, dst_addr + 0 * dst_stride_y);
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001354 VSTORE(VEC_SIZE)
Georgios Pinitas60e98252018-10-22 16:17:20 +01001355 (ACTIVATION_FUNC(res1), 0, dst_addr + 1 * dst_stride_y);
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001356
1357#if((DST_DIM_2 % NUM_PLANES_PROCESSED) != 0)
1358 if((z * NUM_PLANES_PROCESSED + 1) < DST_DIM_2)
1359#endif // ((DST_DIM_2 % NUM_PLANES_PROCESSED) != 0)
1360 {
1361 VSTORE(VEC_SIZE)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001362 (ACTIVATION_FUNC(res2), 0, (__global DATA_TYPE *)(dst_addr + 0 * dst_stride_y + 1 * dst_stride_z));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001363 VSTORE(VEC_SIZE)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001364 (ACTIVATION_FUNC(res3), 0, (__global DATA_TYPE *)(dst_addr + 1 * dst_stride_y + 1 * dst_stride_z));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001365 }
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001366}
1367
giuros016d109962019-01-07 17:47:19 +00001368#if defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) && VEC_SIZE == 4
1369/** 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 Arenaeff8d952018-07-02 15:29:57 +01001370 *
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001371 * @note Per-channel quantization is not supported by this kernel.
giuros016d109962019-01-07 17:47:19 +00001372 * @note This kernel assumes VEC_SIZE is 4.
1373 * @note The weights tensor is expected to be reshaped using @ref CLDepthwiseConvolutionLayerReshapeWeightsKernel.
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001374 * @note The number of elements read per thread must be passed at compile time using -DVEC_SIZE (e.g. -DVEC_SIZE=2)
1375 * @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)
1376 * @note The number of rows processed per thread must be passed at compile time using -DNUM_ROWS_PROCESSED (i.e. -DNUM_ROWS_PROCESSED=2)
1377 * @note The number of planes processed per thread must be passed at compile time using -DNUM_PLANES_PROCESSED (i.e. -DNUM_PLANES_PROCESSED=2)
1378 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1)
1379 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1).
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001380 * @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.
1381 * If not, the quantization will be performed using a fixed point multiplication
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001382 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +01001383 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001384 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
1385 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
1386 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
1387 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
1388 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
1389 * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes)
1390 * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes)
1391 * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes)
1392 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
1393 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
1394 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
1395 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
1396 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
1397 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
1398 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
1399 * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
1400 * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes)
1401 * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes)
1402 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
1403 * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: same as @p src_ptr
1404 * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
1405 * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
1406 * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
1407 * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
1408 * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
1409 * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32
1410 * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes)
1411 * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes)
1412 * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector
1413 * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32
1414 * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes)
1415 * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes)
1416 * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector
1417 * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32
1418 * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
1419 * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
1420 * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
1421 * @param[in] max_offset The maximum allowed offset for the input tensor
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001422 */
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001423__kernel void dwc_3x3_reshaped_quantized8_dot8_stride1_nhwc(
Georgios Pinitas37044642018-10-30 14:53:25 +00001424 TENSOR4D_DECLARATION(src),
1425 TENSOR4D_DECLARATION(dst),
giuros016d109962019-01-07 17:47:19 +00001426 IMAGE_DECLARATION(weights),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001427 VECTOR_DECLARATION(output_multipliers),
1428 VECTOR_DECLARATION(output_shifts),
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001429#if defined(HAS_BIAS)
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001430 VECTOR_DECLARATION(biases),
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001431#endif // defined(HAS_BIAS)
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001432 int max_offset)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001433{
Giorgio Arenafa23f112018-06-19 11:27:38 +01001434 int x = get_global_id(0);
1435 int y = get_global_id(1);
Georgios Pinitas37044642018-10-30 14:53:25 +00001436#if defined(DST_DEPTH)
1437 int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y
1438 int b = get_global_id(2) / (int)DST_DEPTH; // batch
Pablo Tello47104362019-02-27 13:32:51 +00001439#else // defined(DST_DEPTH)
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001440 int z = get_global_id(2); // spatial coordinate y
Pablo Tello47104362019-02-27 13:32:51 +00001441#endif // defined(DST_DEPTH)
Giorgio Arenafa23f112018-06-19 11:27:38 +01001442
giuros016d109962019-01-07 17:47:19 +00001443 __global uchar *weights_addr = weights_ptr + weights_offset_first_element_in_bytes + x * weights_stride_y;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001444
Georgios Pinitas37044642018-10-30 14:53:25 +00001445#if defined(DST_DEPTH)
1446 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE + b * src_stride_w;
1447#else /* defined(DST_DEPTH) */
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001448 __global uchar *src_addr = src_ptr + src_offset_first_element_in_bytes + x * VEC_SIZE;
Georgios Pinitas37044642018-10-30 14:53:25 +00001449#endif /* defined(DST_DEPTH) */
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001450
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001451 int z_coord = 0;
1452 int4 offset = 0;
1453 int4 y_coord = ((int4)(y * NUM_ROWS_PROCESSED) + (int4)(0, 1, 2, 3)) - (int)CONV_PAD_LEFT;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001454
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001455 // Only for y = 0 we can have a negative coordinate. If so, we convert it to SRC_DIM_1
1456 y_coord.s0 = min((uint)y_coord.s0, (uint)SRC_DIM_1);
1457 y_coord.s1 = min((uint)y_coord.s1, (uint)SRC_DIM_1);
1458 y_coord.s2 = min((uint)y_coord.s2, (uint)SRC_DIM_1);
1459 y_coord.s3 = min((uint)y_coord.s3, (uint)SRC_DIM_1);
1460
1461 int4 y_offset = convert_int4(y_coord * (int)src_stride_y);
1462
1463 // We compute 4x2x1 [C,W,H] elements
1464 VEC_INT acc0 = 0;
1465 VEC_INT acc1 = 0;
1466 VEC_INT sum0 = 0;
1467 VEC_INT sum1 = 0;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001468
1469 // Load weights
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001470 VEC_TYPE(16)
1471 w0 = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr));
1472 VEC_TYPE(16)
1473 w1 = VLOAD(16)(0, (__global WEIGHTS_TYPE *)(weights_addr + 16));
1474 VEC_TYPE(4)
1475 w2 = VLOAD(4)(0, (__global WEIGHTS_TYPE *)(weights_addr + 32));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001476
1477#if INPUT_OFFSET != 0
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001478 // Initilize the final result with the weights reduction multiplied by INPUT_OFFSET
giuros016d109962019-01-07 17:47:19 +00001479 DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s0, w0.s01234567, w0.s8);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001480 DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s1, (VEC_TYPE(8))((w0.s9ABC), (w0.sDEF), w1.s0), w1.s1);
giuros016d109962019-01-07 17:47:19 +00001481 DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s2, w1.s23456789, w1.sA);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001482 DOT_PRODUCT_REDUCTION_WEIGHTS(acc0.s3, (VEC_TYPE(8))((w1.sBCD), (w1.sEF), (w2.s012)), w2.s3);
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001483
1484 // Multiply the weights reduction with INPUT_OFFSET
1485 acc0 = INPUT_OFFSET * acc0;
1486
1487 acc1 = acc0;
1488#endif // INPUT_OFFSET != 0
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001489
1490 // Load input values
1491 // z == 0
1492 // Clamp z_coord as for z = 0, it can be negative
1493 // z_coord is casted to unsigned int in order to use just a min() operation
1494 // A "-1" 32 bit signed variable converted to unsigned gives 4294967295
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001495 z_coord = z - (int)CONV_PAD_TOP;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001496 z_coord = min((uint)z_coord, (uint)SRC_DIM_2);
1497 offset = y_offset + (int4)(z_coord * src_stride_z);
Georgios Pinitas4e0d3812018-08-01 20:16:34 +01001498 offset = min(offset, (int4)max_offset);
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001499
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001500 VEC_TYPE(VEC_SIZE)
1501 values0 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1502 VEC_TYPE(VEC_SIZE)
1503 values1 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1504 VEC_TYPE(VEC_SIZE)
1505 values2 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1506 VEC_TYPE(VEC_SIZE)
1507 values3 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001508
1509 // z == 1
1510 // z_coord can be only negative for z = 0 so we do not need to clamp it
1511 // Moreover z_coord cannot be out-of-bound for z = 1 so we do not need to clamp the offset
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001512 z_coord = z - (int)CONV_PAD_TOP + 1;
1513 offset = y_offset + (int4)(z_coord * src_stride_z);
1514 VEC_TYPE(VEC_SIZE)
1515 values4 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1516 VEC_TYPE(VEC_SIZE)
1517 values5 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1518 VEC_TYPE(VEC_SIZE)
1519 values6 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1520 VEC_TYPE(VEC_SIZE)
1521 values7 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001522
1523 // z == 2
1524 // After z = 1 we can simply add src_stride_z to offset without updating z_coord
1525 // However offset can be out-of-bound so we need to check if it is greater than max_offset
1526 offset += (int4)src_stride_z;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001527 offset = min(offset, (int4)max_offset);
1528 VEC_TYPE(VEC_SIZE)
1529 values8 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s0));
1530 VEC_TYPE(VEC_SIZE)
1531 values9 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s1));
1532 VEC_TYPE(VEC_SIZE)
1533 values10 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s2));
1534 VEC_TYPE(VEC_SIZE)
1535 values11 = VLOAD(VEC_SIZE)(0, (__global DATA_TYPE *)(src_addr + offset.s3));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001536
giuros016d109962019-01-07 17:47:19 +00001537 DOT_PRODUCT_REDUCTION(sum0.s0, values0.s0, values1.s0, values2.s0, values4.s0, values5.s0, values6.s0, values8.s0, values9.s0, values10.s0);
1538 DOT_PRODUCT_REDUCTION(sum1.s0, values1.s0, values2.s0, values3.s0, values5.s0, values6.s0, values7.s0, values9.s0, values10.s0, values11.s0);
1539 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);
1540 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 Arenaeff8d952018-07-02 15:29:57 +01001541
giuros016d109962019-01-07 17:47:19 +00001542 DOT_PRODUCT_REDUCTION(sum0.s1, values0.s1, values1.s1, values2.s1, values4.s1, values5.s1, values6.s1, values8.s1, values9.s1, values10.s1);
1543 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 Giorgiodf4cf572019-10-09 15:32:39 +01001544 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);
1545 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);
giuros016d109962019-01-07 17:47:19 +00001546
1547 DOT_PRODUCT_REDUCTION(sum0.s2, values0.s2, values1.s2, values2.s2, values4.s2, values5.s2, values6.s2, values8.s2, values9.s2, values10.s2);
1548 DOT_PRODUCT_REDUCTION(sum1.s2, values1.s2, values2.s2, values3.s2, values5.s2, values6.s2, values7.s2, values9.s2, values10.s2, values11.s2);
1549 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);
1550 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);
1551
1552 DOT_PRODUCT_REDUCTION(sum0.s3, values0.s3, values1.s3, values2.s3, values4.s3, values5.s3, values6.s3, values8.s3, values9.s3, values10.s3);
1553 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 Giorgiodf4cf572019-10-09 15:32:39 +01001554 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);
1555 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 Arenaeff8d952018-07-02 15:29:57 +01001556
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001557#if defined(HAS_BIAS)
1558 Vector biases = CONVERT_TO_VECTOR_STRUCT(biases);
1559
1560 VEC_INT bias_values = VLOAD(VEC_SIZE)(0, (__global int *)biases.ptr);
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001561
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001562 acc0 += bias_values;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001563 acc1 += bias_values;
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001564
1565#endif // defined(HAS_BIAS)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001566
1567#if WEIGHTS_OFFSET != 0
1568 acc0 += WEIGHTS_OFFSET * sum0;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001569 acc1 += WEIGHTS_OFFSET * sum1;
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001570#endif // WEIGHTS_OFFSET != 0
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001571
1572#if K_OFFSET != 0
1573 acc0 += (VEC_INT)K_OFFSET;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001574 acc1 += (VEC_INT)K_OFFSET;
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001575
1576#endif // K_OFFSET != 0
1577
1578#if defined(REAL_MULTIPLIER)
1579
1580 acc0 = CONVERT(round(CONVERT(acc0, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1581 acc1 = CONVERT(round(CONVERT(acc1, VEC_FLOAT) * (VEC_FLOAT)REAL_MULTIPLIER), VEC_INT);
1582
1583#else // defined(REAL_MULTIPLIER)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001584
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001585#if OUTPUT_SHIFT < 0
1586 acc0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
1587 acc1 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, VEC_SIZE);
1588#else // OUTPUT_SHIFT < 0
1589 acc0 = asymm_mult_by_quant_multiplier_less_than_one(acc0, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1590 acc1 = asymm_mult_by_quant_multiplier_less_than_one(acc1, OUTPUT_MULTIPLIER, OUTPUT_SHIFT);
1591#endif // OUTPUT_SHIFT < 0
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001592
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001593#endif // defined(REAL_MULTIPLIER)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001594 acc0 += (VEC_INT)OUTPUT_OFFSET;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001595 acc1 += (VEC_INT)OUTPUT_OFFSET;
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001596
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001597 VEC_TYPE(VEC_SIZE)
1598 res0 = CONVERT_SAT(acc0, VEC_TYPE(VEC_SIZE));
1599 VEC_TYPE(VEC_SIZE)
1600 res1 = CONVERT_SAT(acc1, VEC_TYPE(VEC_SIZE));
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001601
Georgios Pinitas37044642018-10-30 14:53:25 +00001602#if defined(DST_DEPTH)
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 + b * dst_stride_w;
1604#else /* defined(DST_DEPTH) */
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001605 __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 Pinitas37044642018-10-30 14:53:25 +00001606#endif /* defined(DST_DEPTH) */
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001607
1608 VSTORE(VEC_SIZE)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001609 (ACTIVATION_FUNC(res0), 0, (__global DATA_TYPE *)(dst_addr + 0 * dst_stride_y));
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001610 VSTORE(VEC_SIZE)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001611 (ACTIVATION_FUNC(res1), 0, (__global DATA_TYPE *)(dst_addr + 1 * dst_stride_y));
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001612}
giuros016d109962019-01-07 17:47:19 +00001613#endif // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) && VEC_SIZE==4
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001614
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001615#endif // defined(NUM_ROWS_PROCESSED) && defined(NUM_PLANES_PROCESSED)
Giorgio Arenadfca60b2018-01-31 10:30:59 +00001616
Giorgio Arenaeff8d952018-07-02 15:29:57 +01001617#endif // defined(VEC_SIZE) && defined(SRC_DIM_1) && defined(SRC_DIM_2) && defined(CONV_PAD_TOP) && defined(CONV_PAD_LEFT)
1618
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001619#endif // defined(WEIGHTS_PROMOTED_TYPE)
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001620
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001621#endif // defined(WEIGHTS_OFFSET) && defined(INPUT_OFFSET) && defined(K_OFFSET) && ((defined(OUTPUT_OFFSET) && defined(OUTPUT_MULTIPLIER) && defined(OUTPUT_SHIFT)) || defined(REAL_MULTIPLIER))
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001622
Giorgio Arena79acd772020-10-22 14:29:50 +01001623#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) && defined(VEC_SIZE_LEFTOVER)
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001624/** This function computes the depthwise convolution for NHWC data layout. This kernel assumes that the weights tensor is NOT reshaped
1625 *
1626 * @note The number of elements processed must be passed at compile time using -DN0 (e.g. -DN0=2)
1627 * @note The depth multiplier must be passed at compile time using -DDEPTH_MULTIPLIER (e.g. -DDEPTH_MULTIPLIER=1)
1628 * @note The first dimension of the input tensor must be passed at compile time using -DSRC_DIM1 (e.g. -DSRC_DIM1=112)
1629 * @note The second dimension of the input tensor must be passed at compile time using -DSRC_DIM2 (e.g. -DSRC_DIM2=80)
1630 * @note The kernel width must be passed at compile time using -DKERNEL_WIDTH (e.g. -DKERNEL_WIDTH=5)
1631 * @note The kernel height must be passed at compile time using -DKERNEL_HEIGHT (e.g. -DKERNEL_HEIGHT=5)
1632 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_TOP (e.g. -DCONV_PAD_TOP=1)
1633 * @note The convolution pad top must be passed at compile time using -DCONV_PAD_LEFT (e.g. -DCONV_PAD_LEFT=1)
1634 * @note The convolution stride along the width must be passed at compile time using -DCONV_STRIDE_X (e.g. -DCONV_STRIDE_Y=X)
1635 * @note The convolution stride along the height must be passed at compile time using -DCONV_STRIDE_Y (e.g. -DCONV_STRIDE_Y=1)
Giorgio Arena79acd772020-10-22 14:29:50 +01001636 * @note Leftover vector size has to be passed at compile time using -DVEC_SIZE_LEFTOVER. e.g. -DVEC_SIZE=3. It is defined as the remainder between the input's first dimension and VEC_SIZE
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001637 * @note It is possible to select the activation function to apply using -DACTIVATION_TYPE e.g. -DACTIVATION_TYPE=relu
1638 * @note A, B variables required by some activation functions are set using -DA_VAL= and -DB_VAL= respectively
1639 *
Michele Di Giorgio4cd4cde2020-01-06 14:07:44 +00001640 * @param[in] src_ptr Pointer to the source tensor. Supported data types: QASYMM8/QASYMM8_SIGNED
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001641 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
1642 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
1643 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
1644 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
1645 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
1646 * @param[in] src_step_z src_stride_y * number of elements along Z processed per workitem(in bytes)
1647 * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes)
1648 * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes)
1649 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
1650 * @param[in] dst_ptr Pointer to the destination tensor. Supported data types: same as @p src_ptr
1651 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
1652 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
1653 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
1654 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
1655 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
1656 * @param[in] dst_step_z dst_stride_z * number of elements along Y processed per workitem(in bytes)
1657 * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes)
1658 * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes)
1659 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
Michele Di Giorgio4cd4cde2020-01-06 14:07:44 +00001660 * @param[in] weights_ptr Pointer to the weights tensor. Supported data types: QASYMM8/QASYMM8_SIGNED/QSYMM8_PER_CHANNEL
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001661 * @param[in] weights_stride_x Stride of the weights tensor in X dimension (in bytes)
1662 * @param[in] weights_step_x weights_stride_x * number of elements along X processed per workitem(in bytes)
1663 * @param[in] weights_stride_y Stride of the weights tensor in Y dimension (in bytes)
1664 * @param[in] weights_step_y weights_stride_y * number of elements along Y processed per workitem(in bytes)
1665 * @param[in] weights_stride_z Stride of the weights tensor in Z dimension (in bytes)
1666 * @param[in] weights_step_z weights_stride_z * number of elements along Y processed per workitem(in bytes)
1667 * @param[in] weights_offset_first_element_in_bytes The offset of the first element in the weights tensor
1668 * @param[in] output_multipliers_ptr Pointer to the output multipliers vector. Supported data types: S32
1669 * @param[in] output_multipliers_stride_x Stride of the output multipliers vector in X dimension (in bytes)
1670 * @param[in] output_multipliers_step_x output_multipliers_stride_x * number of elements along X processed per workitem(in bytes)
1671 * @param[in] output_multipliers_offset_first_element_in_bytes The offset of the first element in the output multipliers vector
1672 * @param[in] output_shifts_ptr Pointer to the output shifts vector. Supported data types: S32
1673 * @param[in] output_shifts_stride_x Stride of the output shifts vector in X dimension (in bytes)
1674 * @param[in] output_shifts_step_x output_shifts_stride_x * number of elements along X processed per workitem(in bytes)
1675 * @param[in] output_shifts_offset_first_element_in_bytes The offset of the first element in the output shifts vector
1676 * @param[in] biases_ptr (Optional) Pointer to the biases vector. Supported data types: S32
1677 * @param[in] biases_stride_x (Optional) Stride of the biases vector in X dimension (in bytes)
1678 * @param[in] biases_step_x (Optional) biases_stride_x * number of elements along X processed per workitem(in bytes)
1679 * @param[in] biases_offset_first_element_in_bytes (Optional) The offset of the first element in the biases vector
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001680 */
1681__kernel void dwc_MxN_native_quantized8_nhwc(
1682 TENSOR4D_DECLARATION(src),
1683 TENSOR4D_DECLARATION(dst),
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001684 TENSOR3D_DECLARATION(weights),
1685 VECTOR_DECLARATION(output_multipliers),
1686 VECTOR_DECLARATION(output_shifts)
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001687#if defined(HAS_BIAS)
Michele Di Giorgio1dce3102019-10-22 10:29:03 +01001688 ,
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001689 VECTOR_DECLARATION(biases)
1690#endif // defined(HAS_BIAS)
1691)
1692{
Giorgio Arena79acd772020-10-22 14:29:50 +01001693 int x_offs = max((int)(get_global_id(0) * N0 - (N0 - VEC_SIZE_LEFTOVER) % N0), 0);
1694 int y = get_global_id(1); // spatial coordinate x
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001695#if defined(DST_DEPTH)
1696 int z = get_global_id(2) % (int)DST_DEPTH; // spatial coordinate y
1697 int b = get_global_id(2) / (int)DST_DEPTH; // batch
1698#else // defined(DST_DEPTH)
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001699 int z = get_global_id(2); // spatial coordinate y
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001700#endif // defined(DST_DEPTH)
1701
Giorgio Arena79acd772020-10-22 14:29:50 +01001702 __global uchar *s_addr = src_ptr + src_offset_first_element_in_bytes + x_offs * sizeof(DATA_TYPE);
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001703
Giorgio Arena79acd772020-10-22 14:29:50 +01001704 __global uchar *d_addr = dst_ptr + dst_offset_first_element_in_bytes + x_offs * sizeof(DATA_TYPE) * (int)DEPTH_MULTIPLIER + y * dst_stride_y + z * dst_stride_z;
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001705
Giorgio Arena79acd772020-10-22 14:29:50 +01001706 __global uchar *w_addr = weights_ptr + weights_offset_first_element_in_bytes + x_offs * sizeof(WEIGHTS_TYPE) * (int)DEPTH_MULTIPLIER;
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001707
1708#if defined(HAS_BIAS)
Giorgio Arena79acd772020-10-22 14:29:50 +01001709 __global uchar *b_addr = biases_ptr + biases_offset_first_element_in_bytes + x_offs * sizeof(int) * (int)DEPTH_MULTIPLIER;
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001710#endif // defined(HAS_BIAS)
1711
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001712#if defined(PER_CHANNEL_QUANTIZATION)
Giorgio Arena79acd772020-10-22 14:29:50 +01001713 __global uchar *out_mul_addr = output_multipliers_ptr + output_multipliers_offset_first_element_in_bytes + x_offs * sizeof(int) * (int)DEPTH_MULTIPLIER;
1714 __global uchar *out_shift_addr = output_shifts_ptr + output_shifts_offset_first_element_in_bytes + x_offs * sizeof(int) * (int)DEPTH_MULTIPLIER;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001715#endif // defined(PER_CHANNEL_QUANTIZATION)
1716
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001717#if defined(DST_DEPTH)
1718 s_addr += b * src_stride_w;
1719 d_addr += b * dst_stride_w;
1720#endif // defined(DST_DEPTH)
1721
1722#if DEPTH_MULTIPLIER > 1
1723 for(int d = 0; d < (int)DEPTH_MULTIPLIER; ++d)
1724 {
1725#endif // DEPTH_MULTIPLIER > 1
1726 // Each work-item computes N0x1x1 elements
Sang-Hoon Park15396ff2019-11-07 09:37:29 +00001727 VEC_INT res = 0;
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001728
1729 int x_coord = y * CONV_STRIDE_X - (int)CONV_PAD_LEFT;
1730 int y_coord = z * CONV_STRIDE_Y - (int)CONV_PAD_TOP;
1731
1732 for(int yk = 0; yk < KERNEL_HEIGHT; ++yk)
1733 {
1734 if(y_coord >= 0 && y_coord < SRC_DIM2)
1735 {
1736 int x_coord_tmp = x_coord;
1737
1738 for(int xk = 0; xk < KERNEL_WIDTH; ++xk)
1739 {
1740 if(x_coord_tmp >= 0 && x_coord_tmp < SRC_DIM1)
1741 {
1742 int s_offset = x_coord_tmp * (int)src_stride_y + y_coord * (int)src_stride_z;
1743 int w_offset = xk * weights_stride_y + yk * weights_stride_z;
1744
1745 // Load input and weights values
Sang-Hoon Park15396ff2019-11-07 09:37:29 +00001746 VEC_INT i = CONVERT(VLOAD(N0)(0, (__global DATA_TYPE *)(s_addr + s_offset)), VEC_INT);
1747 VEC_INT w = CONVERT(VLOAD(N0)(0, (__global WEIGHTS_TYPE *)(w_addr + w_offset)), VEC_INT);
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001748
Sang-Hoon Park15396ff2019-11-07 09:37:29 +00001749 res += (i + (VEC_INT)INPUT_OFFSET) * (w + (VEC_INT)WEIGHTS_OFFSET);
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001750 }
1751 x_coord_tmp += DILATION_X;
1752 }
1753 }
1754 y_coord += DILATION_Y;
1755 }
1756
1757#if defined(HAS_BIAS)
Sang-Hoon Park15396ff2019-11-07 09:37:29 +00001758 VEC_INT bias = VLOAD(N0)(0, (__global int *)(b_addr));
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001759 res += bias;
1760#endif // defined(HAS_BIAS)
1761
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001762#if defined(PER_CHANNEL_QUANTIZATION)
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +01001763 VEC_INT output_multiplier = VLOAD(N0)(0, (__global int *)(out_mul_addr));
1764 VEC_INT output_shift = VLOAD(N0)(0, (__global int *)(out_shift_addr));
1765
1766 VEC_INT res_shift_lt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(res, output_multiplier, output_shift, N0);
1767 VEC_INT res_shift_gt0 = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(res, output_multiplier, output_shift, N0);
1768 res = select(res_shift_lt0, res_shift_gt0, (VEC_INT)(output_shift) >= 0);
1769#else // defined(PER_CHANNEL_QUANTIZATION)
1770#if OUTPUT_SHIFT < 0
1771 res = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(res, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, N0);
1772#else // OUTPUT_SHIFT < 0
1773 res = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(res, OUTPUT_MULTIPLIER, OUTPUT_SHIFT, N0);
1774#endif // OUTPUT_OFFSET < 0
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001775#endif // defined(PER_CHANNEL_QUANTIZATION)
1776
Sang-Hoon Park15396ff2019-11-07 09:37:29 +00001777 res += (VEC_INT)OUTPUT_OFFSET;
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001778
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001779 VEC_TYPE(VEC_SIZE)
Giorgio Arena79acd772020-10-22 14:29:50 +01001780 res0 = CONVERT_SAT(res, VEC_TYPE(VEC_SIZE));
1781 res0 = ACTIVATION_FUNC(res0);
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001782
Giorgio Arena79acd772020-10-22 14:29:50 +01001783 STORE_VECTOR_SELECT(res, DATA_TYPE, d_addr, N0, VEC_SIZE_LEFTOVER, VEC_SIZE_LEFTOVER != 0 && get_global_id(0) == 0)
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001784
1785#if DEPTH_MULTIPLIER > 1
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001786 w_addr += sizeof(WEIGHTS_TYPE);
1787 d_addr += sizeof(DATA_TYPE);
1788#if defined(PER_CHANNEL_QUANTIZATION)
1789 out_mul_addr += sizeof(int);
1790 out_shift_addr += sizeof(int);
1791#endif // defined(PER_CHANNEL_QUANTIZATION)
Michele Di Giorgioa046e162019-10-08 09:36:26 +01001792#if defined(HAS_BIAS)
1793 b_addr += sizeof(int);
1794#endif // defined(HAS_BIAS)
1795 }
1796#endif // DEPTH_MULTIPLIER > 1
1797}
Giorgio Arena79acd772020-10-22 14:29:50 +01001798#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) && defined(VEC_SIZE_LEFTOVER)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +01001799#endif // defined(DATA_TYPE) && defined(WEIGHTS_TYPE)