1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *xe_lp_conv_fwd_data_ow_block_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_types.h" )==" "\n" |
23 | R"==(#include "gpu/ocl/ocl_zero_points.h" )==" "\n" |
24 | R"==(#if IC % IC_BLOCK != 0 )==" "\n" |
25 | R"==(#define IC_NBLOCKS_TAIL ((IC - (IC & ~(IC_BLOCK - 1)) + 3) / 4) )==" "\n" |
26 | R"==(#else )==" "\n" |
27 | R"==(#define IC_NBLOCKS_TAIL 8 )==" "\n" |
28 | R"==(#endif )==" "\n" |
29 | R"==(#if OW_BLOCK == 4 )==" "\n" |
30 | R"==(#define BLOCK 4 )==" "\n" |
31 | R"==(#define ACC_DATA_BLOCK int4 )==" "\n" |
32 | R"==(#define SRC_DATA_BLOCK_T SRC_MMAD_DATA4_T )==" "\n" |
33 | R"==(#define READ_BLOCK intel_sub_group_block_read4 )==" "\n" |
34 | R"==(#define WRITE_LOCAL block_write4 )==" "\n" |
35 | R"==(DECLARE_MMAD_EMU(mmad_tail, idot4, IC_NBLOCKS_TAIL, 4, SRC_DATA_BLOCK_T, int8, )==" "\n" |
36 | R"==(ACC_DATA_BLOCK) )==" "\n" |
37 | R"==(#define MMAD_FULL mmad8x4 )==" "\n" |
38 | R"==(#define MMAD_TAIL mmad_tail )==" "\n" |
39 | R"==(#else )==" "\n" |
40 | R"==(#define BLOCK 8 )==" "\n" |
41 | R"==(#define ACC_DATA_BLOCK int8 )==" "\n" |
42 | R"==(#define SRC_DATA_BLOCK_T SRC_MMAD_DATA8_T )==" "\n" |
43 | R"==(#define READ_BLOCK intel_sub_group_block_read8 )==" "\n" |
44 | R"==(#define WRITE_LOCAL block_write8 )==" "\n" |
45 | R"==(DECLARE_MMAD_EMU(mmad_tail, idot4, IC_NBLOCKS_TAIL, 8, SRC_DATA_BLOCK_T, int8, )==" "\n" |
46 | R"==(ACC_DATA_BLOCK) )==" "\n" |
47 | R"==(#define MMAD_FULL mmad8x8 )==" "\n" |
48 | R"==(#define MMAD_TAIL mmad_tail )==" "\n" |
49 | R"==(#endif )==" "\n" |
50 | R"==(#define BLOCK_READ_SRC(data, idx) \ )==" "\n" |
51 | R"==(data = intel_sub_group_block_read8((__global uint *)&src[idx]); )==" "\n" |
52 | R"==(#define BLOCK_READ_WHT_1x32(data, idx) \ )==" "\n" |
53 | R"==(data = as_int(intel_sub_group_block_read((__global uint *)&wei[idx])); )==" "\n" |
54 | R"==(#define BLOCK_READ_WHT_8x32(data, idx) \ )==" "\n" |
55 | R"==(data = as_int8(intel_sub_group_block_read8((__global uint *)&wei[idx])); )==" "\n" |
56 | R"==(#if OC % OC_BLOCK == 0 )==" "\n" |
57 | R"==(#define BLOCK_READ_BIA(data, idx) \ )==" "\n" |
58 | R"==(data = as_float4(intel_sub_group_block_read4((__global uint *)&bias[idx])); )==" "\n" |
59 | R"==(#else )==" "\n" |
60 | R"==(#define BLOCK_READ_BIA(data, idx) \ )==" "\n" |
61 | R"==(data = (float4)0; \ )==" "\n" |
62 | R"==(int i; \ )==" "\n" |
63 | R"==(for (i = idx; i < idx + OC_BLOCK && i < OC - (OC % SUB_GROUP_SIZE); \ )==" "\n" |
64 | R"==(i += SUB_GROUP_SIZE) { \ )==" "\n" |
65 | R"==(data[(i - idx) / SUB_GROUP_SIZE] = as_float( \ )==" "\n" |
66 | R"==(intel_sub_group_block_read((__global uint *)&bias[i])); \ )==" "\n" |
67 | R"==(} \ )==" "\n" |
68 | R"==(if ((get_sub_group_local_id() < OC % SUB_GROUP_SIZE) && i < OC \ )==" "\n" |
69 | R"==(&& (i - idx) / SUB_GROUP_SIZE < 4) { \ )==" "\n" |
70 | R"==(data[(i - idx) / SUB_GROUP_SIZE] \ )==" "\n" |
71 | R"==(= as_float(bias[i + get_sub_group_local_id()]); \ )==" "\n" |
72 | R"==(} )==" "\n" |
73 | R"==(#endif )==" "\n" |
74 | R"==(#define BLOCK_READ_SCALES(data, idx) \ )==" "\n" |
75 | R"==(if (OC >= idx + (SUB_GROUP_SIZE * 4)) { \ )==" "\n" |
76 | R"==(data = as_float4(intel_sub_group_block_read4( \ )==" "\n" |
77 | R"==((__global uint *)&runtime_scales[idx])); \ )==" "\n" |
78 | R"==(} else { \ )==" "\n" |
79 | R"==(float local_dat[4] = {}; \ )==" "\n" |
80 | R"==(for (int i = 0; i < 4; ++i) \ )==" "\n" |
81 | R"==(if (idx + ((i + 1) * SUB_GROUP_SIZE) <= OC) { \ )==" "\n" |
82 | R"==(local_dat[i] = as_float(intel_sub_group_block_read( \ )==" "\n" |
83 | R"==((__global uint *)&runtime_scales[idx \ )==" "\n" |
84 | R"==(+ (SUB_GROUP_SIZE * i)])); \ )==" "\n" |
85 | R"==(} else if (idx + (i * SUB_GROUP_SIZE) + subg_local_id < OC) { \ )==" "\n" |
86 | R"==(local_dat[i] = runtime_scales[idx + (SUB_GROUP_SIZE * i) \ )==" "\n" |
87 | R"==(+ subg_local_id]; \ )==" "\n" |
88 | R"==(} \ )==" "\n" |
89 | R"==(data.s0 = local_dat[0]; \ )==" "\n" |
90 | R"==(data.s1 = local_dat[1]; \ )==" "\n" |
91 | R"==(data.s2 = local_dat[2]; \ )==" "\n" |
92 | R"==(data.s3 = local_dat[3]; \ )==" "\n" |
93 | R"==(} )==" "\n" |
94 | R"==(#if SCALES_PER_OC )==" "\n" |
95 | R"==(#define SCALE scales )==" "\n" |
96 | R"==(#elif SCALES_COMMON )==" "\n" |
97 | R"==(#define SCALE runtime_scales[0] )==" "\n" |
98 | R"==(#else )==" "\n" |
99 | R"==(#define SCALE 1 )==" "\n" |
100 | R"==(#endif )==" "\n" |
101 | R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) )==" "\n" |
102 | R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) __kernel void )==" "\n" |
103 | R"==(conv_fwd_ow_block_x8s8x(const __global SRC_DATA_T *src, )==" "\n" |
104 | R"==(const __global char *wei, const __global float *bias, )==" "\n" |
105 | R"==(__global DATA_T *dst POST_OP_ARGS, const __global float *runtime_scales, )==" "\n" |
106 | R"==(const __global int *src_compensation, const __global int *src_zpoints, )==" "\n" |
107 | R"==(const __global int *dst_compensation) { )==" "\n" |
108 | R"==(const int group_oc = get_group_id(0) * OC_GROUP; )==" "\n" |
109 | R"==(const int group_mb = get_group_id(2) * MB_GROUP; )==" "\n" |
110 | R"==(const int group_sp = get_group_id(1) * SP_GROUP; )==" "\n" |
111 | R"==(const int sub_group_id = get_sub_group_id(); )==" "\n" |
112 | R"==(const int subg_local_id = get_sub_group_local_id(); )==" "\n" |
113 | R"==(const int oc = (sub_group_id % OC_GROUP); )==" "\n" |
114 | R"==(const int sp = (sub_group_id / OC_GROUP); )==" "\n" |
115 | R"==(const int g = (group_oc + oc) / OC_NCHUNK; )==" "\n" |
116 | R"==(const int group_ic = IC_NCHUNK * g; )==" "\n" |
117 | R"==(const int god = group_sp / (OW_PADDED * OH); )==" "\n" |
118 | R"==(const int gohw = group_sp % (OW_PADDED * OH); )==" "\n" |
119 | R"==(const int goh = gohw / OW_PADDED; )==" "\n" |
120 | R"==(const int gow = OW_BLOCK * (gohw % OW_PADDED); )==" "\n" |
121 | R"==(const int gid = god * SD; )==" "\n" |
122 | R"==(const int gih = goh * SH; )==" "\n" |
123 | R"==(const int giw = gow * SW; )==" "\n" |
124 | R"==(const int local_ow = OW_BLOCK * sp; )==" "\n" |
125 | R"==(const int local_iw = local_ow * SW; )==" "\n" |
126 | R"==(const int od = god; )==" "\n" |
127 | R"==(const int ow = gow + local_ow; )==" "\n" |
128 | R"==(const int oh = goh; )==" "\n" |
129 | R"==(const int id = gid - PD; )==" "\n" |
130 | R"==(const int iw = giw + local_iw - PW; )==" "\n" |
131 | R"==(const int ih = gih - PH; )==" "\n" |
132 | R"==(__local uint S_slice[SRC_SLM_SIZE]; )==" "\n" |
133 | R"==(__local uint *S_part = S_slice + IC_BLOCK / 4 * (sp * SW * OW_BLOCK + PW); )==" "\n" |
134 | R"==(__local uint *S_work = S_slice + IC_BLOCK / 4 * (sp * SW * OW_BLOCK); )==" "\n" |
135 | R"==(const bool left_tail = iw < 0; )==" "\n" |
136 | R"==(const bool left_nozero_tail = sub_group_id == 0 && iw > -PW; )==" "\n" |
137 | R"==(const bool right_tail = (iw + PW + SLM_TAIL >= IW) && (iw + PW < IW); )==" "\n" |
138 | R"==(const bool right_nozero_tail )==" "\n" |
139 | R"==(= sp == (LWS_1 - 1) && (iw + PW + SLM_TAIL < IW); )==" "\n" |
140 | R"==(const bool empty = (iw + PW >= IW); )==" "\n" |
141 | R"==(dst += OC_BLOCK * OD * OH * OW * MB_BLOCK * (group_oc + oc); )==" "\n" |
142 | R"==(dst += OC_BLOCK * OD * OH * OW * OC_NCHUNK * G * MB_BLOCK * group_mb; )==" "\n" |
143 | R"==(dst += OC_BLOCK * MB_BLOCK * (OW * OH * od + OW * oh + ow); )==" "\n" |
144 | R"==(src += IC_BLOCK * ID * IH * IW * MB_BLOCK * group_ic; )==" "\n" |
145 | R"==(src += IC_BLOCK * ID * IH * IW * IC_NCHUNK * G * MB_BLOCK * group_mb; )==" "\n" |
146 | R"==(src += IC_BLOCK * MB_BLOCK * (IW * IH * id + IW * ih + iw + PW); )==" "\n" |
147 | R"==(wei += IC_BLOCK * KD * KH * KW * OC_BLOCK * (group_oc + oc) * IC_NCHUNK; )==" "\n" |
148 | R"==(/* Prepare S_slice tails */ )==" "\n" |
149 | R"==(#if PW > 0 )==" "\n" |
150 | R"==(if (left_tail) { )==" "\n" |
151 | R"==(for (int i = 0; i < PW; i++) { )==" "\n" |
152 | R"==(block_write(S_slice + i * 8, 0); )==" "\n" |
153 | R"==(} )==" "\n" |
154 | R"==(} )==" "\n" |
155 | R"==(#endif )==" "\n" |
156 | R"==(#if ZERO_TAIL > 0 )==" "\n" |
157 | R"==(if (right_tail) { )==" "\n" |
158 | R"==(for (int i = SLM_TAIL; i < SW * OW_BLOCK + (KW - 1) * (1 + DW) - PW; )==" "\n" |
159 | R"==(i++) { )==" "\n" |
160 | R"==(block_write(S_part + i * 8, 0); )==" "\n" |
161 | R"==(} )==" "\n" |
162 | R"==(} )==" "\n" |
163 | R"==(#if SLM_NCHUNK < OW_NCHUNK )==" "\n" |
164 | R"==(if (empty) { )==" "\n" |
165 | R"==(for (int i = -PW; i < SW * OW_BLOCK + (KW - 1) * (1 + DW) - PW; i++) { )==" "\n" |
166 | R"==(block_write(S_part + i * 8, 0); )==" "\n" |
167 | R"==(} )==" "\n" |
168 | R"==(} )==" "\n" |
169 | R"==(#endif )==" "\n" |
170 | R"==(#endif )==" "\n" |
171 | R"==(ACC_DATA_BLOCK C00 = 0, C01 = 0, C02 = 0, C03 = 0; )==" "\n" |
172 | R"==(for (int ic_chunk = 0; ic_chunk < IC_NCHUNK; ic_chunk++) { )==" "\n" |
173 | R"==(SRC_DATA_BLOCK_T S0; )==" "\n" |
174 | R"==(for (int kd = 0; kd < KD; kd++) { )==" "\n" |
175 | R"==(if (kd * (1 + DD) + id < 0 || kd * (1 + DD) + id >= ID) { )==" "\n" |
176 | R"==(src += IC_BLOCK * MB_BLOCK * IH * IW * (1 + DD); )==" "\n" |
177 | R"==(wei += IC_BLOCK * OC_BLOCK * KH * KW; )==" "\n" |
178 | R"==(continue; )==" "\n" |
179 | R"==(} )==" "\n" |
180 | R"==(for (int kh = 0; kh < KH; kh++) { )==" "\n" |
181 | R"==(if (kh * (1 + DH) + ih < 0 || kh * (1 + DH) + ih >= IH) { )==" "\n" |
182 | R"==(src += IC_BLOCK * MB_BLOCK * IW * (1 + DH); )==" "\n" |
183 | R"==(wei += IC_BLOCK * OC_BLOCK * KW; )==" "\n" |
184 | R"==(continue; )==" "\n" |
185 | R"==(} )==" "\n" |
186 | R"==(barrier(CLK_LOCAL_MEM_FENCE); )==" "\n" |
187 | R"==(#if SLM_NCHUNK < OW_NCHUNK )==" "\n" |
188 | R"==(if (iw + PW < IW) { )==" "\n" |
189 | R"==(#endif )==" "\n" |
190 | R"==(#if OW_NCHUNK > LWS_1 )==" "\n" |
191 | R"==(/* Copy tails in case of multigroups */ )==" "\n" |
192 | R"==(if (ow < OW) { )==" "\n" |
193 | R"==(#if PW > 0 )==" "\n" |
194 | R"==(if (left_nozero_tail) { )==" "\n" |
195 | R"==(for (int i = -PW - min(iw, 0); i < 0; i++) { )==" "\n" |
196 | R"==(block_write(S_part + i * 8, )==" "\n" |
197 | R"==(intel_sub_group_block_read( )==" "\n" |
198 | R"==((const __global uint *)(&src[i )==" "\n" |
199 | R"==(* IC_BLOCK]))); )==" "\n" |
200 | R"==(} )==" "\n" |
201 | R"==(} )==" "\n" |
202 | R"==(#endif )==" "\n" |
203 | R"==(if (right_nozero_tail) { )==" "\n" |
204 | R"==(int buffer_last = (KW - 1) * (1 + DW) - PW; )==" "\n" |
205 | R"==(int src_last = IW - iw - SW * OW_BLOCK - PW; )==" "\n" |
206 | R"==(for (int i = SW * OW_BLOCK; i < SW * OW_BLOCK )==" "\n" |
207 | R"==(+ min(buffer_last, src_last); )==" "\n" |
208 | R"==(i++) { )==" "\n" |
209 | R"==(block_write(S_part + i * 8, )==" "\n" |
210 | R"==(intel_sub_group_block_read( )==" "\n" |
211 | R"==((const __global uint *)(&src[i )==" "\n" |
212 | R"==(* IC_BLOCK]))); )==" "\n" |
213 | R"==(} )==" "\n" |
214 | R"==(for (int i = SW * OW_BLOCK )==" "\n" |
215 | R"==(+ min(buffer_last, src_last); )==" "\n" |
216 | R"==(i < SW * OW_BLOCK + buffer_last; i++) { )==" "\n" |
217 | R"==(block_write(S_part + i * 8, 0); )==" "\n" |
218 | R"==(} )==" "\n" |
219 | R"==(} )==" "\n" |
220 | R"==(#endif )==" "\n" |
221 | R"==(#if SLM_TAIL != OW_BLOCK * SW )==" "\n" |
222 | R"==(/* Copy last block to SLM */ )==" "\n" |
223 | R"==(if (right_tail) { )==" "\n" |
224 | R"==(__attribute__((opencl_unroll_hint)) for (int i = 0; )==" "\n" |
225 | R"==(i )==" "\n" |
226 | R"==(< SLM_TAIL; )==" "\n" |
227 | R"==(i++) { )==" "\n" |
228 | R"==(block_write(S_part + i * 8, )==" "\n" |
229 | R"==(intel_sub_group_block_read( )==" "\n" |
230 | R"==((const __global uint *)(&src[i )==" "\n" |
231 | R"==(* IC_BLOCK]))); )==" "\n" |
232 | R"==(} )==" "\n" |
233 | R"==(} else { )==" "\n" |
234 | R"==(#endif )==" "\n" |
235 | R"==(/* Copy block to SLM */ )==" "\n" |
236 | R"==(__attribute__(( )==" "\n" |
237 | R"==(opencl_unroll_hint)) for (int i = 0; )==" "\n" |
238 | R"==(i < SW * OW_BLOCK; )==" "\n" |
239 | R"==(i += OW_BLOCK) { )==" "\n" |
240 | R"==(WRITE_LOCAL(S_part + i * 8, )==" "\n" |
241 | R"==(READ_BLOCK( )==" "\n" |
242 | R"==((const __global uint *)(&src[i )==" "\n" |
243 | R"==(* IC_BLOCK]))); )==" "\n" |
244 | R"==(} )==" "\n" |
245 | R"==(#if SLM_TAIL != OW_BLOCK * SW )==" "\n" |
246 | R"==(} )==" "\n" |
247 | R"==(#endif )==" "\n" |
248 | R"==(#if OW_NCHUNK > LWS_1 )==" "\n" |
249 | R"==(} )==" "\n" |
250 | R"==(#endif )==" "\n" |
251 | R"==(#if SLM_NCHUNK < OW_NCHUNK )==" "\n" |
252 | R"==(} )==" "\n" |
253 | R"==(#endif )==" "\n" |
254 | R"==(barrier(CLK_LOCAL_MEM_FENCE); )==" "\n" |
255 | R"==(for (int kw = 0; kw < KW; kw++) { )==" "\n" |
256 | R"==(unroll_for(int i = 0; i < OW_BLOCK; i++) { )==" "\n" |
257 | R"==(S0[i] = block_read( )==" "\n" |
258 | R"==(S_work + (kw * (1 + DW) + SW * i) * 8); )==" "\n" |
259 | R"==(} )==" "\n" |
260 | R"==(int8 W0 = 0, W1 = 0, W2 = 0, W3 = 0; )==" "\n" |
261 | R"==(#if IC % IC_BLOCK != 0 )==" "\n" |
262 | R"==(if (ic_chunk == IC_NCHUNK - 1) { )==" "\n" |
263 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
264 | R"==(BLOCK_READ_WHT_1x32(W0[i], (i + 0) * IC_BLOCK); )==" "\n" |
265 | R"==(if (OC > 8) )==" "\n" |
266 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
267 | R"==(BLOCK_READ_WHT_1x32( )==" "\n" |
268 | R"==(W1[i], (i + 8) * IC_BLOCK); )==" "\n" |
269 | R"==(if (OC > 16) )==" "\n" |
270 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
271 | R"==(BLOCK_READ_WHT_1x32( )==" "\n" |
272 | R"==(W2[i], (i + 16) * IC_BLOCK); )==" "\n" |
273 | R"==(if (OC > 24) )==" "\n" |
274 | R"==(unroll_for(int i = 0; i < IC_NBLOCKS_TAIL; ++i) )==" "\n" |
275 | R"==(BLOCK_READ_WHT_1x32( )==" "\n" |
276 | R"==(W3[i], (i + 24) * IC_BLOCK); )==" "\n" |
277 | R"==(C00 = MMAD_TAIL(S0, W0, C00); )==" "\n" |
278 | R"==(if (OC > 8) C01 = MMAD_TAIL(S0, W1, C01); )==" "\n" |
279 | R"==(if (OC > 16) C02 = MMAD_TAIL(S0, W2, C02); )==" "\n" |
280 | R"==(if (OC > 24) C03 = MMAD_TAIL(S0, W3, C03); )==" "\n" |
281 | R"==(} else )==" "\n" |
282 | R"==(#endif )==" "\n" |
283 | R"==({ )==" "\n" |
284 | R"==(BLOCK_READ_WHT_8x32(W0, 0); )==" "\n" |
285 | R"==(if (OC > 8) BLOCK_READ_WHT_8x32(W1, 8 * IC_BLOCK); )==" "\n" |
286 | R"==(if (OC > 16) BLOCK_READ_WHT_8x32(W2, 16 * IC_BLOCK); )==" "\n" |
287 | R"==(if (OC > 24) BLOCK_READ_WHT_8x32(W3, 24 * IC_BLOCK); )==" "\n" |
288 | R"==(C00 = MMAD_FULL(S0, W0, C00); )==" "\n" |
289 | R"==(if (OC > 8) C01 = MMAD_FULL(S0, W1, C01); )==" "\n" |
290 | R"==(if (OC > 16) C02 = MMAD_FULL(S0, W2, C02); )==" "\n" |
291 | R"==(if (OC > 24) C03 = MMAD_FULL(S0, W3, C03); )==" "\n" |
292 | R"==(} )==" "\n" |
293 | R"==(wei += IC_BLOCK * OC_BLOCK; )==" "\n" |
294 | R"==(} )==" "\n" |
295 | R"==(src += IC_BLOCK * MB_BLOCK * IW * (1 + DH); )==" "\n" |
296 | R"==(} )==" "\n" |
297 | R"==(src += IC_BLOCK * MB_BLOCK * (IH * (1 + DD) - KH * (1 + DH)) * IW; )==" "\n" |
298 | R"==(} )==" "\n" |
299 | R"==(src += IC_BLOCK * MB_BLOCK * (ID - KD * (1 + DD)) * IH * IW; )==" "\n" |
300 | R"==(} )==" "\n" |
301 | R"==(#if WITH_SRC_ZPOINTS )==" "\n" |
302 | R"==(const int has_pad_d = id < 0 || id + KD * (1 + DD) >= ID; )==" "\n" |
303 | R"==(const int has_pad_h = ih < 0 || ih + KH * (1 + DH) >= IH; )==" "\n" |
304 | R"==(const int has_pad_w = iw < 0 || iw + KW * (1 + DW) + OW_BLOCK * SW >= IW; )==" "\n" |
305 | R"==(if (has_pad_d || has_pad_h || has_pad_w) { )==" "\n" |
306 | R"==(wei -= IC_NCHUNK * KD * KH * KW * IC_BLOCK * OC_BLOCK; )==" "\n" |
307 | R"==(for (int ic_chunk = 0; ic_chunk < IC_NCHUNK; ic_chunk++) { )==" "\n" |
308 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
309 | R"==(const int4 z = read_src_zero_points_32c( )==" "\n" |
310 | R"==(src_zpoints, (group_ic + ic_chunk) * IC_BLOCK); )==" "\n" |
311 | R"==(#else )==" "\n" |
312 | R"==(const int z = read_src_zero_point(src_zpoints); )==" "\n" |
313 | R"==(#endif )==" "\n" |
314 | R"==(for (int kd = 0; kd < KD; kd++) { )==" "\n" |
315 | R"==(for (int kh = 0; kh < KH; kh++) { )==" "\n" |
316 | R"==(for (int kw = 0; kw < KW; kw++) { )==" "\n" |
317 | R"==(int8 w0, w1, w2, w3; )==" "\n" |
318 | R"==(BLOCK_READ_WHT_8x32(w0, 0); )==" "\n" |
319 | R"==(BLOCK_READ_WHT_8x32(w1, 8 * IC_BLOCK); )==" "\n" |
320 | R"==(BLOCK_READ_WHT_8x32(w2, 16 * IC_BLOCK); )==" "\n" |
321 | R"==(BLOCK_READ_WHT_8x32(w3, 24 * IC_BLOCK); )==" "\n" |
322 | R"==(int4 acc = 0; )==" "\n" |
323 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
324 | R"==(acc.s0 += calc_src_compensation_x32(z, w0); )==" "\n" |
325 | R"==(acc.s1 += calc_src_compensation_x32(z, w1); )==" "\n" |
326 | R"==(acc.s2 += calc_src_compensation_x32(z, w2); )==" "\n" |
327 | R"==(acc.s3 += calc_src_compensation_x32(z, w3); )==" "\n" |
328 | R"==(#else )==" "\n" |
329 | R"==(unroll_for(uint j = 0; j < 8; ++j) { )==" "\n" |
330 | R"==(acc.s0 = idot4(0x01010101, w0[j], acc.s0); )==" "\n" |
331 | R"==(acc.s1 = idot4(0x01010101, w1[j], acc.s1); )==" "\n" |
332 | R"==(acc.s2 = idot4(0x01010101, w2[j], acc.s2); )==" "\n" |
333 | R"==(acc.s3 = idot4(0x01010101, w3[j], acc.s3); )==" "\n" |
334 | R"==(} )==" "\n" |
335 | R"==(acc = z * acc; )==" "\n" |
336 | R"==(#endif )==" "\n" |
337 | R"==(for (int i = 0; i < OW_BLOCK; ++i) { )==" "\n" |
338 | R"==(const int id0 = kd * (1 + DD) + id; )==" "\n" |
339 | R"==(const int ih0 = kh * (1 + DH) + ih; )==" "\n" |
340 | R"==(const int iw0 = kw * (1 + DW) + iw + i * SW; )==" "\n" |
341 | R"==(const int is_pad_d = id0 < 0 || id0 >= ID; )==" "\n" |
342 | R"==(const int is_pad_h = ih0 < 0 || ih0 >= IH; )==" "\n" |
343 | R"==(const int is_pad_w = iw0 < 0 || iw0 >= IW; )==" "\n" |
344 | R"==(if (is_pad_d || is_pad_h || is_pad_w) { )==" "\n" |
345 | R"==(C00[i] += acc.s0; )==" "\n" |
346 | R"==(C01[i] += acc.s1; )==" "\n" |
347 | R"==(C02[i] += acc.s2; )==" "\n" |
348 | R"==(C03[i] += acc.s3; )==" "\n" |
349 | R"==(} )==" "\n" |
350 | R"==(} )==" "\n" |
351 | R"==(wei += IC_BLOCK * OC_BLOCK; )==" "\n" |
352 | R"==(} )==" "\n" |
353 | R"==(} )==" "\n" |
354 | R"==(} )==" "\n" |
355 | R"==(} )==" "\n" |
356 | R"==(} )==" "\n" |
357 | R"==(int4 src_comp = as_int4(intel_sub_group_block_read4( )==" "\n" |
358 | R"==((__global uint *)(&src_compensation[(group_oc + oc) * OC_BLOCK]))); )==" "\n" |
359 | R"==(C00 -= src_comp.s0; )==" "\n" |
360 | R"==(C01 -= src_comp.s1; )==" "\n" |
361 | R"==(C02 -= src_comp.s2; )==" "\n" |
362 | R"==(C03 -= src_comp.s3; )==" "\n" |
363 | R"==(#endif )==" "\n" |
364 | R"==(if (ow < OW) { )==" "\n" |
365 | R"==(float4 tmp; )==" "\n" |
366 | R"==(DST_DATA4_T dst_pack[BLOCK]; )==" "\n" |
367 | R"==(DST_DATA4_T D0[BLOCK]; )==" "\n" |
368 | R"==(#if SCALES_PER_OC )==" "\n" |
369 | R"==(float4 scales = 1; )==" "\n" |
370 | R"==(BLOCK_READ_SCALES(scales, (group_oc + oc) * OC_BLOCK); )==" "\n" |
371 | R"==(#endif )==" "\n" |
372 | R"==(#if WITH_BIAS )==" "\n" |
373 | R"==(float4 bia; )==" "\n" |
374 | R"==(BLOCK_READ_BIA(bia, (group_oc + oc) * OC_BLOCK); )==" "\n" |
375 | R"==(#define QUANTIZE_ADD_BIAS() tmp = SCALE * fma(tmp, (float4)1, bia); )==" "\n" |
376 | R"==(#else )==" "\n" |
377 | R"==(#define QUANTIZE_ADD_BIAS() tmp *= SCALE; )==" "\n" |
378 | R"==(#endif )==" "\n" |
379 | R"==(#if WITH_SUM )==" "\n" |
380 | R"==(#if OW_BLOCK == 4 )==" "\n" |
381 | R"==(*(DST_DATA16_T *)D0 = BLOCK_READ_DST16(dst); )==" "\n" |
382 | R"==(#endif )==" "\n" |
383 | R"==(#if OW_BLOCK == 8 )==" "\n" |
384 | R"==(*(DST_DATA16_T *)(D0 + 0) = BLOCK_READ_DST16(dst); )==" "\n" |
385 | R"==(*(DST_DATA16_T *)(D0 + 4) = BLOCK_READ_DST16(dst + 16 * 8); )==" "\n" |
386 | R"==(#endif )==" "\n" |
387 | R"==(#endif )==" "\n" |
388 | R"==(#if WITH_DST_ZPOINTS )==" "\n" |
389 | R"==(int4 dst_zp = read_dst_zero_points_32c( )==" "\n" |
390 | R"==(dst_compensation, (group_oc + oc) * OC_BLOCK); )==" "\n" |
391 | R"==(#if !WITH_DST_ZPOINTS_PER_OC && OC % 32 != 0 )==" "\n" |
392 | R"==(dst_zp = convert_int4(zero_pad_dst_32c( )==" "\n" |
393 | R"==(convert_float4(dst_zp), (group_oc + oc) * OC_BLOCK)); )==" "\n" |
394 | R"==(#endif )==" "\n" |
395 | R"==(#define ADD_DST_COMPENSATION() tmp += convert_float4(dst_zp); )==" "\n" |
396 | R"==(#else )==" "\n" |
397 | R"==(#define ADD_DST_COMPENSATION() )==" "\n" |
398 | R"==(#endif )==" "\n" |
399 | R"==(#if WITH_SRC_ZPOINTS )==" "\n" |
400 | R"==(#define ZERO_PAD_DST() tmp = zero_pad_dst_32c(tmp, (group_oc + oc) * OC_BLOCK); )==" "\n" |
401 | R"==(#else )==" "\n" |
402 | R"==(#define ZERO_PAD_DST() )==" "\n" |
403 | R"==(#endif )==" "\n" |
404 | R"==(#define PACK(C0, C1, C2, C3, idx) \ )==" "\n" |
405 | R"==(do { \ )==" "\n" |
406 | R"==(tmp[0] = convert_float(C0[idx]); \ )==" "\n" |
407 | R"==(tmp[1] = convert_float(C1[idx]); \ )==" "\n" |
408 | R"==(tmp[2] = convert_float(C2[idx]); \ )==" "\n" |
409 | R"==(tmp[3] = convert_float(C3[idx]); \ )==" "\n" |
410 | R"==(} while (0) )==" "\n" |
411 | R"==(#define CONVERT_PACK(idx) \ )==" "\n" |
412 | R"==(do { \ )==" "\n" |
413 | R"==(dst_pack[idx] = CONVERT_DST_DATA4_T(tmp); \ )==" "\n" |
414 | R"==(} while (0) )==" "\n" |
415 | R"==(#define PACK_DST(C0, C1, C2, C3, D) \ )==" "\n" |
416 | R"==(do { \ )==" "\n" |
417 | R"==(for (int n_i = 0; n_i < OW_BLOCK; ++n_i) { \ )==" "\n" |
418 | R"==(PACK(C0, C1, C2, C3, n_i); \ )==" "\n" |
419 | R"==(QUANTIZE_ADD_BIAS(); \ )==" "\n" |
420 | R"==(const int po_mb = group_mb * MB_BLOCK; \ )==" "\n" |
421 | R"==(const int po_oc \ )==" "\n" |
422 | R"==(= (group_oc * OC_BLOCK + oc * OC_BLOCK) % (OC * G); \ )==" "\n" |
423 | R"==(float4 dni = convert_float4(SUM_TO_REF(AS_SUM_DATA4_T(D[n_i]))); \ )==" "\n" |
424 | R"==(APPLY_POST_OPS_TRY_BURST(tmp, float, dni, float, po_mb, 1, po_oc, \ )==" "\n" |
425 | R"==(4 * SUB_GROUP_SIZE, subg_local_id); \ )==" "\n" |
426 | R"==(ADD_DST_COMPENSATION(); \ )==" "\n" |
427 | R"==(ZERO_PAD_DST(); \ )==" "\n" |
428 | R"==(CONVERT_PACK(n_i); \ )==" "\n" |
429 | R"==(} \ )==" "\n" |
430 | R"==(} while (0) )==" "\n" |
431 | R"==(PACK_DST(C00, C01, C02, C03, D0); )==" "\n" |
432 | R"==(#if OW_TAIL )==" "\n" |
433 | R"==(if (ow + OW_BLOCK > OW) { )==" "\n" |
434 | R"==(__attribute__((opencl_unroll_hint(OW_TAIL))) for (int i = 0; )==" "\n" |
435 | R"==(i < OW_TAIL; )==" "\n" |
436 | R"==(i++) { )==" "\n" |
437 | R"==(BLOCK_WRITE_DST4(&dst[i * 32], dst_pack[i]); )==" "\n" |
438 | R"==(} )==" "\n" |
439 | R"==(} else { )==" "\n" |
440 | R"==(#endif )==" "\n" |
441 | R"==(#if OW_BLOCK == 4 )==" "\n" |
442 | R"==(BLOCK_WRITE_DST16(dst, *(DST_DATA16_T *)dst_pack); )==" "\n" |
443 | R"==(#endif )==" "\n" |
444 | R"==(#if OW_BLOCK == 8 )==" "\n" |
445 | R"==(BLOCK_WRITE_DST16(dst, *(DST_DATA16_T *)dst_pack); )==" "\n" |
446 | R"==(BLOCK_WRITE_DST16(dst + 16 * 8, *(DST_DATA16_T *)(dst_pack + 4)); )==" "\n" |
447 | R"==(#endif )==" "\n" |
448 | R"==(#if OW_TAIL )==" "\n" |
449 | R"==(} )==" "\n" |
450 | R"==(#endif )==" "\n" |
451 | R"==(} )==" "\n" |
452 | R"==(} )==" "\n" |
453 | R"==()==" ; |
454 | } |
455 | } |
456 | } |
457 | } |