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