1namespace dnnl {
2namespace impl {
3namespace gpu {
4namespace ocl {
5const char *xe_lp_conv_nhwc_fwd_dw_mb_block_x8s8x_kernel = R"==(/******************************************************************************* )==""\n"
6R"==(* Copyright 2020-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"==(#define KDHW_SIZE KD *KH *KW )==""\n"
24R"==(#define MB_BLOCK_PER_THREAD (MB_BLOCK / 4) )==""\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"==(void block_read_src( )==""\n"
36R"==(uchar *s, __global uchar *src, const int g, const int cur_mb_blk) { )==""\n"
37R"==(const int sglid = get_sub_group_local_id(); )==""\n"
38R"==(int mb_tail = (MB - cur_mb_blk) % MB_BLOCK_PER_THREAD; )==""\n"
39R"==(int po_mb = (cur_mb_blk + mb_tail < MB) ? MB_BLOCK_PER_THREAD : mb_tail; )==""\n"
40R"==(for (int i = 0; i < SUB_GROUP_SIZE; i++) { )==""\n"
41R"==(if ((i % 2) * SUB_GROUP_SIZE + sglid )==""\n"
42R"==(< (g + IC_BLOCK > G ? G % IC_BLOCK : IC_BLOCK) )==""\n"
43R"==(&& (i / 2) < po_mb) )==""\n"
44R"==(s[i] = src[(i / 2) * (ID * IH * IW * G) + (i % 2) * SUB_GROUP_SIZE )==""\n"
45R"==(+ sglid]; )==""\n"
46R"==(else )==""\n"
47R"==(s[i] = 0; )==""\n"
48R"==(} )==""\n"
49R"==(} )==""\n"
50R"==(void block_write_dst(const DST_DATA_T *d, __global DST_DATA_T *dst, const int g, )==""\n"
51R"==(const int cur_mb_blk) { )==""\n"
52R"==(const int sglid = get_sub_group_local_id(); )==""\n"
53R"==(int mb_tail = (MB - cur_mb_blk) % MB_BLOCK_PER_THREAD; )==""\n"
54R"==(int po_mb = (cur_mb_blk + mb_tail < MB) ? MB_BLOCK_PER_THREAD : mb_tail; )==""\n"
55R"==(for (int i = 0; i < SUB_GROUP_SIZE; i++) { )==""\n"
56R"==(if ((i % 2) * SUB_GROUP_SIZE + sglid )==""\n"
57R"==(< (g + OC_BLOCK > G ? G % OC_BLOCK : OC_BLOCK) )==""\n"
58R"==(&& (i / 2) < po_mb) )==""\n"
59R"==(dst[(i / 2) * (OD * OH * OW * G) + (i % 2) * SUB_GROUP_SIZE + sglid] )==""\n"
60R"==(= d[i]; )==""\n"
61R"==(} )==""\n"
62R"==(} )==""\n"
63R"==(void block_read_dst_as_sum(SUM_DATA_T *d, __global DST_DATA_T *dst, const int g, )==""\n"
64R"==(const int cur_mb_blk) { )==""\n"
65R"==(const int sglid = get_sub_group_local_id(); )==""\n"
66R"==(int mb_tail = (MB - cur_mb_blk) % MB_BLOCK_PER_THREAD; )==""\n"
67R"==(int po_mb = (cur_mb_blk + mb_tail < MB) ? MB_BLOCK_PER_THREAD : mb_tail; )==""\n"
68R"==(for (int i = 0; i < SUB_GROUP_SIZE; i++) { )==""\n"
69R"==(if ((i % 2) * SUB_GROUP_SIZE + sglid )==""\n"
70R"==(< (g + IC_BLOCK > G ? G % IC_BLOCK : IC_BLOCK) )==""\n"
71R"==(&& (i / 2) < po_mb) )==""\n"
72R"==(d[i] = AS_SUM_DATA_T(dst[(i / 2) * (OD * OH * OW * G) )==""\n"
73R"==(+ (i % 2) * SUB_GROUP_SIZE + sglid]); )==""\n"
74R"==(else )==""\n"
75R"==(d[i] = 0; )==""\n"
76R"==(} )==""\n"
77R"==(} )==""\n"
78R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) )==""\n"
79R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) __kernel void )==""\n"
80R"==(conv_nhwc_fwd_dw_mb_block_x8s8x(const __global uchar *src, )==""\n"
81R"==(const __global char *wei, const __global float *bias, )==""\n"
82R"==(__global DST_DATA_T *dst POST_OP_ARGS, )==""\n"
83R"==(const __global float *runtime_scales, )==""\n"
84R"==(const __global int *src_compensation, const __global int *src_zpoints, )==""\n"
85R"==(const __global int *dst_compensation) { )==""\n"
86R"==(const int osp = get_global_id(1); )==""\n"
87R"==(const int od = osp / (OW * OH); )==""\n"
88R"==(const int ohw = osp % (OW * OH); )==""\n"
89R"==(const int ow = (ohw % OW); )==""\n"
90R"==(const int oh = ohw / OW; )==""\n"
91R"==(const int g = get_group_id(0) * OC_BLOCK; )==""\n"
92R"==(const int cur_mb_blk = (get_global_id(2) % 4) * MB_BLOCK_PER_THREAD; )==""\n"
93R"==(const int id = od * SD - PD; )==""\n"
94R"==(const int ih = oh * SH - PH; )==""\n"
95R"==(const int iw = ow * SW - PW; )==""\n"
96R"==(const int sglid = get_sub_group_local_id(); )==""\n"
97R"==(src += cur_mb_blk * ID * IH * IW * G + (id * IH * IW + ih * IW + iw) * G )==""\n"
98R"==(+ g; )==""\n"
99R"==(dst += cur_mb_blk * OD * OH * OW * G + (od * OH * OW + oh * OW + ow) * G )==""\n"
100R"==(+ g; )==""\n"
101R"==(wei += g * KDHW_SIZE; )==""\n"
102R"==(int8 S00 = 0; )==""\n"
103R"==(int8 S01 = 0; )==""\n"
104R"==(uchar16 A00, A10, A20, A30; )==""\n"
105R"==(__attribute__((opencl_unroll_hint)) for (int sp = 0; )==""\n"
106R"==(sp < KDHW_SIZE - KDHW_SIZE % 4; )==""\n"
107R"==(sp += 4) { )==""\n"
108R"==(const int4 s = {sp, sp + 1, sp + 2, sp + 3}; )==""\n"
109R"==(const int4 kd = s / (KH * KW); )==""\n"
110R"==(const int4 kh = (s % (KH * KW)) / KW; )==""\n"
111R"==(const int4 kw = (s % (KH * KW)) % KW; )==""\n"
112R"==(const int4 src_index )==""\n"
113R"==(= (kd * (1 + DD) * IH * IW + kh * (1 + DH) * IW + kw * (1 + DW)) )==""\n"
114R"==(* G; )==""\n"
115R"==(const int4 index = id + kd * (1 + DD) < 0 || id + kd * (1 + DD) >= ID )==""\n"
116R"==(|| ih + kh * (1 + DH) < 0 || ih + kh * (1 + DH) >= IH )==""\n"
117R"==(|| iw + kw * (1 + DW) < 0 || iw + kw * (1 + DW) >= IW; )==""\n"
118R"==(if (index.s0) { )==""\n"
119R"==(A00 = 0; )==""\n"
120R"==(} else { )==""\n"
121R"==(block_read_src((uchar *)&A00, src + src_index.s0, g, cur_mb_blk); )==""\n"
122R"==(} )==""\n"
123R"==(if (index.s1) { )==""\n"
124R"==(A10 = 0; )==""\n"
125R"==(} else { )==""\n"
126R"==(block_read_src((uchar *)&A10, src + src_index.s1, g, cur_mb_blk); )==""\n"
127R"==(} )==""\n"
128R"==(if (index.s2) { )==""\n"
129R"==(A20 = 0; )==""\n"
130R"==(} else { )==""\n"
131R"==(block_read_src((uchar *)&A20, src + src_index.s2, g, cur_mb_blk); )==""\n"
132R"==(} )==""\n"
133R"==(if (index.s3) { )==""\n"
134R"==(A30 = 0; )==""\n"
135R"==(} else { )==""\n"
136R"==(block_read_src((uchar *)&A30, src + src_index.s3, g, cur_mb_blk); )==""\n"
137R"==(} )==""\n"
138R"==(char8 W = as_char8( )==""\n"
139R"==(intel_sub_group_block_read_uc8((const __global uchar *)(wei))); )==""\n"
140R"==(char4 W1 = W.s0246; )==""\n"
141R"==(char4 W2 = W.s1357; )==""\n"
142R"==(S00.s0 = idot4( )==""\n"
143R"==((SRC_DATA4_T)(A00.s0, A10.s0, A20.s0, A30.s0), W1, S00.s0); )==""\n"
144R"==(S00.s1 = idot4( )==""\n"
145R"==((SRC_DATA4_T)(A00.s1, A10.s1, A20.s1, A30.s1), W2, S00.s1); )==""\n"
146R"==(S00.s2 = idot4( )==""\n"
147R"==((SRC_DATA4_T)(A00.s2, A10.s2, A20.s2, A30.s2), W1, S00.s2); )==""\n"
148R"==(S00.s3 = idot4( )==""\n"
149R"==((SRC_DATA4_T)(A00.s3, A10.s3, A20.s3, A30.s3), W2, S00.s3); )==""\n"
150R"==(S00.s4 = idot4( )==""\n"
151R"==((SRC_DATA4_T)(A00.s4, A10.s4, A20.s4, A30.s4), W1, S00.s4); )==""\n"
152R"==(S00.s5 = idot4( )==""\n"
153R"==((SRC_DATA4_T)(A00.s5, A10.s5, A20.s5, A30.s5), W2, S00.s5); )==""\n"
154R"==(S00.s6 = idot4( )==""\n"
155R"==((SRC_DATA4_T)(A00.s6, A10.s6, A20.s6, A30.s6), W1, S00.s6); )==""\n"
156R"==(S00.s7 = idot4( )==""\n"
157R"==((SRC_DATA4_T)(A00.s7, A10.s7, A20.s7, A30.s7), W2, S00.s7); )==""\n"
158R"==(S01.s0 = idot4( )==""\n"
159R"==((SRC_DATA4_T)(A00.s8, A10.s8, A20.s8, A30.s8), W1, S01.s0); )==""\n"
160R"==(S01.s1 = idot4( )==""\n"
161R"==((SRC_DATA4_T)(A00.s9, A10.s9, A20.s9, A30.s9), W2, S01.s1); )==""\n"
162R"==(S01.s2 = idot4( )==""\n"
163R"==((SRC_DATA4_T)(A00.sa, A10.sa, A20.sa, A30.sa), W1, S01.s2); )==""\n"
164R"==(S01.s3 = idot4( )==""\n"
165R"==((SRC_DATA4_T)(A00.sb, A10.sb, A20.sb, A30.sb), W2, S01.s3); )==""\n"
166R"==(S01.s4 = idot4( )==""\n"
167R"==((SRC_DATA4_T)(A00.sc, A10.sc, A20.sc, A30.sc), W1, S01.s4); )==""\n"
168R"==(S01.s5 = idot4( )==""\n"
169R"==((SRC_DATA4_T)(A00.sd, A10.sd, A20.sd, A30.sd), W2, S01.s5); )==""\n"
170R"==(S01.s6 = idot4( )==""\n"
171R"==((SRC_DATA4_T)(A00.se, A10.se, A20.se, A30.se), W1, S01.s6); )==""\n"
172R"==(S01.s7 = idot4( )==""\n"
173R"==((SRC_DATA4_T)(A00.sf, A10.sf, A20.sf, A30.sf), W2, S01.s7); )==""\n"
174R"==(wei += 4 * OC_BLOCK; )==""\n"
175R"==(} )==""\n"
176R"==(__attribute__((opencl_unroll_hint)) for (int sp = KDHW_SIZE - KDHW_SIZE % 4; )==""\n"
177R"==(sp < KDHW_SIZE; sp++) { )==""\n"
178R"==(const int kd = sp / (KH * KW); )==""\n"
179R"==(const int kh = (sp % (KH * KW)) / KW; )==""\n"
180R"==(const int kw = (sp % (KH * KW)) % KW; )==""\n"
181R"==(const int src_index )==""\n"
182R"==(= (kd * (1 + DD) * IH * IW + kh * (1 + DH) * IW + kw * (1 + DW)) )==""\n"
183R"==(* G; )==""\n"
184R"==(const int index = id + kd * (1 + DD) < 0 || id + kd * (1 + DD) >= ID )==""\n"
185R"==(|| ih + kh * (1 + DH) < 0 || ih + kh * (1 + DH) >= IH )==""\n"
186R"==(|| iw + kw * (1 + DW) < 0 || iw + kw * (1 + DW) >= IW; )==""\n"
187R"==(if (index) { )==""\n"
188R"==(A00 = 0; )==""\n"
189R"==(} else { )==""\n"
190R"==(block_read_src((uchar *)&A00, src + src_index, g, cur_mb_blk); )==""\n"
191R"==(} )==""\n"
192R"==(const char2 W = as_char2( )==""\n"
193R"==(intel_sub_group_block_read_uc2((const __global uchar *)(wei))); )==""\n"
194R"==(const char W1 = W.s0; )==""\n"
195R"==(const char W2 = W.s1; )==""\n"
196R"==(S00.s0 += ((SRC_DATA_T)A00.s0) * W1; )==""\n"
197R"==(S00.s1 += ((SRC_DATA_T)A00.s1) * W2; )==""\n"
198R"==(S00.s2 += ((SRC_DATA_T)A00.s2) * W1; )==""\n"
199R"==(S00.s3 += ((SRC_DATA_T)A00.s3) * W2; )==""\n"
200R"==(S00.s4 += ((SRC_DATA_T)A00.s4) * W1; )==""\n"
201R"==(S00.s5 += ((SRC_DATA_T)A00.s5) * W2; )==""\n"
202R"==(S00.s6 += ((SRC_DATA_T)A00.s6) * W1; )==""\n"
203R"==(S00.s7 += ((SRC_DATA_T)A00.s7) * W2; )==""\n"
204R"==(S01.s0 += ((SRC_DATA_T)A00.s8) * W1; )==""\n"
205R"==(S01.s1 += ((SRC_DATA_T)A00.s9) * W2; )==""\n"
206R"==(S01.s2 += ((SRC_DATA_T)A00.sa) * W1; )==""\n"
207R"==(S01.s3 += ((SRC_DATA_T)A00.sb) * W2; )==""\n"
208R"==(S01.s4 += ((SRC_DATA_T)A00.sc) * W1; )==""\n"
209R"==(S01.s5 += ((SRC_DATA_T)A00.sd) * W2; )==""\n"
210R"==(S01.s6 += ((SRC_DATA_T)A00.se) * W1; )==""\n"
211R"==(S01.s7 += ((SRC_DATA_T)A00.sf) * W2; )==""\n"
212R"==(wei += OC_BLOCK; )==""\n"
213R"==(} )==""\n"
214R"==(float8 tmp00 = convert_float8(S00); )==""\n"
215R"==(float8 tmp01 = convert_float8(S01); )==""\n"
216R"==(#if SCALES_PER_OC )==""\n"
217R"==(float2 scales = as_float2(intel_sub_group_block_read2( )==""\n"
218R"==((const __global uint *)&runtime_scales[g])); )==""\n"
219R"==(#endif )==""\n"
220R"==(#if WITH_BIAS )==""\n"
221R"==(float2 B = as_float2( )==""\n"
222R"==(intel_sub_group_block_read2((const __global uint *)&bias[g])); )==""\n"
223R"==(tmp00 = SCALE_VEC8 * fma(tmp00, (float8)1, B.s01010101); )==""\n"
224R"==(tmp01 = SCALE_VEC8 * fma(tmp01, (float8)1, B.s01010101); )==""\n"
225R"==(#else )==""\n"
226R"==(tmp00 *= SCALE_VEC8; )==""\n"
227R"==(tmp01 *= SCALE_VEC8; )==""\n"
228R"==(#endif )==""\n"
229R"==(SUM_DATA16_T D00; )==""\n"
230R"==(#if WITH_SUM )==""\n"
231R"==(block_read_dst_as_sum(&D00, dst, g, cur_mb_blk); )==""\n"
232R"==(#endif )==""\n"
233R"==(float16 tmp_x16 = (float16)(tmp00, tmp01); )==""\n"
234R"==(APPLY_POST_OPS_SERIAL_BINARY_2D( )==""\n"
235R"==(tmp_x16, float, D00, SUM_DATA_T, 0, 1, 0, 1); )==""\n"
236R"==(DST_DATA16_T R0 = CONVERT_DST_DATA16_T(tmp_x16); )==""\n"
237R"==(block_write_dst((DST_DATA16_T *)&R0, dst, g, cur_mb_blk); )==""\n"
238R"==(} )==""\n"
239R"==()==";
240}
241}
242}
243}