1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *gen9_conv_fwd_data_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2020-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_post_ops.h" )==" "\n" |
21 | R"==(#include "gpu/ocl/ocl_types.h" )==" "\n" |
22 | R"==(#include "gpu/ocl/offsets.h" )==" "\n" |
23 | R"==(#define BASE_OC_TAIL (SUB_GROUP_SIZE - (OC - OC_WO_PADDING)) )==" "\n" |
24 | R"==(#define _BLOCK_READ_DST(v, n_c, ptr) \ )==" "\n" |
25 | R"==(if (n_c == 8) \ )==" "\n" |
26 | R"==((*(DATA8_T *)(v)) = CONVERT_DATA8_T( \ )==" "\n" |
27 | R"==(vload8(0, (const __global DST_DATA_T *)(ptr))); \ )==" "\n" |
28 | R"==(if (n_c == 4) \ )==" "\n" |
29 | R"==((*(DATA4_T *)(v)) = CONVERT_DATA4_T( \ )==" "\n" |
30 | R"==(vload4(0, (const __global DST_DATA_T *)(ptr))); \ )==" "\n" |
31 | R"==(if (n_c == 2) \ )==" "\n" |
32 | R"==((*(DATA2_T *)(v)) = CONVERT_DATA2_T( \ )==" "\n" |
33 | R"==(vload2(0, (const __global DST_DATA_T *)(ptr))); \ )==" "\n" |
34 | R"==(if (n_c == 1) \ )==" "\n" |
35 | R"==((*(DATA_T *)(v)) = CONVERT_DATA_T(*(__global DST_DATA_T *)(ptr)); )==" "\n" |
36 | R"==(#define _BLOCK_READ8(ptr) \ )==" "\n" |
37 | R"==(AS_DATA8_T(BLOCK_READ8((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
38 | R"==(#define _BLOCK_READ4(ptr) \ )==" "\n" |
39 | R"==(AS_DATA4_T(BLOCK_READ4((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
40 | R"==(#define _BLOCK_READ2(ptr) \ )==" "\n" |
41 | R"==(AS_DATA2_T(BLOCK_READ2((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
42 | R"==(#define _BLOCK_READ(ptr) \ )==" "\n" |
43 | R"==(AS_DATA_T(BLOCK_READ((const __global BLOCK_DATA_T *)(ptr))) )==" "\n" |
44 | R"==(#ifdef DST_DT_S8 )==" "\n" |
45 | R"==(#if DST_NCHW )==" "\n" |
46 | R"==(#define _BLOCK_WRITE8(ptr, v) \ )==" "\n" |
47 | R"==(vstore8(CONVERT_DST_DATA8_T(v), 0, (__global DST_DATA_T *)(ptr)); )==" "\n" |
48 | R"==(#define _BLOCK_WRITE4(ptr, v) \ )==" "\n" |
49 | R"==(vstore4(CONVERT_DST_DATA4_T(v), 0, (__global DST_DATA_T *)(ptr)); )==" "\n" |
50 | R"==(#define _BLOCK_WRITE2(ptr, v) \ )==" "\n" |
51 | R"==(vstore2(CONVERT_DST_DATA2_T(v), 0, (__global DST_DATA_T *)(ptr)); )==" "\n" |
52 | R"==(#define _BLOCK_WRITE(ptr, v) \ )==" "\n" |
53 | R"==(*(__global DST_DATA_T *)(ptr) = CONVERT_DST_DATA_T(v); )==" "\n" |
54 | R"==(#else )==" "\n" |
55 | R"==(#define _BLOCK_WRITE8(ptr, v) \ )==" "\n" |
56 | R"==(BLOCK_WRITE_DST8((__global DST_DATA_T *)(ptr), CONVERT_DST_DATA8_T(v)); )==" "\n" |
57 | R"==(#define _BLOCK_WRITE4(ptr, v) \ )==" "\n" |
58 | R"==(BLOCK_WRITE_DST4((__global DST_DATA_T *)(ptr), CONVERT_DST_DATA4_T(v)); )==" "\n" |
59 | R"==(#define _BLOCK_WRITE2(ptr, v) \ )==" "\n" |
60 | R"==(BLOCK_WRITE_DST2((__global DST_DATA_T *)(ptr), CONVERT_DST_DATA2_T(v)); )==" "\n" |
61 | R"==(#define _BLOCK_WRITE(ptr, v) \ )==" "\n" |
62 | R"==(BLOCK_WRITE_DST((__global DST_DATA_T *)(ptr), CONVERT_DST_DATA_T(v)); )==" "\n" |
63 | R"==(#endif )==" "\n" |
64 | R"==(#else )==" "\n" |
65 | R"==(#define _BLOCK_WRITE8(ptr, v) \ )==" "\n" |
66 | R"==(BLOCK_WRITE8((__global BLOCK_DATA_T *)(ptr), AS_BLOCK_DATA8_T(v)); )==" "\n" |
67 | R"==(#define _BLOCK_WRITE4(ptr, v) \ )==" "\n" |
68 | R"==(BLOCK_WRITE4((__global BLOCK_DATA_T *)(ptr), AS_BLOCK_DATA4_T(v)); )==" "\n" |
69 | R"==(#define _BLOCK_WRITE2(ptr, v) \ )==" "\n" |
70 | R"==(BLOCK_WRITE2((__global BLOCK_DATA_T *)(ptr), AS_BLOCK_DATA2_T(v)); )==" "\n" |
71 | R"==(#define _BLOCK_WRITE(ptr, v) \ )==" "\n" |
72 | R"==(BLOCK_WRITE((__global BLOCK_DATA_T *)(ptr), AS_BLOCK_DATA_T(v)); )==" "\n" |
73 | R"==(#endif )==" "\n" |
74 | R"==(#define IS_3D (OD > 1) )==" "\n" |
75 | R"==(#define IS_1STCONV (IC == 3) )==" "\n" |
76 | R"==(#define HAS_PAD_D (PD > 0 || OD * SD - PD + (KD - 1) * (1 + DD) >= ID) )==" "\n" |
77 | R"==(#define HAS_PAD_H (PH > 0 || OH * SH - PH + (KH - 1) * (1 + DH) >= IH) )==" "\n" |
78 | R"==(#define HAS_PAD_W (PW > 0 || OW * SW - PW + (KW - 1) * (1 + DW) >= IW) )==" "\n" |
79 | R"==(#define ENABLE_SRC_BUF (MB_BLOCK == 1 && KW >= 3) )==" "\n" |
80 | R"==(#define W_VEC (IS_1STCONV && ENABLE_SRC_BUF && KW >= 5 && SW <= 3) )==" "\n" |
81 | R"==(#define C_VEC (!W_VEC) )==" "\n" |
82 | R"==(#define IC_INNER (C_VEC ? (IC < 16 ? IC : 16) : 1) )==" "\n" |
83 | R"==(#define IC_OUTER (IC_BLOCK / IC_INNER) )==" "\n" |
84 | R"==(#define OC_OUTER (OC_BLOCK / 16) )==" "\n" |
85 | R"==(#define IW_BLOCK (SW * (OW_BLOCK - 1) + (KW - 1) * (1 + DW) + 1) )==" "\n" |
86 | R"==(#define OW_INNER (C_VEC ? 1 : 16) )==" "\n" |
87 | R"==(#define IW_INNER OW_INNER )==" "\n" |
88 | R"==(#define OW_OUTER ((OW_BLOCK + OW_INNER - 1) / OW_INNER) )==" "\n" |
89 | R"==(#define IW_OUTER ((IW_BLOCK + IW_INNER - 1) / IW_INNER) )==" "\n" |
90 | R"==(#define C_SIZE (MB_BLOCK * OC_OUTER * OW_BLOCK) )==" "\n" |
91 | R"==(#if OW_BLOCK >= 32 )==" "\n" |
92 | R"==(#error "Block is too big for unrolled_read and unrolled_write." )==" "\n" |
93 | R"==(#endif )==" "\n" |
94 | R"==(int src_idx_c_vec(int mb_block, int ic_outer, int ow_outer) { )==" "\n" |
95 | R"==(if (SRC_16N16C) )==" "\n" |
96 | R"==(return ic_outer * OW_BLOCK * MB_BLOCK + ow_outer * MB_BLOCK + mb_block; )==" "\n" |
97 | R"==(return mb_block * IC_OUTER * OW_BLOCK + ic_outer * OW_BLOCK + ow_outer; )==" "\n" |
98 | R"==(} )==" "\n" |
99 | R"==(int src_idx_w_vec(int mb_block, int ic_outer, int ow_outer) { )==" "\n" |
100 | R"==(return mb_block * IC_OUTER * OW_OUTER + ic_outer * OW_OUTER + ow_outer; )==" "\n" |
101 | R"==(} )==" "\n" |
102 | R"==(int src_idx(int mb_block, int ic_outer, int ow_outer) { )==" "\n" |
103 | R"==(if (C_VEC) return src_idx_c_vec(mb_block, ic_outer, ow_outer); )==" "\n" |
104 | R"==(return src_idx_w_vec(mb_block, ic_outer, ow_outer); )==" "\n" |
105 | R"==(} )==" "\n" |
106 | R"==(int src_buf_idx_c_vec(int mb_block, int ic_outer, int iw_outer) { )==" "\n" |
107 | R"==(if (SRC_16N16C) )==" "\n" |
108 | R"==(return mb_block * IC_OUTER * IW_OUTER + ic_outer * IW_OUTER + iw_outer; )==" "\n" |
109 | R"==(return ic_outer * IW_OUTER * MB_BLOCK + iw_outer * MB_BLOCK + mb_block; )==" "\n" |
110 | R"==(} )==" "\n" |
111 | R"==(int src_buf_idx_w_vec(int mb_block, int ic_outer, int iw_outer) { )==" "\n" |
112 | R"==(return mb_block * IC_OUTER * IW_OUTER + ic_outer * IW_OUTER + iw_outer; )==" "\n" |
113 | R"==(} )==" "\n" |
114 | R"==(int src_buf_idx(int mb_block, int ic_outer, int iw_outer) { )==" "\n" |
115 | R"==(if (C_VEC) return src_buf_idx_c_vec(mb_block, ic_outer, iw_outer); )==" "\n" |
116 | R"==(return src_buf_idx_w_vec(mb_block, ic_outer, iw_outer); )==" "\n" |
117 | R"==(} )==" "\n" |
118 | R"==(int wei_idx_c_vec(int oc_outer, int ic_outer) { )==" "\n" |
119 | R"==(return ic_outer * OC_OUTER * IC_INNER + oc_outer * IC_INNER; )==" "\n" |
120 | R"==(} )==" "\n" |
121 | R"==(int wei_idx_w_vec(int oc_outer, int ic_outer) { )==" "\n" |
122 | R"==(return oc_outer * IC_OUTER + ic_outer; )==" "\n" |
123 | R"==(} )==" "\n" |
124 | R"==(int wei_idx(int oc_outer, int ic_outer) { )==" "\n" |
125 | R"==(if (C_VEC) return wei_idx_c_vec(oc_outer, ic_outer); )==" "\n" |
126 | R"==(return wei_idx_w_vec(oc_outer, ic_outer); )==" "\n" |
127 | R"==(} )==" "\n" |
128 | R"==(int dst_idx(int mb_block, int oc_outer, int ow_block) { )==" "\n" |
129 | R"==(if (DST_16N16C || DST_32N16C) )==" "\n" |
130 | R"==(return oc_outer * OW_BLOCK * MB_BLOCK + ow_block * MB_BLOCK + mb_block; )==" "\n" |
131 | R"==(return mb_block * OC_OUTER * OW_BLOCK + oc_outer * OW_BLOCK + ow_block; )==" "\n" |
132 | R"==(} )==" "\n" |
133 | R"==(#define copy(dst, src, n) \ )==" "\n" |
134 | R"==(do { \ )==" "\n" |
135 | R"==(for (int i = 0; i < (n); i++) \ )==" "\n" |
136 | R"==((dst)[i] = (src)[i]; \ )==" "\n" |
137 | R"==(} while (0) )==" "\n" |
138 | R"==(#define unrolled_read(n, block, ptr) \ )==" "\n" |
139 | R"==(do { \ )==" "\n" |
140 | R"==(if ((n)&16) { \ )==" "\n" |
141 | R"==(*((DATA8_T *)(block)) = _BLOCK_READ8((ptr)); \ )==" "\n" |
142 | R"==(*((DATA8_T *)((block) + 8)) = _BLOCK_READ8((ptr) + 8 * 16); \ )==" "\n" |
143 | R"==(} \ )==" "\n" |
144 | R"==(if ((n)&8) \ )==" "\n" |
145 | R"==(*((DATA8_T *)((block) + ((n) & ~15))) \ )==" "\n" |
146 | R"==(= _BLOCK_READ8((ptr) + ((n) & ~15) * 16); \ )==" "\n" |
147 | R"==(if ((n)&4) \ )==" "\n" |
148 | R"==(*((DATA4_T *)((block) + ((n) & ~7))) \ )==" "\n" |
149 | R"==(= _BLOCK_READ4((ptr) + ((n) & ~7) * 16); \ )==" "\n" |
150 | R"==(if ((n)&2) \ )==" "\n" |
151 | R"==(*((DATA2_T *)((block) + ((n) & ~3))) \ )==" "\n" |
152 | R"==(= _BLOCK_READ2((ptr) + ((n) & ~3) * 16); \ )==" "\n" |
153 | R"==(if ((n)&1) \ )==" "\n" |
154 | R"==(*((block) + ((n) & ~1)) = _BLOCK_READ((ptr) + ((n) & ~1) * 16); \ )==" "\n" |
155 | R"==(} while (0) )==" "\n" |
156 | R"==(#define strided_read(block, ptr, n, stride) \ )==" "\n" |
157 | R"==(do { \ )==" "\n" |
158 | R"==(if ((n) == 16 && (stride) == 1) { \ )==" "\n" |
159 | R"==((block)[0] = _BLOCK_READ((ptr)); \ )==" "\n" |
160 | R"==(} else { \ )==" "\n" |
161 | R"==(int sglid = get_sub_group_local_id(); \ )==" "\n" |
162 | R"==((block)[0] = (sglid < (n)) ? (ptr)[sglid * (stride)] : 0; \ )==" "\n" |
163 | R"==(} \ )==" "\n" |
164 | R"==(} while (0) )==" "\n" |
165 | R"==(#if DST_NCHW )==" "\n" |
166 | R"==(#define unrolled_write(n, block, ptr) \ )==" "\n" |
167 | R"==(do { \ )==" "\n" |
168 | R"==(if ((n)&16) { \ )==" "\n" |
169 | R"==(_BLOCK_WRITE8((ptr), *(DATA8_T *)((block))); \ )==" "\n" |
170 | R"==(_BLOCK_WRITE8((ptr) + 8 * 16, *(DATA8_T *)((block) + 8)); \ )==" "\n" |
171 | R"==(} \ )==" "\n" |
172 | R"==(if ((n)&8) \ )==" "\n" |
173 | R"==(_BLOCK_WRITE8( \ )==" "\n" |
174 | R"==((ptr) + ((n) & ~15), *(DATA8_T *)((block) + ((n) & ~15))); \ )==" "\n" |
175 | R"==(if ((n)&4) \ )==" "\n" |
176 | R"==(_BLOCK_WRITE4( \ )==" "\n" |
177 | R"==((ptr) + ((n) & ~7), *(DATA4_T *)((block) + ((n) & ~7))); \ )==" "\n" |
178 | R"==(if ((n)&2) \ )==" "\n" |
179 | R"==(_BLOCK_WRITE2( \ )==" "\n" |
180 | R"==((ptr) + ((n) & ~3), *(DATA2_T *)((block) + ((n) & ~3))); \ )==" "\n" |
181 | R"==(if ((n)&1) _BLOCK_WRITE((ptr) + ((n) & ~1), *((block) + ((n) & ~1))); \ )==" "\n" |
182 | R"==(} while (0) )==" "\n" |
183 | R"==(#else )==" "\n" |
184 | R"==(#define unrolled_write(n, block, ptr) \ )==" "\n" |
185 | R"==(do { \ )==" "\n" |
186 | R"==(if ((n)&16) { \ )==" "\n" |
187 | R"==(_BLOCK_WRITE8((ptr), *(DATA8_T *)((block))); \ )==" "\n" |
188 | R"==(_BLOCK_WRITE8((ptr) + 8 * 16, *(DATA8_T *)((block) + 8)); \ )==" "\n" |
189 | R"==(} \ )==" "\n" |
190 | R"==(if ((n)&8) \ )==" "\n" |
191 | R"==(_BLOCK_WRITE8((ptr) + ((n) & ~15) * 16, \ )==" "\n" |
192 | R"==(*(DATA8_T *)((block) + ((n) & ~15))); \ )==" "\n" |
193 | R"==(if ((n)&4) \ )==" "\n" |
194 | R"==(_BLOCK_WRITE4((ptr) + ((n) & ~7) * 16, \ )==" "\n" |
195 | R"==(*(DATA4_T *)((block) + ((n) & ~7))); \ )==" "\n" |
196 | R"==(if ((n)&2) \ )==" "\n" |
197 | R"==(_BLOCK_WRITE2((ptr) + ((n) & ~3) * 16, \ )==" "\n" |
198 | R"==(*(DATA2_T *)((block) + ((n) & ~3))); \ )==" "\n" |
199 | R"==(if ((n)&1) \ )==" "\n" |
200 | R"==(_BLOCK_WRITE((ptr) + ((n) & ~1) * 16, *((block) + ((n) & ~1))); \ )==" "\n" |
201 | R"==(} while (0) )==" "\n" |
202 | R"==(#endif )==" "\n" |
203 | R"==(#define multiply_row(C, A, B, mb_block, oc_outer, ic_outer, ow_outer) \ )==" "\n" |
204 | R"==(do { \ )==" "\n" |
205 | R"==(int b_off = wei_idx((oc_outer), (ic_outer)); \ )==" "\n" |
206 | R"==(int c_off = dst_idx((mb_block), (oc_outer), (ow_outer)); \ )==" "\n" |
207 | R"==(for (int ic_inner = 0; ic_inner < min(IC_WO_PADDING, IC_INNER); \ )==" "\n" |
208 | R"==(ic_inner++) { \ )==" "\n" |
209 | R"==((C)[c_off] = fma(intel_sub_group_shuffle((A), ic_inner), \ )==" "\n" |
210 | R"==((B)[b_off + ic_inner], (C)[c_off]); \ )==" "\n" |
211 | R"==(} \ )==" "\n" |
212 | R"==(} while (0) )==" "\n" |
213 | R"==(#define read_src_and_multiply_w16c_dense(ptr, iw, kw, C, B) \ )==" "\n" |
214 | R"==(do { \ )==" "\n" |
215 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) \ )==" "\n" |
216 | R"==(for (int ic_outer = 0; ic_outer < IC_OUTER; ic_outer++) { \ )==" "\n" |
217 | R"==(int idx = src_idx(mb_block, ic_outer, 0); \ )==" "\n" |
218 | R"==(for (int ow_block = 0; ow_block < OW_BLOCK; ow_block += 8) { \ )==" "\n" |
219 | R"==(int ow_bound = min(8, OW_BLOCK - ow_block); \ )==" "\n" |
220 | R"==(DATA_T A[8]; \ )==" "\n" |
221 | R"==(int off = src_off(mb_block, ic_outer * IC_INNER, 0, 0, \ )==" "\n" |
222 | R"==(ow_block + (kw) * (1 + DW)); \ )==" "\n" |
223 | R"==(unrolled_read(ow_bound, A, &(ptr)[off]); \ )==" "\n" |
224 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
225 | R"==(for (int i = 0; i < ow_bound; i++) { \ )==" "\n" |
226 | R"==(multiply_row((C), A[i], (B), mb_block, oc_outer, \ )==" "\n" |
227 | R"==(ic_outer, ow_block + i); \ )==" "\n" |
228 | R"==(} \ )==" "\n" |
229 | R"==(} \ )==" "\n" |
230 | R"==(} \ )==" "\n" |
231 | R"==(} \ )==" "\n" |
232 | R"==(} while (0) )==" "\n" |
233 | R"==(#define read_src_and_multiply_16n16c(ptr, iw, kw, do_w_check, C, B) \ )==" "\n" |
234 | R"==(do { \ )==" "\n" |
235 | R"==(for (int ow_block = 0; ow_block < OW_BLOCK; ow_block++) { \ )==" "\n" |
236 | R"==(int iw_off = ow_block * SW + (kw) * (1 + DW); \ )==" "\n" |
237 | R"==(if ((do_w_check) && HAS_PAD_W \ )==" "\n" |
238 | R"==(&& ((iw) + iw_off < 0 || (iw) + iw_off >= IW)) \ )==" "\n" |
239 | R"==(continue; \ )==" "\n" |
240 | R"==(for (int ic_outer = 0; ic_outer < IC_OUTER; ic_outer++) \ )==" "\n" |
241 | R"==(__attribute__((opencl_unroll_hint)) /* attr:no-format */ \ )==" "\n" |
242 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; \ )==" "\n" |
243 | R"==(mb_block += 8) { \ )==" "\n" |
244 | R"==(int mb_bound = min(8, MB_BLOCK - mb_block); \ )==" "\n" |
245 | R"==(DATA_T A[8]; \ )==" "\n" |
246 | R"==(int off = src_off( \ )==" "\n" |
247 | R"==(mb_block, ic_outer * IC_INNER, 0, 0, iw_off); \ )==" "\n" |
248 | R"==(unrolled_read(mb_bound, A, &(ptr)[off]); \ )==" "\n" |
249 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
250 | R"==(for (int i = 0; i < mb_bound; i++) { \ )==" "\n" |
251 | R"==(multiply_row((C), A[i], (B), mb_block + i, \ )==" "\n" |
252 | R"==(oc_outer, ic_outer, ow_block); \ )==" "\n" |
253 | R"==(} \ )==" "\n" |
254 | R"==(} \ )==" "\n" |
255 | R"==(} \ )==" "\n" |
256 | R"==(} \ )==" "\n" |
257 | R"==(} while (0) )==" "\n" |
258 | R"==(#define read_src_and_multiply_common(ptr, iw, kw, do_w_check, C, B) \ )==" "\n" |
259 | R"==(do { \ )==" "\n" |
260 | R"==(for (int i = 0; i < OW_BLOCK; i++) { \ )==" "\n" |
261 | R"==(int iw_off = i * SW + (kw) * (1 + DW); \ )==" "\n" |
262 | R"==(if ((do_w_check) && HAS_PAD_W \ )==" "\n" |
263 | R"==(&& ((iw) + iw_off < 0 || (iw) + iw_off >= IW)) \ )==" "\n" |
264 | R"==(continue; \ )==" "\n" |
265 | R"==(for (int ic_outer = 0; ic_outer < IC_OUTER; ic_outer++) { \ )==" "\n" |
266 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { \ )==" "\n" |
267 | R"==(int off = src_off( \ )==" "\n" |
268 | R"==(mb_block, ic_outer * IC_INNER, 0, 0, iw_off); \ )==" "\n" |
269 | R"==(DATA_T A; \ )==" "\n" |
270 | R"==(strided_read(&A, &(ptr)[off], IC_INNER, \ )==" "\n" |
271 | R"==(src_off(0, 1, 0, 0, 0)); \ )==" "\n" |
272 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
273 | R"==(int b_off = wei_idx(oc_outer, ic_outer); \ )==" "\n" |
274 | R"==(int c_off = dst_idx(mb_block, oc_outer, i); \ )==" "\n" |
275 | R"==(for (int ic_inner = 0; \ )==" "\n" |
276 | R"==(ic_inner < min(IC_WO_PADDING, IC_INNER); \ )==" "\n" |
277 | R"==(ic_inner++) { \ )==" "\n" |
278 | R"==((C)[c_off] = fma( \ )==" "\n" |
279 | R"==(intel_sub_group_shuffle(A, ic_inner), \ )==" "\n" |
280 | R"==((B)[b_off + ic_inner], (C)[c_off]); \ )==" "\n" |
281 | R"==(} \ )==" "\n" |
282 | R"==(} \ )==" "\n" |
283 | R"==(} \ )==" "\n" |
284 | R"==(} \ )==" "\n" |
285 | R"==(} \ )==" "\n" |
286 | R"==(} while (0) )==" "\n" |
287 | R"==(#define read_src_and_multiply(ptr, iw, kw, do_w_check, C, B) \ )==" "\n" |
288 | R"==(do { \ )==" "\n" |
289 | R"==(if (SRC_W16C && (!(do_w_check) || (!HAS_PAD_W && SW == 1))) { \ )==" "\n" |
290 | R"==(read_src_and_multiply_w16c_dense((ptr), (iw), (kw), (C), (B)); \ )==" "\n" |
291 | R"==(} else if (SRC_16N16C) { \ )==" "\n" |
292 | R"==(read_src_and_multiply_16n16c( \ )==" "\n" |
293 | R"==((ptr), (iw), (kw), (do_w_check), (C), (B)); \ )==" "\n" |
294 | R"==(} else { \ )==" "\n" |
295 | R"==(read_src_and_multiply_common( \ )==" "\n" |
296 | R"==((ptr), (iw), (kw), (do_w_check), (C), (B)); \ )==" "\n" |
297 | R"==(} \ )==" "\n" |
298 | R"==(} while (0) )==" "\n" |
299 | R"==(#define read_src_buf(buf, ptr, iw) \ )==" "\n" |
300 | R"==(do { \ )==" "\n" |
301 | R"==(for (int iw_outer = 0; iw_outer < IW_OUTER; iw_outer++) { \ )==" "\n" |
302 | R"==(int iw_inner = (C_VEC ? 0 : get_sub_group_local_id()); \ )==" "\n" |
303 | R"==(int iw_block = iw_outer * IW_INNER + iw_inner; \ )==" "\n" |
304 | R"==(if (HAS_PAD_W && ((iw) + iw_block < 0 || (iw) + iw_block >= IW)) \ )==" "\n" |
305 | R"==(continue; \ )==" "\n" |
306 | R"==(for (int ic_outer = 0; ic_outer < IC_OUTER; ic_outer++) { \ )==" "\n" |
307 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { \ )==" "\n" |
308 | R"==(int off = src_off( \ )==" "\n" |
309 | R"==(mb_block, ic_outer * IC_INNER, 0, 0, iw_block); \ )==" "\n" |
310 | R"==(int idx = src_buf_idx(mb_block, ic_outer, iw_outer); \ )==" "\n" |
311 | R"==(if (C_VEC) { \ )==" "\n" |
312 | R"==(strided_read(&(buf)[idx], &(ptr)[off], IC_INNER, \ )==" "\n" |
313 | R"==(src_off(0, 1, 0, 0, 0)); \ )==" "\n" |
314 | R"==(} else { \ )==" "\n" |
315 | R"==((buf)[idx] = (ptr)[off]; \ )==" "\n" |
316 | R"==(} \ )==" "\n" |
317 | R"==(} \ )==" "\n" |
318 | R"==(} \ )==" "\n" |
319 | R"==(} \ )==" "\n" |
320 | R"==(} while (0) )==" "\n" |
321 | R"==(#define read_wei_block(block, ptr) \ )==" "\n" |
322 | R"==(do { \ )==" "\n" |
323 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
324 | R"==(int ic_bound = min(IC_WO_PADDING, IC_BLOCK); \ )==" "\n" |
325 | R"==(for (int ic_block = 0; ic_block < ic_bound; ic_block += 16) { \ )==" "\n" |
326 | R"==(int off = wei_off(0, oc_outer * 16, ic_block, 0, 0, 0); \ )==" "\n" |
327 | R"==(int idx = wei_idx(oc_outer, ic_block); \ )==" "\n" |
328 | R"==(unrolled_read(min(16, ic_bound - ic_block), &(block)[idx], \ )==" "\n" |
329 | R"==(&(ptr)[off]); \ )==" "\n" |
330 | R"==(} \ )==" "\n" |
331 | R"==(} \ )==" "\n" |
332 | R"==(} while (0) )==" "\n" |
333 | R"==(#define read_wei_and_multiply_c_vec(wei, kw, C, A) \ )==" "\n" |
334 | R"==(do { \ )==" "\n" |
335 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
336 | R"==(int ic_bound1 = min(IC_WO_PADDING, IC_BLOCK); \ )==" "\n" |
337 | R"==(for (int ic_block = 0; ic_block < ic_bound1; ic_block += 8) { \ )==" "\n" |
338 | R"==(int ic_bound2 = min(8, ic_bound1 - ic_block); \ )==" "\n" |
339 | R"==(int off = wei_off(0, oc_outer * 16, ic_block, 0, 0, 0); \ )==" "\n" |
340 | R"==(DATA_T B[8]; \ )==" "\n" |
341 | R"==(unrolled_read(ic_bound2, B, &(wei)[off]); \ )==" "\n" |
342 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { \ )==" "\n" |
343 | R"==(for (int ow_block = 0; ow_block < OW_BLOCK; ow_block++) { \ )==" "\n" |
344 | R"==(int iw_off = ow_block * SW + (kw) * (1 + DW); \ )==" "\n" |
345 | R"==(int buf_idx = src_buf_idx(mb_block, 0, iw_off); \ )==" "\n" |
346 | R"==(int c_off = dst_idx(mb_block, oc_outer, ow_block); \ )==" "\n" |
347 | R"==(for (int i = 0; i < ic_bound2; i++) { \ )==" "\n" |
348 | R"==((C)[c_off] \ )==" "\n" |
349 | R"==(= fma(intel_sub_group_shuffle( \ )==" "\n" |
350 | R"==((A)[buf_idx], ic_block + i), \ )==" "\n" |
351 | R"==(B[i], (C)[c_off]); \ )==" "\n" |
352 | R"==(} \ )==" "\n" |
353 | R"==(} \ )==" "\n" |
354 | R"==(} \ )==" "\n" |
355 | R"==(} \ )==" "\n" |
356 | R"==(} \ )==" "\n" |
357 | R"==(} while (0) )==" "\n" |
358 | R"==(DATA_T shuffle_a_value(int mb_block, int ic_block, int ow_outer, int ow_inner, )==" "\n" |
359 | R"==(int kw, const DATA_T *A) { )==" "\n" |
360 | R"==(int iw_off0 = ow_outer * OW_INNER * SW + kw * (1 + DW); )==" "\n" |
361 | R"==(int iw_outer0 = iw_off0 / IW_INNER; )==" "\n" |
362 | R"==(int buf_idx0 = src_buf_idx(mb_block, ic_block, iw_outer0); )==" "\n" |
363 | R"==(int iw_off = iw_off0 + ow_inner * SW; )==" "\n" |
364 | R"==(int iw_outer = iw_off / IW_INNER; )==" "\n" |
365 | R"==(DATA4_T A_shuf = 0; )==" "\n" |
366 | R"==(for (int i = 0; i < SW + 1; i++) { )==" "\n" |
367 | R"==(A_shuf[i] = (iw_outer0 + i < IW_OUTER) ? A[buf_idx0 + i] : 0; )==" "\n" |
368 | R"==(} )==" "\n" |
369 | R"==(A_shuf = AS_DATA4_T(intel_sub_group_shuffle( )==" "\n" |
370 | R"==(AS_BLOCK_DATA4_T(A_shuf), iw_off % IW_INNER)); )==" "\n" |
371 | R"==(return A_shuf[iw_outer - iw_outer0]; )==" "\n" |
372 | R"==(} )==" "\n" |
373 | R"==(#define read_wei_and_multiply_w_vec(wei, kw, C, A) \ )==" "\n" |
374 | R"==(do { \ )==" "\n" |
375 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
376 | R"==(int ic_bound1 = min(IC_WO_PADDING, IC_BLOCK); \ )==" "\n" |
377 | R"==(for (int ic_block = 0; ic_block < ic_bound1; ic_block += 8) { \ )==" "\n" |
378 | R"==(int ic_bound2 = min(8, ic_bound1 - ic_block); \ )==" "\n" |
379 | R"==(int off = wei_off(0, oc_outer * 16, ic_block, 0, 0, 0); \ )==" "\n" |
380 | R"==(DATA_T B[8]; \ )==" "\n" |
381 | R"==(unrolled_read(ic_bound2, B, &(wei)[off]); \ )==" "\n" |
382 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) \ )==" "\n" |
383 | R"==(/* IC_INNER is 1 with W vectorization. */ \ )==" "\n" |
384 | R"==(for (int ic_inner = 0; ic_inner < ic_bound2; ic_inner++) \ )==" "\n" |
385 | R"==(for (int ow_outer = 0; ow_outer < OW_OUTER; \ )==" "\n" |
386 | R"==(ow_outer++) { \ )==" "\n" |
387 | R"==(int ow_bound = min( \ )==" "\n" |
388 | R"==(OW_INNER, OW_BLOCK - ow_outer * OW_INNER); \ )==" "\n" |
389 | R"==(for (int i = 0; i < ow_bound; i++) { \ )==" "\n" |
390 | R"==(DATA_T A_val = shuffle_a_value(mb_block, \ )==" "\n" |
391 | R"==(ic_block + ic_inner, ow_outer, i, \ )==" "\n" |
392 | R"==((kw), (A)); \ )==" "\n" |
393 | R"==(int c_off = dst_idx(mb_block, oc_outer, \ )==" "\n" |
394 | R"==(ow_outer * OW_INNER + i); \ )==" "\n" |
395 | R"==((C)[c_off] = fma(A_val, \ )==" "\n" |
396 | R"==(B[ic_block + ic_inner], (C)[c_off]); \ )==" "\n" |
397 | R"==(} \ )==" "\n" |
398 | R"==(} \ )==" "\n" |
399 | R"==(} \ )==" "\n" |
400 | R"==(} \ )==" "\n" |
401 | R"==(} while (0) )==" "\n" |
402 | R"==(#define read_wei_and_multiply(wei, kw, C, A) \ )==" "\n" |
403 | R"==(do { \ )==" "\n" |
404 | R"==(if (W_VEC) \ )==" "\n" |
405 | R"==(read_wei_and_multiply_w_vec((wei), (kw), (C), (A)); \ )==" "\n" |
406 | R"==(else \ )==" "\n" |
407 | R"==(read_wei_and_multiply_c_vec((wei), (kw), (C), (A)); \ )==" "\n" |
408 | R"==(} while (0) )==" "\n" |
409 | R"==(#define read_dst_block(block, ptr, ow) \ )==" "\n" |
410 | R"==(do { \ )==" "\n" |
411 | R"==(if (DST_NCHW) { \ )==" "\n" |
412 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { \ )==" "\n" |
413 | R"==(int n_channels = min(min(C_SIZE, OW - ow), OW_BLOCK); \ )==" "\n" |
414 | R"==(bool w_oc_tail = BASE_OC_TAIL > 0 \ )==" "\n" |
415 | R"==(&& OC_WO_PADDING - (ocb ? ocb : SUB_GROUP_SIZE) \ )==" "\n" |
416 | R"==(< OC_BLOCK; \ )==" "\n" |
417 | R"==(int loc_oc_tail = w_oc_tail ? BASE_OC_TAIL : SUB_GROUP_SIZE; \ )==" "\n" |
418 | R"==(int oc_loop = (!w_oc_tail || sglid < loc_oc_tail) \ )==" "\n" |
419 | R"==(? C_SIZE \ )==" "\n" |
420 | R"==(: n_channels; \ )==" "\n" |
421 | R"==(for (int oc_outer = 0; oc_outer < oc_loop; oc_outer += 1) { \ )==" "\n" |
422 | R"==(int oc_tail_idx = ((sglid < loc_oc_tail \ )==" "\n" |
423 | R"==(&& oc_outer >= n_channels) \ )==" "\n" |
424 | R"==(? (sglid + (16 * (C_SIZE / OW_BLOCK - 1))) \ )==" "\n" |
425 | R"==(: sglid); \ )==" "\n" |
426 | R"==(int off = dst_off( \ )==" "\n" |
427 | R"==(0, oc_tail_idx, 0, 0, (oc_outer % n_channels)); \ )==" "\n" |
428 | R"==(int idx = oc_outer; \ )==" "\n" |
429 | R"==(_BLOCK_READ_DST(&(block)[idx], 1, &(ptr)[off]); \ )==" "\n" |
430 | R"==(} \ )==" "\n" |
431 | R"==(} \ )==" "\n" |
432 | R"==(} else { \ )==" "\n" |
433 | R"==(int ow_bound = (OW % OW_BLOCK == 0) ? OW_BLOCK \ )==" "\n" |
434 | R"==(: min(OW_BLOCK, OW - (ow)); \ )==" "\n" |
435 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) \ )==" "\n" |
436 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) \ )==" "\n" |
437 | R"==(for (int ow_block = 0; ow_block < ow_bound; ow_block++) { \ )==" "\n" |
438 | R"==(int off = dst_off( \ )==" "\n" |
439 | R"==(mb_block, oc_outer * 16, 0, 0, ow_block); \ )==" "\n" |
440 | R"==(int idx = dst_idx(mb_block, oc_outer, ow_block); \ )==" "\n" |
441 | R"==(if (DST_W32C) { \ )==" "\n" |
442 | R"==(int off = dst_off( \ )==" "\n" |
443 | R"==(mb_block, oc_outer * 16, 0, 0, 0); \ )==" "\n" |
444 | R"==(int idx = dst_idx(mb_block, oc_outer, 0); \ )==" "\n" |
445 | R"==(for (int i = 0; i < OW_BLOCK && ow + i < OW; \ )==" "\n" |
446 | R"==(++i) { \ )==" "\n" |
447 | R"==(*((DATA_T *)&(block)[idx + i]) \ )==" "\n" |
448 | R"==(= CONVERT_DATA_T(BLOCK_READ_DST( \ )==" "\n" |
449 | R"==(&(ptr)[off + (32 * i)])); \ )==" "\n" |
450 | R"==(} \ )==" "\n" |
451 | R"==(} else if (DST_32N32C) { \ )==" "\n" |
452 | R"==(int off = dst_off(mb_block, \ )==" "\n" |
453 | R"==(oc_outer * (DST_32N32C ? 32 : 16), 0, 0, \ )==" "\n" |
454 | R"==(ow_block); \ )==" "\n" |
455 | R"==(int idx = dst_idx(mb_block, oc_outer, ow_block); \ )==" "\n" |
456 | R"==(mb_block ? mb_block += 31 : mb_block; \ )==" "\n" |
457 | R"==(for (int i = 0; i < 16; ++i) { \ )==" "\n" |
458 | R"==(*((DATA_T *)&(block)[idx + i]) \ )==" "\n" |
459 | R"==(= CONVERT_DATA_T(BLOCK_READ_DST( \ )==" "\n" |
460 | R"==(&(ptr)[off + (32 * i)])); \ )==" "\n" |
461 | R"==(} \ )==" "\n" |
462 | R"==(} else { \ )==" "\n" |
463 | R"==((block)[idx] = _BLOCK_READ(&(ptr)[off]); \ )==" "\n" |
464 | R"==(} \ )==" "\n" |
465 | R"==(} \ )==" "\n" |
466 | R"==(} \ )==" "\n" |
467 | R"==(} while (0) )==" "\n" |
468 | R"==(#define write_dst_block(block, ptr, ow) \ )==" "\n" |
469 | R"==(do { \ )==" "\n" |
470 | R"==(if (DST_W16C || DST_W32C) { \ )==" "\n" |
471 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) \ )==" "\n" |
472 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { \ )==" "\n" |
473 | R"==(int off = dst_off(mb_block, oc_outer * 16, 0, 0, 0); \ )==" "\n" |
474 | R"==(int idx = dst_idx(mb_block, oc_outer, 0); \ )==" "\n" |
475 | R"==(if (DST_W32C) { \ )==" "\n" |
476 | R"==(for (int i = 0; i < OW_BLOCK && ow + i < OW; ++i) { \ )==" "\n" |
477 | R"==(unrolled_write(1, &(block)[idx + i], \ )==" "\n" |
478 | R"==(&(ptr)[off + (32 * i)]); \ )==" "\n" |
479 | R"==(} \ )==" "\n" |
480 | R"==(} else if (OW % OW_BLOCK == 0 || (ow) + OW_BLOCK <= OW) { \ )==" "\n" |
481 | R"==(unrolled_write(OW_BLOCK, &(block)[idx], &(ptr)[off]); \ )==" "\n" |
482 | R"==(} else { \ )==" "\n" |
483 | R"==(unrolled_write( \ )==" "\n" |
484 | R"==(OW % OW_BLOCK, &(block)[idx], &(ptr)[off]); \ )==" "\n" |
485 | R"==(} \ )==" "\n" |
486 | R"==(} \ )==" "\n" |
487 | R"==(} else if (DST_16N16C || DST_32N32C) { \ )==" "\n" |
488 | R"==(int ow_bound = (OW % OW_BLOCK == 0) ? OW_BLOCK \ )==" "\n" |
489 | R"==(: min(OW_BLOCK, OW - (ow)); \ )==" "\n" |
490 | R"==(for (int ow_block = 0; ow_block < ow_bound; ow_block++) \ )==" "\n" |
491 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) \ )==" "\n" |
492 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; \ )==" "\n" |
493 | R"==(mb_block += (DST_32N32C ? 32 : 16)) { \ )==" "\n" |
494 | R"==(int off = dst_off(mb_block, \ )==" "\n" |
495 | R"==(oc_outer * (DST_32N32C ? 32 : 16), 0, 0, \ )==" "\n" |
496 | R"==(ow_block); \ )==" "\n" |
497 | R"==(int idx = dst_idx(mb_block, oc_outer, ow_block); \ )==" "\n" |
498 | R"==(if (DST_32N32C && MB > 8) { \ )==" "\n" |
499 | R"==(for (int i = 0; i < C_SIZE; ++i) { \ )==" "\n" |
500 | R"==(unrolled_write(1, &(block)[idx + i], \ )==" "\n" |
501 | R"==(&(ptr)[off + (32 * i)]); \ )==" "\n" |
502 | R"==(} \ )==" "\n" |
503 | R"==(} else { \ )==" "\n" |
504 | R"==(unrolled_write(min(16, MB_BLOCK), &(block)[idx], \ )==" "\n" |
505 | R"==(&(ptr)[off]); \ )==" "\n" |
506 | R"==(} \ )==" "\n" |
507 | R"==(} \ )==" "\n" |
508 | R"==(} else if (DST_32N16C) { \ )==" "\n" |
509 | R"==(int ow_bound = (OW % OW_BLOCK == 0) ? OW_BLOCK \ )==" "\n" |
510 | R"==(: min(OW_BLOCK, OW - (ow)); \ )==" "\n" |
511 | R"==(for (int ow_block = 0; ow_block < ow_bound; ow_block++) \ )==" "\n" |
512 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) \ )==" "\n" |
513 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; \ )==" "\n" |
514 | R"==(mb_block += 32) { \ )==" "\n" |
515 | R"==(int off = dst_off( \ )==" "\n" |
516 | R"==(mb_block, oc_outer * 16, 0, 0, ow_block); \ )==" "\n" |
517 | R"==(int idx = dst_idx(mb_block, oc_outer, ow_block); \ )==" "\n" |
518 | R"==(unrolled_write(min(32, MB_BLOCK), &(block)[idx], \ )==" "\n" |
519 | R"==(&(ptr)[off]); \ )==" "\n" |
520 | R"==(} \ )==" "\n" |
521 | R"==(} else if (DST_NCHW && sglid < OC_WO_PADDING - oc) { \ )==" "\n" |
522 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { \ )==" "\n" |
523 | R"==(int n_channels = min(min(C_SIZE, OW - ow), OW_BLOCK); \ )==" "\n" |
524 | R"==(bool w_oc_tail = BASE_OC_TAIL > 0 \ )==" "\n" |
525 | R"==(&& OC_WO_PADDING - (ocb ? ocb : SUB_GROUP_SIZE) \ )==" "\n" |
526 | R"==(< OC_BLOCK; \ )==" "\n" |
527 | R"==(int loc_oc_tail = w_oc_tail ? BASE_OC_TAIL : SUB_GROUP_SIZE; \ )==" "\n" |
528 | R"==(int oc_loop = (!w_oc_tail || sglid < loc_oc_tail) \ )==" "\n" |
529 | R"==(? C_SIZE \ )==" "\n" |
530 | R"==(: n_channels; \ )==" "\n" |
531 | R"==(for (int oc_outer = 0; oc_outer < oc_loop; oc_outer += 1) { \ )==" "\n" |
532 | R"==(int oc_tail_idx = ((sglid < loc_oc_tail \ )==" "\n" |
533 | R"==(&& oc_outer >= n_channels) \ )==" "\n" |
534 | R"==(? (sglid + (16 * (C_SIZE / OW_BLOCK - 1))) \ )==" "\n" |
535 | R"==(: sglid); \ )==" "\n" |
536 | R"==(int off = dst_off( \ )==" "\n" |
537 | R"==(0, oc_tail_idx, 0, 0, (oc_outer % n_channels)); \ )==" "\n" |
538 | R"==(int idx = oc_outer; \ )==" "\n" |
539 | R"==(unrolled_write(1, &(block)[oc_outer], &(ptr)[off]); \ )==" "\n" |
540 | R"==(} \ )==" "\n" |
541 | R"==(} \ )==" "\n" |
542 | R"==(} \ )==" "\n" |
543 | R"==(} while (0) )==" "\n" |
544 | R"==(#define loop_ic_outermost(src, wei, C, id, ih, iw) \ )==" "\n" |
545 | R"==(do { \ )==" "\n" |
546 | R"==(__attribute__((opencl_unroll_hint(1))) /* attr:no-format */ \ )==" "\n" |
547 | R"==(for (int ic = 0; ic < IC; ic += IC_BLOCK) { \ )==" "\n" |
548 | R"==(__attribute__((opencl_unroll_hint(1))) /* attr:no-format */ \ )==" "\n" |
549 | R"==(for (int kd = 0; kd < KD; kd++) { \ )==" "\n" |
550 | R"==(if (HAS_PAD_D \ )==" "\n" |
551 | R"==(&& ((id) + kd * (1 + DD) < 0 \ )==" "\n" |
552 | R"==(|| (id) + kd * (1 + DD) >= ID)) \ )==" "\n" |
553 | R"==(continue; \ )==" "\n" |
554 | R"==(__attribute__((opencl_unroll_hint(1))) /* attr:no-format */ \ )==" "\n" |
555 | R"==(for (int kh = 0; kh < KH; kh++) { \ )==" "\n" |
556 | R"==(if (HAS_PAD_H \ )==" "\n" |
557 | R"==(&& ((ih) + kh * (1 + DH) < 0 \ )==" "\n" |
558 | R"==(|| (ih) + kh * (1 + DH) >= IH)) \ )==" "\n" |
559 | R"==(continue; \ )==" "\n" |
560 | R"==(const __global DATA_T *src1 = (src) \ )==" "\n" |
561 | R"==(+ src_off(0, 0, kd * (1 + DD), kh * (1 + DH), 0); \ )==" "\n" |
562 | R"==(DATA_T A_buf[MB_BLOCK * IC_OUTER * IW_OUTER] = {0}; \ )==" "\n" |
563 | R"==(if (ENABLE_SRC_BUF) read_src_buf(A_buf, src1, (iw)); \ )==" "\n" |
564 | R"==(__attribute__( \ )==" "\n" |
565 | R"==((opencl_unroll_hint(KW))) /* attr:no-format */ \ )==" "\n" |
566 | R"==(for (int kw = 0; kw < KW; kw++) { \ )==" "\n" |
567 | R"==(const __global DATA_T *wei1 \ )==" "\n" |
568 | R"==(= (wei) + wei_off(0, 0, 0, kd, kh, kw); \ )==" "\n" |
569 | R"==(DATA_T B[IC_OUTER * OC_OUTER * IC_INNER]; \ )==" "\n" |
570 | R"==(if (ENABLE_SRC_BUF) { \ )==" "\n" |
571 | R"==(read_wei_and_multiply(wei1, kw, (C), A_buf); \ )==" "\n" |
572 | R"==(} else { \ )==" "\n" |
573 | R"==(read_wei_block(B, wei1); \ )==" "\n" |
574 | R"==(read_src_and_multiply(src1, (iw), kw, 1, (C), B); \ )==" "\n" |
575 | R"==(} \ )==" "\n" |
576 | R"==(} \ )==" "\n" |
577 | R"==(} \ )==" "\n" |
578 | R"==(} \ )==" "\n" |
579 | R"==((src) += src_off(0, IC_BLOCK, 0, 0, 0); \ )==" "\n" |
580 | R"==((wei) += wei_off(0, 0, IC_BLOCK, 0, 0, 0); \ )==" "\n" |
581 | R"==(} \ )==" "\n" |
582 | R"==(} while (0) )==" "\n" |
583 | R"==(#define loop_kdhw_outermost(src, wei, C, id, ih, iw) \ )==" "\n" |
584 | R"==(do { \ )==" "\n" |
585 | R"==(for (int kd = 0; kd < KD; kd++) { \ )==" "\n" |
586 | R"==(if (HAS_PAD_D \ )==" "\n" |
587 | R"==(&& ((id) + kd * (1 + DD) < 0 \ )==" "\n" |
588 | R"==(|| (id) + kd * (1 + DD) >= ID)) \ )==" "\n" |
589 | R"==(continue; \ )==" "\n" |
590 | R"==(for (int kh = 0; kh < KH; kh++) { \ )==" "\n" |
591 | R"==(if (HAS_PAD_H \ )==" "\n" |
592 | R"==(&& ((ih) + kh * (1 + DH) < 0 \ )==" "\n" |
593 | R"==(|| (ih) + kh * (1 + DH) >= IH)) \ )==" "\n" |
594 | R"==(continue; \ )==" "\n" |
595 | R"==(for (int kw = 0; kw < KW; kw++) { \ )==" "\n" |
596 | R"==(if (HAS_PAD_W \ )==" "\n" |
597 | R"==(&& ((iw) + kw * (1 + DW) < 0 \ )==" "\n" |
598 | R"==(|| (iw) + kw * (1 + DW) >= IW)) \ )==" "\n" |
599 | R"==(continue; \ )==" "\n" |
600 | R"==(/* XXX: kw offset is applied in read_src_and_multiply(). */ \ )==" "\n" |
601 | R"==(const __global DATA_T *src1 = (src) \ )==" "\n" |
602 | R"==(+ src_off(0, 0, kd * (1 + DD), kh * (1 + DH), 0); \ )==" "\n" |
603 | R"==(const __global DATA_T *wei1 \ )==" "\n" |
604 | R"==(= (wei) + wei_off(0, 0, 0, kd, kh, kw); \ )==" "\n" |
605 | R"==(__attribute__((opencl_unroll_hint)) /* attr:no-format */ \ )==" "\n" |
606 | R"==(for (int ic = 0; ic < IC; ic += IC_BLOCK) { \ )==" "\n" |
607 | R"==(DATA_T B[IC_OUTER * OC_OUTER * IC_INNER]; \ )==" "\n" |
608 | R"==(read_wei_block(B, wei1); \ )==" "\n" |
609 | R"==(read_src_and_multiply(src1, (iw), kw, 0, (C), B); \ )==" "\n" |
610 | R"==(src1 += src_off(0, IC_BLOCK, 0, 0, 0); \ )==" "\n" |
611 | R"==(wei1 += wei_off(0, 0, IC_BLOCK, 0, 0, 0); \ )==" "\n" |
612 | R"==(} \ )==" "\n" |
613 | R"==(} \ )==" "\n" |
614 | R"==(} \ )==" "\n" |
615 | R"==(} \ )==" "\n" |
616 | R"==(} while (0) )==" "\n" |
617 | R"==(__attribute__((reqd_work_group_size(LWS_0, LWS_1, LWS_2))) )==" "\n" |
618 | R"==(__attribute__((intel_reqd_sub_group_size(SUB_GROUP_SIZE))) __kernel void )==" "\n" |
619 | R"==(gen9_conv_fwd(const __global DATA_T *src, const __global DATA_T *wei, )==" "\n" |
620 | R"==(const __global DATA_T *bia, __global DST_DATA_T *dst POST_OP_ARGS) { )==" "\n" |
621 | R"==(MAYBE_SKIP_NON_UNIFORM_WG(); )==" "\n" |
622 | R"==(int sglid = get_sub_group_local_id(); )==" "\n" |
623 | R"==(int g_ocb = get_group_id(0) * (LWS_0 / SUB_GROUP_SIZE) + get_sub_group_id(); )==" "\n" |
624 | R"==(int g = g_ocb / (OCB / OC_BLOCK); )==" "\n" |
625 | R"==(int ocb = g_ocb % (OCB / OC_BLOCK) * OC_BLOCK; )==" "\n" |
626 | R"==(int odhw = get_group_id(1) / (OMB / MB_BLOCK); )==" "\n" |
627 | R"==(int omb = get_group_id(1) % (OMB / MB_BLOCK) * MB_BLOCK; )==" "\n" |
628 | R"==(int ohw = IS_3D ? odhw % (OWB * OHB) : odhw; )==" "\n" |
629 | R"==(int od = IS_3D ? odhw / (OWB * OHB) : 0; )==" "\n" |
630 | R"==(int oh = (ohw / OWB) * OH_BLOCK; )==" "\n" |
631 | R"==(int ow = (ohw % OWB) * OW_BLOCK; )==" "\n" |
632 | R"==(int ocb_idx_omb_idx = get_group_id(2); )==" "\n" |
633 | R"==(int ocb_idx = ocb_idx_omb_idx / (MB / OMB); )==" "\n" |
634 | R"==(int omb_idx = ocb_idx_omb_idx % (MB / OMB); )==" "\n" |
635 | R"==(int oc = ocb_idx * OCB + ocb; )==" "\n" |
636 | R"==(int mb = omb_idx * OMB + omb; )==" "\n" |
637 | R"==(int ih = oh * SH - PH; )==" "\n" |
638 | R"==(int iw = ow * SW - PW; )==" "\n" |
639 | R"==(int id = od * SD - PD; )==" "\n" |
640 | R"==(#if DT_F16 && C_SIZE == 8 )==" "\n" |
641 | R"==(DATA8_T C = 0; )==" "\n" |
642 | R"==(#elif DT_F16 && C_SIZE == 16 )==" "\n" |
643 | R"==(DATA16_T C = 0; )==" "\n" |
644 | R"==(#else )==" "\n" |
645 | R"==(DATA_T C[C_SIZE] = {0}; )==" "\n" |
646 | R"==(#endif )==" "\n" |
647 | R"==(src += src_off(mb, g * IC, id, ih, iw); )==" "\n" |
648 | R"==(wei += wei_off(g, oc, 0, 0, 0, 0); )==" "\n" |
649 | R"==(dst += dst_off(mb, g * OC + oc, od, oh, ow); )==" "\n" |
650 | R"==(if ((DST_32N32C || DST_W32C) && (OC_BLOCK % 32 != 0) )==" "\n" |
651 | R"==(&& oc > OC_WO_PADDING) { )==" "\n" |
652 | R"==(write_dst_block((DATA_T *)(&C), dst, ow); )==" "\n" |
653 | R"==(return; )==" "\n" |
654 | R"==(} )==" "\n" |
655 | R"==(if (WITH_BIAS) { )==" "\n" |
656 | R"==(for (int mb_block = 0; mb_block < MB_BLOCK; mb_block++) { )==" "\n" |
657 | R"==(for (int oc_outer = 0; oc_outer < OC_OUTER; oc_outer++) { )==" "\n" |
658 | R"==(const int bg_off = g * OC; )==" "\n" |
659 | R"==(const int bc_off = oc + oc_outer * 16 + sglid; )==" "\n" |
660 | R"==(#if (DT_F16 || DST_DT_U8 || DST_DT_S8) )==" "\n" |
661 | R"==(#if OC_WO_PADDING == SUB_GROUP_SIZE && (DST_DT_U8 || DST_DT_S8) )==" "\n" |
662 | R"==(if (OC_WO_PADDING % OC_BLOCK == 0 && bc_off < OC_WO_PADDING) { )==" "\n" |
663 | R"==(#else )==" "\n" |
664 | R"==(if (OC_WO_PADDING % OC_BLOCK == 0 || bc_off < OC_WO_PADDING) { )==" "\n" |
665 | R"==(#endif )==" "\n" |
666 | R"==(for (int ow_block = 0; ow_block < OW_BLOCK; ow_block++) { )==" "\n" |
667 | R"==(const int c_off = dst_idx(mb_block, oc_outer, ow_block); )==" "\n" |
668 | R"==(C[c_off] = bia[bg_off + bc_off]; )==" "\n" |
669 | R"==(} )==" "\n" |
670 | R"==(} )==" "\n" |
671 | R"==(#else )==" "\n" |
672 | R"==(for (int ow_block = 0; ow_block < OW_BLOCK; ow_block++) { )==" "\n" |
673 | R"==(const int c_off = dst_idx(mb_block, oc_outer, ow_block); )==" "\n" |
674 | R"==(C[c_off] = (OC_WO_PADDING % OC_BLOCK == 0 )==" "\n" |
675 | R"==(|| bc_off < OC_WO_PADDING) )==" "\n" |
676 | R"==(? bia[bg_off + bc_off] )==" "\n" |
677 | R"==(: DATA_ZERO; )==" "\n" |
678 | R"==(} )==" "\n" |
679 | R"==(#endif )==" "\n" |
680 | R"==(} )==" "\n" |
681 | R"==(} )==" "\n" |
682 | R"==(} )==" "\n" |
683 | R"==(#if OC_WO_PADDING == SUB_GROUP_SIZE && (DST_DT_U8 || DST_DT_S8) )==" "\n" |
684 | R"==(const bool DO_MUL = ((OC_BLOCK * g_ocb) < OC_WO_PADDING); )==" "\n" |
685 | R"==(#else )==" "\n" |
686 | R"==(const bool DO_MUL = true; )==" "\n" |
687 | R"==(#endif )==" "\n" |
688 | R"==(if (OW_BLOCK == 1 && DO_MUL) { )==" "\n" |
689 | R"==(loop_kdhw_outermost(src, wei, C, id, ih, iw); )==" "\n" |
690 | R"==(} else if (DO_MUL) { )==" "\n" |
691 | R"==(loop_ic_outermost(src, wei, C, id, ih, iw); )==" "\n" |
692 | R"==(} )==" "\n" |
693 | R"==(DATA_T S[MB_BLOCK * OC_OUTER * OW_BLOCK]; )==" "\n" |
694 | R"==(if (WITH_SUM) { read_dst_block(S, dst, ow); } )==" "\n" |
695 | R"==(#if WITH_POST_OP )==" "\n" |
696 | R"==(if (OW_BLOCK == 1) { )==" "\n" |
697 | R"==(const int po_mb = mb; )==" "\n" |
698 | R"==(const int po_oc = (g * OC + oc) % (OC * G); )==" "\n" |
699 | R"==(APPLY_POST_OPS_TRY_BURST(C, DATA_T, S, DATA_T, po_mb, MB_BLOCK, po_oc, )==" "\n" |
700 | R"==(OC_OUTER * SUB_GROUP_SIZE, sglid); )==" "\n" |
701 | R"==(} else { )==" "\n" |
702 | R"==(unroll_for(int mb_idx = 0; mb_idx < MB_BLOCK; ++mb_idx) { )==" "\n" |
703 | R"==(unroll_for(int oc_idx = 0; oc_idx < OC_OUTER; ++oc_idx) { )==" "\n" |
704 | R"==(const int po_mb = (mb + mb_idx) % MB; )==" "\n" |
705 | R"==(const int po_oc = (g * OC + oc + (oc_idx * 16)) % (OC * G); )==" "\n" |
706 | R"==(float acc_ow[OW_BLOCK]; )==" "\n" |
707 | R"==(float sum_ow[OW_BLOCK]; )==" "\n" |
708 | R"==(unroll_for(int ow_idx = 0; ow_idx < OW_BLOCK; ++ow_idx) { )==" "\n" |
709 | R"==(acc_ow[ow_idx] )==" "\n" |
710 | R"==(= CONVERT_FLOAT_T(C[mb_idx * OC_OUTER * OW_BLOCK )==" "\n" |
711 | R"==(+ oc_idx * OW_BLOCK + ow_idx]); )==" "\n" |
712 | R"==(sum_ow[ow_idx] )==" "\n" |
713 | R"==(= CONVERT_FLOAT_T(S[mb_idx * OC_OUTER * OW_BLOCK )==" "\n" |
714 | R"==(+ oc_idx * OW_BLOCK + ow_idx]); )==" "\n" |
715 | R"==(} )==" "\n" |
716 | R"==(APPLY_POST_OPS_TRY_BURST(acc_ow, float, sum_ow, float, po_mb, 1, )==" "\n" |
717 | R"==(po_oc, SUB_GROUP_SIZE, sglid); )==" "\n" |
718 | R"==(unroll_for(int ow_idx = 0; ow_idx < OW_BLOCK; ++ow_idx) { )==" "\n" |
719 | R"==(C[mb_idx * OC_OUTER * OW_BLOCK + oc_idx * OW_BLOCK + ow_idx] )==" "\n" |
720 | R"==(= acc_ow[ow_idx]; )==" "\n" |
721 | R"==(} )==" "\n" |
722 | R"==(} )==" "\n" |
723 | R"==(} )==" "\n" |
724 | R"==(} )==" "\n" |
725 | R"==(#endif )==" "\n" |
726 | R"==(write_dst_block((DATA_T *)(&C), dst, ow); )==" "\n" |
727 | R"==(} )==" "\n" |
728 | R"==()==" ; |
729 | } |
730 | } |
731 | } |
732 | } |