1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2022 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
20
#if NCNN_fp16_arithmetic
21
#extension GL_EXT_shader_explicit_arithmetic_types_float16: require
24
#extension GL_GOOGLE_include_directive: enable
25
#include "vulkan_activation.comp"
27
layout (constant_id = 0) const int kernel_w = 1;
28
layout (constant_id = 1) const int kernel_h = 1;
29
layout (constant_id = 2) const int dilation_w = 1;
30
layout (constant_id = 3) const int dilation_h = 1;
31
layout (constant_id = 4) const int stride_w = 1;
32
layout (constant_id = 5) const int stride_h = 1;
33
layout (constant_id = 6) const int bias_term = 0;
34
layout (constant_id = 7) const int activation_type = 0;
35
layout (constant_id = 8) const float activation_param_0 = 0;
36
layout (constant_id = 9) const float activation_param_1 = 0;
38
#define shape_constant_id_offset 10
39
layout (constant_id = shape_constant_id_offset + 0) const int w = 0;
40
layout (constant_id = shape_constant_id_offset + 1) const int h = 0;
42
layout (constant_id = shape_constant_id_offset + 2) const int outw = 0;
43
layout (constant_id = shape_constant_id_offset + 3) const int outh = 0;
44
layout (constant_id = shape_constant_id_offset + 4) const int outc = 0;
45
layout (constant_id = shape_constant_id_offset + 5) const int outcstep = 0;
48
layout (binding = 0) uniform unfp sampler3D col_blob;
49
layout (binding = 1, imfmtc1) writeonly uniform unfp image3D top_blob;
50
layout (binding = 2) uniform unfp sampler3D bias_blob;
52
layout (binding = 0) readonly buffer col_blob { sfp col_blob_data[]; };
53
layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; };
54
layout (binding = 2) readonly buffer bias_blob { sfp bias_data[]; };
57
layout (push_constant) uniform parameter
70
int gx = int(gl_GlobalInvocationID.x);
71
int gy = int(gl_GlobalInvocationID.y);
72
int gz = int(gl_GlobalInvocationID.z);
74
if (gx >= psc(outw) || gy >= psc(outh) || gz >= psc(outc))
82
sum = image3d_ld1(bias_blob, ivec3(gz, 0, 0));
84
sum = buffer_ld1(bias_data, gz);
92
const int maxk = kernel_w * kernel_h;
94
const int kernel_extent_w = dilation_w * (kernel_w - 1) + 1;
95
const int kernel_extent_h = dilation_h * (kernel_h - 1) + 1;
97
const int sx_start = (gx < kernel_extent_w) ? 0 : (gx - kernel_extent_w) / stride_w + 1;
98
const int sx_end = min(gx / stride_w + 1, psc(w));
100
const int sy_start = (gy < kernel_extent_h) ? 0 : (gy - kernel_extent_h) / stride_h + 1;
101
const int sy_end = min(gy / stride_h + 1, psc(h));
103
for (int sy = sy_start; sy < sy_end; sy += 1)
105
for (int sx = sx_start; sx < sx_end; sx += 1)
107
int h_k = (gy - sy * stride_h);
108
int w_k = (gx - sx * stride_w);
110
if (h_k % dilation_h == 0 && w_k % dilation_w == 0)
116
sum += image3d_ld1(col_blob, ivec3(sy * psc(w) + sx, gz * maxk + h_k * kernel_w + w_k, 0));
118
const int gi = (gz * maxk + h_k * kernel_w + w_k) * psc(w) * psc(h) + sy * psc(w) + sx;
120
sum += buffer_ld1(col_blob_data, gi);
126
sum = activation_afp(sum, activation_type, activation_param_0, activation_param_1);
129
image3d_st1(top_blob, ivec3(gx, gy, gz), sum);
131
const int gi = gz * psc(outcstep) + gy * psc(outw) + gx;
133
buffer_st1(top_blob_data, gi, sum);