blob: 4959c044485519659f788effba5e8ae18020dd43 [file] [log] [blame]
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +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 */
24
Giorgio Arenabdd16d12021-05-13 16:58:51 +010025// *INDENT-OFF*
26// clang-format off
27
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000028/** Tile object
29 * A tile object is a 2D memory block and can be accessed using the following syntax:
30 * -# a[m0].v = access the the vector at row "m0" (OpenCL vector)
31 * -# a[m0].s[x] = access the scalar element at row "m0" and column "n0" (scalar access)
32 *
33 * @param[in] DATA_TYPE Data type of the tile
34 * @param[in] H Number of tile rows
35 * @param[in] W Number of tile colums
36 * @param[in] BASENAME Tile's name
37 */
38#define TILE(DATA_TYPE, H, W, BASENAME) TILE_STR(DATA_TYPE, H, W, BASENAME)
39#define TILE_STR(DATA_TYPE, H, W, BASENAME) \
40 union { \
41 DATA_TYPE s[W]; \
42 DATA_TYPE##W v; \
43 } BASENAME[H]
44
Giorgio Arenabdd16d12021-05-13 16:58:51 +010045#define TENSOR4D_IMAGE(name) \
46 __read_only image2d_t name##_img, \
47 __global uchar *name##_ptr, \
48 uint name##_stride_x, \
49 uint name##_step_x, \
50 uint name##_stride_y, \
51 uint name##_step_y, \
52 uint name##_stride_z, \
53 uint name##_step_z, \
54 uint name##_stride_w, \
55 uint name##_step_w, \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000056 uint name##_offset_first_element_in_bytes
57
Giorgio Arenabdd16d12021-05-13 16:58:51 +010058#define TENSOR4D_BUFFER(name) \
59 __global uchar *name##_ptr, \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +000060 uint name##_stride_x, \
61 uint name##_step_x, \
62 uint name##_stride_y, \
63 uint name##_step_y, \
64 uint name##_stride_z, \
65 uint name##_step_z, \
66 uint name##_stride_w, \
67 uint name##_step_w, \
68 uint name##_offset_first_element_in_bytes
69
70#define TENSOR4D_STR(name, type) TENSOR4D_##type(name)
71#define TENSOR4D(name, type) TENSOR4D_STR(name, type)
72
Giorgio Arenabdd16d12021-05-13 16:58:51 +010073#define UNROLL_INCR(idx, step, macro) idx += (step); (macro)
74
75#define LOOP_UNROLLING_1(idx, step, macro) (macro)
76#define LOOP_UNROLLING_2(idx, step, macro) LOOP_UNROLLING_1(idx, step, macro); UNROLL_INCR(idx, step, macro)
77#define LOOP_UNROLLING_3(idx, step, macro) LOOP_UNROLLING_2(idx, step, macro); UNROLL_INCR(idx, step, macro)
78#define LOOP_UNROLLING_4(idx, step, macro) LOOP_UNROLLING_3(idx, step, macro); UNROLL_INCR(idx, step, macro)
79#define LOOP_UNROLLING_5(idx, step, macro) LOOP_UNROLLING_4(idx, step, macro); UNROLL_INCR(idx, step, macro)
80#define LOOP_UNROLLING_6(idx, step, macro) LOOP_UNROLLING_5(idx, step, macro); UNROLL_INCR(idx, step, macro)
81#define LOOP_UNROLLING_7(idx, step, macro) LOOP_UNROLLING_6(idx, step, macro); UNROLL_INCR(idx, step, macro)
82#define LOOP_UNROLLING_8(idx, step, macro) LOOP_UNROLLING_7(idx, step, macro); UNROLL_INCR(idx, step, macro)
83#define LOOP_UNROLLING_9(idx, step, macro) LOOP_UNROLLING_8(idx, step, macro); UNROLL_INCR(idx, step, macro)
84#define LOOP_UNROLLING_10(idx, step, macro) LOOP_UNROLLING_9(idx, step, macro); UNROLL_INCR(idx, step, macro)
85#define LOOP_UNROLLING_11(idx, step, macro) LOOP_UNROLLING_10(idx, step, macro); UNROLL_INCR(idx, step, macro)
86#define LOOP_UNROLLING_12(idx, step, macro) LOOP_UNROLLING_11(idx, step, macro); UNROLL_INCR(idx, step, macro)
87#define LOOP_UNROLLING_13(idx, step, macro) LOOP_UNROLLING_12(idx, step, macro); UNROLL_INCR(idx, step, macro)
88#define LOOP_UNROLLING_14(idx, step, macro) LOOP_UNROLLING_13(idx, step, macro); UNROLL_INCR(idx, step, macro)
89#define LOOP_UNROLLING_15(idx, step, macro) LOOP_UNROLLING_14(idx, step, macro); UNROLL_INCR(idx, step, macro)
90#define LOOP_UNROLLING_16(idx, step, macro) LOOP_UNROLLING_15(idx, step, macro); UNROLL_INCR(idx, step, macro)
91#define LOOP_UNROLLING_17(idx, step, macro) LOOP_UNROLLING_16(idx, step, macro); UNROLL_INCR(idx, step, macro)
92#define LOOP_UNROLLING_18(idx, step, macro) LOOP_UNROLLING_17(idx, step, macro); UNROLL_INCR(idx, step, macro)
93#define LOOP_UNROLLING_19(idx, step, macro) LOOP_UNROLLING_18(idx, step, macro); UNROLL_INCR(idx, step, macro)
94#define LOOP_UNROLLING_20(idx, step, macro) LOOP_UNROLLING_19(idx, step, macro); UNROLL_INCR(idx, step, macro)
95#define LOOP_UNROLLING_21(idx, step, macro) LOOP_UNROLLING_20(idx, step, macro); UNROLL_INCR(idx, step, macro)
96#define LOOP_UNROLLING_22(idx, step, macro) LOOP_UNROLLING_21(idx, step, macro); UNROLL_INCR(idx, step, macro)
97#define LOOP_UNROLLING_23(idx, step, macro) LOOP_UNROLLING_22(idx, step, macro); UNROLL_INCR(idx, step, macro)
98#define LOOP_UNROLLING_24(idx, step, macro) LOOP_UNROLLING_23(idx, step, macro); UNROLL_INCR(idx, step, macro)
99#define LOOP_UNROLLING_25(idx, step, macro) LOOP_UNROLLING_24(idx, step, macro); UNROLL_INCR(idx, step, macro)
100#define LOOP_UNROLLING_26(idx, step, macro) LOOP_UNROLLING_25(idx, step, macro); UNROLL_INCR(idx, step, macro)
101#define LOOP_UNROLLING_27(idx, step, macro) LOOP_UNROLLING_26(idx, step, macro); UNROLL_INCR(idx, step, macro)
102#define LOOP_UNROLLING_28(idx, step, macro) LOOP_UNROLLING_27(idx, step, macro); UNROLL_INCR(idx, step, macro)
103#define LOOP_UNROLLING_29(idx, step, macro) LOOP_UNROLLING_28(idx, step, macro); UNROLL_INCR(idx, step, macro)
104#define LOOP_UNROLLING_30(idx, step, macro) LOOP_UNROLLING_29(idx, step, macro); UNROLL_INCR(idx, step, macro)
105#define LOOP_UNROLLING_31(idx, step, macro) LOOP_UNROLLING_30(idx, step, macro); UNROLL_INCR(idx, step, macro)
106#define LOOP_UNROLLING_32(idx, step, macro) LOOP_UNROLLING_31(idx, step, macro); UNROLL_INCR(idx, step, macro)
107#define LOOP_UNROLLING_33(idx, step, macro) LOOP_UNROLLING_32(idx, step, macro); UNROLL_INCR(idx, step, macro)
108#define LOOP_UNROLLING_34(idx, step, macro) LOOP_UNROLLING_33(idx, step, macro); UNROLL_INCR(idx, step, macro)
109#define LOOP_UNROLLING_35(idx, step, macro) LOOP_UNROLLING_34(idx, step, macro); UNROLL_INCR(idx, step, macro)
110#define LOOP_UNROLLING_36(idx, step, macro) LOOP_UNROLLING_35(idx, step, macro); UNROLL_INCR(idx, step, macro)
111#define LOOP_UNROLLING_37(idx, step, macro) LOOP_UNROLLING_36(idx, step, macro); UNROLL_INCR(idx, step, macro)
112#define LOOP_UNROLLING_38(idx, step, macro) LOOP_UNROLLING_37(idx, step, macro); UNROLL_INCR(idx, step, macro)
113#define LOOP_UNROLLING_39(idx, step, macro) LOOP_UNROLLING_38(idx, step, macro); UNROLL_INCR(idx, step, macro)
114#define LOOP_UNROLLING_40(idx, step, macro) LOOP_UNROLLING_39(idx, step, macro); UNROLL_INCR(idx, step, macro)
115#define LOOP_UNROLLING_41(idx, step, macro) LOOP_UNROLLING_40(idx, step, macro); UNROLL_INCR(idx, step, macro)
116#define LOOP_UNROLLING_42(idx, step, macro) LOOP_UNROLLING_41(idx, step, macro); UNROLL_INCR(idx, step, macro)
117#define LOOP_UNROLLING_43(idx, step, macro) LOOP_UNROLLING_42(idx, step, macro); UNROLL_INCR(idx, step, macro)
118#define LOOP_UNROLLING_44(idx, step, macro) LOOP_UNROLLING_43(idx, step, macro); UNROLL_INCR(idx, step, macro)
119#define LOOP_UNROLLING_45(idx, step, macro) LOOP_UNROLLING_44(idx, step, macro); UNROLL_INCR(idx, step, macro)
120#define LOOP_UNROLLING_46(idx, step, macro) LOOP_UNROLLING_45(idx, step, macro); UNROLL_INCR(idx, step, macro)
121#define LOOP_UNROLLING_47(idx, step, macro) LOOP_UNROLLING_46(idx, step, macro); UNROLL_INCR(idx, step, macro)
122#define LOOP_UNROLLING_48(idx, step, macro) LOOP_UNROLLING_47(idx, step, macro); UNROLL_INCR(idx, step, macro)
123#define LOOP_UNROLLING_49(idx, step, macro) LOOP_UNROLLING_48(idx, step, macro); UNROLL_INCR(idx, step, macro)
124#define LOOP_UNROLLING_50(idx, step, macro) LOOP_UNROLLING_49(idx, step, macro); UNROLL_INCR(idx, step, macro)
125#define LOOP_UNROLLING_51(idx, step, macro) LOOP_UNROLLING_50(idx, step, macro); UNROLL_INCR(idx, step, macro)
126#define LOOP_UNROLLING_52(idx, step, macro) LOOP_UNROLLING_51(idx, step, macro); UNROLL_INCR(idx, step, macro)
127#define LOOP_UNROLLING_53(idx, step, macro) LOOP_UNROLLING_52(idx, step, macro); UNROLL_INCR(idx, step, macro)
128#define LOOP_UNROLLING_54(idx, step, macro) LOOP_UNROLLING_53(idx, step, macro); UNROLL_INCR(idx, step, macro)
129#define LOOP_UNROLLING_55(idx, step, macro) LOOP_UNROLLING_54(idx, step, macro); UNROLL_INCR(idx, step, macro)
130#define LOOP_UNROLLING_56(idx, step, macro) LOOP_UNROLLING_55(idx, step, macro); UNROLL_INCR(idx, step, macro)
131#define LOOP_UNROLLING_57(idx, step, macro) LOOP_UNROLLING_56(idx, step, macro); UNROLL_INCR(idx, step, macro)
132#define LOOP_UNROLLING_58(idx, step, macro) LOOP_UNROLLING_57(idx, step, macro); UNROLL_INCR(idx, step, macro)
133#define LOOP_UNROLLING_59(idx, step, macro) LOOP_UNROLLING_58(idx, step, macro); UNROLL_INCR(idx, step, macro)
134#define LOOP_UNROLLING_60(idx, step, macro) LOOP_UNROLLING_59(idx, step, macro); UNROLL_INCR(idx, step, macro)
135#define LOOP_UNROLLING_61(idx, step, macro) LOOP_UNROLLING_60(idx, step, macro); UNROLL_INCR(idx, step, macro)
136#define LOOP_UNROLLING_62(idx, step, macro) LOOP_UNROLLING_61(idx, step, macro); UNROLL_INCR(idx, step, macro)
137#define LOOP_UNROLLING_63(idx, step, macro) LOOP_UNROLLING_62(idx, step, macro); UNROLL_INCR(idx, step, macro)
138#define LOOP_UNROLLING_64(idx, step, macro) LOOP_UNROLLING_63(idx, step, macro); UNROLL_INCR(idx, step, macro)
139#define LOOP_UNROLLING_65(idx, step, macro) LOOP_UNROLLING_64(idx, step, macro); UNROLL_INCR(idx, step, macro)
140#define LOOP_UNROLLING_66(idx, step, macro) LOOP_UNROLLING_65(idx, step, macro); UNROLL_INCR(idx, step, macro)
141#define LOOP_UNROLLING_67(idx, step, macro) LOOP_UNROLLING_66(idx, step, macro); UNROLL_INCR(idx, step, macro)
142#define LOOP_UNROLLING_68(idx, step, macro) LOOP_UNROLLING_67(idx, step, macro); UNROLL_INCR(idx, step, macro)
143#define LOOP_UNROLLING_69(idx, step, macro) LOOP_UNROLLING_68(idx, step, macro); UNROLL_INCR(idx, step, macro)
144#define LOOP_UNROLLING_70(idx, step, macro) LOOP_UNROLLING_69(idx, step, macro); UNROLL_INCR(idx, step, macro)
145#define LOOP_UNROLLING_71(idx, step, macro) LOOP_UNROLLING_70(idx, step, macro); UNROLL_INCR(idx, step, macro)
146#define LOOP_UNROLLING_72(idx, step, macro) LOOP_UNROLLING_71(idx, step, macro); UNROLL_INCR(idx, step, macro)
147#define LOOP_UNROLLING_73(idx, step, macro) LOOP_UNROLLING_72(idx, step, macro); UNROLL_INCR(idx, step, macro)
148#define LOOP_UNROLLING_74(idx, step, macro) LOOP_UNROLLING_73(idx, step, macro); UNROLL_INCR(idx, step, macro)
149#define LOOP_UNROLLING_75(idx, step, macro) LOOP_UNROLLING_74(idx, step, macro); UNROLL_INCR(idx, step, macro)
150#define LOOP_UNROLLING_76(idx, step, macro) LOOP_UNROLLING_75(idx, step, macro); UNROLL_INCR(idx, step, macro)
151#define LOOP_UNROLLING_77(idx, step, macro) LOOP_UNROLLING_76(idx, step, macro); UNROLL_INCR(idx, step, macro)
152#define LOOP_UNROLLING_78(idx, step, macro) LOOP_UNROLLING_77(idx, step, macro); UNROLL_INCR(idx, step, macro)
153#define LOOP_UNROLLING_79(idx, step, macro) LOOP_UNROLLING_78(idx, step, macro); UNROLL_INCR(idx, step, macro)
154#define LOOP_UNROLLING_80(idx, step, macro) LOOP_UNROLLING_79(idx, step, macro); UNROLL_INCR(idx, step, macro)
155#define LOOP_UNROLLING_81(idx, step, macro) LOOP_UNROLLING_80(idx, step, macro); UNROLL_INCR(idx, step, macro)
156#define LOOP_UNROLLING_82(idx, step, macro) LOOP_UNROLLING_81(idx, step, macro); UNROLL_INCR(idx, step, macro)
157#define LOOP_UNROLLING_83(idx, step, macro) LOOP_UNROLLING_82(idx, step, macro); UNROLL_INCR(idx, step, macro)
158#define LOOP_UNROLLING_84(idx, step, macro) LOOP_UNROLLING_83(idx, step, macro); UNROLL_INCR(idx, step, macro)
159#define LOOP_UNROLLING_85(idx, step, macro) LOOP_UNROLLING_84(idx, step, macro); UNROLL_INCR(idx, step, macro)
160#define LOOP_UNROLLING_86(idx, step, macro) LOOP_UNROLLING_85(idx, step, macro); UNROLL_INCR(idx, step, macro)
161#define LOOP_UNROLLING_87(idx, step, macro) LOOP_UNROLLING_86(idx, step, macro); UNROLL_INCR(idx, step, macro)
162#define LOOP_UNROLLING_88(idx, step, macro) LOOP_UNROLLING_87(idx, step, macro); UNROLL_INCR(idx, step, macro)
163#define LOOP_UNROLLING_89(idx, step, macro) LOOP_UNROLLING_88(idx, step, macro); UNROLL_INCR(idx, step, macro)
164#define LOOP_UNROLLING_90(idx, step, macro) LOOP_UNROLLING_89(idx, step, macro); UNROLL_INCR(idx, step, macro)
165#define LOOP_UNROLLING_91(idx, step, macro) LOOP_UNROLLING_90(idx, step, macro); UNROLL_INCR(idx, step, macro)
166#define LOOP_UNROLLING_92(idx, step, macro) LOOP_UNROLLING_91(idx, step, macro); UNROLL_INCR(idx, step, macro)
167#define LOOP_UNROLLING_93(idx, step, macro) LOOP_UNROLLING_92(idx, step, macro); UNROLL_INCR(idx, step, macro)
168#define LOOP_UNROLLING_94(idx, step, macro) LOOP_UNROLLING_93(idx, step, macro); UNROLL_INCR(idx, step, macro)
169#define LOOP_UNROLLING_95(idx, step, macro) LOOP_UNROLLING_94(idx, step, macro); UNROLL_INCR(idx, step, macro)
170#define LOOP_UNROLLING_96(idx, step, macro) LOOP_UNROLLING_95(idx, step, macro); UNROLL_INCR(idx, step, macro)
171#define LOOP_UNROLLING_97(idx, step, macro) LOOP_UNROLLING_96(idx, step, macro); UNROLL_INCR(idx, step, macro)
172#define LOOP_UNROLLING_98(idx, step, macro) LOOP_UNROLLING_97(idx, step, macro); UNROLL_INCR(idx, step, macro)
173#define LOOP_UNROLLING_99(idx, step, macro) LOOP_UNROLLING_98(idx, step, macro); UNROLL_INCR(idx, step, macro)
174#define LOOP_UNROLLING_100(idx, step, macro) LOOP_UNROLLING_99(idx, step, macro); UNROLL_INCR(idx, step, macro)
175#define LOOP_UNROLLING_101(idx, step, macro) LOOP_UNROLLING_100(idx, step, macro); UNROLL_INCR(idx, step, macro)
176#define LOOP_UNROLLING_102(idx, step, macro) LOOP_UNROLLING_101(idx, step, macro); UNROLL_INCR(idx, step, macro)
177#define LOOP_UNROLLING_103(idx, step, macro) LOOP_UNROLLING_102(idx, step, macro); UNROLL_INCR(idx, step, macro)
178#define LOOP_UNROLLING_104(idx, step, macro) LOOP_UNROLLING_103(idx, step, macro); UNROLL_INCR(idx, step, macro)
179#define LOOP_UNROLLING_105(idx, step, macro) LOOP_UNROLLING_104(idx, step, macro); UNROLL_INCR(idx, step, macro)
180#define LOOP_UNROLLING_106(idx, step, macro) LOOP_UNROLLING_105(idx, step, macro); UNROLL_INCR(idx, step, macro)
181#define LOOP_UNROLLING_107(idx, step, macro) LOOP_UNROLLING_106(idx, step, macro); UNROLL_INCR(idx, step, macro)
182#define LOOP_UNROLLING_108(idx, step, macro) LOOP_UNROLLING_107(idx, step, macro); UNROLL_INCR(idx, step, macro)
183#define LOOP_UNROLLING_109(idx, step, macro) LOOP_UNROLLING_108(idx, step, macro); UNROLL_INCR(idx, step, macro)
184#define LOOP_UNROLLING_110(idx, step, macro) LOOP_UNROLLING_109(idx, step, macro); UNROLL_INCR(idx, step, macro)
185#define LOOP_UNROLLING_111(idx, step, macro) LOOP_UNROLLING_110(idx, step, macro); UNROLL_INCR(idx, step, macro)
186#define LOOP_UNROLLING_112(idx, step, macro) LOOP_UNROLLING_111(idx, step, macro); UNROLL_INCR(idx, step, macro)
187#define LOOP_UNROLLING_113(idx, step, macro) LOOP_UNROLLING_112(idx, step, macro); UNROLL_INCR(idx, step, macro)
188#define LOOP_UNROLLING_114(idx, step, macro) LOOP_UNROLLING_113(idx, step, macro); UNROLL_INCR(idx, step, macro)
189#define LOOP_UNROLLING_115(idx, step, macro) LOOP_UNROLLING_114(idx, step, macro); UNROLL_INCR(idx, step, macro)
190#define LOOP_UNROLLING_116(idx, step, macro) LOOP_UNROLLING_115(idx, step, macro); UNROLL_INCR(idx, step, macro)
191#define LOOP_UNROLLING_117(idx, step, macro) LOOP_UNROLLING_116(idx, step, macro); UNROLL_INCR(idx, step, macro)
192#define LOOP_UNROLLING_118(idx, step, macro) LOOP_UNROLLING_117(idx, step, macro); UNROLL_INCR(idx, step, macro)
193#define LOOP_UNROLLING_119(idx, step, macro) LOOP_UNROLLING_118(idx, step, macro); UNROLL_INCR(idx, step, macro)
194#define LOOP_UNROLLING_120(idx, step, macro) LOOP_UNROLLING_119(idx, step, macro); UNROLL_INCR(idx, step, macro)
195#define LOOP_UNROLLING_121(idx, step, macro) LOOP_UNROLLING_120(idx, step, macro); UNROLL_INCR(idx, step, macro)
196#define LOOP_UNROLLING_122(idx, step, macro) LOOP_UNROLLING_121(idx, step, macro); UNROLL_INCR(idx, step, macro)
197#define LOOP_UNROLLING_123(idx, step, macro) LOOP_UNROLLING_122(idx, step, macro); UNROLL_INCR(idx, step, macro)
198#define LOOP_UNROLLING_124(idx, step, macro) LOOP_UNROLLING_123(idx, step, macro); UNROLL_INCR(idx, step, macro)
199#define LOOP_UNROLLING_125(idx, step, macro) LOOP_UNROLLING_124(idx, step, macro); UNROLL_INCR(idx, step, macro)
200#define LOOP_UNROLLING_126(idx, step, macro) LOOP_UNROLLING_125(idx, step, macro); UNROLL_INCR(idx, step, macro)
201#define LOOP_UNROLLING_127(idx, step, macro) LOOP_UNROLLING_126(idx, step, macro); UNROLL_INCR(idx, step, macro)
202#define LOOP_UNROLLING_128(idx, step, macro) LOOP_UNROLLING_127(idx, step, macro); UNROLL_INCR(idx, step, macro)
203
204#define LOOP_UNROLLING(type, idx, start, step, num, macro) LOOP_UNROLLING_STR(type, idx, start, step, num, macro)
205#define LOOP_UNROLLING_STR(type, idx, start, step, num, macro) \
206 { \
207 type idx = start; \
208 LOOP_UNROLLING_##num(idx, step, macro); \
209 }
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000210
211/** Get the get_global_id with partial N0. This function is useful when the dimension is not multiple of N0 and we need to use a partial N0
212 * to avoid out-of-bound read/write
213 *
214 * @note PARTIAL_N0 is used for get_global_id(n) = 0.
215 *
216 * @param[in] IDX get_global_id index (0,1 and 2 only)
217 * @param[in] N0 Number of elements read/written on the IDX direction
218 * @param[in] PARTIAL_N0 Number of elements read/written on the IDX direction for get_global_id(IDX) = 0. If zero,
219 * the Number of elements read/written on the IDX direction for get_global_id(IDX) = 0 is N0
220 */
221#define GET_SPATIAL_IDX(IDX, N0, PARTIAL_N0) (max((int)(get_global_id(IDX) * N0 - (N0 - PARTIAL_N0) % N0), 0))
222
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000223/** Dot product integet 8bit function
224 *
225 * @note Performs: c += dot(a, b)
226 *
227 * @param[in] DST_DATA_TYPE Accumulator data type
228 * @param[in] K0 Number of accumulations
229 * @param[in] a OpenCL vector a
230 * @param[in] b OpenCL vector b
231 * @param[in] c Scalar variable c
232 */
233#define DOT_PRODUCT_INTEGER8(DST_DATA_TYPE, K0, a, b, c) DOT_PRODUCT_INTEGER8_STR(DST_DATA_TYPE, K0, a, b, c)
234#define DOT_PRODUCT_INTEGER8_STR(DST_DATA_TYPE, K0, a, b, c) DOT_PRODUCT##K0##_INTEGER8(DST_DATA_TYPE, a, b, c)
235#define DOT_PRODUCT1_INTEGER8(DST_DATA_TYPE, a, b, c) \
236 ({ \
237 c += (DST_DATA_TYPE)a * (DST_DATA_TYPE)b; \
238 })
239#define DOT_PRODUCT2_INTEGER8(DST_DATA_TYPE, a, b, c) \
240 ({ \
241 c += (DST_DATA_TYPE)a.s0 * (DST_DATA_TYPE)b.s0; \
242 c += (DST_DATA_TYPE)a.s1 * (DST_DATA_TYPE)b.s1; \
243 })
244#define DOT_PRODUCT3_INTEGER8(DST_DATA_TYPE, a, b, c) \
245 ({ \
246 DOT_PRODUCT2_INTEGER8(DST_DATA_TYPE, a, b, c); \
247 c += (DST_DATA_TYPE)a.s2 * (DST_DATA_TYPE)b.s2; \
248 })
249#if defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
250#define DOT_PRODUCT4_INTEGER8(DST_DATA_TYPE, x, y, val) val = arm_dot_acc((x), (y), (val));
251#elif defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8) // defined(ARM_COMPUTE_OPENCL_DOT8_ENABLED) && defined(cl_arm_integer_dot_product_int8)
252#define DOT_PRODUCT4_INTEGER8(DST_DATA_TYPE, x, y, val) val += arm_dot((x), (y));
253#else // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
254#define DOT_PRODUCT4_INTEGER8(DST_DATA_TYPE, x, y, val) \
255 ({ \
256 val += (DST_DATA_TYPE)x.s0 * (DST_DATA_TYPE)y.s0; \
257 val += (DST_DATA_TYPE)x.s1 * (DST_DATA_TYPE)y.s1; \
258 val += (DST_DATA_TYPE)x.s2 * (DST_DATA_TYPE)y.s2; \
259 val += (DST_DATA_TYPE)x.s3 * (DST_DATA_TYPE)y.s3; \
260 })
261#endif // defined(ARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED) && defined(cl_arm_integer_dot_product_accumulate_int8)
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100262#define DOT_PRODUCT8_INTEGER8(DST_DATA_TYPE, a, b, c) \
263 ({ \
264 DOT_PRODUCT4_INTEGER8(DST_DATA_TYPE, (a.lo), (b.lo), c); \
265 DOT_PRODUCT4_INTEGER8(DST_DATA_TYPE, (a.hi), (b.hi), c); \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000266 })
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100267#define DOT_PRODUCT16_INTEGER8(DST_DATA_TYPE, a, b, c) \
268 ({ \
269 DOT_PRODUCT8_INTEGER8(DST_DATA_TYPE, (a.lo), (b.lo), c); \
270 DOT_PRODUCT8_INTEGER8(DST_DATA_TYPE, (a.hi), (b.hi), c); \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000271 })
272
273/** Load a vector from global memory (tensor)
274 *
275 * @param[in] DATA_TYPE Data type
276 * @param[in] WIDTH Number of dst columns
277 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image).
278 * In case of cl_image, only WIDTH multiples of 4 are supported (4, 8, 16)
279 * @param[in] TENSOR Tensor basename
280 * @param[in] X Starting X position
281 * @param[in] Y Starting Y position
282 * @param[in] STRIDE_Y Stride Y (in bytes)
283 */
284#define V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y) V_LOAD_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y)
285#define V_LOAD_STR(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, Y, STRIDE_Y) V_LOAD_##TENSOR_TYPE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y)
286#define V_LOAD_BUFFER(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) \
287 VLOAD(WIDTH) \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000288 (0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (Y)*STRIDE_Y))
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000289#define V_LOAD_IMAGE(DATA_TYPE, WIDTH, TENSOR, X, Y, STRIDE_Y) READ_IMAGE2D(DATA_TYPE, CONVERT_VECTOR_SIZE_TO_PIXEL_UNIT(WIDTH), TENSOR##_img, (X) / 4, (Y))
290
291/** Load a tile from global memory (tensor)
292 *
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100293 * @param[in] DATA_TYPE Data type
294 * @param[in] HEIGHT Number of dst rows
295 * @param[in] WIDTH Number of dst columns
296 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image).
297 * In case of cl_image, only WIDTH multiples of 4 are supported (4, 8, 16)
298 * @param[in] TENSOR Tensor basename
299 * @param[in] X Starting X position
300 * @param[in] Y Starting Y position
301 * @param[in] YI_MULTIPLIER Parameter used to multiply the internal row increment (_i).
302 * In common cases should be 1 but it becomes useful when we want to load rows which are multiple of STRIDE_Y. (e.g. loading the weights of convolution layer).
303 * In this case the address calculation is performed as: (Y + _i * Y_MULTIPLIER) * STRIDE_Y
304 * @param[in] STRIDE_Y Stride Y (in bytes) used to load each row.
305 * @param[out] dst Output tile
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000306 */
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100307#define T_LOAD(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, Y, YI_MULTIPLIER, STRIDE_Y, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100308 ({ \
309 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \
310 { \
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100311 dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, ((Y) + _i * (int)(YI_MULTIPLIER)), STRIDE_Y); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100312 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000313 })
314
315/** Load a tile from global memory (tensor) using an indirect Y index tile
316 *
317 * @param[in] DATA_TYPE Data type
318 * @param[in] HEIGHT Number of dst rows
319 * @param[in] WIDTH Number of dst columns
320 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image). Currently BUFFER only is supported
321 * In case of cl_image, only WIDTH multiples of 4 are supported (4, 8, 16)
322 * @param[in] TENSOR Tensor basename
323 * @param[in] X Starting X position
324 * @param[in] STRIDE_Y Stride Y (in bytes)
325 * @param[in] indirect_y Indirect Y index tile
326 * @param[out] dst Output tile
327 */
328#define T_LOAD_INDIRECT(DATA_TYPE, HEIGHT, WIDTH, TENSOR_TYPE, TENSOR, X, STRIDE_Y, indirect_y, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100329 ({ \
330 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \
331 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000332 dst[_i].v = V_LOAD(DATA_TYPE, WIDTH, TENSOR_TYPE, TENSOR, X, (indirect_y[_i].v), STRIDE_Y); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100333 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000334 })
335
Gian Marco Iodice534b8892021-04-01 16:17:16 +0100336/** Load a tile from global memory (tensor) when the tensor is stored using a NHWC layout
337 *
338 * @param[in] DATA_TYPE Data type
339 * @param[in] TILE_HEIGHT Number of elements to load from Y (height) dimension
340 * @param[in] TILE_WIDTH Number of elements to load from X (width) dimension
341 * @param[in] TILE_CHANNELS Number of elements to load from C (channel) dimension
342 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image). Currently BUFFER only is supported
343 * In case of cl_image, only TILE_CHANNELS multiples of 4 are supported (4, 8, 16)
344 * @param[in] TENSOR Tensor basename
345 * @param[in] B Starting batch index
346 * @param[in] Y Starting Y index
347 * @param[in] X Starting X index
348 * @param[in] C Starting C index
349 * @param[in] TENSOR_HEIGHT Number of elements to load from Y (height) dimension
350 * @param[in] TENSOR_WIDTH Number of elements to load from X (width) dimension
351 * @param[in] STRIDE_Y Stride Y (in bytes)
352 * @param[out] dst Output tile
353 */
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100354#define T_LOAD_NHWC(DATA_TYPE, TILE_HEIGHT, TILE_WIDTH, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, STRIDE_Y, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100355 ({ \
356 LOOP_UNROLLING(int, _yk, 0, 1, TILE_HEIGHT, \
357 { \
358 LOOP_UNROLLING(int, _xk, 0, 1, TILE_WIDTH, \
359 { \
360 int _src_y = (X) + _xk + ((Y) + _yk) * (TENSOR_WIDTH); \
361 _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \
Gian Marco Iodice534b8892021-04-01 16:17:16 +0100362 int _src_valid_y = (((X) + _xk) >= 0 && ((X) + _xk) < (int)(TENSOR_WIDTH) && ((Y) + _yk) >= 0 && ((Y) + _yk) < (int)(TENSOR_HEIGHT)); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100363 if(_src_valid_y != 0) \
364 { \
365 dst[_xk + _yk * (TILE_WIDTH)].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100366 } \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100367 }) \
368 }) \
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100369 })
370
371/** Load a tile from global memory (tensor) when the tensor is stored using a NHWC layout using indirect X and Y coordinates
372 *
373 * @param[in] DATA_TYPE Data type
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100374 * @param[in] TILE_AREA Number of elements to load from Y (height) dimension * Number of elements to load from X (width) dimension
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100375 * @param[in] TILE_CHANNELS Number of elements to load from C (channel) dimension
376 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image). Currently BUFFER only is supported
377 * In case of cl_image, only TILE_CHANNELS multiples of 4 are supported (4, 8, 16)
378 * @param[in] TENSOR Tensor basename
379 * @param[in] B Starting batch index
380 * @param[in] Y Starting Y index
381 * @param[in] X Starting X index
382 * @param[in] C Starting C index
383 * @param[in] TENSOR_HEIGHT Number of elements to load from Y (height) dimension
384 * @param[in] TENSOR_WIDTH Number of elements to load from X (width) dimension
385 * @param[in] STRIDE_Y Stride Y (in bytes)
386 * @param[out] xi A tile with (TILE_WIDTH x TILE_HEIGHT) values with the indirect X coordinate
387 * @param[out] yi A tile with (TILE_WIDTH x TILE_HEIGHT) values with the indirect Y coordinate
388 * @param[out] dst Output tile
389 */
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100390#define T_LOAD_NHWC_INDIRECT(DATA_TYPE, TILE_AREA, TILE_CHANNELS, TENSOR_TYPE, TENSOR, B, Y, X, C, TENSOR_WIDTH, TENSOR_HEIGHT, STRIDE_Y, xi, yi, dst) \
391 ({ \
392 LOOP_UNROLLING(int, _i, 0, 1, TILE_AREA, \
393 { \
394 int _src_y = (X) + xi[_i].v + ((Y) + yi[_i].v) * (TENSOR_WIDTH); \
395 _src_y += (B) * (int)(TENSOR_WIDTH) * (int)(TENSOR_HEIGHT); \
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100396 int _src_valid_y = (((X) + xi[_i].v) >= 0 && ((X) + xi[_i].v) < (int)(TENSOR_WIDTH) && ((Y) + yi[_i].v) >= 0 && ((Y) + yi[_i].v) < (int)(TENSOR_HEIGHT)); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100397 if(_src_valid_y != 0) \
398 { \
399 dst[_i].v = V_LOAD(DATA_TYPE, TILE_CHANNELS, TENSOR_TYPE, TENSOR, C, _src_y, STRIDE_Y); \
Gian Marco Iodice0b76f7d2021-04-08 17:20:00 +0100400 } \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100401 }) \
Gian Marco Iodice534b8892021-04-01 16:17:16 +0100402 })
403
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000404/** Store a tile to global memory (tensor) using an indirect Y index tile and conditionally use a different length for the store
405 *
406 * @note If WIDTH1_CONDITION is true, the store will use the WIDTH1 length for the store
407 * @note The vectors are stored in reverse order so the invalid rows are overwritten by the valid ones
408 *
409 * @param[in] DATA_TYPE Data type
410 * @param[in] HEIGHT Number of src rows
411 * @param[in] WIDTH0 Store width to use if WIDTH1_CONDITION = false
412 * @param[in] WIDTH1 Store width to use if WIDTH1_CONDITION = true
413 * @param[in] TENSOR_TYPE Type of cl_type used to store the tensor in global memory (BUFFER=cl_buffer, IMAGE=cl_image). Currently BUFFER only is supported
414 * cl_image is not supported.
415 * @param[in] TENSOR Tensor basename
416 * @param[in] X Starting X position
417 * @param[in] STRIDE_Y Stride Y (in bytes)
418 * @param[in] WIDTH1_CONDITION Condition to select the WIDTH1 store
419 * @param[in] src Input tile
420 * @param[in] indirect_y Indirect Y index tile
421 */
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000422#define T_STORE_INDIRECT_WIDTH_SELECT(DATA_TYPE, HEIGHT, WIDTH0, WIDTH1, TENSOR_TYPE, TENSOR, X, STRIDE_Y, WIDTH1_CONDITION, src, indirect_y) \
423 ({ \
424 if(WIDTH1_CONDITION) \
425 { \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100426 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000427 { \
428 VSTORE_PARTIAL(WIDTH0, WIDTH1) \
429 (src[HEIGHT - 1 - _i].v, 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (indirect_y[HEIGHT - 1 - _i].v) * STRIDE_Y)); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100430 }) \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000431 } \
432 else \
433 { \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100434 LOOP_UNROLLING(int, _i, 0, 1, HEIGHT, \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000435 { \
436 VSTORE(WIDTH0) \
437 (src[HEIGHT - 1 - _i].v, 0, (__global DATA_TYPE *)(TENSOR##_ptr + TENSOR##_offset_first_element_in_bytes + (X) * sizeof(DATA_TYPE) + (indirect_y[HEIGHT - 1 - _i].v) * STRIDE_Y)); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100438 }) \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000439 } \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000440 })
441
442/** Offset correction for the QASYMM8 computation
443 *
444 * @param[in] ACC_DATA_TYPE Accumulator data type
445 * @param[in] M0 Number of src/dst rows
446 * @param[in] N0 Number of src/dst columns
447 * @param[in] K0 Number of src columns
448 * @param[in] SRC_OFFSET Source quantization offset
449 * @param[in] WEI_OFFSET Weights quantization shift
450 * @param[in] lhs LHS tile
451 * @param[in] rhs RHS tile
452 * @param[out] dst DST tile
453 */
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100454#define T_OFFSET_CORRECTION(ACC_DATA_TYPE, M0, N0, K0, SRC_OFFSET, WEI_OFFSET, lhs, rhs, dst) \
455 ({ \
456 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
457 { \
458 ACC_DATA_TYPE _tm = 0; \
459 LOOP_UNROLLING(int, _k0, 0, 1, K0, \
460 { \
461 _tm += ((ACC_DATA_TYPE)lhs[_m0].s[_k0] * (ACC_DATA_TYPE)WEI_OFFSET); \
462 }) \
463 LOOP_UNROLLING(int, _n0, 0, 1, N0, \
464 { \
465 dst[_m0].s[_n0] += _tm; \
466 LOOP_UNROLLING(int, _k0, 0, 1, K0, \
467 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000468 dst[_m0].s[_n0] += ((ACC_DATA_TYPE)rhs[_n0].s[_k0] * (ACC_DATA_TYPE)SRC_OFFSET); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100469 }) \
470 }) \
471 }); \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000472 })
473
474/** Quantized the tile (ASYMMETRIC) with fixed-point scale
475 *
476 * @param[in] SRC_DATA_TYPE SRC data type
477 * @param[in] DST_DATA_TYPE DST data type
478 * @param[in] M0 Number of src/dst rows
479 * @param[in] N0 Number of src/dst columns
480 * @param[in] DST_OFFSET Quantization offset
481 * @param[in] DST_SHIFT Quantization shift
482 * @param[in] DST_MULTIPLIER Quantization multiplier
483 * @param[in] src Input tile
484 * @param[out] dst Output tile
485 */
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100486#define T_QUANTIZE8_ASYMMETRIC(SRC_DATA_TYPE, DST_DATA_TYPE, M0, N0, DST_OFFSET, DST_SHIFT, DST_MULTIPLIER, src, dst) \
487 ({ \
488 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
489 { \
490 LOOP_UNROLLING(int, _n0, 0, 1, N0, \
491 { \
492 SRC_DATA_TYPE _tmp = 0; \
493 if(DST_SHIFT < 0) \
494 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000495 _tmp = ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(src[_m0].s[_n0], DST_MULTIPLIER, DST_SHIFT, 1); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100496 } \
497 else \
498 { \
499 _tmp = ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(src[_m0].s[_n0], DST_MULTIPLIER, DST_SHIFT, 1); \
500 } \
501 _tmp += DST_OFFSET; \
502 dst[_m0].s[_n0] = CONVERT_SAT(_tmp, DST_DATA_TYPE); \
503 }) \
504 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000505 })
506
507/** Conditional rowset (memset by row)
508 *
509 * @note Set the row to VALUE_TO_SET if the corresponding mask == 0
510 *
511 * @param[in] DATA_TYPE Data type
512 * @param[in] M0 Number of LHS rows
513 * @param[in] N0 Number of LHS columns
514 * @param[in] VALUE_TO_SET Value to set the row
515 * @param[in, out] a Input/output tile
516 * @param[out] mask Mask to check for setting the row to VALUE_TO_SET
517 */
518#define T_ROWSET_MASK(DATA_TYPE, M0, N0, VALUE_TO_SET, a, mask) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100519 ({ \
520 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
521 { \
522 LOOP_UNROLLING(int, _n0, 0, 1, N0, \
523 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000524 a[_m0].s[_n0] = select((DATA_TYPE)(a[_m0].s[_n0]), (DATA_TYPE)(VALUE_TO_SET), (SELECT_DATA_TYPE(DATA_TYPE))(mask[_m0].v == (DATA_TYPE)0)); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100525 }) \
526 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000527 })
528
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000529/** Element-wise activation
530 *
531 * @note Performs: activation(LHS) = DST
532 *
533 * @param[in] DATA_TYPE SRC/DST data type
534 * @param[in] M0 Number of SRC/DST rows
535 * @param[in] N0 Number of SRC/DST columns
536 * @param[in] ACTIVATION_TYPE Activation type
537 * @param[in] A_VAL A value used for the activation (e.g. tanh_op, brelu,..)
538 * @param[in] B_VAL B value used for the activation (e.g. tanh_op, brelu,..)
539 * @param[out] src SRC tile
540 * @param[out] dst DST tile
541 */
542#define T_ACTIVATION(DATA_TYPE, M0, N0, ACTIVATION_TYPE, A_VAL, B_VAL, src, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100543 ({ \
544 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
545 { \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000546 dst[_m0].v = ACTIVATION(ACTIVATION_TYPE, DATA_TYPE, N0, src[_m0].v, A_VAL, B_VAL); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100547 }) \
Gian Marco Iodicea8903c82021-03-24 14:48:22 +0000548 })
549
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000550/** Element-wise addition with a constant value
551 *
552 * @note Performs: LHS + constant = DST
553 *
554 * @param[in] DATA_TYPE LHS/RHS/DST data type
555 * @param[in] M0 Number of LHS rows
556 * @param[in] N0 Number of LHS columns
557 * @param[in] lhs LHS tile
558 * @param[in] rhs_constant Constant value
559 * @param[out] dst DST tile
560 */
561#define T_ADD_CONSTANT(DATA_TYPE, M0, N0, lhs, rhs_constant, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100562 ({ \
563 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
564 { \
565 LOOP_UNROLLING(int, _n0, 0, 1, N0, \
566 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000567 dst[_m0].s[_n0] = lhs[_m0].s[_n0] + rhs_constant; \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100568 }) \
569 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000570 })
571
572/** Element-wise addition with RHS broadcasted (RHS has the X dimension only)
573 *
574 * @note Performs: LHS + RHS[broadcasted] = DST
575 * @note Both tiles must have same data type
576 *
577 * @param[in] DATA_TYPE LHS/RHS/DST data type
578 * @param[in] M0 Number of LHS rows
579 * @param[in] N0 Number of LHS columns
580 * @param[in] lhs LHS tile
581 * @param[in] rhs RHS tile
582 * @param[out] dst DST tile
583 */
584#define T_ADD_BROADCAST_X(DATA_TYPE, M0, N0, lhs, rhs, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100585 ({ \
586 LOOP_UNROLLING(int, _m0, 0, 1, M0, \
587 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000588 dst[_m0].v = lhs[_m0].v + rhs[0].v; \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100589 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000590 })
591
592/** Matrix multiplication
593 *
594 * @note Performs: LHS X RHS + DST = DST
595 *
596 * @param[in] LHS_DATA_TYPE LHS tile data type
597 * @param[in] RHS_DATA_TYPE RHS tile data type
598 * @param[in] DST_DATA_TYPE RHS tile data type
599 * @param[in] M0 Number of LHS rows
600 * @param[in] N0 Number of RHS columns
601 * @param[in] K0 Number of LHS columns
602 * @param[in] LHS_LAYOUT LHS layout (T= transposed, NT= not transposed)
603 * @param[in] RHS_LAYOUT RHS layout (T= transposed, NT= not transposed)
604 * @param[in] lhs LHS tile
605 * @param[in] rhs RHS tile
606 * @param[in, out] dst DST tile
607 */
608#define T_MMUL(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, LHS_LAYOUT, RHS_LAYOUT, lhs, rhs, dst) T_MMUL_##LHS_LAYOUT##_##RHS_LAYOUT(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
609#define T_MMUL_NT_T(LHS_DATA_TYPE, RHS_DATA_TYPE, DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_##LHS_DATA_TYPE##_##RHS_DATA_TYPE##_##DST_DATA_TYPE(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
610#define T_MMUL_NT_T_float_float_float(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_FLOAT(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
611#define T_MMUL_NT_T_half_half_half(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_FLOAT(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
612#define T_MMUL_NT_T_char_char_int(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
613#define T_MMUL_NT_T_uchar_uchar_uint(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
614#define T_MMUL_NT_T_uchar_uchar_int(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) T_MMUL_NT_T_INTEGER8(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst)
615#define T_MMUL_NT_T_FLOAT(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \
616 { \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100617 LOOP_UNROLLING(int, _m, 0, 1, M0, \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000618 { \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100619 LOOP_UNROLLING(int, _n, 0, 1, N0, \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000620 { \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100621 LOOP_UNROLLING(int, _k, 0, 1, K0, \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000622 { \
623 dst[_m].s[_n] = fma((lhs[_m].s[_k]), (rhs[_n].s[_k]), dst[_m].s[_n]); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100624 }) \
625 }) \
626 }) \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000627 }
628#define T_MMUL_NT_T_INTEGER8(DST_DATA_TYPE, M0, N0, K0, lhs, rhs, dst) \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100629 ({ \
630 LOOP_UNROLLING(int, _m, 0, 1, M0, \
631 { \
632 LOOP_UNROLLING(int, _n, 0, 1, N0, \
633 { \
Gian Marco Iodice5c9eed82021-03-19 11:26:20 +0000634 DOT_PRODUCT_INTEGER8(DST_DATA_TYPE, K0, (lhs[_m].v), (rhs[_n].v), dst[_m].s[_n]); \
Giorgio Arenabdd16d12021-05-13 16:58:51 +0100635 }) \
636 }) \
637 })
638
639// clang-format on
640// *INDENT-ON*