1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char * = 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"==(#ifndef GPU_OCL_OFFSETS_H )==" "\n" |
21 | R"==(#define GPU_OCL_OFFSETS_H )==" "\n" |
22 | R"==(int off_ncdhw(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
23 | R"==(int off = 0; )==" "\n" |
24 | R"==(off += n * C * D * H * W; )==" "\n" |
25 | R"==(off += c * D * H * W; )==" "\n" |
26 | R"==(off += d * H * W; )==" "\n" |
27 | R"==(off += h * W; )==" "\n" |
28 | R"==(off += w; )==" "\n" |
29 | R"==(return off; )==" "\n" |
30 | R"==(} )==" "\n" |
31 | R"==(int off_ndhwc(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
32 | R"==(int off = 0; )==" "\n" |
33 | R"==(off += n * D * H * W * C; )==" "\n" |
34 | R"==(off += d * H * W * C; )==" "\n" |
35 | R"==(off += h * W * C; )==" "\n" |
36 | R"==(off += w * C; )==" "\n" |
37 | R"==(off += c; )==" "\n" |
38 | R"==(return off; )==" "\n" |
39 | R"==(} )==" "\n" |
40 | R"==(int off_nCdhw16c( )==" "\n" |
41 | R"==(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
42 | R"==(int off = 0; )==" "\n" |
43 | R"==(off += n * (C / 16) * D * H * W * 16; )==" "\n" |
44 | R"==(off += (c / 16) * D * H * W * 16; )==" "\n" |
45 | R"==(off += d * H * W * 16; )==" "\n" |
46 | R"==(off += h * W * 16; )==" "\n" |
47 | R"==(off += w * 16; )==" "\n" |
48 | R"==(off += c % 16; )==" "\n" |
49 | R"==(return off; )==" "\n" |
50 | R"==(} )==" "\n" |
51 | R"==(int off_NCdhw16n16c( )==" "\n" |
52 | R"==(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
53 | R"==(int off = 0; )==" "\n" |
54 | R"==(off += (n / 16) * (C / 16) * D * H * W * 16 * 16; )==" "\n" |
55 | R"==(off += (c / 16) * D * H * W * 16 * 16; )==" "\n" |
56 | R"==(off += d * H * W * 16 * 16; )==" "\n" |
57 | R"==(off += h * W * 16 * 16; )==" "\n" |
58 | R"==(off += w * 16 * 16; )==" "\n" |
59 | R"==(off += (n % 16) * 16; )==" "\n" |
60 | R"==(off += (c % 16); )==" "\n" |
61 | R"==(return off; )==" "\n" |
62 | R"==(} )==" "\n" |
63 | R"==(int off_nCdhw32c( )==" "\n" |
64 | R"==(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
65 | R"==(int c_32_block = OC % 32 ? (32 + OC - (OC % 32)) : OC; )==" "\n" |
66 | R"==(int off = 0; )==" "\n" |
67 | R"==(off += n * (c_32_block / 32) * G * D * H * W * 32; )==" "\n" |
68 | R"==(off += (c / 32) * D * H * W * 32; )==" "\n" |
69 | R"==(off += d * H * W * 32; )==" "\n" |
70 | R"==(off += h * W * 32; )==" "\n" |
71 | R"==(off += w * 32; )==" "\n" |
72 | R"==(off += c % 32; )==" "\n" |
73 | R"==(return off; )==" "\n" |
74 | R"==(} )==" "\n" |
75 | R"==(int off_NCdhw32n16c( )==" "\n" |
76 | R"==(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
77 | R"==(int off = 0; )==" "\n" |
78 | R"==(off += (n / 32) * (C / 16) * D * H * W * 32 * 16; )==" "\n" |
79 | R"==(off += (c / 16) * D * H * W * 32 * 16; )==" "\n" |
80 | R"==(off += d * H * W * 32 * 16; )==" "\n" |
81 | R"==(off += h * W * 32 * 16; )==" "\n" |
82 | R"==(off += w * 32 * 16; )==" "\n" |
83 | R"==(off += (n % 32) * 16; )==" "\n" |
84 | R"==(off += (c % 16); )==" "\n" |
85 | R"==(return off; )==" "\n" |
86 | R"==(} )==" "\n" |
87 | R"==(int off_NCdhw32n32c( )==" "\n" |
88 | R"==(int n, int c, int d, int h, int w, int C, int D, int H, int W) { )==" "\n" |
89 | R"==(int c_32_block = OC % 32 ? (32 + OC - (OC % 32)) : OC; )==" "\n" |
90 | R"==(int off = 0; )==" "\n" |
91 | R"==(off += (n / 32) * (c_32_block / 32) * D * H * W * 32 * 32; )==" "\n" |
92 | R"==(off += (c / 32) * D * H * W * 32 * 32; )==" "\n" |
93 | R"==(off += d * H * W * 32 * 32; )==" "\n" |
94 | R"==(off += h * W * 32 * 32; )==" "\n" |
95 | R"==(off += w * 32 * 32; )==" "\n" |
96 | R"==(off += (n % 32) * 32; )==" "\n" |
97 | R"==(off += (c % 32); )==" "\n" |
98 | R"==(return off; )==" "\n" |
99 | R"==(} )==" "\n" |
100 | R"==(int off_gOdhwi16o(int g, int o, int i, int d, int h, int w, int O, int I, int D, )==" "\n" |
101 | R"==(int H, int W) { )==" "\n" |
102 | R"==(int off = 0; )==" "\n" |
103 | R"==(off += g * (O / 16) * D * H * W * I * 16; )==" "\n" |
104 | R"==(off += (o / 16) * D * H * W * I * 16; )==" "\n" |
105 | R"==(off += d * H * W * I * 16; )==" "\n" |
106 | R"==(off += h * W * I * 16; )==" "\n" |
107 | R"==(off += w * I * 16; )==" "\n" |
108 | R"==(off += i * 16; )==" "\n" |
109 | R"==(off += (o % 16); )==" "\n" |
110 | R"==(return off; )==" "\n" |
111 | R"==(} )==" "\n" |
112 | R"==(int off_gOIdhw16i16o(int g, int o, int i, int d, int h, int w, int O, int I, )==" "\n" |
113 | R"==(int D, int H, int W) { )==" "\n" |
114 | R"==(int off = 0; )==" "\n" |
115 | R"==(off += g * (O / 16) * (I / 16) * D * H * W * 16 * 16; )==" "\n" |
116 | R"==(off += (o / 16) * (I / 16) * D * H * W * 16 * 16; )==" "\n" |
117 | R"==(off += (i / 16) * D * H * W * 16 * 16; )==" "\n" |
118 | R"==(off += d * H * W * 16 * 16; )==" "\n" |
119 | R"==(off += h * W * 16 * 16; )==" "\n" |
120 | R"==(off += w * 16 * 16; )==" "\n" |
121 | R"==(off += (i % 16) * 16; )==" "\n" |
122 | R"==(off += (o % 16); )==" "\n" |
123 | R"==(return off; )==" "\n" |
124 | R"==(} )==" "\n" |
125 | R"==(int off_gIOdhw16i16o(int g, int o, int i, int d, int h, int w, int O, int I, )==" "\n" |
126 | R"==(int D, int H, int W) { )==" "\n" |
127 | R"==(int off = 0; )==" "\n" |
128 | R"==(off += g * (I / 16) * (O / 16) * D * H * W * 16 * 16; )==" "\n" |
129 | R"==(off += (i / 16) * (O / 16) * D * H * W * 16 * 16; )==" "\n" |
130 | R"==(off += (o / 16) * D * H * W * 16 * 16; )==" "\n" |
131 | R"==(off += d * H * W * 16 * 16; )==" "\n" |
132 | R"==(off += h * W * 16 * 16; )==" "\n" |
133 | R"==(off += w * 16 * 16; )==" "\n" |
134 | R"==(off += (i % 16) * 16; )==" "\n" |
135 | R"==(off += (o % 16); )==" "\n" |
136 | R"==(return off; )==" "\n" |
137 | R"==(} )==" "\n" |
138 | R"==(int src_off(int n, int c, int d, int h, int w) { )==" "\n" |
139 | R"==(#if SRC_NCHW )==" "\n" |
140 | R"==(return off_ncdhw(n, c, d, h, w, G * IC, ID, IH, IW); )==" "\n" |
141 | R"==(#elif SRC_NHWC )==" "\n" |
142 | R"==(return off_ndhwc(n, c, d, h, w, G * IC, ID, IH, IW); )==" "\n" |
143 | R"==(#elif SRC_W16C )==" "\n" |
144 | R"==(return off_nCdhw16c(n, c, d, h, w, G * IC, ID, IH, IW); )==" "\n" |
145 | R"==(#elif SRC_16N16C )==" "\n" |
146 | R"==(return off_NCdhw16n16c(n, c, d, h, w, G * IC, ID, IH, IW); )==" "\n" |
147 | R"==(#else )==" "\n" |
148 | R"==(#error "Unknown layout" )==" "\n" |
149 | R"==(#endif )==" "\n" |
150 | R"==(} )==" "\n" |
151 | R"==(int wei_off(int g, int o, int i, int d, int h, int w) { )==" "\n" |
152 | R"==(#if WEI_I16O )==" "\n" |
153 | R"==(return off_gOdhwi16o(g, o, i, d, h, w, OC, IC, KD, KH, KW); )==" "\n" |
154 | R"==(#elif WEI_16I16O )==" "\n" |
155 | R"==(return off_gOIdhw16i16o(g, o, i, d, h, w, OC, IC, KD, KH, KW); )==" "\n" |
156 | R"==(#elif WEI_16I16O_FLIPPED )==" "\n" |
157 | R"==(return off_gIOdhw16i16o(g, o, i, d, h, w, OC, IC, KD, KH, KW); )==" "\n" |
158 | R"==(#else )==" "\n" |
159 | R"==(#error "Unknown layout" )==" "\n" |
160 | R"==(#endif )==" "\n" |
161 | R"==(return 0; )==" "\n" |
162 | R"==(} )==" "\n" |
163 | R"==(int dst_off(int n, int c, int d, int h, int w) { )==" "\n" |
164 | R"==(#if DST_NCHW )==" "\n" |
165 | R"==(return off_ncdhw(n, c, d, h, w, G * OC_WO_PADDING, OD, OH, OW); )==" "\n" |
166 | R"==(#elif DST_NHWC )==" "\n" |
167 | R"==(return off_ndhwc(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
168 | R"==(#elif DST_W16C )==" "\n" |
169 | R"==(return off_nCdhw16c(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
170 | R"==(#elif DST_16N16C )==" "\n" |
171 | R"==(return off_NCdhw16n16c(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
172 | R"==(#elif DST_W32C )==" "\n" |
173 | R"==(return off_nCdhw32c(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
174 | R"==(#elif DST_32N16C )==" "\n" |
175 | R"==(return off_NCdhw32n16c(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
176 | R"==(#elif DST_32N32C )==" "\n" |
177 | R"==(return off_NCdhw32n32c(n, c, d, h, w, G * OC, OD, OH, OW); )==" "\n" |
178 | R"==(#else )==" "\n" |
179 | R"==(#error "Unknown layout" )==" "\n" |
180 | R"==(#endif )==" "\n" |
181 | R"==(} )==" "\n" |
182 | R"==(#endif )==" "\n" |
183 | R"==()==" ; |
184 | } |
185 | } |
186 | } |
187 | } |