1namespace dnnl {
2namespace impl {
3namespace gpu {
4namespace ocl {
5const char *xe_lp_conv_dw_fwd_data_mb_block_x8s8x_kernel = R"==(/******************************************************************************* )==""\n"
6R"==(* Copyright 2019-2022 Intel Corporation )==""\n"
7R"==(* )==""\n"
8R"==(* Licensed under the Apache License, Version 2.0 (the "License"); )==""\n"
9R"==(* you may not use this file except in compliance with the License. )==""\n"
10R"==(* You may obtain a copy of the License at )==""\n"
11R"==(* )==""\n"
12R"==(* http: )==""\n"
13R"==(* )==""\n"
14R"==(* Unless required by applicable law or agreed to in writing, software )==""\n"
15R"==(* distributed under the License is distributed on an "AS IS" BASIS, )==""\n"
16R"==(* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. )==""\n"
17R"==(* See the License for the specific language governing permissions and )==""\n"
18R"==(* limitations under the License. )==""\n"
19R"==(*******************************************************************************/ )==""\n"
20R"==(#include "gpu/ocl/ocl_math_utils.h" )==""\n"
21R"==(#include "gpu/ocl/ocl_post_ops.h" )==""\n"
22R"==(#include "gpu/ocl/ocl_types.h" )==""\n"
23R"==(#include "gpu/ocl/ocl_zero_points.h" )==""\n"
24R"==(#define KDHW_SIZE (KD * KH * KW) )==""\n"
25R"==(#if SCALES_PER_OC )==""\n"
26R"==(#define SCALE scales )==""\n"
27R"==(#define SCALE_VEC8 scales.s01010101 )==""\n"
28R"==(#elif SCALES_COMMON )==""\n"
29R"==(#define SCALE runtime_scales[0] )==""\n"
30R"==(#define SCALE_VEC8 runtime_scales[0] )==""\n"
31R"==(#else )==""\n"
32R"==(#define SCALE 1 )==""\n"
33R"==(#define SCALE_VEC8 1 )==""\n"
34R"==(#endif )==""\n"
35R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) )==""\n"
36R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) __kernel void )==""\n"
37R"==(conv_dw_fwd_mb_block_x8s8x(const __global uchar *src, const __global char *wei, )==""\n"
38R"==(const __global float *bias, __global DST_DATA_T *dst POST_OP_ARGS, )==""\n"
39R"==(const __global float *runtime_scales, )==""\n"
40R"==(const __global int *src_compensation, const __global int *src_zpoints, )==""\n"
41R"==(const __global int *dst_compensation) { )==""\n"
42R"==(const int osp = get_global_id(1); )==""\n"
43R"==(const int ocl_local_id = get_local_id(0); )==""\n"
44R"==(const int od = osp / (OW * OH); )==""\n"
45R"==(const int ohw = osp % (OW * OH); )==""\n"
46R"==(const int ow = (ohw % OW); )==""\n"
47R"==(const int oh = ohw / OW; )==""\n"
48R"==(const int g = get_group_id(0) * OC_BLOCK; )==""\n"
49R"==(const int mb = (get_global_id(2) / 4) * MB_BLOCK; )==""\n"
50R"==(const int mb_half = (get_global_id(2) % 4) * MB_BLOCK / 4; )==""\n"
51R"==(const int id = od * SD - PD; )==""\n"
52R"==(const int ih = oh * SH - PH; )==""\n"
53R"==(const int iw = ow * SW - PW; )==""\n"
54R"==(dst += mb * G_PADDED * OD * OH * OW + g * OD * OH * OW * MB_BLOCK )==""\n"
55R"==(+ (od * OH * OW + oh * OW + ow) * MB_BLOCK * OC_BLOCK )==""\n"
56R"==(+ mb_half * OC_BLOCK; )==""\n"
57R"==(src += mb * G_PADDED * ID * IH * IW + g * ID * IH * IW * MB_BLOCK )==""\n"
58R"==(+ (id * IH * IW + ih * IW + iw) * MB_BLOCK * IC_BLOCK )==""\n"
59R"==(+ mb_half * IC_BLOCK; )==""\n"
60R"==(wei += g * KDHW_SIZE; )==""\n"
61R"==(int8 S00 = 0; )==""\n"
62R"==(int8 S01 = 0; )==""\n"
63R"==(uchar16 A00, A10, A20, A30; )==""\n"
64R"==(#if WITH_SRC_ZPOINTS )==""\n"
65R"==(#if WITH_SRC_ZPOINTS_PER_IC )==""\n"
66R"==(const int2 z = read_src_zero_points_32g(src_zpoints, g); )==""\n"
67R"==(#else )==""\n"
68R"==(const int2 z = read_src_zero_point(src_zpoints); )==""\n"
69R"==(#endif )==""\n"
70R"==(#endif )==""\n"
71R"==(unroll_for(int sp = 0; sp < KDHW_SIZE - KDHW_SIZE % 4; sp += 4) { )==""\n"
72R"==(const int4 s = {sp, sp + 1, sp + 2, sp + 3}; )==""\n"
73R"==(const int4 kd = s / (KH * KW); )==""\n"
74R"==(const int4 kh = (s % (KH * KW)) / KW; )==""\n"
75R"==(const int4 kw = (s % (KH * KW)) % KW; )==""\n"
76R"==(const int4 src_index )==""\n"
77R"==(= (kd * (1 + DD) * IH * IW + kh * (1 + DH) * IW + kw * (1 + DW)) )==""\n"
78R"==(* MB_BLOCK * IC_BLOCK; )==""\n"
79R"==(const int4 index = id + kd * (1 + DD) < 0 || id + kd * (1 + DD) >= ID )==""\n"
80R"==(|| ih + kh * (1 + DH) < 0 || ih + kh * (1 + DH) >= IH )==""\n"
81R"==(|| iw + kw * (1 + DW) < 0 || iw + kw * (1 + DW) >= IW; )==""\n"
82R"==(if (index.s0) { )==""\n"
83R"==(A00 = 0; )==""\n"
84R"==(} else { )==""\n"
85R"==(A00 = (intel_sub_group_block_read_uc16( )==""\n"
86R"==((const __global uchar *)(&src[src_index.s0]))); )==""\n"
87R"==(} )==""\n"
88R"==(if (index.s1) { )==""\n"
89R"==(A10 = 0; )==""\n"
90R"==(} else { )==""\n"
91R"==(A10 = (intel_sub_group_block_read_uc16( )==""\n"
92R"==((const __global uchar *)(&src[src_index.s1]))); )==""\n"
93R"==(} )==""\n"
94R"==(if (index.s2) { )==""\n"
95R"==(A20 = 0; )==""\n"
96R"==(} else { )==""\n"
97R"==(A20 = (intel_sub_group_block_read_uc16( )==""\n"
98R"==((const __global uchar *)(&src[src_index.s2]))); )==""\n"
99R"==(} )==""\n"
100R"==(if (index.s3) { )==""\n"
101R"==(A30 = 0; )==""\n"
102R"==(} else { )==""\n"
103R"==(A30 = (intel_sub_group_block_read_uc16( )==""\n"
104R"==((const __global uchar *)(&src[src_index.s3]))); )==""\n"
105R"==(} )==""\n"
106R"==(char8 W = as_char8( )==""\n"
107R"==(intel_sub_group_block_read_uc8((const __global uchar *)(wei))); )==""\n"
108R"==(char4 W1 = W.s0246; )==""\n"
109R"==(char4 W2 = W.s1357; )==""\n"
110R"==(#if WITH_SRC_ZPOINTS )==""\n"
111R"==(if (index.s0) { )==""\n"
112R"==(int2 src_comp; )==""\n"
113R"==(src_comp.s0 = z.s0 * W.s0; )==""\n"
114R"==(src_comp.s1 = z.s1 * W.s1; )==""\n"
115R"==(S00 += src_comp.s01010101; )==""\n"
116R"==(S01 += src_comp.s01010101; )==""\n"
117R"==(} )==""\n"
118R"==(if (index.s1) { )==""\n"
119R"==(int2 src_comp; )==""\n"
120R"==(src_comp.s0 = z.s0 * W.s2; )==""\n"
121R"==(src_comp.s1 = z.s1 * W.s3; )==""\n"
122R"==(S00 += src_comp.s01010101; )==""\n"
123R"==(S01 += src_comp.s01010101; )==""\n"
124R"==(} )==""\n"
125R"==(if (index.s2) { )==""\n"
126R"==(int2 src_comp; )==""\n"
127R"==(src_comp.s0 = z.s0 * W.s4; )==""\n"
128R"==(src_comp.s1 = z.s1 * W.s5; )==""\n"
129R"==(S00 += src_comp.s01010101; )==""\n"
130R"==(S01 += src_comp.s01010101; )==""\n"
131R"==(} )==""\n"
132R"==(if (index.s3) { )==""\n"
133R"==(int2 src_comp; )==""\n"
134R"==(src_comp.s0 = z.s0 * W.s6; )==""\n"
135R"==(src_comp.s1 = z.s1 * W.s7; )==""\n"
136R"==(S00 += src_comp.s01010101; )==""\n"
137R"==(S01 += src_comp.s01010101; )==""\n"
138R"==(} )==""\n"
139R"==(#endif )==""\n"
140R"==(S00.s0 = idot4( )==""\n"
141R"==((SRC_DATA4_T)(A00.s0, A10.s0, A20.s0, A30.s0), W1, S00.s0); )==""\n"
142R"==(S00.s1 = idot4( )==""\n"
143R"==((SRC_DATA4_T)(A00.s1, A10.s1, A20.s1, A30.s1), W2, S00.s1); )==""\n"
144R"==(S00.s2 = idot4( )==""\n"
145R"==((SRC_DATA4_T)(A00.s2, A10.s2, A20.s2, A30.s2), W1, S00.s2); )==""\n"
146R"==(S00.s3 = idot4( )==""\n"
147R"==((SRC_DATA4_T)(A00.s3, A10.s3, A20.s3, A30.s3), W2, S00.s3); )==""\n"
148R"==(S00.s4 = idot4( )==""\n"
149R"==((SRC_DATA4_T)(A00.s4, A10.s4, A20.s4, A30.s4), W1, S00.s4); )==""\n"
150R"==(S00.s5 = idot4( )==""\n"
151R"==((SRC_DATA4_T)(A00.s5, A10.s5, A20.s5, A30.s5), W2, S00.s5); )==""\n"
152R"==(S00.s6 = idot4( )==""\n"
153R"==((SRC_DATA4_T)(A00.s6, A10.s6, A20.s6, A30.s6), W1, S00.s6); )==""\n"
154R"==(S00.s7 = idot4( )==""\n"
155R"==((SRC_DATA4_T)(A00.s7, A10.s7, A20.s7, A30.s7), W2, S00.s7); )==""\n"
156R"==(S01.s0 = idot4( )==""\n"
157R"==((SRC_DATA4_T)(A00.s8, A10.s8, A20.s8, A30.s8), W1, S01.s0); )==""\n"
158R"==(S01.s1 = idot4( )==""\n"
159R"==((SRC_DATA4_T)(A00.s9, A10.s9, A20.s9, A30.s9), W2, S01.s1); )==""\n"
160R"==(S01.s2 = idot4( )==""\n"
161R"==((SRC_DATA4_T)(A00.sa, A10.sa, A20.sa, A30.sa), W1, S01.s2); )==""\n"
162R"==(S01.s3 = idot4( )==""\n"
163R"==((SRC_DATA4_T)(A00.sb, A10.sb, A20.sb, A30.sb), W2, S01.s3); )==""\n"
164R"==(S01.s4 = idot4( )==""\n"
165R"==((SRC_DATA4_T)(A00.sc, A10.sc, A20.sc, A30.sc), W1, S01.s4); )==""\n"
166R"==(S01.s5 = idot4( )==""\n"
167R"==((SRC_DATA4_T)(A00.sd, A10.sd, A20.sd, A30.sd), W2, S01.s5); )==""\n"
168R"==(S01.s6 = idot4( )==""\n"
169R"==((SRC_DATA4_T)(A00.se, A10.se, A20.se, A30.se), W1, S01.s6); )==""\n"
170R"==(S01.s7 = idot4( )==""\n"
171R"==((SRC_DATA4_T)(A00.sf, A10.sf, A20.sf, A30.sf), W2, S01.s7); )==""\n"
172R"==(wei += 4 * OC_BLOCK; )==""\n"
173R"==(} )==""\n"
174R"==(unroll_for(int sp = KDHW_SIZE - KDHW_SIZE % 4; sp < KDHW_SIZE; sp++) { )==""\n"
175R"==(const int kd = sp / (KH * KW); )==""\n"
176R"==(const int kh = (sp % (KH * KW)) / KW; )==""\n"
177R"==(const int kw = (sp % (KH * KW)) % KW; )==""\n"
178R"==(const int src_index )==""\n"
179R"==(= (kd * (1 + DD) * IH * IW + kh * (1 + DH) * IW + kw * (1 + DW)) )==""\n"
180R"==(* MB_BLOCK * IC_BLOCK; )==""\n"
181R"==(const int index = id + kd * (1 + DD) < 0 || id + kd * (1 + DD) >= ID )==""\n"
182R"==(|| ih + kh * (1 + DH) < 0 || ih + kh * (1 + DH) >= IH )==""\n"
183R"==(|| iw + kw * (1 + DW) < 0 || iw + kw * (1 + DW) >= IW; )==""\n"
184R"==(if (index) { )==""\n"
185R"==(A00 = 0; )==""\n"
186R"==(} else { )==""\n"
187R"==(A00 = (intel_sub_group_block_read_uc16( )==""\n"
188R"==((const __global uchar *)(&src[src_index]))); )==""\n"
189R"==(} )==""\n"
190R"==(const char2 W = as_char2( )==""\n"
191R"==(intel_sub_group_block_read_uc2((const __global uchar *)(wei))); )==""\n"
192R"==(const char W1 = W.s0; )==""\n"
193R"==(const char W2 = W.s1; )==""\n"
194R"==(#if WITH_SRC_ZPOINTS )==""\n"
195R"==(if (index) { )==""\n"
196R"==(int2 src_comp; )==""\n"
197R"==(src_comp.s0 = z.s0 * W.s0; )==""\n"
198R"==(src_comp.s1 = z.s1 * W.s1; )==""\n"
199R"==(S00 += src_comp.s01010101; )==""\n"
200R"==(S01 += src_comp.s01010101; )==""\n"
201R"==(} )==""\n"
202R"==(#endif )==""\n"
203R"==(S00.s0 += ((SRC_DATA_T)A00.s0) * W1; )==""\n"
204R"==(S00.s1 += ((SRC_DATA_T)A00.s1) * W2; )==""\n"
205R"==(S00.s2 += ((SRC_DATA_T)A00.s2) * W1; )==""\n"
206R"==(S00.s3 += ((SRC_DATA_T)A00.s3) * W2; )==""\n"
207R"==(S00.s4 += ((SRC_DATA_T)A00.s4) * W1; )==""\n"
208R"==(S00.s5 += ((SRC_DATA_T)A00.s5) * W2; )==""\n"
209R"==(S00.s6 += ((SRC_DATA_T)A00.s6) * W1; )==""\n"
210R"==(S00.s7 += ((SRC_DATA_T)A00.s7) * W2; )==""\n"
211R"==(S01.s0 += ((SRC_DATA_T)A00.s8) * W1; )==""\n"
212R"==(S01.s1 += ((SRC_DATA_T)A00.s9) * W2; )==""\n"
213R"==(S01.s2 += ((SRC_DATA_T)A00.sa) * W1; )==""\n"
214R"==(S01.s3 += ((SRC_DATA_T)A00.sb) * W2; )==""\n"
215R"==(S01.s4 += ((SRC_DATA_T)A00.sc) * W1; )==""\n"
216R"==(S01.s5 += ((SRC_DATA_T)A00.sd) * W2; )==""\n"
217R"==(S01.s6 += ((SRC_DATA_T)A00.se) * W1; )==""\n"
218R"==(S01.s7 += ((SRC_DATA_T)A00.sf) * W2; )==""\n"
219R"==(wei += OC_BLOCK; )==""\n"
220R"==(} )==""\n"
221R"==(#if WITH_SRC_ZPOINTS )==""\n"
222R"==(const int2 src_comp = as_int2(intel_sub_group_block_read2( )==""\n"
223R"==((__global uint *)(&src_compensation[g]))); )==""\n"
224R"==(S00 -= src_comp.s01010101; )==""\n"
225R"==(S01 -= src_comp.s01010101; )==""\n"
226R"==(#endif )==""\n"
227R"==(float8 tmp00 = convert_float8(S00); )==""\n"
228R"==(float8 tmp01 = convert_float8(S01); )==""\n"
229R"==(#if SCALES_PER_OC )==""\n"
230R"==(float2 scales = 1; )==""\n"
231R"==(if (g < G - 2) { )==""\n"
232R"==(scales = as_float2(intel_sub_group_block_read2( )==""\n"
233R"==((const __global uint *)&runtime_scales[g])); )==""\n"
234R"==(} else { )==""\n"
235R"==(scales.s1 = as_float(intel_sub_group_block_read( )==""\n"
236R"==((const __global uint *)&runtime_scales[g])); )==""\n"
237R"==(} )==""\n"
238R"==(#endif )==""\n"
239R"==(#if WITH_BIAS )==""\n"
240R"==(#if OC % OC_BLOCK == 0 )==""\n"
241R"==(float2 B = as_float2( )==""\n"
242R"==(intel_sub_group_block_read2((const __global uint *)&bias[g])); )==""\n"
243R"==(#else )==""\n"
244R"==(float2 B = 0; )==""\n"
245R"==(int i = 0; )==""\n"
246R"==(for (i = 0; i < (G - g) / SUB_GROUP_SIZE && i < 2; ++i) { )==""\n"
247R"==(B[i] = as_float(intel_sub_group_block_read( )==""\n"
248R"==((const __global uint *)&bias[g + (i * SUB_GROUP_SIZE)])); )==""\n"
249R"==(} )==""\n"
250R"==(if (i < 2 && get_sub_group_local_id() < (G - g) % SUB_GROUP_SIZE) { )==""\n"
251R"==(B[i] = bias[g + (i * SUB_GROUP_SIZE) + get_sub_group_local_id()]; )==""\n"
252R"==(} )==""\n"
253R"==(#endif )==""\n"
254R"==(float8 B0123 = B.s01010101; )==""\n"
255R"==(float8 B4567 = B.s01010101; )==""\n"
256R"==(if (MB % MB_BLOCK != 0) { )==""\n"
257R"==(int8 mb_vec = mb + mb_half; )==""\n"
258R"==(int8 m0123 = (mb_vec + (int8)(0, 0, 1, 1, 2, 2, 3, 3)) < MB; )==""\n"
259R"==(int8 m4567 = (mb_vec + (int8)(4, 4, 5, 5, 6, 6, 7, 7)) < MB; )==""\n"
260R"==(B0123 = select((float8)0, B0123, m0123); )==""\n"
261R"==(B4567 = select((float8)0, B4567, m4567); )==""\n"
262R"==(} )==""\n"
263R"==(tmp00 = SCALE_VEC8 * fma(tmp00, (float8)1, B0123); )==""\n"
264R"==(tmp01 = SCALE_VEC8 * fma(tmp01, (float8)1, B4567); )==""\n"
265R"==(#else )==""\n"
266R"==(tmp00 *= SCALE_VEC8; )==""\n"
267R"==(tmp01 *= SCALE_VEC8; )==""\n"
268R"==(#endif )==""\n"
269R"==(SUM_DATA16_T D00; )==""\n"
270R"==(#if WITH_SUM )==""\n"
271R"==(D00 = AS_SUM_DATA16_T(BLOCK_READ_DST16(dst)); )==""\n"
272R"==(#endif )==""\n"
273R"==(float16 tmp_x16 = (float16)(tmp00, tmp01); )==""\n"
274R"==(const int po_mb = mb + mb_half; )==""\n"
275R"==(const int po_oc = g * OC; )==""\n"
276R"==(APPLY_POST_OPS_TRY_BURST(tmp_x16, float, D00, SUM_DATA_T, po_mb, 8, po_oc, )==""\n"
277R"==(2 * SUB_GROUP_SIZE, ocl_local_id); )==""\n"
278R"==(#if WITH_DST_ZPOINTS )==""\n"
279R"==(float2 dst_zp )==""\n"
280R"==(= convert_float2(read_dst_zero_points_32g(dst_compensation, g)); )==""\n"
281R"==(float8 tmp_zp = dst_zp.s01010101; )==""\n"
282R"==(tmp_x16 += (float16)(tmp_zp, tmp_zp); )==""\n"
283R"==(#endif )==""\n"
284R"==(DST_DATA16_T R0 = CONVERT_DST_DATA16_T(tmp_x16); )==""\n"
285R"==(BLOCK_WRITE_DST16(dst, R0); )==""\n"
286R"==(} )==""\n"
287R"==()==";
288}
289}
290}
291}