1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2020 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;
26
layout (constant_id = 1) const int with_scalar = 0;
27
layout (constant_id = 2) const float const_b = 0;
29
#define shape_constant_id_offset 3
30
layout (constant_id = shape_constant_id_offset + 0) const int adims = 0;
31
layout (constant_id = shape_constant_id_offset + 1) const int aw = 0;
32
layout (constant_id = shape_constant_id_offset + 2) const int ah = 0;
33
layout (constant_id = shape_constant_id_offset + 3) const int ac = 0;
34
layout (constant_id = shape_constant_id_offset + 4) const int acstep = 0;
36
layout (constant_id = shape_constant_id_offset + 5) const int bdims = 0;
37
layout (constant_id = shape_constant_id_offset + 6) const int bw = 0;
38
layout (constant_id = shape_constant_id_offset + 7) const int bh = 0;
39
layout (constant_id = shape_constant_id_offset + 8) const int bc = 0;
40
layout (constant_id = shape_constant_id_offset + 9) const int bcstep = 0;
42
layout (constant_id = shape_constant_id_offset + 10) const int outdims = 0;
43
layout (constant_id = shape_constant_id_offset + 11) const int outw = 0;
44
layout (constant_id = shape_constant_id_offset + 12) const int outh = 0;
45
layout (constant_id = shape_constant_id_offset + 13) const int outc = 0;
46
layout (constant_id = shape_constant_id_offset + 14) const int outcstep = 0;
49
layout (binding = 0) uniform unfp sampler3D a_blob_3d;
50
layout (binding = 1) uniform unfp sampler3D b_blob_3d;
51
layout (binding = 2, imfmtc4) writeonly uniform unfp image3D top_blob_3d;
53
layout (binding = 0) buffer a_blob { sfpvec8 a_blob_data[]; };
54
layout (binding = 1) readonly buffer b_blob { sfpvec8 b_blob_data[]; };
55
layout (binding = 2) writeonly buffer top_blob { sfpvec8 top_blob_data[]; };
58
layout (push_constant) uniform parameter
81
int gx = int(gl_GlobalInvocationID.x);
82
int gy = int(gl_GlobalInvocationID.y);
83
int gz = int(gl_GlobalInvocationID.z);
85
if (gx >= psc(outw) || gy >= psc(outh) || gz >= psc(outc))
89
afpvec8 v1 = image3d_ld8(a_blob_3d, ivec3(gx, gy, gz));
91
const int gi = gz * psc(outcstep) + gy * psc(outw) + gx;
93
afpvec8 v1 = buffer_ld8(a_blob_data, gi);
101
v2[0] = afpvec4(afp(const_b));
102
v2[1] = afpvec4(afp(const_b));
108
v2 = image3d_ld8(b_blob_3d, ivec3(gx, gy, gz));
110
v2 = buffer_ld8(b_blob_data, gi);
118
res[0] = v1[0] + v2[0];
119
res[1] = v1[1] + v2[1];
123
res[0] = v1[0] - v2[0];
124
res[1] = v1[1] - v2[1];
128
res[0] = v1[0] * v2[0];
129
res[1] = v1[1] * v2[1];
133
res[0] = v1[0] / v2[0];
134
res[1] = v1[1] / v2[1];
138
res[0] = max(v1[0], v2[0]);
139
res[1] = max(v1[1], v2[1]);
143
res[0] = min(v1[0], v2[0]);
144
res[1] = min(v1[1], v2[1]);
148
res[0] = pow(v1[0], v2[0]);
149
res[1] = pow(v1[1], v2[1]);
153
res[0] = v2[0] - v1[0];
154
res[1] = v2[1] - v1[1];
158
res[0] = v2[0] / v1[0];
159
res[1] = v2[1] / v1[1];
163
res[0] = pow(v2[0], v1[0]);
164
res[1] = pow(v2[1], v1[1]);
169
res[0] = afpvec4(atan(vec4(v1[0]), vec4(v2[0])));
170
res[1] = afpvec4(atan(vec4(v1[1]), vec4(v2[1])));
172
res[0] = atan(v1[0], v2[0]);
173
res[1] = atan(v1[1], v2[1]);
179
res[0] = afpvec4(atan(vec4(v2[0]), vec4(v1[0])));
180
res[1] = afpvec4(atan(vec4(v2[1]), vec4(v1[1])));
182
res[0] = atan(v2[0], v1[0]);
183
res[1] = atan(v2[1], v1[1]);
188
image3d_st8(top_blob_3d, ivec3(gx, gy, gz), res);
190
buffer_st8(top_blob_data, gi, res);