1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *gen9_conv_bwd_data_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2019-2021 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_types.h" )==" "\n" |
21 | R"==(#if ID > 1 )==" "\n" |
22 | R"==(#define CASE_3D 1 )==" "\n" |
23 | R"==(#else )==" "\n" |
24 | R"==(#define CASE_3D 0 )==" "\n" |
25 | R"==(#endif )==" "\n" |
26 | R"==(#if BWD_DATA == 1 )==" "\n" |
27 | R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) )==" "\n" |
28 | R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) )==" "\n" |
29 | R"==(__kernel void )==" "\n" |
30 | R"==(gen9_conv_bwd_data(__global DATA_T *diff_src, __global DATA_T *wei, )==" "\n" |
31 | R"==(__global DATA_T *diff_dst, __global DATA_T *bias) { )==" "\n" |
32 | R"==(MAYBE_SKIP_NON_UNIFORM_WG(); )==" "\n" |
33 | R"==(#if VER_16MB16C == 1 )==" "\n" |
34 | R"==(const int sp = get_group_id(1); )==" "\n" |
35 | R"==(const int sglid = get_sub_group_local_id(); )==" "\n" |
36 | R"==(const int icb_mb = get_group_id(2); )==" "\n" |
37 | R"==(const int mb = icb_mb / (G * IC / ICB) * MB_BLOCK; )==" "\n" |
38 | R"==(const int icb = icb_mb % (G * IC / ICB); )==" "\n" |
39 | R"==(const int ic = (icb * ICB) / IC_BLOCK )==" "\n" |
40 | R"==(+ get_group_id(0) * (LWS_0 / SUB_GROUP_SIZE) + get_sub_group_id(); )==" "\n" |
41 | R"==(const int g = ic / (IC / IC_BLOCK); )==" "\n" |
42 | R"==(const int gic = ic % (IC / IC_BLOCK); )==" "\n" |
43 | R"==(#if CASE_3D )==" "\n" |
44 | R"==(const int id = sp / (IW * IH); )==" "\n" |
45 | R"==(const int ihw = sp % (IW * IH); )==" "\n" |
46 | R"==(#else )==" "\n" |
47 | R"==(const int id = 0; )==" "\n" |
48 | R"==(const int ihw = sp; )==" "\n" |
49 | R"==(#endif )==" "\n" |
50 | R"==(const int ih = ihw / IW; )==" "\n" |
51 | R"==(const int iw = ihw % IW; )==" "\n" |
52 | R"==(diff_dst += mb * OC * G * OD * OH * OW + g * OC * OD * OH * OW * MB_BLOCK; )==" "\n" |
53 | R"==(DATA8_T blockC00 = (DATA8_T)DATA_ZERO; )==" "\n" |
54 | R"==(DATA8_T blockC01 = (DATA8_T)DATA_ZERO; )==" "\n" |
55 | R"==(if (WITH_BIAS) { )==" "\n" |
56 | R"==(#if IS_DW )==" "\n" |
57 | R"==(const int bg_off = g * IC + sglid; )==" "\n" |
58 | R"==(const int bc_off = gic * IC_BLOCK; )==" "\n" |
59 | R"==(DATA_T b = (G_WO_PADDING % IC_BLOCK == 0 || bg_off < G_WO_PADDING) )==" "\n" |
60 | R"==(? bias[bg_off + bc_off] )==" "\n" |
61 | R"==(: DATA_ZERO; )==" "\n" |
62 | R"==(#else )==" "\n" |
63 | R"==(const int bg_off = g * IC; )==" "\n" |
64 | R"==(const int bc_off = gic * IC_BLOCK + sglid; )==" "\n" |
65 | R"==(DATA_T b = (IC_WO_PADDING % IC_BLOCK == 0 || bc_off < IC_WO_PADDING) )==" "\n" |
66 | R"==(? bias[bg_off + bc_off] )==" "\n" |
67 | R"==(: DATA_ZERO; )==" "\n" |
68 | R"==(#endif )==" "\n" |
69 | R"==(unroll_for(int i = 0; i < 8; ++i) { )==" "\n" |
70 | R"==(blockC00[i] = b; )==" "\n" |
71 | R"==(blockC01[i] = b; )==" "\n" |
72 | R"==(} )==" "\n" |
73 | R"==(} )==" "\n" |
74 | R"==(wei += gic * KD * KH * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
75 | R"==(+ g * IC * OC * KD * KH * KW; )==" "\n" |
76 | R"==(int ocb = 0; )==" "\n" |
77 | R"==(do { )==" "\n" |
78 | R"==(#if KH != 1 || KW != 1 || KD != 1 )==" "\n" |
79 | R"==(for (int kd = 0; kd < KD; ++kd) )==" "\n" |
80 | R"==(for (int kh = 0; kh < KH; ++kh) )==" "\n" |
81 | R"==(for (int kw = 0; kw < KW; ++kw) { )==" "\n" |
82 | R"==(if (iw + PW < kw * (1 + DW) || ih + PH < kh * (1 + DH)) )==" "\n" |
83 | R"==(continue; )==" "\n" |
84 | R"==(#if CASE_3D )==" "\n" |
85 | R"==(if (id + PD < kd * (1 + DD)) continue; )==" "\n" |
86 | R"==(int od = id - kd * (1 + DD) + PD; )==" "\n" |
87 | R"==(if (od % SD != 0) continue; )==" "\n" |
88 | R"==(od /= SD; )==" "\n" |
89 | R"==(if (od >= OD) continue; )==" "\n" |
90 | R"==(#endif )==" "\n" |
91 | R"==(int ow = iw - kw * (1 + DW) + PW; )==" "\n" |
92 | R"==(int oh = ih - kh * (1 + DH) + PH; )==" "\n" |
93 | R"==(#if SW != 1 || SH != 1 )==" "\n" |
94 | R"==(if (ow % SW != 0 || oh % SH != 0) continue; )==" "\n" |
95 | R"==(ow /= SW; )==" "\n" |
96 | R"==(oh /= SH; )==" "\n" |
97 | R"==(#endif )==" "\n" |
98 | R"==(if (oh >= OH || ow >= OW) continue; )==" "\n" |
99 | R"==(const __global DATA_T *diff_dst1 = diff_dst )==" "\n" |
100 | R"==(+ ow * OC_BLOCK * MB_BLOCK )==" "\n" |
101 | R"==(+ oh * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
102 | R"==(#if CASE_3D )==" "\n" |
103 | R"==(diff_dst1 += od * OH * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
104 | R"==(#endif )==" "\n" |
105 | R"==(const __global DATA_T *wei1 = wei )==" "\n" |
106 | R"==(#if CASE_3D )==" "\n" |
107 | R"==(+ kd * KH * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
108 | R"==(#endif )==" "\n" |
109 | R"==(+ kh * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
110 | R"==(+ kw * OC_BLOCK * IC_BLOCK; )==" "\n" |
111 | R"==(#else )==" "\n" |
112 | R"==(int ow = (iw + PW); )==" "\n" |
113 | R"==(int oh = (ih + PH); )==" "\n" |
114 | R"==(#if CASE_3D )==" "\n" |
115 | R"==(int od = (id + PD); )==" "\n" |
116 | R"==(#endif )==" "\n" |
117 | R"==(bool do_ker = true; )==" "\n" |
118 | R"==(#if SW != 1 || SH != 1 || SD != 1 )==" "\n" |
119 | R"==(do_ker = ow % SW == 0 && oh % SH == 0; )==" "\n" |
120 | R"==(ow /= SW; )==" "\n" |
121 | R"==(oh /= SH; )==" "\n" |
122 | R"==(#if CASE_3D )==" "\n" |
123 | R"==(do_ker = do_ker && od % SD == 0; )==" "\n" |
124 | R"==(od /= SD; )==" "\n" |
125 | R"==(#endif )==" "\n" |
126 | R"==(#endif )==" "\n" |
127 | R"==(#if PH != 0 || PW != 0 || PD != 0 )==" "\n" |
128 | R"==(do_ker = do_ker && (oh < OH && ow < OW); )==" "\n" |
129 | R"==(#if CASE_3D )==" "\n" |
130 | R"==(do_ker = do_ker && (od < OD); )==" "\n" |
131 | R"==(#endif )==" "\n" |
132 | R"==(#endif )==" "\n" |
133 | R"==(#if SW != 1 || SH != 1 || SD != 1 || PH != 0 || PW != 0 || PD != 0 )==" "\n" |
134 | R"==(if (do_ker) { )==" "\n" |
135 | R"==(#endif )==" "\n" |
136 | R"==(const __global DATA_T *diff_dst1 = diff_dst )==" "\n" |
137 | R"==(+ ow * OC_BLOCK * MB_BLOCK + oh * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
138 | R"==(#if CASE_3D )==" "\n" |
139 | R"==(diff_dst1 += od * OH * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
140 | R"==(#endif )==" "\n" |
141 | R"==(const __global DATA_T *wei1 = wei; )==" "\n" |
142 | R"==(#endif )==" "\n" |
143 | R"==(#define LOAD_DIFF_DST(_block, _diff_dst, mb_chunk) \ )==" "\n" |
144 | R"==({ \ )==" "\n" |
145 | R"==((_block) = AS_DATA8_T( \ )==" "\n" |
146 | R"==(BLOCK_READ8((const __global BLOCK_DATA_T *)((_diff_dst) \ )==" "\n" |
147 | R"==(+ (mb_chunk)*OC_BLOCK))); \ )==" "\n" |
148 | R"==(} )==" "\n" |
149 | R"==(#define SAVE_SRC_DIFF(_block, _diff_src, mb_chunk) \ )==" "\n" |
150 | R"==({ \ )==" "\n" |
151 | R"==(BLOCK_WRITE8((const __global BLOCK_DATA_T *)(&( \ )==" "\n" |
152 | R"==(_diff_src)[(mb_chunk)*IC_BLOCK]), \ )==" "\n" |
153 | R"==(AS_BLOCK_DATA8_T((_block))); \ )==" "\n" |
154 | R"==(} )==" "\n" |
155 | R"==(#if DT_F32 )==" "\n" |
156 | R"==(#define TRANSPOSE_8(_block, _col) \ )==" "\n" |
157 | R"==((DATA8_T)(intel_sub_group_shuffle(_block, _col)) )==" "\n" |
158 | R"==(#else )==" "\n" |
159 | R"==(#define TRANSPOSE_8(_block, _col) \ )==" "\n" |
160 | R"==((DATA8_T)(intel_sub_group_shuffle(_block[0], _col), \ )==" "\n" |
161 | R"==(intel_sub_group_shuffle(_block[1], _col), \ )==" "\n" |
162 | R"==(intel_sub_group_shuffle(_block[2], _col), \ )==" "\n" |
163 | R"==(intel_sub_group_shuffle(_block[3], _col), \ )==" "\n" |
164 | R"==(intel_sub_group_shuffle(_block[4], _col), \ )==" "\n" |
165 | R"==(intel_sub_group_shuffle(_block[5], _col), \ )==" "\n" |
166 | R"==(intel_sub_group_shuffle(_block[6], _col), \ )==" "\n" |
167 | R"==(intel_sub_group_shuffle(_block[7], _col)) )==" "\n" |
168 | R"==(#endif )==" "\n" |
169 | R"==(#define FMA8(a, b, c) fma((DATA8_T)(a), (DATA8_T)b, (DATA8_T)c) )==" "\n" |
170 | R"==(#define MULTIPLY_BLOCKS_8x8(_result, _blockA, _blockB, _blockB1) \ )==" "\n" |
171 | R"==({ \ )==" "\n" |
172 | R"==(_result = FMA8(_blockB.s0, TRANSPOSE_8(_blockA, 0), _result); \ )==" "\n" |
173 | R"==(_result = FMA8(_blockB.s1, TRANSPOSE_8(_blockA, 1), _result); \ )==" "\n" |
174 | R"==(_result = FMA8(_blockB.s2, TRANSPOSE_8(_blockA, 2), _result); \ )==" "\n" |
175 | R"==(_result = FMA8(_blockB.s3, TRANSPOSE_8(_blockA, 3), _result); \ )==" "\n" |
176 | R"==(_result = FMA8(_blockB.s4, TRANSPOSE_8(_blockA, 4), _result); \ )==" "\n" |
177 | R"==(_result = FMA8(_blockB.s5, TRANSPOSE_8(_blockA, 5), _result); \ )==" "\n" |
178 | R"==(_result = FMA8(_blockB.s6, TRANSPOSE_8(_blockA, 6), _result); \ )==" "\n" |
179 | R"==(_result = FMA8(_blockB.s7, TRANSPOSE_8(_blockA, 7), _result); \ )==" "\n" |
180 | R"==(_result = FMA8(_blockB1.s0, TRANSPOSE_8(_blockA, 8), _result); \ )==" "\n" |
181 | R"==(_result = FMA8(_blockB1.s1, TRANSPOSE_8(_blockA, 9), _result); \ )==" "\n" |
182 | R"==(_result = FMA8(_blockB1.s2, TRANSPOSE_8(_blockA, 10), _result); \ )==" "\n" |
183 | R"==(_result = FMA8(_blockB1.s3, TRANSPOSE_8(_blockA, 11), _result); \ )==" "\n" |
184 | R"==(_result = FMA8(_blockB1.s4, TRANSPOSE_8(_blockA, 12), _result); \ )==" "\n" |
185 | R"==(_result = FMA8(_blockB1.s5, TRANSPOSE_8(_blockA, 13), _result); \ )==" "\n" |
186 | R"==(_result = FMA8(_blockB1.s6, TRANSPOSE_8(_blockA, 14), _result); \ )==" "\n" |
187 | R"==(_result = FMA8(_blockB1.s7, TRANSPOSE_8(_blockA, 15), _result); \ )==" "\n" |
188 | R"==(} )==" "\n" |
189 | R"==(DATA8_T blockA0, blockA1; )==" "\n" |
190 | R"==(LOAD_DIFF_DST(blockA0, diff_dst1, 0); )==" "\n" |
191 | R"==(LOAD_DIFF_DST(blockA1, diff_dst1, 8); )==" "\n" |
192 | R"==(DATA8_T blockB00 = AS_DATA8_T( )==" "\n" |
193 | R"==(BLOCK_READ8((const __global BLOCK_DATA_T *)wei1)); )==" "\n" |
194 | R"==(DATA8_T blockB01 = AS_DATA8_T( )==" "\n" |
195 | R"==(BLOCK_READ8((const __global BLOCK_DATA_T *)(wei1 )==" "\n" |
196 | R"==(+ 8 * IC_BLOCK))); )==" "\n" |
197 | R"==(MULTIPLY_BLOCKS_8x8(blockC00, blockA0, blockB00, blockB01); )==" "\n" |
198 | R"==(MULTIPLY_BLOCKS_8x8(blockC01, blockA1, blockB00, blockB01); )==" "\n" |
199 | R"==(#undef TRANSPOSE_BLOCK_8 )==" "\n" |
200 | R"==(#undef MULTIPLY_BLOCKS_8x8 )==" "\n" |
201 | R"==(#if KH != 1 || KW != 1 || KD != 1 )==" "\n" |
202 | R"==(} )==" "\n" |
203 | R"==(#else )==" "\n" |
204 | R"==(#if SW != 1 || SH != 1 || SD != 1 || PH != 0 || PW != 0 || PD != 0 )==" "\n" |
205 | R"==(} )==" "\n" |
206 | R"==(#endif )==" "\n" |
207 | R"==(#endif )==" "\n" |
208 | R"==(diff_dst += OC_BLOCK * OD * OH * OW * MB_BLOCK; )==" "\n" |
209 | R"==(wei += IC * KD * KH * KW * OC_BLOCK; )==" "\n" |
210 | R"==(ocb += OC_BLOCK; )==" "\n" |
211 | R"==(} while (ocb < OC); )==" "\n" |
212 | R"==(__global DATA_T *src_write0 = diff_src + mb * IC * G * ID * IH * IW )==" "\n" |
213 | R"==(+ gic * ID * IH * IW * IC_BLOCK * MB_BLOCK )==" "\n" |
214 | R"==(+ g * IC * ID * IH * IW * MB_BLOCK )==" "\n" |
215 | R"==(+ id * IH * IW * IC_BLOCK * MB_BLOCK + ih * IW * IC_BLOCK * MB_BLOCK )==" "\n" |
216 | R"==(+ iw * IC_BLOCK * MB_BLOCK; )==" "\n" |
217 | R"==(SAVE_SRC_DIFF(blockC00, src_write0, 0); )==" "\n" |
218 | R"==(SAVE_SRC_DIFF(blockC01, src_write0, 8); )==" "\n" |
219 | R"==(#endif )==" "\n" |
220 | R"==(#if VER_8OW16C == 1 )==" "\n" |
221 | R"==(const int sp = get_group_id(1); )==" "\n" |
222 | R"==(const int sglid = get_sub_group_local_id(); )==" "\n" |
223 | R"==(const int icb_mb = get_group_id(2); )==" "\n" |
224 | R"==(const int mb = icb_mb / (G * IC / ICB); )==" "\n" |
225 | R"==(const int icb = icb_mb % (G * IC / ICB); )==" "\n" |
226 | R"==(const int ic = (icb * ICB) / IC_BLOCK )==" "\n" |
227 | R"==(+ get_group_id(0) * (LWS_0 / SUB_GROUP_SIZE) + get_sub_group_id(); )==" "\n" |
228 | R"==(const int g = ic / (IC / IC_BLOCK); )==" "\n" |
229 | R"==(const int gic = ic % (IC / IC_BLOCK); )==" "\n" |
230 | R"==(#if CASE_3D )==" "\n" |
231 | R"==(const int id = sp / (IWB * IH); )==" "\n" |
232 | R"==(const int ihw = sp % (IWB * IH); )==" "\n" |
233 | R"==(#else )==" "\n" |
234 | R"==(const int id = 0; )==" "\n" |
235 | R"==(const int ihw = sp; )==" "\n" |
236 | R"==(#endif )==" "\n" |
237 | R"==(const int ih = ihw / IWB; )==" "\n" |
238 | R"==(const int iw = (ihw % IWB) * IW_BLOCK; )==" "\n" |
239 | R"==(diff_dst += mb * OC * G * OD * OH * OW + g * OC * OD * OH * OW * MB_BLOCK; )==" "\n" |
240 | R"==(DATA_T blockC00[IW_BLOCK] = {DATA_ZERO}; )==" "\n" |
241 | R"==(if (WITH_BIAS) { )==" "\n" |
242 | R"==(#if IS_DW )==" "\n" |
243 | R"==(const int bg_off = g * IC + sglid; )==" "\n" |
244 | R"==(const int bc_off = gic * IC_BLOCK; )==" "\n" |
245 | R"==(DATA_T b = (G_WO_PADDING % IC_BLOCK == 0 || bg_off < G_WO_PADDING) )==" "\n" |
246 | R"==(? bias[bg_off + bc_off] )==" "\n" |
247 | R"==(: DATA_ZERO; )==" "\n" |
248 | R"==(#else )==" "\n" |
249 | R"==(const int bg_off = g * IC; )==" "\n" |
250 | R"==(const int bc_off = gic * IC_BLOCK + sglid; )==" "\n" |
251 | R"==(DATA_T b = (IC_WO_PADDING % IC_BLOCK == 0 || bc_off < IC_WO_PADDING) )==" "\n" |
252 | R"==(? bias[bg_off + bc_off] )==" "\n" |
253 | R"==(: DATA_ZERO; )==" "\n" |
254 | R"==(#endif )==" "\n" |
255 | R"==(unroll_for(int i = 0; i < IW_BLOCK; ++i) { blockC00[i] = b; } )==" "\n" |
256 | R"==(} )==" "\n" |
257 | R"==(wei += gic * KD * KH * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
258 | R"==(+ g * IC * OC * KD * KH * KW; )==" "\n" |
259 | R"==(for (int ocb = 0; ocb < OC; ocb += OC_BLOCK) { )==" "\n" |
260 | R"==(const __global DATA_T *diff_dst1; )==" "\n" |
261 | R"==(const __global DATA_T *wei1; )==" "\n" |
262 | R"==(#if KH != 1 || KW != 1 || KD != 1 )==" "\n" |
263 | R"==(for (int kd = 0; kd < KD; ++kd) { )==" "\n" |
264 | R"==(#if CASE_3D )==" "\n" |
265 | R"==(if (id + PD < kd * (1 + DD)) continue; )==" "\n" |
266 | R"==(int od = id - kd * (1 + DD) + PD; )==" "\n" |
267 | R"==(if (od % SD != 0) continue; )==" "\n" |
268 | R"==(od /= SD; )==" "\n" |
269 | R"==(if (od >= OD) continue; )==" "\n" |
270 | R"==(#endif )==" "\n" |
271 | R"==(for (int kh = 0; kh < KH; ++kh) { )==" "\n" |
272 | R"==(if (ih + PH < kh * (1 + DH)) continue; )==" "\n" |
273 | R"==(int oh = ih - kh * (1 + DH) + PH; )==" "\n" |
274 | R"==(if (oh % SH != 0) continue; )==" "\n" |
275 | R"==(oh /= SH; )==" "\n" |
276 | R"==(if (oh >= OH) continue; )==" "\n" |
277 | R"==(__attribute__((opencl_unroll_hint(KW))) )==" "\n" |
278 | R"==(for (int kw = 0; kw < KW; ++kw) { )==" "\n" |
279 | R"==(diff_dst1 = diff_dst + oh * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
280 | R"==(#if CASE_3D )==" "\n" |
281 | R"==(diff_dst1 += od * OH * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
282 | R"==(#endif )==" "\n" |
283 | R"==(wei1 = wei )==" "\n" |
284 | R"==(#if CASE_3D )==" "\n" |
285 | R"==(+ kd * KH * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
286 | R"==(#endif )==" "\n" |
287 | R"==(+ kh * KW * OC_BLOCK * IC_BLOCK )==" "\n" |
288 | R"==(+ kw * OC_BLOCK * IC_BLOCK; )==" "\n" |
289 | R"==(#else )==" "\n" |
290 | R"==(int oh = (ih + PH); )==" "\n" |
291 | R"==(#if CASE_3D )==" "\n" |
292 | R"==(int od = (id + PD); )==" "\n" |
293 | R"==(#endif )==" "\n" |
294 | R"==(bool do_ker = true; )==" "\n" |
295 | R"==(#if SW != 1 || SH != 1 || SD != 1 )==" "\n" |
296 | R"==(do_ker = oh % SH == 0; )==" "\n" |
297 | R"==(oh /= SH; )==" "\n" |
298 | R"==(#if CASE_3D )==" "\n" |
299 | R"==(do_ker = do_ker && od % SD == 0; )==" "\n" |
300 | R"==(od /= SD; )==" "\n" |
301 | R"==(#endif )==" "\n" |
302 | R"==(#endif )==" "\n" |
303 | R"==(#if PH != 0 || PW != 0 || PD != 0 )==" "\n" |
304 | R"==(do_ker = do_ker && (oh < OH); )==" "\n" |
305 | R"==(#if CASE_3D )==" "\n" |
306 | R"==(do_ker = do_ker && (od < OD); )==" "\n" |
307 | R"==(#endif )==" "\n" |
308 | R"==(#endif )==" "\n" |
309 | R"==(#if SW != 1 || SH != 1 || SD != 1 || PH != 0 || PW != 0 || PD != 0 )==" "\n" |
310 | R"==(if (do_ker) { )==" "\n" |
311 | R"==(#endif )==" "\n" |
312 | R"==(diff_dst1 = diff_dst + oh * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
313 | R"==(#if CASE_3D )==" "\n" |
314 | R"==(diff_dst1 += od * OH * OW * OC_BLOCK * MB_BLOCK; )==" "\n" |
315 | R"==(#endif )==" "\n" |
316 | R"==(wei1 = wei; )==" "\n" |
317 | R"==(#endif )==" "\n" |
318 | R"==(#define TRANSPOSE_1(_block, _col) \ )==" "\n" |
319 | R"==((DATA_T)(intel_sub_group_shuffle(_block, _col)) )==" "\n" |
320 | R"==(#define FMA1(a, b, c) fma((DATA_T)(a), (DATA_T)b, (DATA_T)c) )==" "\n" |
321 | R"==(#define HAS_PAD_W (PW > 0 || OW * SW - PW + (KW - 1) * (1 + DW) >= IW) )==" "\n" |
322 | R"==(#define _BLOCK_READ8(ptr) \ )==" "\n" |
323 | R"==(AS_DATA8_T(BLOCK_READ8((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
324 | R"==(#define _BLOCK_READ4(ptr) \ )==" "\n" |
325 | R"==(AS_DATA4_T(BLOCK_READ4((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
326 | R"==(#define _BLOCK_READ2(ptr) \ )==" "\n" |
327 | R"==(AS_DATA2_T(BLOCK_READ2((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
328 | R"==(#define _BLOCK_READ(ptr) \ )==" "\n" |
329 | R"==(AS_DATA_T(BLOCK_READ((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
330 | R"==(#define unrolled_read(n, block, ptr) \ )==" "\n" |
331 | R"==(do { \ )==" "\n" |
332 | R"==(if ((n)&16) { \ )==" "\n" |
333 | R"==(*((DATA8_T *)(block)) = _BLOCK_READ8((ptr)); \ )==" "\n" |
334 | R"==(*((DATA8_T *)((block) + 8)) = _BLOCK_READ8((ptr) + 8 * 16); \ )==" "\n" |
335 | R"==(} \ )==" "\n" |
336 | R"==(if ((n)&8) \ )==" "\n" |
337 | R"==(*((DATA8_T *)((block) + ((n) & ~15))) \ )==" "\n" |
338 | R"==(= _BLOCK_READ8((ptr) + ((n) & ~15) * 16); \ )==" "\n" |
339 | R"==(if ((n)&4) \ )==" "\n" |
340 | R"==(*((DATA4_T *)((block) + ((n) & ~7))) \ )==" "\n" |
341 | R"==(= _BLOCK_READ4((ptr) + ((n) & ~7) * 16); \ )==" "\n" |
342 | R"==(if ((n)&2) \ )==" "\n" |
343 | R"==(*((DATA2_T *)((block) + ((n) & ~3))) \ )==" "\n" |
344 | R"==(= _BLOCK_READ2((ptr) + ((n) & ~3) * 16); \ )==" "\n" |
345 | R"==(if ((n)&1) \ )==" "\n" |
346 | R"==(*((block) + ((n) & ~1)) = _BLOCK_READ((ptr) + ((n) & ~1) * 16); \ )==" "\n" |
347 | R"==(} while (0) )==" "\n" |
348 | R"==(#define MULTIPLY_BLOCKS_8x8(_result, _blockA, _blockB, _blockB1) \ )==" "\n" |
349 | R"==({ \ )==" "\n" |
350 | R"==(_result = FMA1(_blockB.s0, TRANSPOSE_1(_blockA, 0), _result); \ )==" "\n" |
351 | R"==(_result = FMA1(_blockB.s1, TRANSPOSE_1(_blockA, 1), _result); \ )==" "\n" |
352 | R"==(_result = FMA1(_blockB.s2, TRANSPOSE_1(_blockA, 2), _result); \ )==" "\n" |
353 | R"==(_result = FMA1(_blockB.s3, TRANSPOSE_1(_blockA, 3), _result); \ )==" "\n" |
354 | R"==(_result = FMA1(_blockB.s4, TRANSPOSE_1(_blockA, 4), _result); \ )==" "\n" |
355 | R"==(_result = FMA1(_blockB.s5, TRANSPOSE_1(_blockA, 5), _result); \ )==" "\n" |
356 | R"==(_result = FMA1(_blockB.s6, TRANSPOSE_1(_blockA, 6), _result); \ )==" "\n" |
357 | R"==(_result = FMA1(_blockB.s7, TRANSPOSE_1(_blockA, 7), _result); \ )==" "\n" |
358 | R"==(_result = FMA1(_blockB1.s0, TRANSPOSE_1(_blockA, 8), _result); \ )==" "\n" |
359 | R"==(_result = FMA1(_blockB1.s1, TRANSPOSE_1(_blockA, 9), _result); \ )==" "\n" |
360 | R"==(_result = FMA1(_blockB1.s2, TRANSPOSE_1(_blockA, 10), _result); \ )==" "\n" |
361 | R"==(_result = FMA1(_blockB1.s3, TRANSPOSE_1(_blockA, 11), _result); \ )==" "\n" |
362 | R"==(_result = FMA1(_blockB1.s4, TRANSPOSE_1(_blockA, 12), _result); \ )==" "\n" |
363 | R"==(_result = FMA1(_blockB1.s5, TRANSPOSE_1(_blockA, 13), _result); \ )==" "\n" |
364 | R"==(_result = FMA1(_blockB1.s6, TRANSPOSE_1(_blockA, 14), _result); \ )==" "\n" |
365 | R"==(_result = FMA1(_blockB1.s7, TRANSPOSE_1(_blockA, 15), _result); \ )==" "\n" |
366 | R"==(} )==" "\n" |
367 | R"==(DATA8_T blockB00 = AS_DATA8_T( )==" "\n" |
368 | R"==(BLOCK_READ8((const __global BLOCK_DATA_T *)wei1)); )==" "\n" |
369 | R"==(DATA8_T blockB01 = AS_DATA8_T( )==" "\n" |
370 | R"==(BLOCK_READ8((const __global BLOCK_DATA_T *)(wei1 )==" "\n" |
371 | R"==(+ 8 * IC_BLOCK))); )==" "\n" |
372 | R"==(DATA_T blockA[IW_BLOCK] = {0}; )==" "\n" |
373 | R"==(#if KW == 1 && !HAS_PAD_W && SW == 1 )==" "\n" |
374 | R"==(int iw_bound = min(IW_BLOCK, IW - iw); )==" "\n" |
375 | R"==(int ow = iw; )==" "\n" |
376 | R"==(unrolled_read( )==" "\n" |
377 | R"==(iw_bound, &blockA[0], &(diff_dst1)[ow * OC_BLOCK]); )==" "\n" |
378 | R"==(__attribute__(( )==" "\n" |
379 | R"==(opencl_unroll_hint(IW_BLOCK))) )==" "\n" |
380 | R"==(for (int i = 0; i < IW_BLOCK; i++) { )==" "\n" |
381 | R"==(MULTIPLY_BLOCKS_8x8( )==" "\n" |
382 | R"==(blockC00[i], blockA[i], blockB00, blockB01); )==" "\n" |
383 | R"==(} )==" "\n" |
384 | R"==(#else )==" "\n" |
385 | R"==(__attribute__((opencl_unroll_hint(IW_BLOCK))) )==" "\n" |
386 | R"==(for (int i = 0; i < IW_BLOCK; i++) { )==" "\n" |
387 | R"==(#if KW != 1 )==" "\n" |
388 | R"==(if (iw + i + PW < kw * (1 + DW)) continue; )==" "\n" |
389 | R"==(int ow = iw + i - kw * (1 + DW) + PW; )==" "\n" |
390 | R"==(#else )==" "\n" |
391 | R"==(int ow = iw + i + PW; )==" "\n" |
392 | R"==(#endif )==" "\n" |
393 | R"==(#if SW != 1 )==" "\n" |
394 | R"==(if (ow % SW != 0) continue; )==" "\n" |
395 | R"==(ow /= SW; )==" "\n" |
396 | R"==(#endif )==" "\n" |
397 | R"==(if (ow >= OW) continue; )==" "\n" |
398 | R"==(blockA[i] = AS_DATA_T( )==" "\n" |
399 | R"==(BLOCK_READ((const __global BLOCK_DATA_T *)(&( )==" "\n" |
400 | R"==(diff_dst1)[ow * OC_BLOCK]))); )==" "\n" |
401 | R"==(} )==" "\n" |
402 | R"==(__attribute__((opencl_unroll_hint(IW_BLOCK))) )==" "\n" |
403 | R"==(for (int i = 0; i < IW_BLOCK; i++) { )==" "\n" |
404 | R"==(MULTIPLY_BLOCKS_8x8(blockC00[i], blockA[i], blockB00, blockB01); )==" "\n" |
405 | R"==(} )==" "\n" |
406 | R"==(#endif )==" "\n" |
407 | R"==(#undef TRANSPOSE_BLOCK_8 )==" "\n" |
408 | R"==(#undef MULTIPLY_BLOCKS_8x8 )==" "\n" |
409 | R"==(#if KH != 1 || KW != 1 || KD != 1 )==" "\n" |
410 | R"==(} )==" "\n" |
411 | R"==(} )==" "\n" |
412 | R"==(} )==" "\n" |
413 | R"==(#else )==" "\n" |
414 | R"==(#if SW != 1 || SH != 1 || SD != 1 || PH != 0 || PW != 0 || PD != 0 )==" "\n" |
415 | R"==(} )==" "\n" |
416 | R"==(#endif )==" "\n" |
417 | R"==(#endif )==" "\n" |
418 | R"==(diff_dst += OC_BLOCK * OD * OH * OW * MB_BLOCK; )==" "\n" |
419 | R"==(wei += IC * KD * KH * KW * OC_BLOCK; )==" "\n" |
420 | R"==(} )==" "\n" |
421 | R"==(__global DATA_T *src_write0 = diff_src + mb * IC * G * ID * IH * IW )==" "\n" |
422 | R"==(+ gic * ID * IH * IW * IC_BLOCK * MB_BLOCK )==" "\n" |
423 | R"==(+ g * IC * ID * IH * IW * MB_BLOCK )==" "\n" |
424 | R"==(+ id * IH * IW * IC_BLOCK * MB_BLOCK + ih * IW * IC_BLOCK * MB_BLOCK )==" "\n" |
425 | R"==(+ iw * IC_BLOCK * MB_BLOCK; )==" "\n" |
426 | R"==(for (int i = 0; i < IW_BLOCK; i++) { )==" "\n" |
427 | R"==(if (iw + i >= IW) continue; )==" "\n" |
428 | R"==(BLOCK_WRITE((__global BLOCK_DATA_T *)(&(src_write0)[i * IC_BLOCK]), )==" "\n" |
429 | R"==(AS_BLOCK_DATA_T(blockC00[i])); )==" "\n" |
430 | R"==(} )==" "\n" |
431 | R"==(#endif )==" "\n" |
432 | R"==(} )==" "\n" |
433 | R"==(#endif )==" "\n" |
434 | R"==()==" ; |
435 | } |
436 | } |
437 | } |
438 | } |