1namespace dnnl {
2namespace impl {
3namespace gpu {
4namespace ocl {
5const char *gen9_wino_conv_fwd_data_fused_kernel = R"==(/******************************************************************************* )==""\n"
6R"==(* Copyright 2020-2021 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_post_ops.h" )==""\n"
21R"==(#include "gpu/ocl/ocl_types.h" )==""\n"
22R"==(#include "gpu/ocl/offsets.h" )==""\n"
23R"==(#define IW_BLOCK (OW_BLOCK + KW - 1) )==""\n"
24R"==(#define IW_INTERNAL_BLOCK 16 )==""\n"
25R"==(#if IW_BLOCK > IW_INTERNAL_BLOCK )==""\n"
26R"==(#error "Invalid IW_BLOCK value" )==""\n"
27R"==(#endif )==""\n"
28R"==(#define LWY 8 )==""\n"
29R"==(#define LWX (WINO_IC_BLOCK / 2) )==""\n"
30R"==(#define COMP_UNITS ((OC_BLOCK * WINO_D)) )==""\n"
31R"==(#define COMP_OC_STRIDE LWX )==""\n"
32R"==(#define COMP_OC_COUNT (OC_BLOCK / COMP_OC_STRIDE) )==""\n"
33R"==(#define WINO_D (WINO_M + WINO_R - 1) )==""\n"
34R"==(#define TO_TYPE(value) ((DATA_T)value) )==""\n"
35R"==(#define UTRANS_BLOCK VECT_DT_N )==""\n"
36R"==(#define UTRANS_DATA_T VECT_DATA_T )==""\n"
37R"==(#define AS_UTRANS_DATA_T AS_VECT_DATA_T )==""\n"
38R"==(#define UTRANS_BLOCK_READ(ptr) \ )==""\n"
39R"==(AS_UTRANS_DATA_T(VECT_BLOCK_READ((const __global BLOCK_DATA_T *)ptr)) )==""\n"
40R"==(#define UTRANS_BLOCK_WRITE(data, ptr) \ )==""\n"
41R"==(VECT_BLOCK_WRITE((__global BLOCK_DATA_T *)ptr, AS_VECT_BLOCK_DATA_T(data)) )==""\n"
42R"==(#define VTRANS_BLOCK 4 )==""\n"
43R"==(#define VTRANS_DATA_T CONCAT2(DATA_T, VTRANS_BLOCK) )==""\n"
44R"==(#define COMP_BLOCK VECT_DT_N )==""\n"
45R"==(#define COMP_DATA_T VECT_DATA_T )==""\n"
46R"==(#define AS_COMP_DATA_T AS_VECT_DATA_T )==""\n"
47R"==(#define COMP_READ(ptr) CONCAT2(vload, COMP_BLOCK)(0, ptr) )==""\n"
48R"==(#define COMP_WRITE(data, ptr) CONCAT2(vstore, COMP_BLOCK)(data, 0, ptr) )==""\n"
49R"==(#define COMP_BLOCK_READ(ptr) \ )==""\n"
50R"==(AS_COMP_DATA_T(VECT_BLOCK_READ((const __global BLOCK_DATA_T *)ptr)) )==""\n"
51R"==(#define COMP_UNROLL (IC_BLOCK / COMP_BLOCK) )==""\n"
52R"==(#define OUT_TYPE_BLOCK 2 )==""\n"
53R"==(#define OUT_BLOCK_DATA_T CONCAT2(DATA_T, OUT_TYPE_BLOCK) )==""\n"
54R"==(#define OUT_BLOCK_READ(ptr) CONCAT2(vload, OUT_TYPE_BLOCK)(0, ptr) )==""\n"
55R"==(#define OUT_BLOCK_WRITE(data, ptr) \ )==""\n"
56R"==(do { \ )==""\n"
57R"==(OUT_BLOCK_DATA_T result = data; \ )==""\n"
58R"==(unroll_for(int _i = 0; _i < OUT_TYPE_BLOCK; _i++) { \ )==""\n"
59R"==((ptr)[_i] = result[_i]; \ )==""\n"
60R"==(} \ )==""\n"
61R"==(} while (0) )==""\n"
62R"==(static inline int U_off(int o, int i, int z, int w) { )==""\n"
63R"==(const int ic_internal_block = 16; )==""\n"
64R"==(const int oc_internal_block = LWX; )==""\n"
65R"==(int icb = i / ic_internal_block; )==""\n"
66R"==(int ic = i % ic_internal_block; )==""\n"
67R"==(int ocb = o / oc_internal_block; )==""\n"
68R"==(int oc = o % oc_internal_block; )==""\n"
69R"==(int off = ocb * (WINO_IC / ic_internal_block) * KW * ic_internal_block )==""\n"
70R"==(* WINO_D * oc_internal_block; )==""\n"
71R"==(off += icb * KW * ic_internal_block * WINO_D * oc_internal_block; )==""\n"
72R"==(off += w * ic_internal_block * WINO_D * oc_internal_block; )==""\n"
73R"==(off += z * ic_internal_block * oc_internal_block; )==""\n"
74R"==(off += ic * oc_internal_block; )==""\n"
75R"==(off += oc; )==""\n"
76R"==(return off; )==""\n"
77R"==(} )==""\n"
78R"==(static inline int V_off(int i, int z, int w, int block_size) { )==""\n"
79R"==(const int ic_internal_block = 16; )==""\n"
80R"==(int icb = i / ic_internal_block; )==""\n"
81R"==(int ic = i % ic_internal_block; )==""\n"
82R"==(int off = icb * WINO_D * IW_INTERNAL_BLOCK * ic_internal_block; )==""\n"
83R"==(off += z * IW_INTERNAL_BLOCK * ic_internal_block; )==""\n"
84R"==(off += w * ic_internal_block; )==""\n"
85R"==(off += ic; )==""\n"
86R"==(return off / block_size; )==""\n"
87R"==(} )==""\n"
88R"==(static inline int M_off(int o, int z, int w, int block_size) { )==""\n"
89R"==(const int ow_internal_block = OUT_TYPE_BLOCK; )==""\n"
90R"==(int owb = w / ow_internal_block; )==""\n"
91R"==(int ow = w % ow_internal_block; )==""\n"
92R"==(int off = z * OW_BLOCK / ow_internal_block * OC_BLOCK * ow_internal_block; )==""\n"
93R"==(off += owb * OC_BLOCK * ow_internal_block; )==""\n"
94R"==(off += o * ow_internal_block; )==""\n"
95R"==(off += ow; )==""\n"
96R"==(return off / block_size; )==""\n"
97R"==(} )==""\n"
98R"==(#define VTRANS_LY_STRIDE 2 )==""\n"
99R"==(#define VTRANS_LX_CYCLE (LWX / VTRANS_LY_STRIDE) )==""\n"
100R"==(static inline int get_Vtrans_ic0(int lx, int ly) { )==""\n"
101R"==(return VTRANS_BLOCK * (lx % VTRANS_LX_CYCLE); )==""\n"
102R"==(} )==""\n"
103R"==(static inline int get_Vtrans_ih0(int lx, int ly) { )==""\n"
104R"==(return 0; )==""\n"
105R"==(} )==""\n"
106R"==(static inline int get_Vtrans_iw0(int lx, int ly) { )==""\n"
107R"==(return LWY * (lx / VTRANS_LX_CYCLE) + ly; )==""\n"
108R"==(} )==""\n"
109R"==(#define VCOMP_LX_CYCLE (LWX / 8) )==""\n"
110R"==(static inline int get_Vcomp_ic0(int lx, int ly) { )==""\n"
111R"==(return 8 * (lx % VCOMP_LX_CYCLE); )==""\n"
112R"==(} )==""\n"
113R"==(static inline int get_Vcomp_ih0(int lx, int ly) { )==""\n"
114R"==(return ly; )==""\n"
115R"==(} )==""\n"
116R"==(static inline int get_Vcomp_iw0(int lx, int ly) { )==""\n"
117R"==(return lx / VCOMP_LX_CYCLE; )==""\n"
118R"==(} )==""\n"
119R"==(static inline int get_Ucomp_ic0(int lx, int ly) { )==""\n"
120R"==(return 0; )==""\n"
121R"==(} )==""\n"
122R"==(static inline int get_Ucomp_oc0(int lx, int ly) { )==""\n"
123R"==(return lx; )==""\n"
124R"==(} )==""\n"
125R"==(static inline int get_Ucomp_kh0(int lx, int ly) { )==""\n"
126R"==(return get_Vcomp_ih0(lx, ly); )==""\n"
127R"==(} )==""\n"
128R"==(static inline int get_Ucomp_kw0(int lx, int ly) { )==""\n"
129R"==(return 0; )==""\n"
130R"==(} )==""\n"
131R"==(static inline int get_Mcomp_oc0(int lx, int ly) { )==""\n"
132R"==(return get_Ucomp_oc0(lx, ly); )==""\n"
133R"==(} )==""\n"
134R"==(static inline int get_Mcomp_oh0(int lx, int ly) { )==""\n"
135R"==(return get_Vcomp_ih0(lx, ly); )==""\n"
136R"==(} )==""\n"
137R"==(static inline int get_Mcomp_ow0(int lx, int ly) { )==""\n"
138R"==(return 0; )==""\n"
139R"==(} )==""\n"
140R"==(static inline int get_out_oh0(int lx, int ly) { )==""\n"
141R"==(return 0; )==""\n"
142R"==(} )==""\n"
143R"==(#define OUT_LY_CYCLE (16 / OUT_TYPE_BLOCK) )==""\n"
144R"==(static inline int get_out_ow0(int lx, int ly) { )==""\n"
145R"==(return OUT_TYPE_BLOCK * (ly % OUT_LY_CYCLE); )==""\n"
146R"==(} )==""\n"
147R"==(static inline int get_out_oc0(int lx, int ly) { )==""\n"
148R"==(return lx + LWX * (ly / OUT_LY_CYCLE); )==""\n"
149R"==(} )==""\n"
150R"==(#if WINO_M == 6 )==""\n"
151R"==(static inline void wino_U_transform( )==""\n"
152R"==(UTRANS_DATA_T U[WINO_D], UTRANS_DATA_T wei[WINO_R]) { )==""\n"
153R"==(U[0] = wei[0]; )==""\n"
154R"==(U[1] = TO_TYPE(-2.0 / 9) * (wei[0] + wei[1] + wei[2]); )==""\n"
155R"==(U[2] = TO_TYPE(2.0 / 9) * (-wei[0] + wei[1] - wei[2]); )==""\n"
156R"==(U[3] = TO_TYPE(1.0 / 90) * wei[0] + TO_TYPE(2.0 / 90) * wei[1] )==""\n"
157R"==(+ TO_TYPE(4.0 / 90) * wei[2]; )==""\n"
158R"==(U[4] = TO_TYPE(1.0 / 90) * wei[0] - TO_TYPE(2.0 / 90) * wei[1] )==""\n"
159R"==(+ TO_TYPE(4.0 / 90) * wei[2]; )==""\n"
160R"==(U[5] = TO_TYPE(64.0 / 90) * wei[0] + TO_TYPE(32.0 / 90) * wei[1] )==""\n"
161R"==(+ TO_TYPE(16.0 / 90) * wei[2]; )==""\n"
162R"==(U[6] = TO_TYPE(64.0 / 90) * wei[0] - TO_TYPE(32.0 / 90) * wei[1] )==""\n"
163R"==(+ TO_TYPE(16.0 / 90) * wei[2]; )==""\n"
164R"==(U[7] = wei[2]; )==""\n"
165R"==(} )==""\n"
166R"==(static inline void wino_V_transform( )==""\n"
167R"==(__local VTRANS_DATA_T *V, const VTRANS_DATA_T src[WINO_D]) { )==""\n"
168R"==(V[V_off(0, 0, 0, VTRANS_BLOCK)] )==""\n"
169R"==(= src[0] - TO_TYPE(5.25) * src[2] + TO_TYPE(5.25) * src[4] - src[6]; )==""\n"
170R"==(VTRANS_DATA_T x0 = src[1] - TO_TYPE(4.25) * src[3] + src[5]; )==""\n"
171R"==(VTRANS_DATA_T x1 = src[2] - TO_TYPE(4.25) * src[4] + src[6]; )==""\n"
172R"==(V[V_off(0, 1, 0, VTRANS_BLOCK)] = x1 + x0; )==""\n"
173R"==(V[V_off(0, 2, 0, VTRANS_BLOCK)] = x1 - x0; )==""\n"
174R"==(VTRANS_DATA_T x2 = TO_TYPE(-5) * src[3] + src[1]; )==""\n"
175R"==(VTRANS_DATA_T x3 = TO_TYPE(4) * src[5] + x2; )==""\n"
176R"==(VTRANS_DATA_T x4 = TO_TYPE(0.25) * src[2] + src[6]; )==""\n"
177R"==(VTRANS_DATA_T x5 = TO_TYPE(-1.25) * src[4] + x4; )==""\n"
178R"==(V[V_off(0, 3, 0, VTRANS_BLOCK)] = TO_TYPE(0.5) * x3 + x5; )==""\n"
179R"==(V[V_off(0, 4, 0, VTRANS_BLOCK)] = TO_TYPE(-0.5) * x3 + x5; )==""\n"
180R"==(VTRANS_DATA_T x6 = TO_TYPE(4) * src[1] + src[5]; )==""\n"
181R"==(VTRANS_DATA_T x7 = TO_TYPE(-5) * src[3] + x6; )==""\n"
182R"==(VTRANS_DATA_T x8 = TO_TYPE(4) * src[2] + src[6]; )==""\n"
183R"==(VTRANS_DATA_T x9 = TO_TYPE(-5) * src[4] + x8; )==""\n"
184R"==(V[V_off(0, 5, 0, VTRANS_BLOCK)] = TO_TYPE(+0.5) * x7 + x9; )==""\n"
185R"==(V[V_off(0, 6, 0, VTRANS_BLOCK)] = TO_TYPE(-0.5) * x7 + x9; )==""\n"
186R"==(V[V_off(0, 7, 0, VTRANS_BLOCK)] = -src[1] + TO_TYPE(5.25) * src[3] )==""\n"
187R"==(- TO_TYPE(5.25) * src[5] + src[7]; )==""\n"
188R"==(} )==""\n"
189R"==(static inline void wino_m_transform( )==""\n"
190R"==(OUT_BLOCK_DATA_T C[WINO_M], OUT_BLOCK_DATA_T M[WINO_D]) { )==""\n"
191R"==(OUT_BLOCK_DATA_T x0 = M[1] + M[2]; )==""\n"
192R"==(OUT_BLOCK_DATA_T x1 = M[1] - M[2]; )==""\n"
193R"==(OUT_BLOCK_DATA_T x2 = M[3] + M[4]; )==""\n"
194R"==(OUT_BLOCK_DATA_T x3 = M[3] - M[4]; )==""\n"
195R"==(OUT_BLOCK_DATA_T x4 = M[5] + M[6]; )==""\n"
196R"==(OUT_BLOCK_DATA_T x5 = M[5] - M[6]; )==""\n"
197R"==(C[0] = M[0] + x0 + x2 + x4; )==""\n"
198R"==(C[1] = x1 + TO_TYPE(2) * x3 + TO_TYPE(0.5f) * x5; )==""\n"
199R"==(C[2] = x0 + TO_TYPE(4.f) * x2 + TO_TYPE(0.25f) * x4; )==""\n"
200R"==(C[3] = x1 + TO_TYPE(8.f) * x3 + TO_TYPE(0.125f) * x5; )==""\n"
201R"==(C[4] = x0 + TO_TYPE(16.f) * x2 + TO_TYPE(0.0625f) * x4; )==""\n"
202R"==(C[5] = x1 + TO_TYPE(32.f) * x3 + TO_TYPE(0.03125f) * x5 + M[7]; )==""\n"
203R"==(} )==""\n"
204R"==(#elif WINO_M == 4 )==""\n"
205R"==(static inline void wino_U_transform( )==""\n"
206R"==(UTRANS_DATA_T U[WINO_D], UTRANS_DATA_T wei[WINO_R]) { )==""\n"
207R"==(U[0] = wei[0] / 4; )==""\n"
208R"==(U[1] = (wei[0] + wei[1] + wei[2]) / (-6); )==""\n"
209R"==(U[2] = (wei[0] - wei[1] + wei[2]) / (-6); )==""\n"
210R"==(U[3] = (wei[0] + 2 * wei[1] + 4 * wei[2]) / 24; )==""\n"
211R"==(U[4] = (wei[0] - 2 * wei[1] + 4 * wei[2]) / 24; )==""\n"
212R"==(U[5] = wei[2]; )==""\n"
213R"==(} )==""\n"
214R"==(static inline void wino_V_transform( )==""\n"
215R"==(__local VTRANS_DATA_T *V, const VTRANS_DATA_T src[WINO_D]) { )==""\n"
216R"==(V[V_off(0, 0, 0, VTRANS_BLOCK)] = 4 * src[0] - 5 * src[2] + src[4]; )==""\n"
217R"==(V[V_off(0, 1, 0, VTRANS_BLOCK)] = -4 * (src[1] + src[2]) + src[3] + src[4]; )==""\n"
218R"==(V[V_off(0, 2, 0, VTRANS_BLOCK)] = 4 * (src[1] - src[2]) - src[3] + src[4]; )==""\n"
219R"==(V[V_off(0, 3, 0, VTRANS_BLOCK)] )==""\n"
220R"==(= -2 * src[1] - src[2] + 2 * src[3] + src[4]; )==""\n"
221R"==(V[V_off(0, 4, 0, VTRANS_BLOCK)] = 2 * src[1] - src[2] - 2 * src[3] + src[4]; )==""\n"
222R"==(V[V_off(0, 5, 0, VTRANS_BLOCK)] = 4 * src[1] - 5 * src[3] + src[5]; )==""\n"
223R"==(} )==""\n"
224R"==(static inline void wino_m_transform( )==""\n"
225R"==(OUT_BLOCK_DATA_T C[WINO_M], OUT_BLOCK_DATA_T M[WINO_D]) { )==""\n"
226R"==(OUT_BLOCK_DATA_T x0 = M[1] + M[2]; )==""\n"
227R"==(OUT_BLOCK_DATA_T x1 = M[1] - M[2]; )==""\n"
228R"==(OUT_BLOCK_DATA_T x2 = M[3] + M[4]; )==""\n"
229R"==(OUT_BLOCK_DATA_T x3 = M[3] - M[4]; )==""\n"
230R"==(C[0] = M[0] + x0 + x2; )==""\n"
231R"==(C[1] = x1 + 2 * x3; )==""\n"
232R"==(C[2] = x0 + 4 * x2; )==""\n"
233R"==(C[3] = x1 + 8 * x3 + M[5]; )==""\n"
234R"==(} )==""\n"
235R"==(#elif WINO_M == 2 )==""\n"
236R"==(static inline void wino_U_transform( )==""\n"
237R"==(UTRANS_DATA_T U[WINO_D], UTRANS_DATA_T wei[WINO_R]) { )==""\n"
238R"==(U[0] = wei[0]; )==""\n"
239R"==(U[1] = (wei[0] + wei[1] + wei[2]) / 2; )==""\n"
240R"==(U[2] = (wei[0] - wei[1] + wei[2]) / 2; )==""\n"
241R"==(U[3] = wei[2]; )==""\n"
242R"==(} )==""\n"
243R"==(static inline void wino_V_transform( )==""\n"
244R"==(__local VTRANS_DATA_T *V, const VTRANS_DATA_T src[WINO_D]) { )==""\n"
245R"==(V[V_off(0, 0, 0, VTRANS_BLOCK)] = src[0] - src[2]; )==""\n"
246R"==(V[V_off(0, 1, 0, VTRANS_BLOCK)] = src[1] + src[2]; )==""\n"
247R"==(V[V_off(0, 2, 0, VTRANS_BLOCK)] = -src[1] + src[2]; )==""\n"
248R"==(V[V_off(0, 3, 0, VTRANS_BLOCK)] = src[1] - src[3]; )==""\n"
249R"==(} )==""\n"
250R"==(static inline void wino_m_transform( )==""\n"
251R"==(OUT_BLOCK_DATA_T C[WINO_M], OUT_BLOCK_DATA_T M[WINO_D]) { )==""\n"
252R"==(C[0] = M[0] + M[1] + M[2]; )==""\n"
253R"==(C[1] = M[1] - M[2] - M[3]; )==""\n"
254R"==(} )==""\n"
255R"==(#else )==""\n"
256R"==(#error "Unsupported Winograd Tile Size" )==""\n"
257R"==(#endif )==""\n"
258R"==(__attribute__((reqd_work_group_size(LWX, 1, 1))) )==""\n"
259R"==(__attribute__((intel_reqd_sub_group_size(LWX))) __kernel void )==""\n"
260R"==(gen9_wino_wei_transform(__global DATA_T *U, const __global DATA_T *weights) { )==""\n"
261R"==(const uint weights_tile_width = 1; )==""\n"
262R"==(const uint weights_tile_height = WINO_M; )==""\n"
263R"==(const uint in_kw = get_global_id(1) * weights_tile_width; )==""\n"
264R"==(const uint in_kh = get_global_id(2) * weights_tile_height; )==""\n"
265R"==(const uint U_tile_width = 1; )==""\n"
266R"==(const uint U_tile_height = WINO_D; )==""\n"
267R"==(const uint out_kw = get_global_id(1) * U_tile_width; )==""\n"
268R"==(const uint out_kh = get_global_id(2) * U_tile_height; )==""\n"
269R"==(const uint oc0 = (get_group_id(0) % (WINO_OC / LWX)) * LWX; )==""\n"
270R"==(const uint oc = oc0 + get_local_id(0); )==""\n"
271R"==(const uint ic = (get_group_id(0) / (WINO_OC / LWX)) * UTRANS_BLOCK; )==""\n"
272R"==(uint in_idx = wei_off(0, oc, ic, 0, in_kh, in_kw); )==""\n"
273R"==(bool is_valid = ic < IC && oc0 < OC; )==""\n"
274R"==(UTRANS_DATA_T g[WINO_R]; )==""\n"
275R"==(for (int i = 0; i < WINO_R; i++) { )==""\n"
276R"==(for (int j = 0; j < UTRANS_BLOCK; j++) { )==""\n"
277R"==(uint idx = in_idx + wei_off(0, 0, j, 0, 0, 0); )==""\n"
278R"==(g[i][j] = is_valid ? weights[idx] : 0; )==""\n"
279R"==(} )==""\n"
280R"==(in_idx += wei_off(0, 0, 0, 0, 1, 0); )==""\n"
281R"==(} )==""\n"
282R"==(UTRANS_DATA_T out_tile[WINO_D]; )==""\n"
283R"==(wino_U_transform(out_tile, g); )==""\n"
284R"==(uint out_idx = U_off(oc0, ic, out_kh, out_kw); )==""\n"
285R"==(unroll_for(int i = 0; i < WINO_D; i++) { )==""\n"
286R"==(UTRANS_BLOCK_WRITE(out_tile[i], &U[out_idx]); )==""\n"
287R"==(out_idx += U_off(0, 0, 1, 0); )==""\n"
288R"==(} )==""\n"
289R"==(} )==""\n"
290R"==(#define DOTi(_result, _A, _B) \ )==""\n"
291R"==({ _result = mad(_A, _B, _result); } )==""\n"
292R"==(__attribute__((reqd_work_group_size(LWX, LWY, 1))) )==""\n"
293R"==(__attribute__((intel_reqd_sub_group_size(LWX))) __kernel void )==""\n"
294R"==(gen9_wino_conv_fwd(__global DATA_T *dst, const __global DATA_T *src, )==""\n"
295R"==(const __global DATA_T *U_param, )==""\n"
296R"==(const __global DATA_T *bias POST_OP_ARGS) { )==""\n"
297R"==(const uint slm_size )==""\n"
298R"==(= (WINO_IC_BLOCK * WINO_D * IW_INTERNAL_BLOCK) / VTRANS_BLOCK; )==""\n"
299R"==(__local VTRANS_DATA_T V[slm_size]; )==""\n"
300R"==(const DATA_T scl = TO_TYPE(16); )==""\n"
301R"==(const DATA_T sc = TO_TYPE(1) / scl; )==""\n"
302R"==(const VTRANS_DATA_T scl_vec = (VTRANS_DATA_T)(sc, sc, sc, sc); )==""\n"
303R"==(const int ow0 = get_group_id(0) * OW_BLOCK; )==""\n"
304R"==(const int oh0 = get_group_id(1) * OH_BLOCK; )==""\n"
305R"==(const int gid2 = get_group_id(2); )==""\n"
306R"==(const int oc0 = (gid2 % (OC / OC_BLOCK)) * OC_BLOCK; )==""\n"
307R"==(const int mb = gid2 / (OC / OC_BLOCK); )==""\n"
308R"==(const int lx = get_local_id(0); )==""\n"
309R"==(const int ly = get_local_id(1); )==""\n"
310R"==(const int M_ow_size = OW_BLOCK; )==""\n"
311R"==(DATA_T M[COMP_OC_COUNT][M_ow_size]; )==""\n"
312R"==(for (int i = 0; i < COMP_OC_COUNT; i++) { )==""\n"
313R"==(for (int j = 0; j < M_ow_size; j++) { )==""\n"
314R"==(M[i][j] = 0; )==""\n"
315R"==(} )==""\n"
316R"==(} )==""\n"
317R"==(const int Vtrans_ic = get_Vtrans_ic0(lx, ly); )==""\n"
318R"==(const int Vtrans_ih = get_Vtrans_ih0(lx, ly); )==""\n"
319R"==(const int Vtrans_iw = get_Vtrans_iw0(lx, ly); )==""\n"
320R"==(const int src_ic = Vtrans_ic; )==""\n"
321R"==(const int src_ih = oh0 - PH + Vtrans_ih; )==""\n"
322R"==(const int src_iw = ow0 - PW + Vtrans_iw; )==""\n"
323R"==(const __global DATA_T *src_load )==""\n"
324R"==(= src + src_off(mb, src_ic, 0, src_ih, src_iw); )==""\n"
325R"==(const int V_write_idx )==""\n"
326R"==(= V_off(Vtrans_ic, Vtrans_ih, Vtrans_iw, VTRANS_BLOCK); )==""\n"
327R"==(__local VTRANS_DATA_T *V_write = &V[V_write_idx]; )==""\n"
328R"==(const int U_oc = oc0 + get_Ucomp_oc0(lx, ly); )==""\n"
329R"==(const int U_ic = get_Ucomp_ic0(lx, ly); )==""\n"
330R"==(const int U_kh = get_Ucomp_kh0(lx, ly); )==""\n"
331R"==(const int U_kw = get_Ucomp_kw0(lx, ly); )==""\n"
332R"==(const __global DATA_T *U = U_param + U_off(U_oc, U_ic, U_kh, U_kw); )==""\n"
333R"==(const int Vcomp_ic = get_Vcomp_ic0(lx, ly); )==""\n"
334R"==(const int Vcomp_ih = get_Vcomp_ih0(lx, ly); )==""\n"
335R"==(const int Vcomp_iw = get_Vcomp_iw0(lx, ly); )==""\n"
336R"==(const int V_read_idx = V_off(Vcomp_ic, Vcomp_ih, Vcomp_iw, VTRANS_BLOCK); )==""\n"
337R"==(__local const COMP_DATA_T *V_read )==""\n"
338R"==(= (__local const COMP_DATA_T *)&V[V_read_idx]; )==""\n"
339R"==(__attribute__((opencl_unroll_hint(1))) for (uint c = 0; c < IC; )==""\n"
340R"==(c += WINO_IC_BLOCK) { )==""\n"
341R"==(if (IW_BLOCK == 16 || Vtrans_iw < IW_BLOCK) { )==""\n"
342R"==(bool x_in = 0 <= src_iw && src_iw < IW && src_ic + c < IC; )==""\n"
343R"==(VTRANS_DATA_T src[WINO_D]; )==""\n"
344R"==(for (int index = 0; index < WINO_D; index++) { )==""\n"
345R"==(bool y_in = 0 <= (src_ih + index) && (src_ih + index) < IH )==""\n"
346R"==(&& x_in; )==""\n"
347R"==(src[index] = y_in ? *((const __global VTRANS_DATA_T *)(src_load )==""\n"
348R"==(+ src_off(0, 0, 0, index, 0))) )==""\n"
349R"==(: 0; )==""\n"
350R"==(src[index] = src[index] * scl_vec; )==""\n"
351R"==(} )==""\n"
352R"==(wino_V_transform(V_write, src); )==""\n"
353R"==(} )==""\n"
354R"==(src_load += src_off(0, WINO_IC_BLOCK, 0, 0, 0); )==""\n"
355R"==(barrier(CLK_LOCAL_MEM_FENCE); )==""\n"
356R"==(__local const COMP_DATA_T *V_read_outer = V_read; )==""\n"
357R"==(const int outer_c_blocking = COMP_UNROLL * COMP_BLOCK; )==""\n"
358R"==(const int V_local_count = outer_c_blocking * IW_INTERNAL_BLOCK / LWX; )==""\n"
359R"==(__attribute__((opencl_unroll_hint( )==""\n"
360R"==(1))) for (uint c_outer = 0; c_outer < WINO_IC_BLOCK )==""\n"
361R"==(&& (WINO_D == 8 || ly < WINO_D); )==""\n"
362R"==(c_outer += outer_c_blocking) { )==""\n"
363R"==(DATA_T V_block[V_local_count]; )==""\n"
364R"==(const int c_block = IC_BLOCK / VCOMP_LX_CYCLE; )==""\n"
365R"==(const int w_count = V_local_count / c_block; )==""\n"
366R"==(const int w_stride = IW_INTERNAL_BLOCK / w_count; )==""\n"
367R"==(unroll_for(int w_load = 0; w_load < w_count; w_load++) { )==""\n"
368R"==(unroll_for(int c_load = 0; c_load < c_block; )==""\n"
369R"==(c_load += COMP_BLOCK) { )==""\n"
370R"==(COMP_WRITE(V_read_outer[V_off(c_load, 0, w_load * w_stride, )==""\n"
371R"==(COMP_BLOCK)], )==""\n"
372R"==(&V_block[w_load * c_block + c_load]); )==""\n"
373R"==(} )==""\n"
374R"==(} )==""\n"
375R"==(V_read_outer += V_off(outer_c_blocking, 0, 0, COMP_BLOCK); )==""\n"
376R"==(#define V_BLOCK(_ic, _iw) \ )==""\n"
377R"==(sub_group_broadcast( \ )==""\n"
378R"==(V_block[(_ic) % c_block + c_block * ((_iw) / w_stride)], \ )==""\n"
379R"==((IC_BLOCK / c_block) * ((_iw) % w_stride) + ((_ic) / c_block)) )==""\n"
380R"==(unroll_for(int c_inner = 0; c_inner < outer_c_blocking; )==""\n"
381R"==(c_inner += COMP_BLOCK) { )==""\n"
382R"==(unroll_for(int kw_in = 0; kw_in < KW; kw_in++) { )==""\n"
383R"==(unroll_for(int c_out = 0; c_out < COMP_OC_COUNT; c_out++) { )==""\n"
384R"==(const COMP_DATA_T f0 = COMP_BLOCK_READ( )==""\n"
385R"==(&U[U_off(c_out * COMP_OC_STRIDE, 0, 0, kw_in)]); )==""\n"
386R"==(unroll_for(int c_in = 0; c_in < COMP_BLOCK; c_in++) { )==""\n"
387R"==(unroll_for(int ow_in = 0; ow_in < OW_BLOCK; )==""\n"
388R"==(ow_in++) { )==""\n"
389R"==(DOTi(M[c_out][ow_in], f0[c_in], )==""\n"
390R"==(V_BLOCK(c_in + c_inner, kw_in + ow_in)); )==""\n"
391R"==(} )==""\n"
392R"==(} )==""\n"
393R"==(} )==""\n"
394R"==(} )==""\n"
395R"==(U += U_off(0, COMP_BLOCK, 0, 0); )==""\n"
396R"==(} )==""\n"
397R"==(U += U_off(0, COMP_UNROLL * COMP_BLOCK, 0, 0) )==""\n"
398R"==(- COMP_UNROLL * U_off(0, COMP_BLOCK, 0, 0); )==""\n"
399R"==(} )==""\n"
400R"==(barrier(CLK_LOCAL_MEM_FENCE); )==""\n"
401R"==(} )==""\n"
402R"==({ )==""\n"
403R"==(const int M_oc = get_Mcomp_oc0(lx, ly); )==""\n"
404R"==(const int M_oh = get_Mcomp_oh0(lx, ly); )==""\n"
405R"==(const int M_ow = get_Mcomp_ow0(lx, ly); )==""\n"
406R"==(__local DATA_T *M_write = (__local DATA_T *)&V[M_off(0, M_oh, 0, 4)]; )==""\n"
407R"==(M_write += M_off(M_oc, 0, 0, 1); )==""\n"
408R"==(for (int i = 0; i < COMP_OC_COUNT; i++) { )==""\n"
409R"==(for (int j = 0; j < M_ow_size; j++) { )==""\n"
410R"==(M_write[M_off(i * COMP_OC_STRIDE, 0, M_ow + j, 1)] = M[i][j]; )==""\n"
411R"==(} )==""\n"
412R"==(} )==""\n"
413R"==(barrier(CLK_LOCAL_MEM_FENCE); )==""\n"
414R"==(} )==""\n"
415R"==(if (get_out_ow0(lx, ly) < OW_BLOCK) { )==""\n"
416R"==(const int M_oc = get_out_oc0(lx, ly); )==""\n"
417R"==(const int M_oh = get_out_oh0(lx, ly); )==""\n"
418R"==(const int M_ow = get_out_ow0(lx, ly); )==""\n"
419R"==(__local const OUT_BLOCK_DATA_T *M_read )==""\n"
420R"==(= (__local OUT_BLOCK_DATA_T *)&V[M_off(0, 0, M_ow, 4)]; )==""\n"
421R"==(M_read += M_off(M_oc, 0, 0, OUT_TYPE_BLOCK); )==""\n"
422R"==(OUT_BLOCK_DATA_T M[COMP_OC_COUNT][WINO_D]; )==""\n"
423R"==(for (int i = 0; i < COMP_OC_COUNT; i++) { )==""\n"
424R"==(for (int j = 0; j < WINO_D; j++) { )==""\n"
425R"==(M[i][j] = M_read[M_off( )==""\n"
426R"==(i * COMP_OC_STRIDE, M_oh + j, 0, OUT_TYPE_BLOCK)]; )==""\n"
427R"==(} )==""\n"
428R"==(} )==""\n"
429R"==(OUT_BLOCK_DATA_T C[COMP_OC_COUNT][WINO_M]; )==""\n"
430R"==(unroll_for(int i = 0; i < COMP_OC_COUNT; i++) { )==""\n"
431R"==(wino_m_transform(C[i], M[i]); )==""\n"
432R"==(unroll_for(int j = 0; j < WINO_M; j++) { C[i][j] = C[i][j] * scl; } )==""\n"
433R"==(} )==""\n"
434R"==(const int oc = oc0 + M_oc; )==""\n"
435R"==(const int ow = ow0 + M_ow; )==""\n"
436R"==(const int oh = oh0 + M_oh; )==""\n"
437R"==(int dst_idx = dst_off(mb, oc, 0, oh, ow); )==""\n"
438R"==(if (WITH_BIAS || WITH_POST_OP) { )==""\n"
439R"==(const int c_size = COMP_OC_COUNT * WINO_M * OUT_TYPE_BLOCK; )==""\n"
440R"==(if (WITH_BIAS) { )==""\n"
441R"==(for_(int oc_block = 0; oc_block < COMP_OC_COUNT; oc_block++) )==""\n"
442R"==(for_(int oh_block = 0; oh_block < WINO_M; oh_block++) )==""\n"
443R"==(for (int ow_block = 0; ow_block < OUT_TYPE_BLOCK; ow_block++) { )==""\n"
444R"==(const int oc_tmp = oc + COMP_OC_STRIDE * oc_block; )==""\n"
445R"==(C[oc_block][oh_block][ow_block] )==""\n"
446R"==(+= (OC_WO_PADDING % OC_BLOCK == 0 )==""\n"
447R"==(|| oc_tmp < OC_WO_PADDING) )==""\n"
448R"==(? bias[oc_tmp] )==""\n"
449R"==(: DATA_ZERO; )==""\n"
450R"==(} )==""\n"
451R"==(} )==""\n"
452R"==(DATA_T S[COMP_OC_COUNT][WINO_M][OUT_TYPE_BLOCK]; )==""\n"
453R"==(if (WITH_SUM) { )==""\n"
454R"==(for_(int oc_block = 0; oc_block < COMP_OC_COUNT; oc_block++) )==""\n"
455R"==(for (int oh_block = 0; oh_block < WINO_M; oh_block++) { )==""\n"
456R"==(bool valid_oh = OH % OH_BLOCK == 0 || oh + oh_block < OH; )==""\n"
457R"==(for (int ow_block = 0; ow_block < OUT_TYPE_BLOCK; )==""\n"
458R"==(ow_block++) { )==""\n"
459R"==(bool valid_ow )==""\n"
460R"==(= OW % OW_BLOCK == 0 || ow + ow_block < OW; )==""\n"
461R"==(S[oc_block][oh_block][ow_block] = valid_oh && valid_ow )==""\n"
462R"==(? dst[dst_idx )==""\n"
463R"==(+ dst_off(0, oc_block * COMP_OC_STRIDE, )==""\n"
464R"==(0, oh_block, ow_block)] )==""\n"
465R"==(: 0; )==""\n"
466R"==(} )==""\n"
467R"==(} )==""\n"
468R"==(} )==""\n"
469R"==(APPLY_POST_OPS_SERIAL(C, DATA_T, S, DATA_T, mb, 1, oc, )==""\n"
470R"==(COMP_OC_COUNT, oh, WINO_M, ow, OUT_TYPE_BLOCK, 0, 1, 0, 1); )==""\n"
471R"==(} )==""\n"
472R"==(unroll_for(int oc_off = 0; oc_off < COMP_OC_COUNT; oc_off++) { )==""\n"
473R"==(unroll_for(int h_off = 0; h_off < WINO_M; h_off++) { )==""\n"
474R"==(if (h_off == 0 || OH % OH_BLOCK == 0 || oh + h_off < OH) { )==""\n"
475R"==(unroll_for(int w_off = 0; w_off < OUT_TYPE_BLOCK; w_off++) { )==""\n"
476R"==(if (OW % OW_BLOCK == 0 || ow + w_off < OW) )==""\n"
477R"==(dst[dst_idx )==""\n"
478R"==(+ dst_off(0, oc_off * COMP_OC_STRIDE, 0, )==""\n"
479R"==(h_off, w_off)] )==""\n"
480R"==(= C[oc_off][h_off][w_off]; )==""\n"
481R"==(} )==""\n"
482R"==(} )==""\n"
483R"==(} )==""\n"
484R"==(} )==""\n"
485R"==(} )==""\n"
486R"==(} )==""\n"
487R"==()==";
488}
489}
490}
491}