1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6
// in compliance with the License. You may obtain a copy of the License at
8
// https://opensource.org/licenses/BSD-3-Clause
10
// Unless required by applicable law or agreed to in writing, software distributed
11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
// specific language governing permissions and limitations under the License.
18
#extension GL_EXT_shader_16bit_storage: require
19
struct sfpvec8 { f16vec4 abcd; f16vec4 efgh; };
21
#if NCNN_fp16_arithmetic
22
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
25
layout (constant_id = 0) const int op_type = 0;
27
#define shape_constant_id_offset 1
28
layout (constant_id = shape_constant_id_offset + 0) const int adims = 0;
29
layout (constant_id = shape_constant_id_offset + 1) const int aw = 0;
30
layout (constant_id = shape_constant_id_offset + 2) const int ah = 0;
31
layout (constant_id = shape_constant_id_offset + 3) const int ad = 0;
32
layout (constant_id = shape_constant_id_offset + 4) const int ac = 0;
33
layout (constant_id = shape_constant_id_offset + 5) const int acstep = 0;
35
layout (constant_id = shape_constant_id_offset + 6) const int bdims = 0;
36
layout (constant_id = shape_constant_id_offset + 7) const int bw = 0;
37
layout (constant_id = shape_constant_id_offset + 8) const int bh = 0;
38
layout (constant_id = shape_constant_id_offset + 9) const int bd = 0;
39
layout (constant_id = shape_constant_id_offset + 10) const int bc = 0;
40
layout (constant_id = shape_constant_id_offset + 11) const int bcstep = 0;
42
layout (constant_id = shape_constant_id_offset + 12) const int outdims = 0;
43
layout (constant_id = shape_constant_id_offset + 13) const int outw = 0;
44
layout (constant_id = shape_constant_id_offset + 14) const int outh = 0;
45
layout (constant_id = shape_constant_id_offset + 15) const int outd = 0;
46
layout (constant_id = shape_constant_id_offset + 16) const int outc = 0;
47
layout (constant_id = shape_constant_id_offset + 17) const int outcstep = 0;
50
layout (binding = 0) uniform unfp sampler3D a_blob_3d;
51
layout (binding = 1) uniform unfp sampler3D b_blob_3d;
52
layout (binding = 2, imfmtc4) writeonly uniform unfp image3D top_blob_3d;
54
layout (binding = 0) readonly buffer a_blob { sfpvec8 a_blob_data[]; };
55
layout (binding = 1) readonly buffer b_blob { sfpvec8 b_blob_data[]; };
56
layout (binding = 2) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };
59
layout (push_constant) uniform parameter
85
int gx = int(gl_GlobalInvocationID.x);
86
int gy = int(gl_GlobalInvocationID.y);
87
int gz = int(gl_GlobalInvocationID.z);
89
if (gx >= psc(outw) || gy >= psc(outh) * psc(outd) || gz >= psc(outc))
92
int yd = gy / psc(outh);
93
int yh = gy % psc(outh);
103
if (psc(adims) == psc(bdims))
105
// explicit broadcast
106
ax = min(gx, psc(aw) - 1);
107
ay = min(yd, psc(ad) - 1) * psc(ah) + min(yh, psc(ah) - 1);
108
az = min(gz, psc(ac) - 1);
110
bx = min(gx, psc(bw) - 1);
111
by = min(yd, psc(bd) - 1) * psc(bh) + min(yh, psc(bh) - 1);
112
bz = min(gz, psc(bc) - 1);
116
// implicit broadcast
143
else if (psc(adims) == 3)
161
else // if (psc(adims) == 2)
163
// if (psc(bdims) == 1)
174
afpvec8 v1 = image3d_ld8(a_blob_3d, ivec3(ax, ay, az));
175
afpvec8 v2 = image3d_ld8(b_blob_3d, ivec3(bx, by, bz));
177
int ai = az * psc(acstep) + ay * psc(aw) + ax;
178
int bi = bz * psc(bcstep) + by * psc(bw) + bx;
180
afpvec8 v1 = buffer_ld8(a_blob_data, ai);
181
afpvec8 v2 = buffer_ld8(b_blob_data, bi);
188
res[0] = v1[0] + v2[0];
189
res[1] = v1[1] + v2[1];
193
res[0] = v1[0] - v2[0];
194
res[1] = v1[1] - v2[1];
198
res[0] = v1[0] * v2[0];
199
res[1] = v1[1] * v2[1];
203
res[0] = v1[0] / v2[0];
204
res[1] = v1[1] / v2[1];
208
res[0] = max(v1[0], v2[0]);
209
res[1] = max(v1[1], v2[1]);
213
res[0] = min(v1[0], v2[0]);
214
res[1] = min(v1[1], v2[1]);
218
res[0] = pow(v1[0], v2[0]);
219
res[1] = pow(v1[1], v2[1]);
223
res[0] = v2[0] - v1[0];
224
res[1] = v2[1] - v1[1];
228
res[0] = v2[0] / v1[0];
229
res[1] = v2[1] / v1[1];
233
res[0] = pow(v2[0], v1[0]);
234
res[1] = pow(v2[1], v1[1]);
239
res[0] = afpvec4(atan(vec4(v1[0]), vec4(v2[0])));
240
res[1] = afpvec4(atan(vec4(v1[1]), vec4(v2[1])));
242
res[0] = atan(v1[0], v2[0]);
243
res[1] = atan(v1[1], v2[1]);
249
res[0] = afpvec4(atan(vec4(v2[0]), vec4(v1[0])));
250
res[1] = afpvec4(atan(vec4(v2[1]), vec4(v1[1])));
252
res[0] = atan(v2[0], v1[0]);
253
res[1] = atan(v2[1], v1[1]);
258
image3d_st8(top_blob_3d, ivec3(gx, gy, gz), res);
260
int gi = gz * psc(outcstep) + gy * psc(outw) + gx;
261
buffer_st8(top_blob_data, gi, res);