blob: c5444cd7cc90abd9daf68fa55f61e6d9c41e4998 [file] [log] [blame]
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +00001/*
2 * Copyright (c) 2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000024
Georgios Pinitas9fc3be62021-05-29 04:01:51 +010025#include "activation_float_helpers.h"
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000026#include "helpers.h"
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000027#include "helpers_asymm.h"
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000028#include "tile_helpers.h"
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000029
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000030//! @cond Doxygen_Suppress
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000031/** OpenCL kernel to compute the direct convolution.
32 *
33 * @note Data layout supported: NHWC
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +000034 * @note Data type supported: F32/F16/QASYMM8/QASYMM8_SIGNED
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000035 * @note The data type must be passed at compile time using -DDATA_TYPE (e.g. -DDATA_TYPE=half)
36 * @note The accumulation data type must be passed at compile time using -DACC_DATA_TYPE (e.g. -DDATA_TYPE_PROMOTED=half)
37 * @note The convolution padding (left and top) must be passed at compile time using -DPAD_LEFT and -DPAD_TOP (e.g. -DPAD_LEFT=2, -DPAD_TOP=2)
38 * @note The convolution strides must be passed at compile time using -DSTRIDE and -DPAD_TOP (e.g. -DPAD_LEFT=2, -DPAD_TOP=2)
39 * @note The spatial dimensions of the weights must be passed at compile time using -DWEI_WIDTH and -DWEI_HEIGHT (e.g. -DWEI_WIDTH=9, -DWEI_HEIGHT=9)
40 * @note The spatial dimensions of the source tensor must be passed at compile time using -DSRC_WIDTH and -DSRC_HEIGHT (e.g. -DSRC_WIDTH=96, -DSRC_HEIGHT=64)
41 * @note The spatial dimensions of the destination tensor must be passed at compile time using -DDST_WIDTH and -DDST_HEIGHT (e.g. -DDST_WIDTH=96, -DDST_HEIGHT=64)
42 * @note The channels of the source tensor must be passed at compile time using -DSRC_CHANNELS (e.g. -DSRC_CHANNELS=64)
43 * @note The channels of the destination tensor must be passed at compile time using -DDST_CHANNELS (e.g. -DDDST_CHANNELS=64)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000044 * @note The tensor type ("BUFFER" or "IMAGE") of the source tensor must be passed at compile time using -DSRC_TENSOR_TYPE (e.g. -DSRC_TENSOR_TYPE=BUFFER)
45 * @note The tensor type ("BUFFER" or "IMAGE") of the weights tensor must be passed at compile time using -DWEI_TENSOR_TYPE (e.g. -DWEI_TENSOR_TYPE=BUFFER)
46 * @note The tensor type ("BUFFER" or "IMAGE") of the destination tensor must be passed at compile time using -DDST_TENSOR_TYPE (e.g. -DDST_TENSOR_TYPE=BUFFER)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000047 * @note The data type of the source tensor must be passed at compile time using -DSRC_DATA_TYPE (e.g. -DSRC_DATA_TYPE=float)
48 * @note The data type of the weights tensor must be passed at compile time using -DWEI_DATA_TYPE (e.g. -DWEI_DATA_TYPE=float)
49 * @note The data type of the destination tensor must be passed at compile time using -DDST_DATA_TYPE (e.g. -DDST_DATA_TYPE=float)
50 * @note The data type of the accumulators must be passed at compile time using -DACC_DATA_TYPE (e.g. -DACC_DATA_TYPE=float)
51 * @note The number of M0 rows (width*height) to process must be passed at compile time using -DM0 (e.g. -DM0=2)
52 * @note The number of N0 output channels to process must be passed at compile time using -DN0 (e.g. -DN0=2)
53 * @note The number of K0 inner accumulations must be passed at compile time using -DK0 (e.g. -DK0=2)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000054 * @note The size of the partial store block in x must be passed at compile time using -DPARTIAL_N0 (e.g. -DPARTIAL_N0=1)
55 * @note The zero value must be passed at compile time using -DZERO_VALUE (e.g. -DZERO_VALUE=0)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000056 * @note Only the following configurations of M0, N0 and K0 are currently supported:
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000057 * - M0 = 1, 2, 3, 4, 5, .... n
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000058 * - N0 = 2, 3, 4, 8, 16
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000059 * - K0 = 2, 3, 4, 8, 16 (only 4, 8 and 16 if WEI_TENSOR_TYPE=IMAGE)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000060 *
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +000061 *@note In case of QASYMM8/QASYMM8_SIGNED, the following extra information must be passed at compile time:
62 * - -DIS_QUANTIZED
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000063 * - The destination quantization multiplier e.g. -DDST_MULTIPLIER=1234
64 * - The destination quantization shift e.g. -DDST_SHIFT=4
65 * - The destination offset e.g. -DDST_OFFSET=4
66 * - The source offset e.g. -DSRC_OFFSET=4
67 * - The weights offset e.g. -DWEI_OFFSET=4
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +000068 * - The quantized zero value e.g. -DZERO_VALUE=4
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000069 *
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000070 * @param[in] src_ptr Pointer to the source tensor. Supported data type: F16/F32/QASYMM8
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000071 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes)
72 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
73 * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes)
74 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
75 * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes)
76 * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000077 * @param[in] src_stride_w Stride of the source tensor in W dimension (in bytes)
78 * @param[in] src_step_w src_stride_w * number of elements along W processed per workitem(in bytes)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000079 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor
80 * @param[out] dst_ptr Pointer to the destination tensor. Supported data type: same as @p src_ptr
81 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes)
82 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
83 * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes)
84 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
85 * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes)
86 * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000087 * @param[in] dst_stride_w Stride of the destination tensor in W dimension (in bytes)
88 * @param[in] dst_step_w dst_stride_w * number of elements along W processed per workitem(in bytes)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000089 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor
90 * @param[in] wei_ptr Pointer to the weights tensor. Supported data type: same as @p src_ptr
91 * @param[in] wei_stride_x Stride of the weights tensor in X dimension (in bytes)
92 * @param[in] wei_step_x wei_stride_x * number of elements along X processed per workitem(in bytes)
93 * @param[in] wei_stride_y Stride of the weights tensor in Y dimension (in bytes)
94 * @param[in] wei_step_y wei_stride_y * number of elements along Y processed per workitem(in bytes)
95 * @param[in] wei_stride_z Stride of the weights tensor in Z dimension (in bytes)
96 * @param[in] wei_step_z wei_stride_z * number of elements along Z processed per workitem(in bytes)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000097 * @param[in] wei_stride_w Stride of the weights tensor in W dimension (in bytes)
98 * @param[in] wei_step_w wei_stride_w * number of elements along W processed per workitem(in bytes)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +000099 * @param[in] wei_offset_first_element_in_bytes The offset of the first element in the bias matrix
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +0000100 * @param[in] bia_ptr (Optional) Pointer to the bias tensor Supported data type: same as @p src_ptr (if F32/F16) or S32 (if QASYMM8/QASYMM8_SIGNED)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000101 * @param[in] bia_stride_x (Optional) Stride of the bias tensor in X dimension (in bytes)
102 * @param[in] bia_step_x (Optional) bia_stride_x * number of elements along X processed per workitem(in bytes)
103 * @param[in] bia_offset_first_element_in_bytes (Optional) The offset of the first element in the bias matrix
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000104 */
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000105//! @endcond
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000106__kernel void direct_convolution_nhwc(
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000107 TENSOR4D(src, SRC_TENSOR_TYPE),
108 TENSOR4D(dst, DST_TENSOR_TYPE),
Michele Di Giorgio97e25802021-03-25 12:37:45 +0000109 TENSOR4D(wei, WEI_TENSOR_TYPE)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000110#if defined(HAS_BIAS)
Michele Di Giorgio97e25802021-03-25 12:37:45 +0000111 ,
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000112 VECTOR_DECLARATION(bia)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000113#endif // defined(HAS_BIAS)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000114)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000115{
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000116 // All the tensor dimensions are passed at compile time.
117 // In case of dynamic tensor support, the following dimensions should be passed as function argument.
118#define _IWEI_WIDTH WEI_WIDTH
119#define _IWEI_HEIGHT WEI_HEIGHT
120#define _ISRC_WIDTH SRC_WIDTH
121#define _ISRC_HEIGHT SRC_HEIGHT
122#define _ISRC_CHANNELS SRC_CHANNELS
123#define _IDST_WIDTH DST_WIDTH
124#define _IDST_HEIGHT DST_HEIGHT
125#define _IDST_CHANNELS DST_CHANNELS
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100126#define _IY_MULTIPLIER (_IWEI_WIDTH * _IWEI_HEIGHT)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000127
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000128 // If quantized, the output tile has to be quantized first before being stored to global memory
129#if defined(IS_QUANTIZED)
130#define _IOUTPUT_TILE cq
131#else // defined(IS_QUANTIZED)
132#define _IOUTPUT_TILE c
133#endif // defined(IS_QUANTIZED)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000134
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000135 const int cout = GET_SPATIAL_IDX(0, N0, PARTIAL_N0); // OFM
136 const int mout = GET_SPATIAL_IDX(1, M0, 0); // WIDTH x HEIGHT
137 const int bout = GET_SPATIAL_IDX(2, 1, 0); // BATCH SIZE IDX
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000138
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000139 // .v = access the whole vector (OpenCL vector)
140 // .s[x] = access the vector element at position x (scalar access)
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100141 TILE(int, M0, 1, xi);
142 TILE(int, M0, 1, yi);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000143
144 // Convert the linear index to coordinate
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100145 LOOP_UNROLLING(int, i, 0, 1, M0,
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000146 {
147 xi[i].v = ((mout + i) % _IDST_WIDTH) * STRIDE_X;
148 yi[i].v = ((mout + i) / _IDST_WIDTH) * STRIDE_Y;
149 xi[i].v -= PAD_LEFT;
150 yi[i].v -= PAD_TOP;
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100151 })
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000152
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000153 // Initialize the accumulators
Gian Marco Iodice598e3a82021-04-13 15:53:20 +0100154 TILE(ACC_DATA_TYPE, M0, N0, c);
155
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100156 LOOP_UNROLLING(int, i, 0, 1, M0,
Gian Marco Iodice598e3a82021-04-13 15:53:20 +0100157 {
158 c[i].v = 0;
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100159 })
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000160
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000161 for(int i = 0; i < (_IWEI_WIDTH * _IWEI_HEIGHT); ++i)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000162 {
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100163 int ck = 0;
164 int xk = i % _IWEI_WIDTH;
165 int yk = i / _IWEI_WIDTH;
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000166
167 int k = 0;
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000168 for(; k <= (_ISRC_CHANNELS - K0); k += K0)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000169 {
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000170 TILE(SRC_DATA_TYPE, M0, K0, a);
171 TILE(WEI_DATA_TYPE, N0, K0, b);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000172
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100173 LOOP_UNROLLING(int, i, 0, 1, M0,
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100174 {
175 a[i].v = ZERO_VALUE;
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100176 })
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100177
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000178 // Load tile from the src tensor
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100179 T_LOAD_NHWC_INDIRECT(SRC_DATA_TYPE, M0, K0, SRC_TENSOR_TYPE, src, bout, yk, xk, ck, _ISRC_WIDTH, _ISRC_HEIGHT, src_stride_y, xi, yi, a);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000180
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000181 // Load tile from the weights tensor
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100182 T_LOAD(WEI_DATA_TYPE, N0, K0, WEI_TENSOR_TYPE, wei, ck, cout * _IY_MULTIPLIER + i, _IY_MULTIPLIER, wei_stride_y, b);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000183
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000184 // Compute the matrix multiplication between two tiles
185 T_MMUL(SRC_DATA_TYPE, WEI_DATA_TYPE, ACC_DATA_TYPE, M0, N0, K0, NT, T, a, b, c);
186
187 // Apply the offset correction (correction usually needed for asymmetric quantized computation)
188 // The computation is not performed if both SRC_OFFSET and WEI_OFFSET are zero
189 T_OFFSET_CORRECTION(ACC_DATA_TYPE, M0, N0, K0, SRC_OFFSET, WEI_OFFSET, a, b, c);
190
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100191 ck += K0;
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000192 }
193
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000194 // We voluntarily use SRC_CHANNELS rather than _DSRC_CHANNELS
195 // This #if directive should be removed in case of dynamic tensor support
196#if((SRC_CHANNELS % K0) != 0)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000197 // Left-over accumulations
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000198 for(; k < _ISRC_CHANNELS; ++k)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000199 {
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000200 TILE(SRC_DATA_TYPE, M0, 1, a);
201 TILE(WEI_DATA_TYPE, N0, 1, b);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000202
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100203 LOOP_UNROLLING(int, i, 0, 1, M0,
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100204 {
205 a[i].v = ZERO_VALUE;
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100206 })
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100207
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000208 // Load tile from the src tensor
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100209 T_LOAD_NHWC_INDIRECT(SRC_DATA_TYPE, M0, 1, SRC_TENSOR_TYPE, src, bout, yk, xk, ck, _ISRC_WIDTH, _ISRC_HEIGHT, src_stride_y, xi, yi, a);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000210
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000211 // Load tile from the weights tensor
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100212 // The T_LOAD for the left-over elements can only use BUFFER because we load one element per iteration
213 T_LOAD(WEI_DATA_TYPE, N0, 1, BUFFER, wei, ck, cout * _IY_MULTIPLIER + i, _IY_MULTIPLIER, wei_stride_y, b);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000214
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000215 // Compute the matrix multiplication between two tiles
216 T_MMUL(SRC_DATA_TYPE, WEI_DATA_TYPE, ACC_DATA_TYPE, M0, N0, 1, NT, T, a, b, c);
217
218 // Apply the offset correction (operation usually needed for asymmetric quantized computation)
219 // The computation is not performed if both SRC_OFFSET and WEI_OFFSET are zero
220 T_OFFSET_CORRECTION(ACC_DATA_TYPE, M0, N0, 1, SRC_OFFSET, WEI_OFFSET, a, b, c);
221
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100222 ++ck;
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000223 }
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000224#endif // ((SRC_CHANNELS % K0) != 0)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000225 }
226
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000227 // Offset correction required for the quantized asymmetric computation
228 // The computation is not performed if both SRC_OFFSET and WEI_OFFSET are zero
229 T_ADD_CONSTANT(ACC_DATA_TYPE, M0, N0, c, (_IWEI_WIDTH * _IWEI_HEIGHT * _ISRC_CHANNELS * SRC_OFFSET * WEI_OFFSET), c);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000230
231#if defined(HAS_BIAS)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000232 TILE(BIA_DATA_TYPE, 1, N0, bias0);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000233
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100234 T_LOAD(BIA_DATA_TYPE, 1, N0, BUFFER, bia, cout, 0, 1, 0, bias0);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000235
236 // c = c + bias[broadcasted]
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000237 T_ADD_BROADCAST_X(ACC_DATA_TYPE, M0, N0, c, bias0, c);
238
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000239#endif // HAS_BIAS
240
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000241 TILE(uint, M0, 1, dst_indirect_y);
242
243 // Calculate the destination indirect Y
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100244 LOOP_UNROLLING(int, i, 0, 1, M0,
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000245 {
246 dst_indirect_y[i].v = (uint)min(mout + i, (int)(_IDST_WIDTH * _IDST_HEIGHT) - 1);
247 dst_indirect_y[i].v += bout * (int)(_IDST_WIDTH * _IDST_HEIGHT);
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100248 })
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000249
250 bool x_cond = PARTIAL_N0 != 0 && get_global_id(0) == 0;
251
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +0000252#if defined(IS_QUANTIZED)
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000253
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000254 TILE(DST_DATA_TYPE, M0, N0, cq);
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000255
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000256 // Quantize the tile
257 T_QUANTIZE8_ASYMMETRIC(ACC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, c, cq);
Gian Marco Iodiced95c3e82021-01-19 17:39:02 +0000258#endif // defined(IS_QUANTIZED)
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000259
Georgios Pinitas9fc3be62021-05-29 04:01:51 +0100260 // Apply activation
261 T_ACTIVATION(DST_DATA_TYPE, M0, N0, ACTIVATION_TYPE, A_VAL, B_VAL, _IOUTPUT_TILE, _IOUTPUT_TILE);
262
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000263 // _IOUTPUT_TILE: c = fp32/fp16, cq=qasymm8
264 // Store the tile in reverse order so the invalid values are overwritten with the valid ones
265 T_STORE_INDIRECT_WIDTH_SELECT(DST_DATA_TYPE, M0, N0, PARTIAL_N0, DST_TENSOR_TYPE, dst, cout, dst_stride_y, x_cond, _IOUTPUT_TILE, dst_indirect_y);
266
267#undef _IWEI_WIDTH
268#undef _IWEI_HEIGHT
269#undef _ISRC_WIDTH
270#undef _ISRC_HEIGHT
271#undef _ISRC_CHANNELS
272#undef _IDST_WIDTH
273#undef _IDST_HEIGHT
274#undef _IDST_CHANNELS
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100275#undef _IY_MULTIPLIER
Gian Marco Iodiceff1fe3e2021-01-02 09:58:51 +0000276}