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