1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *xe_lp_1x1_conv_fwd_data_x8s8x_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2019-2022 Intel Corporation )==" "\n" |
7 | R"==(* )==" "\n" |
8 | R"==(* licensed under the apache license, version 2.0 (the "license"); )==" "\n" |
9 | R"==(* you may not use this file except in compliance with the license. )==" "\n" |
10 | R"==(* you may obtain a copy of the license at )==" "\n" |
11 | R"==(* )==" "\n" |
12 | R"==(* http: )==" "\n" |
13 | R"==(* )==" "\n" |
14 | R"==(* unless required by applicable law or agreed to in writing, software )==" "\n" |
15 | R"==(* distributed under the license is distributed on an "as is" basis, )==" "\n" |
16 | R"==(* without warranties or conditions of any kind, either express or implied. )==" "\n" |
17 | R"==(* see the license for the specific language governing permissions and )==" "\n" |
18 | R"==(* limitations under the license. )==" "\n" |
19 | R"==(*******************************************************************************/ )==" "\n" |
20 | R"==(#include "gpu/ocl/ocl_math_utils.h" )==" "\n" |
21 | R"==(#include "gpu/ocl/ocl_post_ops.h" )==" "\n" |
22 | R"==(#include "gpu/ocl/ocl_scales.h" )==" "\n" |
23 | R"==(#include "gpu/ocl/ocl_types.h" )==" "\n" |
24 | R"==(#include "gpu/ocl/ocl_zero_points.h" )==" "\n" |
25 | R"==(#if IC % IC_BLOCK != 0 )==" "\n" |
26 | R"==(#define IC_NBLOCKS_TAIL ((IC - (IC & ~(IC_BLOCK - 1)) + 3) / 4) )==" "\n" |
27 | R"==(#else )==" "\n" |
28 | R"==(#define IC_NBLOCKS_TAIL 8 )==" "\n" |
29 | R"==(#endif )==" "\n" |
30 | R"==(#define OWB ((OW + SP_BLOCK - 1) / SP_BLOCK) )==" "\n" |
31 | R"==(#define HAS_PADDING (PW > 0 || PH > 0 || PD > 0) )==" "\n" |
32 | R"==(#define USE_SP_BLOCK (SW == 1 && SH == 1 && SW == 1) || HAS_PADDING )==" "\n" |
33 | R"==(#define SRC_SP (IW * IH * ID) )==" "\n" |
34 | R"==(#define SRC_MB_STRIDE IC_BLOCK )==" "\n" |
35 | R"==(#define SRC_SP_STRIDE (SRC_MB_STRIDE * MB_BLOCK) )==" "\n" |
36 | R"==(#define SRC_ICB_STRIDE (SRC_SP_STRIDE * SRC_SP) )==" "\n" |
37 | R"==(#define DST_SP (OW * OH * OD) )==" "\n" |
38 | R"==(#define DST_MB_STRIDE IC_BLOCK )==" "\n" |
39 | R"==(#define DST_SP_STRIDE (DST_MB_STRIDE * MB_BLOCK) )==" "\n" |
40 | R"==(#define DST_OCB_STRIDE (DST_SP_STRIDE * DST_SP) )==" "\n" |
41 | R"==(#define WEI_BLOCK_STRIDE (4 * 8 * 8 * 4) )==" "\n" |
42 | R"==(#if (MB_BLOCK == 32) \ )==" "\n" |
43 | R"==(|| ((PW == 0 && PH == 0 && PW == 0) \ )==" "\n" |
44 | R"==(&& (SW == 1 && SH == 1 && SD == 1)) )==" "\n" |
45 | R"==(#define BLOCK_READ_SRC_4x32(data, idx, sp_off) \ )==" "\n" |
46 | R"==(data = AS_SRC_MMAD_DATA4_T( \ )==" "\n" |
47 | R"==(intel_sub_group_block_read4((__global uint *)&src[idx])); )==" "\n" |
48 | R"==(#define BLOCK_READ_SRC_8x32(data, idx, sp_off) \ )==" "\n" |
49 | R"==(data = AS_SRC_MMAD_DATA8_T( \ )==" "\n" |
50 | R"==(intel_sub_group_block_read8((__global uint *)&src[idx])); )==" "\n" |
51 | R"==(#else )==" "\n" |
52 | R"==(#define BLOCK_READ_SRC_4x32(data, idx, sp_off) \ )==" "\n" |
53 | R"==(do { \ )==" "\n" |
54 | R"==(unroll_for(uint _i = 0; _i < 4; ++_i) { \ )==" "\n" |
55 | R"==(if (HAS_PADDING) { \ )==" "\n" |
56 | R"==(PAD_BLOCK_READ(data[_i], src, sp, _i + sp_off); \ )==" "\n" |
57 | R"==(} else { \ )==" "\n" |
58 | R"==(data[_i] = AS_SRC_MMAD_DATA_T(intel_sub_group_block_read( \ )==" "\n" |
59 | R"==((__global uint *)&src[idx + _i * SW * IC_BLOCK])); \ )==" "\n" |
60 | R"==(} \ )==" "\n" |
61 | R"==(} \ )==" "\n" |
62 | R"==(} while (0); )==" "\n" |
63 | R"==(#define BLOCK_READ_SRC_8x32(data, idx, sp_off) \ )==" "\n" |
64 | R"==(do { \ )==" "\n" |
65 | R"==(unroll_for(uint _i = 0; _i < 8; ++_i) { \ )==" "\n" |
66 | R"==(if (HAS_PADDING) { \ )==" "\n" |
67 | R"==(PAD_BLOCK_READ(data[_i], src, sp, _i + sp_off); \ )==" "\n" |
68 | R"==(} else { \ )==" "\n" |
69 | R"==(data[_i] = AS_SRC_MMAD_DATA_T(intel_sub_group_block_read( \ )==" "\n" |
70 | R"==((__global uint *)&src[idx + _i * SW * IC_BLOCK])); \ )==" "\n" |
71 | R"==(} \ )==" "\n" |
72 | R"==(} \ )==" "\n" |
73 | R"==(} while (0); )==" "\n" |
74 | R"==(#endif )==" "\n" |
75 | R"==(#if SP_BLOCK == 4 )==" "\n" |
76 | R"==(#define BLOCK0 4 )==" "\n" |
77 | R"==(#define ACC_DATA_BLOCK int4 )==" "\n" |
78 | R"==(#define SRC_DATA_BLOCK_T SRC_MMAD_DATA4_T )==" "\n" |
79 | R"==(#define BLOCK_READ_SRC BLOCK_READ_SRC_4x32 )==" "\n" |
80 | R"==(DECLARE_MMAD_EMU(mmad_tail0, idot4, IC_NBLOCKS_TAIL, 4, SRC_DATA_BLOCK_T, int8, )==" "\n" |
81 | R"==(ACC_DATA_BLOCK) )==" "\n" |
82 | R"==(#define MMAD_FULL0 mmad8x4 )==" "\n" |
83 | R"==(#define MMAD_TAIL0 mmad_tail0 )==" "\n" |
84 | R"==(#else )==" "\n" |
85 | R"==(#define BLOCK0 8 )==" "\n" |
86 | R"==(#define ACC_DATA_BLOCK int8 )==" "\n" |
87 | R"==(#define SRC_DATA_BLOCK_T SRC_MMAD_DATA8_T )==" "\n" |
88 | R"==(#define BLOCK_READ_SRC BLOCK_READ_SRC_8x32 )==" "\n" |
89 | R"==(DECLARE_MMAD_EMU(mmad_tail0, idot4, IC_NBLOCKS_TAIL, 8, SRC_DATA_BLOCK_T, int8, )==" "\n" |
90 | R"==(ACC_DATA_BLOCK) )==" "\n" |
91 | R"==(#define MMAD_FULL0 mmad8x8 )==" "\n" |
92 | R"==(#define MMAD_TAIL0 mmad_tail0 )==" "\n" |
93 | R"==(#endif )==" "\n" |
94 | R"==(#if SP_BLOCK == 12 )==" "\n" |
95 | R"==(#define BLOCK1 4 )==" "\n" |
96 | R"==(#define ACC_DATA_BLOCK1 int4 )==" "\n" |
97 | R"==(#define SRC_DATA_BLOCK_T1 SRC_MMAD_DATA4_T )==" "\n" |
98 | R"==(#define DST_DATA_BLOCK_T1 uint4 )==" "\n" |
99 | R"==(#define BLOCK_READ_SRC1 BLOCK_READ_SRC_4x32 )==" "\n" |
100 | R"==(DECLARE_MMAD_EMU(mmad_tail1, idot4, IC_NBLOCKS_TAIL, 4, SRC_DATA_BLOCK_T1, int8, )==" "\n" |
101 | R"==(ACC_DATA_BLOCK1) )==" "\n" |
102 | R"==(#define MMAD_FULL1 mmad8x4 )==" "\n" |
103 | R"==(#define MMAD_TAIL1 mmad_tail1 )==" "\n" |
104 | R"==(#else )==" "\n" |
105 | R"==(#define BLOCK1 8 )==" "\n" |
106 | R"==(#define ACC_DATA_BLOCK1 int8 )==" "\n" |
107 | R"==(#define SRC_DATA_BLOCK_T1 SRC_MMAD_DATA8_T )==" "\n" |
108 | R"==(#define DST_DATA_BLOCK_T1 uint8 )==" "\n" |
109 | R"==(#define BLOCK_READ_SRC1 BLOCK_READ_SRC_8x32 )==" "\n" |
110 | R"==(DECLARE_MMAD_EMU(mmad_tail1, idot4, IC_NBLOCKS_TAIL, 8, SRC_DATA_BLOCK_T1, int8, )==" "\n" |
111 | R"==(ACC_DATA_BLOCK1) )==" "\n" |
112 | R"==(#define MMAD_FULL1 mmad8x8 )==" "\n" |
113 | R"==(#define MMAD_TAIL1 mmad_tail1 )==" "\n" |
114 | R"==(#endif )==" "\n" |
115 | R"==(#if INT8_WEI_SLM )==" "\n" |
116 | R"==(#define BLOCK_READ_WHT_1x32(data, idx) \ )==" "\n" |
117 | R"==(data = as_int(block_read((__local uint *)&wei_tmp[idx])); )==" "\n" |
118 | R"==(#define BLOCK_READ_WHT_8x32(data, idx) \ )==" "\n" |
119 | R"==(data = as_int8(block_read8((__local uint *)&wei_tmp[idx])); )==" "\n" |
120 | R"==(#else )==" "\n" |
121 | R"==(#define BLOCK_READ_WHT_1x32(data, idx) \ )==" "\n" |
122 | R"==(data = as_int(intel_sub_group_block_read((__global uint *)&wei[idx])); )==" "\n" |
123 | R"==(#define BLOCK_READ_WHT_8x32(data, idx) \ )==" "\n" |
124 | R"==(data = as_int8(intel_sub_group_block_read8((__global uint *)&wei[idx])); )==" "\n" |
125 | R"==(#endif )==" "\n" |
126 | R"==(#if OC % OC_BLOCK == 0 )==" "\n" |
127 | R"==(#define BLOCK_READ_BIA(data, idx) \ )==" "\n" |
128 | R"==(data = as_float4(intel_sub_group_block_read4((__global uint *)&bias[idx])); )==" "\n" |
129 | R"==(#else )==" "\n" |
130 | R"==(#define BLOCK_READ_BIA(data, idx) \ )==" "\n" |
131 | R"==(data = (float4)0; \ )==" "\n" |
132 | R"==(int i; \ )==" "\n" |
133 | R"==(for (i = idx; i < idx + OC_BLOCK && i < OC - (OC % SUB_GROUP_SIZE); \ )==" "\n" |
134 | R"==(i += SUB_GROUP_SIZE) { \ )==" "\n" |
135 | R"==(data[(i - idx) / SUB_GROUP_SIZE] = as_float( \ )==" "\n" |
136 | R"==(intel_sub_group_block_read((__global uint *)&bias[i])); \ )==" "\n" |
137 | R"==(} \ )==" "\n" |
138 | R"==(if (i < OC && (i - idx) / SUB_GROUP_SIZE < 4 \ )==" "\n" |
139 | R"==(&& get_sub_group_local_id() < OC % SUB_GROUP_SIZE) { \ )==" "\n" |
140 | R"==(data[(i - idx) / SUB_GROUP_SIZE] \ )==" "\n" |
141 | R"==(= as_float(bias[i + get_sub_group_local_id()]); \ )==" "\n" |
142 | R"==(} )==" "\n" |
143 | R"==(#endif )==" "\n" |
144 | R"==(#define PAD_BLOCK_READ(data, src, sp, i) \ )==" "\n" |
145 | R"==(do { \ )==" "\n" |
146 | R"==(const int od = (sp + i) / (OW * OH); \ )==" "\n" |
147 | R"==(const int ohw = (sp + i) % (OW * OH); \ )==" "\n" |
148 | R"==(const int oh = ohw / OW; \ )==" "\n" |
149 | R"==(const int ow = (ohw % OW); \ )==" "\n" |
150 | R"==(const int id = SD * od - PD; \ )==" "\n" |
151 | R"==(const int ih = SH * oh - PH; \ )==" "\n" |
152 | R"==(const int iw = SW * ow - PW; \ )==" "\n" |
153 | R"==(bool pad = ((PW > 0 || PH > 0 || PD > 0) \ )==" "\n" |
154 | R"==(&& (iw < 0 || ih < 0 || id < 0 || iw >= IW || ih >= IH \ )==" "\n" |
155 | R"==(|| id >= ID)); \ )==" "\n" |
156 | R"==(int off = id * IH * IW + ih * IW + iw; \ )==" "\n" |
157 | R"==(data = pad ? 0 \ )==" "\n" |
158 | R"==(: AS_SRC_MMAD_DATA_T(intel_sub_group_block_read( \ )==" "\n" |
159 | R"==((global uint *)&src[off * SRC_SP_STRIDE])); \ )==" "\n" |
160 | R"==(} while (0); )==" "\n" |
161 | R"==(#if SCALES_PER_OC )==" "\n" |
162 | R"==(#define SCALE scales )==" "\n" |
163 | R"==(#elif SCALES_COMMON )==" "\n" |
164 | R"==(#define SCALE runtime_scales[0] )==" "\n" |
165 | R"==(#else )==" "\n" |
166 | R"==(#define SCALE 1 )==" "\n" |
167 | R"==(#endif )==" "\n" |
168 | R"==(void block_read_dst(int n, DST_DATA_T *d, const __global DST_DATA_T *dst); )==" "\n" |
169 | R"==(void block_write_dst(int n, const DST_DATA_T *d, __global DST_DATA_T *dst); )==" "\n" |
170 | R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) )==" "\n" |
171 | R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) __kernel void )==" "\n" |
172 | R"==(xe_lp_1x1_conv_fwd_x8s8x(const __global SRC_DATA_T *src, )==" "\n" |
173 | R"==(const __global char *wei, const __global float *bias, )==" "\n" |
174 | R"==(__global DST_DATA_T *dst POST_OP_ARGS, )==" "\n" |
175 | R"==(const __global float *runtime_scales, )==" "\n" |
176 | R"==(const __global int *src_compensation, )==" "\n" |
177 | R"==(const __global int *dst_compensation) { )==" "\n" |
178 | R"==(const uint oc_group_id = get_group_id(0); )==" "\n" |
179 | R"==(const uint sp_group_id = get_group_id(1); )==" "\n" |
180 | R"==(const uint mb_group_id = get_group_id(2); )==" "\n" |
181 | R"==(const uint ic_group_id = oc_group_id / OC_NCHUNK * IC_NCHUNK; )==" "\n" |
182 | R"==(const uint sg_local_id = get_sub_group_local_id(); )==" "\n" |
183 | R"==(const uint sg_id = get_sub_group_id(); )==" "\n" |
184 | R"==(#if USE_SP_BLOCK )==" "\n" |
185 | R"==(const uint sp = get_global_id(1) * SP_BLOCK; )==" "\n" |
186 | R"==(const int sp_local_id = get_local_id(1); )==" "\n" |
187 | R"==(const uint od = sp / (OH * OW); )==" "\n" |
188 | R"==(const uint ohw = sp % (OH * OW); )==" "\n" |
189 | R"==(const uint oh = ohw / OW; )==" "\n" |
190 | R"==(const uint ow = (ohw % OW); )==" "\n" |
191 | R"==(#else )==" "\n" |
192 | R"==(const uint sp = get_global_id(1); )==" "\n" |
193 | R"==(const int sp_local_id = get_local_id(1); )==" "\n" |
194 | R"==(const uint od = sp / (OWB * OH); )==" "\n" |
195 | R"==(const uint ohw = sp % (OWB * OH); )==" "\n" |
196 | R"==(const uint oh = ohw / OWB; )==" "\n" |
197 | R"==(const uint ow = (ohw % OWB) * SP_BLOCK; )==" "\n" |
198 | R"==(#endif )==" "\n" |
199 | R"==(const uint id = SD * od; )==" "\n" |
200 | R"==(const uint ih = SH * oh; )==" "\n" |
201 | R"==(const uint iw = SW * ow; )==" "\n" |
202 | R"==(#if MB_BLOCK == 32 )==" "\n" |
203 | R"==(src += (mb_group_id % 2) * MB_BLOCK / 2 * SRC_MB_STRIDE; )==" "\n" |
204 | R"==(src += (mb_group_id / 2) * SRC_ICB_STRIDE * IC_NCHUNK * G; )==" "\n" |
205 | R"==(#else )==" "\n" |
206 | R"==(src += mb_group_id * SRC_ICB_STRIDE * IC_NCHUNK * G; )==" "\n" |
207 | R"==(#endif )==" "\n" |
208 | R"==(src += ic_group_id * SRC_ICB_STRIDE; )==" "\n" |
209 | R"==(#if !HAS_PADDING )==" "\n" |
210 | R"==(src += (id * IH * IW + ih * IW + iw) * SRC_SP_STRIDE; )==" "\n" |
211 | R"==(#endif )==" "\n" |
212 | R"==(#if MB_BLOCK == 32 )==" "\n" |
213 | R"==(dst += (mb_group_id % 2) * MB_BLOCK / 2 * DST_MB_STRIDE; )==" "\n" |
214 | R"==(dst += (mb_group_id / 2) * DST_OCB_STRIDE * OC_NCHUNK * G; )==" "\n" |
215 | R"==(#else )==" "\n" |
216 | R"==(dst += mb_group_id * DST_OCB_STRIDE * OC_NCHUNK * G; )==" "\n" |
217 | R"==(#endif )==" "\n" |
218 | R"==(dst += oc_group_id * DST_OCB_STRIDE; )==" "\n" |
219 | R"==(dst += (od * OH * OW + oh * OW + ow) * SRC_SP_STRIDE; )==" "\n" |
220 | R"==(wei += oc_group_id * WEI_BLOCK_STRIDE * IC_NCHUNK; )==" "\n" |
221 | R"==(ACC_DATA_BLOCK C00 = 0, C01 = 0, C02 = 0, C03 = 0; )==" "\n" |
222 | R"==(ACC_DATA_BLOCK1 C10 = 0, C11 = 0, C12 = 0, C13 = 0; )==" "\n" |
223 | R"==(#if INT8_WEI_SLM )==" "\n" |
224 | R"==(#define READ_SLM() \ )==" "\n" |
225 | R"==(barrier(CLK_LOCAL_MEM_FENCE); \ )==" "\n" |
226 | R"==(const __global char *wei_copy_from \ )==" "\n" |
227 | R"==(= wei + sp_local_id * WEI_BLOCK_STRIDE / LWS_1; \ )==" "\n" |
228 | R"==(__local char *wei_copy_to \ )==" "\n" |
229 | R"==(= wei_slm + sp_local_id * WEI_BLOCK_STRIDE / LWS_1; \ )==" "\n" |
230 | R"==(block_write4((__local uint *)wei_copy_to, \ )==" "\n" |
231 | R"==(intel_sub_group_block_read4((__global uint *)wei_copy_from)); \ )==" "\n" |
232 | R"==(__local char *wei_tmp = wei_slm; \ )==" "\n" |
233 | R"==(barrier(CLK_LOCAL_MEM_FENCE); )==" "\n" |
234 | R"==(__local char wei_slm[WEI_BLOCK_STRIDE]; )==" "\n" |
235 | R"==(#endif )==" "\n" |
236 | R"==(for (uint ic_block_id = 0; ic_block_id < IC_NCHUNK; ++ic_block_id) { )==" "\n" |
237 | R"==(if (MB % MB_BLOCK != 0 && MB_BLOCK == 32 )==" "\n" |
238 | R"==(&& mb_group_id * MB_BLOCK / 2 > MB) { )==" "\n" |
239 | R"==(break; )==" "\n" |
240 | R"==(} )==" "\n" |
241 | R"==(#if INT8_WEI_SLM )==" "\n" |
242 | R"==(READ_SLM() )==" "\n" |
243 | R"==(#if SP_TAIL )==" "\n" |
244 | R"==(if (ow < OW) )==" "\n" |
245 | R"==(#endif )==" "\n" |
246 | R"==(#endif )==" "\n" |
247 | R"==({ )==" "\n" |
248 | R"==(SRC_DATA_BLOCK_T S0 = 0; )==" "\n" |
249 | R"==(SRC_DATA_BLOCK_T1 S1 = 0; )==" "\n" |
250 | R"==(#if OUT_SP_TAIL )==" "\n" |
251 | R"==(#if USE_SP_BLOCK )==" "\n" |
252 | R"==(if (od * OH * OW + oh * OW + ow + SP_BLOCK > DST_SP) { )==" "\n" |
253 | R"==(#else )==" "\n" |
254 | R"==(if (ow + SP_BLOCK > OW) { )==" "\n" |
255 | R"==(#endif )==" "\n" |
256 | R"==(#if OUT_SP_TAIL < 8 )==" "\n" |
257 | R"==(for (int _i = 0; _i < OUT_SP_TAIL; ++_i) { )==" "\n" |
258 | R"==(if (HAS_PADDING) { )==" "\n" |
259 | R"==(PAD_BLOCK_READ(S0[_i], src, sp, _i); )==" "\n" |
260 | R"==(} else { )==" "\n" |
261 | R"==(S0[_i] = AS_SRC_MMAD_DATA_T(intel_sub_group_block_read( )==" "\n" |
262 | R"==((__global uint *)&src[_i * SW * IC_BLOCK])); )==" "\n" |
263 | R"==(} )==" "\n" |
264 | R"==(} )==" "\n" |
265 | R"==(#else )==" "\n" |
266 | R"==(BLOCK_READ_SRC(S0, 0 * IC_BLOCK, 0); )==" "\n" |
267 | R"==(for (int _i = 8; _i < OUT_SP_TAIL; ++_i) { )==" "\n" |
268 | R"==(if (HAS_PADDING) { )==" "\n" |
269 | R"==(PAD_BLOCK_READ(S1[_i - 8], src, sp, _i) )==" "\n" |
270 | R"==(} else { )==" "\n" |
271 | R"==(S1[_i - 8] = AS_SRC_MMAD_DATA_T( )==" "\n" |
272 | R"==(intel_sub_group_block_read((__global uint )==" "\n" |
273 | R"==(*)&src[_i * SW * IC_BLOCK])); )==" "\n" |
274 | R"==(} )==" "\n" |
275 | R"==(} )==" "\n" |
276 | R"==(#endif )==" "\n" |
277 | R"==(} else )==" "\n" |
278 | R"==(#endif )==" "\n" |
279 | R"==({ )==" "\n" |
280 | R"==(BLOCK_READ_SRC(S0, 0 * IC_BLOCK, 0); )==" "\n" |
281 | R"==(#if (MB_BLOCK == 32 && MB > 8) )==" "\n" |
282 | R"==(BLOCK_READ_SRC1(S1, 8 * IC_BLOCK, 0); )==" "\n" |
283 | R"==(#elif SP_BLOCK > 8 )==" "\n" |
284 | R"==(BLOCK_READ_SRC1(S1, 8 * SW * IC_BLOCK, 8); )==" "\n" |
285 | R"==(#endif )==" "\n" |
286 | R"==(} )==" "\n" |
287 | R"==(int8 W0 = 0, W1 = 0, W2 = 0, W3 = 0; )==" "\n" |
288 | R"==(#if IC % IC_BLOCK != 0 )==" "\n" |
289 | R"==(if (ic_block_id == IC_NCHUNK - 1) { )==" "\n" |
290 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
291 | R"==(BLOCK_READ_WHT_1x32(W0[i], (i + 0) * IC_BLOCK); )==" "\n" |
292 | R"==(if (OC > 8) )==" "\n" |
293 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
294 | R"==(BLOCK_READ_WHT_1x32(W1[i], (i + 8) * IC_BLOCK); )==" "\n" |
295 | R"==(if (OC > 16) )==" "\n" |
296 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
297 | R"==(BLOCK_READ_WHT_1x32(W2[i], (i + 16) * IC_BLOCK); )==" "\n" |
298 | R"==(if (OC > 24) )==" "\n" |
299 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
300 | R"==(BLOCK_READ_WHT_1x32(W3[i], (i + 24) * IC_BLOCK); )==" "\n" |
301 | R"==(C00 = MMAD_TAIL0(S0, W0, C00); )==" "\n" |
302 | R"==(if (OC > 8) C01 = MMAD_TAIL0(S0, W1, C01); )==" "\n" |
303 | R"==(if (OC > 16) C02 = MMAD_TAIL0(S0, W2, C02); )==" "\n" |
304 | R"==(if (OC > 24) C03 = MMAD_TAIL0(S0, W3, C03); )==" "\n" |
305 | R"==(#if (MB_BLOCK == 32 && MB > 8) || SP_BLOCK > 8 )==" "\n" |
306 | R"==(C10 = MMAD_TAIL1(S1, W0, C10); )==" "\n" |
307 | R"==(if (OC > 8) C11 = MMAD_TAIL1(S1, W1, C11); )==" "\n" |
308 | R"==(if (OC > 16) C12 = MMAD_TAIL1(S1, W2, C12); )==" "\n" |
309 | R"==(if (OC > 24) C13 = MMAD_TAIL1(S1, W3, C13); )==" "\n" |
310 | R"==(#endif )==" "\n" |
311 | R"==(} else )==" "\n" |
312 | R"==(#endif )==" "\n" |
313 | R"==({ )==" "\n" |
314 | R"==(BLOCK_READ_WHT_8x32(W0, 0); )==" "\n" |
315 | R"==(if (OC > 8) BLOCK_READ_WHT_8x32(W1, 8 * IC_BLOCK); )==" "\n" |
316 | R"==(if (OC > 16) BLOCK_READ_WHT_8x32(W2, 16 * IC_BLOCK); )==" "\n" |
317 | R"==(if (OC > 24) BLOCK_READ_WHT_8x32(W3, 24 * IC_BLOCK); )==" "\n" |
318 | R"==(C00 = MMAD_FULL0(S0, W0, C00); )==" "\n" |
319 | R"==(if (OC > 8) C01 = MMAD_FULL0(S0, W1, C01); )==" "\n" |
320 | R"==(if (OC > 16) C02 = MMAD_FULL0(S0, W2, C02); )==" "\n" |
321 | R"==(if (OC > 24) C03 = MMAD_FULL0(S0, W3, C03); )==" "\n" |
322 | R"==(#if (MB_BLOCK == 32 && MB > 8) || SP_BLOCK > 8 )==" "\n" |
323 | R"==(C10 = MMAD_FULL1(S1, W0, C10); )==" "\n" |
324 | R"==(if (OC > 8) C11 = MMAD_FULL1(S1, W1, C11); )==" "\n" |
325 | R"==(if (OC > 16) C12 = MMAD_FULL1(S1, W2, C12); )==" "\n" |
326 | R"==(if (OC > 24) C13 = MMAD_FULL1(S1, W3, C13); )==" "\n" |
327 | R"==(#endif )==" "\n" |
328 | R"==(} )==" "\n" |
329 | R"==(} )==" "\n" |
330 | R"==(src += SRC_ICB_STRIDE; )==" "\n" |
331 | R"==(wei += WEI_BLOCK_STRIDE; )==" "\n" |
332 | R"==(} )==" "\n" |
333 | R"==(#if WITH_SRC_ZPOINTS )==" "\n" |
334 | R"==(int4 src_comp = as_int4(intel_sub_group_block_read4( )==" "\n" |
335 | R"==((__global uint *)(&src_compensation[oc_group_id * OC_BLOCK]))); )==" "\n" |
336 | R"==(C00 -= src_comp.s0; )==" "\n" |
337 | R"==(C01 -= src_comp.s1; )==" "\n" |
338 | R"==(C02 -= src_comp.s2; )==" "\n" |
339 | R"==(C03 -= src_comp.s3; )==" "\n" |
340 | R"==(#if (MB_BLOCK == 32 && MB > 8) || SP_BLOCK > 8 )==" "\n" |
341 | R"==(C10 -= src_comp.s0; )==" "\n" |
342 | R"==(C11 -= src_comp.s1; )==" "\n" |
343 | R"==(C12 -= src_comp.s2; )==" "\n" |
344 | R"==(C13 -= src_comp.s3; )==" "\n" |
345 | R"==(#endif )==" "\n" |
346 | R"==(#endif )==" "\n" |
347 | R"==(float4 tmp; )==" "\n" |
348 | R"==(DST_DATA4_T dst_pack[8]; )==" "\n" |
349 | R"==(DST_DATA4_T D0[BLOCK0] = {0}; )==" "\n" |
350 | R"==(DST_DATA4_T D1[BLOCK1] = {0}; )==" "\n" |
351 | R"==(#if SCALES_PER_OC )==" "\n" |
352 | R"==(float4 scales; )==" "\n" |
353 | R"==(block_read_scales( )==" "\n" |
354 | R"==(&scales, oc_group_id * OC_BLOCK, sg_local_id, runtime_scales); )==" "\n" |
355 | R"==(#endif )==" "\n" |
356 | R"==(#if WITH_BIAS )==" "\n" |
357 | R"==(float4 bia; )==" "\n" |
358 | R"==(BLOCK_READ_BIA(bia, oc_group_id * OC_BLOCK); )==" "\n" |
359 | R"==(#define QUANTIZE_ADD_BIAS() tmp = SCALE * fma(tmp, (float4)1, bia); )==" "\n" |
360 | R"==(#else )==" "\n" |
361 | R"==(#define QUANTIZE_ADD_BIAS() tmp *= SCALE; )==" "\n" |
362 | R"==(#endif )==" "\n" |
363 | R"==(#if WITH_SUM )==" "\n" |
364 | R"==(#if USE_SP_BLOCK )==" "\n" |
365 | R"==(if (OUT_SP_TAIL && od * OH * OW + oh * OW + ow + SP_BLOCK > DST_SP) { )==" "\n" |
366 | R"==(#else )==" "\n" |
367 | R"==(if (OUT_SP_TAIL && ow + SP_BLOCK > OW) { )==" "\n" |
368 | R"==(#endif )==" "\n" |
369 | R"==(#if OUT_SP_TAIL < 8 )==" "\n" |
370 | R"==(block_read_dst(OUT_SP_TAIL, D0, dst); )==" "\n" |
371 | R"==(#else )==" "\n" |
372 | R"==(block_read_dst(BLOCK0, D0, dst); )==" "\n" |
373 | R"==(block_read_dst(OUT_SP_TAIL - 8, D1, dst + 8 * OC_BLOCK); )==" "\n" |
374 | R"==(#endif )==" "\n" |
375 | R"==(} else { )==" "\n" |
376 | R"==(block_read_dst(BLOCK0, D0, dst); )==" "\n" |
377 | R"==(if (SP_BLOCK > 8 || (MB_BLOCK == 32 && MB > 8)) { )==" "\n" |
378 | R"==(block_read_dst(BLOCK1, D1, dst + 8 * OC_BLOCK); )==" "\n" |
379 | R"==(} )==" "\n" |
380 | R"==(} )==" "\n" |
381 | R"==(#endif )==" "\n" |
382 | R"==(#if WITH_DST_ZPOINTS )==" "\n" |
383 | R"==(int4 dst_zp = read_dst_zero_points_32c( )==" "\n" |
384 | R"==(dst_compensation, oc_group_id * OC_BLOCK); )==" "\n" |
385 | R"==(#if !WITH_DST_ZPOINTS_PER_OC && OC % 32 != 0 )==" "\n" |
386 | R"==(dst_zp = convert_int4( )==" "\n" |
387 | R"==(zero_pad_dst_32c(convert_float4(dst_zp), oc_group_id * OC_BLOCK)); )==" "\n" |
388 | R"==(#endif )==" "\n" |
389 | R"==(#define ADD_DST_COMPENSATION() tmp += convert_float4(dst_zp); )==" "\n" |
390 | R"==(#else )==" "\n" |
391 | R"==(#define ADD_DST_COMPENSATION() )==" "\n" |
392 | R"==(#endif )==" "\n" |
393 | R"==(#if WITH_SRC_ZPOINTS )==" "\n" |
394 | R"==(#define ZERO_PAD_DST() tmp = zero_pad_dst_32c(tmp, oc_group_id * OC_BLOCK); )==" "\n" |
395 | R"==(#else )==" "\n" |
396 | R"==(#define ZERO_PAD_DST() )==" "\n" |
397 | R"==(#endif )==" "\n" |
398 | R"==(#define PACK(C0, C1, C2, C3, idx) \ )==" "\n" |
399 | R"==(do { \ )==" "\n" |
400 | R"==(tmp[0] = C0[idx]; \ )==" "\n" |
401 | R"==(tmp[1] = C1[idx]; \ )==" "\n" |
402 | R"==(tmp[2] = C2[idx]; \ )==" "\n" |
403 | R"==(tmp[3] = C3[idx]; \ )==" "\n" |
404 | R"==(} while (0) )==" "\n" |
405 | R"==(#define CONVERT_PACK(idx) \ )==" "\n" |
406 | R"==(do { \ )==" "\n" |
407 | R"==(dst_pack[idx] = CONVERT_DST_DATA4_T(tmp); \ )==" "\n" |
408 | R"==(} while (0) )==" "\n" |
409 | R"==(#define STORE_DST(n, C0, C1, C2, C3, D, dst_ptr, mb_stride) \ )==" "\n" |
410 | R"==(do { \ )==" "\n" |
411 | R"==(for (int n_i = 0; n_i < n; n_i++) { \ )==" "\n" |
412 | R"==(PACK(C0, C1, C2, C3, n_i); \ )==" "\n" |
413 | R"==(int po_mb; \ )==" "\n" |
414 | R"==(if (MB_BLOCK == 32) \ )==" "\n" |
415 | R"==(po_mb = (mb_group_id * MB_BLOCK / 2 + mb_stride * 8 + n_i); \ )==" "\n" |
416 | R"==(else \ )==" "\n" |
417 | R"==(po_mb = mb_group_id % MB; \ )==" "\n" |
418 | R"==(if (MB % MB_BLOCK == 0 || po_mb < MB) { \ )==" "\n" |
419 | R"==(QUANTIZE_ADD_BIAS(); \ )==" "\n" |
420 | R"==(const int po_oc = (oc_group_id * OC_BLOCK) % (OC * G); \ )==" "\n" |
421 | R"==(float4 dni = convert_float4(AS_SUM_DATA4_T(D[n_i])); \ )==" "\n" |
422 | R"==(APPLY_POST_OPS_TRY_BURST(tmp, float, dni, float, po_mb, 1, \ )==" "\n" |
423 | R"==(po_oc, 4 * SUB_GROUP_SIZE, sg_local_id); \ )==" "\n" |
424 | R"==(ADD_DST_COMPENSATION(); \ )==" "\n" |
425 | R"==(ZERO_PAD_DST(); \ )==" "\n" |
426 | R"==(} \ )==" "\n" |
427 | R"==(CONVERT_PACK(n_i); \ )==" "\n" |
428 | R"==(} \ )==" "\n" |
429 | R"==(block_write_dst(n, dst_pack, dst_ptr); \ )==" "\n" |
430 | R"==(} while (0) )==" "\n" |
431 | R"==(#if INT8_WEI_SLM && SP_TAIL )==" "\n" |
432 | R"==(if (ow < OW) )==" "\n" |
433 | R"==(#endif )==" "\n" |
434 | R"==({ )==" "\n" |
435 | R"==(#if USE_SP_BLOCK )==" "\n" |
436 | R"==(if (OUT_SP_TAIL && od * OH * OW + oh * OW + ow + SP_BLOCK > DST_SP) { )==" "\n" |
437 | R"==(#else )==" "\n" |
438 | R"==(if (OUT_SP_TAIL && ow + SP_BLOCK > OW) { )==" "\n" |
439 | R"==(#endif )==" "\n" |
440 | R"==(STORE_DST(min(BLOCK0, OUT_SP_TAIL), C00, C01, C02, C03, D0, dst, 0); )==" "\n" |
441 | R"==(STORE_DST(OUT_SP_TAIL - 8, C10, C11, C12, C13, D1, )==" "\n" |
442 | R"==(dst + 8 * OC_BLOCK, 1); )==" "\n" |
443 | R"==(} else { )==" "\n" |
444 | R"==(STORE_DST(BLOCK0, C00, C01, C02, C03, D0, dst, 0); )==" "\n" |
445 | R"==(if (SP_BLOCK > 8 || MB_BLOCK == 32) )==" "\n" |
446 | R"==(STORE_DST( )==" "\n" |
447 | R"==(BLOCK1, C10, C11, C12, C13, D1, dst + 8 * OC_BLOCK, 1); )==" "\n" |
448 | R"==(} )==" "\n" |
449 | R"==(} )==" "\n" |
450 | R"==(} )==" "\n" |
451 | R"==(void block_read_dst(int n, DST_DATA_T *d, const __global DST_DATA_T *dst) { )==" "\n" |
452 | R"==(int nelems = n * 4; )==" "\n" |
453 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
454 | R"==(for (int i = 0; i < nelems / 16 * 16; i += 16) { )==" "\n" |
455 | R"==(*((DST_DATA16_T *)&d[i]) = BLOCK_READ_DST16(dst + i * 8); )==" "\n" |
456 | R"==(} )==" "\n" |
457 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
458 | R"==(for (int i = nelems / 16 * 16; i < nelems / 8 * 8; i += 8) { )==" "\n" |
459 | R"==(*((DST_DATA8_T *)&d[i]) = BLOCK_READ_DST8(dst + i * 8); )==" "\n" |
460 | R"==(} )==" "\n" |
461 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
462 | R"==(for (int i = nelems / 8 * 8; i < nelems; i += 4) { )==" "\n" |
463 | R"==(*((DST_DATA4_T *)&d[i]) = BLOCK_READ_DST4(dst + i * 8); )==" "\n" |
464 | R"==(} )==" "\n" |
465 | R"==(} )==" "\n" |
466 | R"==(void block_write_dst(int n, const DST_DATA_T *d, __global DST_DATA_T *dst) { )==" "\n" |
467 | R"==(int nelems = n * 4; )==" "\n" |
468 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
469 | R"==(for (int i = 0; i < nelems / 16 * 16; i += 16) { )==" "\n" |
470 | R"==(BLOCK_WRITE_DST16(dst + i * 8, *((DST_DATA16_T *)&d[i])); )==" "\n" |
471 | R"==(} )==" "\n" |
472 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
473 | R"==(for (int i = nelems / 16 * 16; i < nelems / 8 * 8; i += 8) { )==" "\n" |
474 | R"==(BLOCK_WRITE_DST8(dst + i * 8, *((DST_DATA8_T *)&d[i])); )==" "\n" |
475 | R"==(} )==" "\n" |
476 | R"==(__attribute__((opencl_unroll_hint)) )==" "\n" |
477 | R"==(for (int i = nelems / 8 * 8; i < nelems; i += 4) { )==" "\n" |
478 | R"==(BLOCK_WRITE_DST4(dst + i * 8, *((DST_DATA4_T *)&d[i])); )==" "\n" |
479 | R"==(} )==" "\n" |
480 | R"==(} )==" "\n" |
481 | R"==()==" ; |
482 | } |
483 | } |
484 | } |
485 | } |