1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char * = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2019-2022 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_OCL_ZERO_POINTS_H )==" "\n" |
21 | R"==(#define GPU_OCL_OCL_ZERO_POINTS_H )==" "\n" |
22 | R"==(#if WITH_SRC_ZPOINTS )==" "\n" |
23 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
24 | R"==(int4 read_src_zero_points_32c(const __global int *ptr, const int ic) { )==" "\n" |
25 | R"==(int4 z; )==" "\n" |
26 | R"==(ptr += ic; )==" "\n" |
27 | R"==(#if IC % 32 != 0 )==" "\n" |
28 | R"==(if (ic + 32 > IC) { )==" "\n" |
29 | R"==(const int max_local_id = IC % 8; )==" "\n" |
30 | R"==(const int local_id = get_sub_group_local_id(); )==" "\n" |
31 | R"==(if (ic + 8 > IC) { )==" "\n" |
32 | R"==(z.s0 = local_id < max_local_id ? ptr[0 + local_id] : 0; )==" "\n" |
33 | R"==(z.s1 = 0; )==" "\n" |
34 | R"==(z.s2 = 0; )==" "\n" |
35 | R"==(z.s3 = 0; )==" "\n" |
36 | R"==(} else if (ic + 16 > IC) { )==" "\n" |
37 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
38 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
39 | R"==(z.s1 = local_id < max_local_id ? ptr[8 + local_id] : 0; )==" "\n" |
40 | R"==(z.s2 = 0; )==" "\n" |
41 | R"==(z.s3 = 0; )==" "\n" |
42 | R"==(} else if (ic + 24 > IC) { )==" "\n" |
43 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
44 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
45 | R"==(z.s1 = as_int(intel_sub_group_block_read( )==" "\n" |
46 | R"==((const __global uint *)(ptr + 8))); )==" "\n" |
47 | R"==(z.s2 = local_id < max_local_id ? ptr[16 + local_id] : 0; )==" "\n" |
48 | R"==(z.s3 = 0; )==" "\n" |
49 | R"==(} else { )==" "\n" |
50 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
51 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
52 | R"==(z.s1 = as_int(intel_sub_group_block_read( )==" "\n" |
53 | R"==((const __global uint *)(ptr + 8))); )==" "\n" |
54 | R"==(z.s2 = as_int(intel_sub_group_block_read( )==" "\n" |
55 | R"==((const __global uint *)(ptr + 16))); )==" "\n" |
56 | R"==(z.s3 = local_id < max_local_id ? ptr[24 + local_id] : 0; )==" "\n" |
57 | R"==(} )==" "\n" |
58 | R"==(} else )==" "\n" |
59 | R"==(#endif )==" "\n" |
60 | R"==({ )==" "\n" |
61 | R"==(z = as_int4(intel_sub_group_block_read4((const __global uint *)ptr)); )==" "\n" |
62 | R"==(} )==" "\n" |
63 | R"==(return z; )==" "\n" |
64 | R"==(} )==" "\n" |
65 | R"==(int2 read_src_zero_points_32g(const __global int *ptr, const int g) { )==" "\n" |
66 | R"==(int2 z; )==" "\n" |
67 | R"==(ptr += g; )==" "\n" |
68 | R"==(#if G % 32 != 0 )==" "\n" |
69 | R"==(if (g + 32 > G) { )==" "\n" |
70 | R"==(const int max_local_id = G % 16; )==" "\n" |
71 | R"==(const int local_id = get_sub_group_local_id(); )==" "\n" |
72 | R"==(if (g + 16 > G) { )==" "\n" |
73 | R"==(z.s0 = local_id < max_local_id ? ptr[0 + local_id] : 0; )==" "\n" |
74 | R"==(z.s1 = 0; )==" "\n" |
75 | R"==(} else { )==" "\n" |
76 | R"==(z.s0 = as_int( )==" "\n" |
77 | R"==(intel_sub_group_block_read((const __global uint *)ptr)); )==" "\n" |
78 | R"==(z.s1 = local_id < max_local_id ? ptr[16 + local_id] : 0; )==" "\n" |
79 | R"==(} )==" "\n" |
80 | R"==(} else )==" "\n" |
81 | R"==(#endif )==" "\n" |
82 | R"==({ )==" "\n" |
83 | R"==(z = as_int2(intel_sub_group_block_read2((const __global uint *)ptr)); )==" "\n" |
84 | R"==(} )==" "\n" |
85 | R"==(return z; )==" "\n" |
86 | R"==(} )==" "\n" |
87 | R"==(int calc_src_compensation_x32(int4 z, int8 wei) { )==" "\n" |
88 | R"==(int sum = 0; )==" "\n" |
89 | R"==(__attribute__((opencl_unroll_hint)) for (uint i = 0; i < 8; ++i) { )==" "\n" |
90 | R"==(char4 w = as_char4(wei[i]); )==" "\n" |
91 | R"==(sum += sub_group_broadcast(z[i >> 1], (i & 1) * 4 + 0) * w[0]; )==" "\n" |
92 | R"==(sum += sub_group_broadcast(z[i >> 1], (i & 1) * 4 + 1) * w[1]; )==" "\n" |
93 | R"==(sum += sub_group_broadcast(z[i >> 1], (i & 1) * 4 + 2) * w[2]; )==" "\n" |
94 | R"==(sum += sub_group_broadcast(z[i >> 1], (i & 1) * 4 + 3) * w[3]; )==" "\n" |
95 | R"==(} )==" "\n" |
96 | R"==(return sum; )==" "\n" |
97 | R"==(} )==" "\n" |
98 | R"==(#else )==" "\n" |
99 | R"==(int read_src_zero_point(const __global int *ptr) { )==" "\n" |
100 | R"==(const int z = ptr[0]; )==" "\n" |
101 | R"==(return z; )==" "\n" |
102 | R"==(} )==" "\n" |
103 | R"==(#endif )==" "\n" |
104 | R"==(int calc_src_compensation_x4(int4 z, int wei) { )==" "\n" |
105 | R"==(int sum = 0; )==" "\n" |
106 | R"==({ )==" "\n" |
107 | R"==(char4 w = as_char4(wei); )==" "\n" |
108 | R"==(sum += z.s0 * w.s0; )==" "\n" |
109 | R"==(sum += z.s1 * w.s1; )==" "\n" |
110 | R"==(sum += z.s2 * w.s2; )==" "\n" |
111 | R"==(sum += z.s3 * w.s3; )==" "\n" |
112 | R"==(} )==" "\n" |
113 | R"==(return sum; )==" "\n" |
114 | R"==(} )==" "\n" |
115 | R"==(#endif )==" "\n" |
116 | R"==(#if WITH_DST_ZPOINTS )==" "\n" |
117 | R"==(int4 read_dst_zero_points_32c(const __global int *ptr, const int oc) { )==" "\n" |
118 | R"==(#if WITH_DST_ZPOINTS_PER_OC )==" "\n" |
119 | R"==(int4 z; )==" "\n" |
120 | R"==(ptr += oc; )==" "\n" |
121 | R"==(#if OC % 32 != 0 )==" "\n" |
122 | R"==(if (oc + 32 > OC) { )==" "\n" |
123 | R"==(const int max_local_id = OC % 8; )==" "\n" |
124 | R"==(const int local_id = get_sub_group_local_id(); )==" "\n" |
125 | R"==(if (oc + 8 > OC) { )==" "\n" |
126 | R"==(z.s0 = local_id < max_local_id ? ptr[0 + local_id] : 0; )==" "\n" |
127 | R"==(z.s1 = 0; )==" "\n" |
128 | R"==(z.s2 = 0; )==" "\n" |
129 | R"==(z.s3 = 0; )==" "\n" |
130 | R"==(} else if (oc + 16 > OC) { )==" "\n" |
131 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
132 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
133 | R"==(z.s1 = local_id < max_local_id ? ptr[8 + local_id] : 0; )==" "\n" |
134 | R"==(z.s2 = 0; )==" "\n" |
135 | R"==(z.s3 = 0; )==" "\n" |
136 | R"==(} else if (oc + 24 > OC) { )==" "\n" |
137 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
138 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
139 | R"==(z.s1 = as_int(intel_sub_group_block_read( )==" "\n" |
140 | R"==((const __global uint *)(ptr + 8))); )==" "\n" |
141 | R"==(z.s2 = local_id < max_local_id ? ptr[16 + local_id] : 0; )==" "\n" |
142 | R"==(z.s3 = 0; )==" "\n" |
143 | R"==(} else { )==" "\n" |
144 | R"==(z.s0 = as_int(intel_sub_group_block_read( )==" "\n" |
145 | R"==((const __global uint *)(ptr + 0))); )==" "\n" |
146 | R"==(z.s1 = as_int(intel_sub_group_block_read( )==" "\n" |
147 | R"==((const __global uint *)(ptr + 8))); )==" "\n" |
148 | R"==(z.s2 = as_int(intel_sub_group_block_read( )==" "\n" |
149 | R"==((const __global uint *)(ptr + 16))); )==" "\n" |
150 | R"==(z.s3 = local_id < max_local_id ? ptr[24 + local_id] : 0; )==" "\n" |
151 | R"==(} )==" "\n" |
152 | R"==(} else )==" "\n" |
153 | R"==(#endif )==" "\n" |
154 | R"==({ )==" "\n" |
155 | R"==(z = as_int4(intel_sub_group_block_read4((const __global uint *)ptr)); )==" "\n" |
156 | R"==(} )==" "\n" |
157 | R"==(#else )==" "\n" |
158 | R"==(const int4 z = ptr[0]; )==" "\n" |
159 | R"==(#endif )==" "\n" |
160 | R"==(return z; )==" "\n" |
161 | R"==(} )==" "\n" |
162 | R"==(int2 read_dst_zero_points_32g(const __global int *ptr, const int g) { )==" "\n" |
163 | R"==(#if WITH_DST_ZPOINTS_PER_OC )==" "\n" |
164 | R"==(int2 z; )==" "\n" |
165 | R"==(ptr += g; )==" "\n" |
166 | R"==(#if G % 32 != 0 )==" "\n" |
167 | R"==(if (g + 32 > G) { )==" "\n" |
168 | R"==(const int max_local_id = G % 16; )==" "\n" |
169 | R"==(const int local_id = get_sub_group_local_id(); )==" "\n" |
170 | R"==(if (g + 16 > G) { )==" "\n" |
171 | R"==(z.s0 = local_id < max_local_id ? ptr[0 + local_id] : 0; )==" "\n" |
172 | R"==(z.s1 = 0; )==" "\n" |
173 | R"==(} else { )==" "\n" |
174 | R"==(z.s0 = as_int( )==" "\n" |
175 | R"==(intel_sub_group_block_read((const __global uint *)ptr)); )==" "\n" |
176 | R"==(z.s1 = local_id < max_local_id ? ptr[16 + local_id] : 0; )==" "\n" |
177 | R"==(} )==" "\n" |
178 | R"==(} else )==" "\n" |
179 | R"==(#endif )==" "\n" |
180 | R"==({ )==" "\n" |
181 | R"==(z = as_int2(intel_sub_group_block_read2((const __global uint *)ptr)); )==" "\n" |
182 | R"==(} )==" "\n" |
183 | R"==(#else )==" "\n" |
184 | R"==(const int2 z = (int2)(ptr[0]); )==" "\n" |
185 | R"==(#endif )==" "\n" |
186 | R"==(return z; )==" "\n" |
187 | R"==(} )==" "\n" |
188 | R"==(#endif )==" "\n" |
189 | R"==(#if WITH_SRC_ZPOINTS || WITH_DST_ZPOINTS )==" "\n" |
190 | R"==(float4 zero_pad_dst_32c(float4 dst, const int oc) { )==" "\n" |
191 | R"==(#if OC % 32 != 0 )==" "\n" |
192 | R"==(if (oc + 32 > OC) { )==" "\n" |
193 | R"==(const int max_local_id = OC % 8; )==" "\n" |
194 | R"==(const int local_id = get_sub_group_local_id(); )==" "\n" |
195 | R"==(if (oc + 8 > OC) { )==" "\n" |
196 | R"==(dst.s0 = local_id < max_local_id ? dst.s0 : 0; )==" "\n" |
197 | R"==(dst.s1 = 0; )==" "\n" |
198 | R"==(dst.s2 = 0; )==" "\n" |
199 | R"==(dst.s3 = 0; )==" "\n" |
200 | R"==(} else if (oc + 16 > OC) { )==" "\n" |
201 | R"==(dst.s1 = local_id < max_local_id ? dst.s1 : 0; )==" "\n" |
202 | R"==(dst.s2 = 0; )==" "\n" |
203 | R"==(dst.s3 = 0; )==" "\n" |
204 | R"==(} else if (oc + 24 > OC) { )==" "\n" |
205 | R"==(dst.s2 = local_id < max_local_id ? dst.s2 : 0; )==" "\n" |
206 | R"==(dst.s3 = 0; )==" "\n" |
207 | R"==(} else { )==" "\n" |
208 | R"==(dst.s3 = local_id < max_local_id ? dst.s3 : 0; )==" "\n" |
209 | R"==(} )==" "\n" |
210 | R"==(} )==" "\n" |
211 | R"==(#endif )==" "\n" |
212 | R"==(return dst; )==" "\n" |
213 | R"==(} )==" "\n" |
214 | R"==(#endif )==" "\n" |
215 | R"==(#endif )==" "\n" |
216 | R"==()==" ; |
217 | } |
218 | } |
219 | } |
220 | } |