Download src/layer/vulkan/shader/convolution.comp from camenduru/ncnn: direct link, hf CLI and curl.
- Browser
- Download file 8.45 kB
-
https://huggingface.co/camenduru/ncnn/resolve/main/src/layer/vulkan/shader/convolution.comp
- Command line
-
hf download hf://camenduru/ncnn/src/layer/vulkan/shader/convolution.comp
-
curl -L -o convolution.comp https://huggingface.co/camenduru/ncnn/resolve/main/src/layer/vulkan/shader/convolution.comp
8.45 kB
| // Tencent is pleased to support the open source community by making ncnn available. | |
| // | |
| // Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved. | |
| // | |
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | |
| // in compliance with the License. You may obtain a copy of the License at | |
| // | |
| // https://opensource.org/licenses/BSD-3-Clause | |
| // | |
| // Unless required by applicable law or agreed to in writing, software distributed | |
| // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | |
| // CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| // specific language governing permissions and limitations under the License. | |
| layout (constant_id = 0) const int kernel_w = 1; | |
| layout (constant_id = 1) const int kernel_h = 1; | |
| layout (constant_id = 2) const int dilation_w = 1; | |
| layout (constant_id = 3) const int dilation_h = 1; | |
| layout (constant_id = 4) const int stride_w = 1; | |
| layout (constant_id = 5) const int stride_h = 1; | |
| layout (constant_id = 6) const int bias_term = 0; | |
| layout (constant_id = 7) const int activation_type = 0; | |
| layout (constant_id = 8) const float activation_param_0 = 0; | |
| layout (constant_id = 9) const float activation_param_1 = 0; | |
| layout (constant_id = shape_constant_id_offset + 0) const int dims = 0; | |
| layout (constant_id = shape_constant_id_offset + 1) const int w = 0; | |
| layout (constant_id = shape_constant_id_offset + 2) const int h = 0; | |
| layout (constant_id = shape_constant_id_offset + 3) const int c = 0; | |
| layout (constant_id = shape_constant_id_offset + 4) const int cstep = 0; | |
| layout (constant_id = shape_constant_id_offset + 5) const int outdims = 0; | |
| layout (constant_id = shape_constant_id_offset + 6) const int outw = 0; | |
| layout (constant_id = shape_constant_id_offset + 7) const int outh = 0; | |
| layout (constant_id = shape_constant_id_offset + 8) const int outc = 0; | |
| layout (constant_id = shape_constant_id_offset + 9) const int outcstep = 0; | |
| layout (binding = 0) uniform unfp sampler3D bottom_blob; | |
| layout (binding = 1, imfmtc1) writeonly uniform unfp image3D top_blob; | |
| layout (binding = 2) uniform unfp sampler3D weight_blob; | |
| layout (binding = 3) uniform unfp sampler3D bias_blob; | |
| layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; }; | |
| layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; }; | |
| layout (binding = 2) readonly buffer weight_blob { sfp weight_data[]; }; | |
| layout (binding = 3) readonly buffer bias_blob { sfp bias_data[]; }; | |
| layout (push_constant) uniform parameter | |
| { | |
| int dims; | |
| int w; | |
| int h; | |
| int c; | |
| int cstep; | |
| int outdims; | |
| int outw; | |
| int outh; | |
| int outc; | |
| int outcstep; | |
| } p; | |
| void main() | |
| { | |
| int gx = int(gl_GlobalInvocationID.x) * 2; | |
| int gy = int(gl_GlobalInvocationID.y) * 2; | |
| int gz = int(gl_GlobalInvocationID.z) * 2; | |
| if (gx >= psc(outw) || gy >= psc(outh) || gz >= psc(outc)) | |
| return; | |
| const ivec2 gx2 = gx + ivec2(0, 1); | |
| const ivec2 gy2 = gy + ivec2(0, 1); | |
| const ivec2 gz2 = gz + ivec2(0, 1); | |
| afp sum0; | |
| afp sum1; | |
| afp sum2; | |
| afp sum3; | |
| afp sum4; | |
| afp sum5; | |
| afp sum6; | |
| afp sum7; | |
| if (bias_term == 1) | |
| { | |
| sum0 = image3d_ld1(bias_blob, ivec3(gz2.x, 0, 0)); | |
| sum4 = image3d_ld1(bias_blob, ivec3(gz2.y, 0, 0)); | |
| sum0 = buffer_ld1(bias_data, gz2.x); | |
| sum4 = buffer_ld1(bias_data, gz2.y); | |
| sum1 = sum0; | |
| sum2 = sum0; | |
| sum3 = sum0; | |
| sum5 = sum4; | |
| sum6 = sum4; | |
| sum7 = sum4; | |
| } | |
| else | |
| { | |
| sum0 = afp(0.f); | |
| sum1 = afp(0.f); | |
| sum2 = afp(0.f); | |
| sum3 = afp(0.f); | |
| sum4 = afp(0.f); | |
| sum5 = afp(0.f); | |
| sum6 = afp(0.f); | |
| sum7 = afp(0.f); | |
| } | |
| for (int z = 0; z < psc(c); z++) | |
| { | |
| ivec2 sy = gy2 * stride_h; | |
| int wx = 0; | |
| for (int y = 0; y < kernel_h; y++) | |
| { | |
| ivec2 sx = gx2 * stride_w; | |
| for (int x = 0; x < kernel_w; x++) | |
| { | |
| afp v0 = image3d_ld1(bottom_blob, ivec3(sx.x, sy.x, z)); | |
| afp v1 = image3d_ld1(bottom_blob, ivec3(sx.y, sy.x, z)); | |
| afp v2 = image3d_ld1(bottom_blob, ivec3(sx.x, sy.y, z)); | |
| afp v3 = image3d_ld1(bottom_blob, ivec3(sx.y, sy.y, z)); | |
| afp k0 = image3d_ld1(weight_blob, ivec3(wx, z, gz2.x)); | |
| afp k1 = image3d_ld1(weight_blob, ivec3(wx, z, gz2.y)); | |
| sum0 += v0 * k0; | |
| sum1 += v1 * k0; | |
| sum2 += v2 * k0; | |
| sum3 += v3 * k0; | |
| sum4 += v0 * k1; | |
| sum5 += v1 * k1; | |
| sum6 += v2 * k1; | |
| sum7 += v3 * k1; | |
| sx += dilation_w; | |
| wx += 1; | |
| } | |
| sy += dilation_h; | |
| } | |
| } | |
| ivec2 w_offset = gz2 * psc(c) * kernel_w * kernel_h; | |
| for (int z = 0; z < psc(c); z++) | |
| { | |
| ivec4 v_offset; | |
| v_offset.rg = z * psc(cstep) + gy2.x * stride_h * psc(w) + gx2 * stride_w; | |
| v_offset.ba = z * psc(cstep) + gy2.y * stride_h * psc(w) + gx2 * stride_w; | |
| for (int y = 0; y < kernel_h; y++) | |
| { | |
| for (int x = 0; x < kernel_w; x++) | |
| { | |
| afp v0 = buffer_ld1(bottom_blob_data, v_offset.r + x * dilation_w); | |
| afp v1 = buffer_ld1(bottom_blob_data, v_offset.g + x * dilation_w); | |
| afp v2 = buffer_ld1(bottom_blob_data, v_offset.b + x * dilation_w); | |
| afp v3 = buffer_ld1(bottom_blob_data, v_offset.a + x * dilation_w); | |
| afp k0 = buffer_ld1(weight_data, w_offset.x + x); | |
| afp k1 = buffer_ld1(weight_data, w_offset.y + x); | |
| sum0 += v0 * k0; | |
| sum1 += v1 * k0; | |
| sum2 += v2 * k0; | |
| sum3 += v3 * k0; | |
| sum4 += v0 * k1; | |
| sum5 += v1 * k1; | |
| sum6 += v2 * k1; | |
| sum7 += v3 * k1; | |
| } | |
| v_offset += dilation_h * psc(w); | |
| w_offset += kernel_w; | |
| } | |
| } | |
| sum0 = activation_afp(sum0, activation_type, activation_param_0, activation_param_1); | |
| sum1 = activation_afp(sum1, activation_type, activation_param_0, activation_param_1); | |
| sum2 = activation_afp(sum2, activation_type, activation_param_0, activation_param_1); | |
| sum3 = activation_afp(sum3, activation_type, activation_param_0, activation_param_1); | |
| sum4 = activation_afp(sum4, activation_type, activation_param_0, activation_param_1); | |
| sum5 = activation_afp(sum5, activation_type, activation_param_0, activation_param_1); | |
| sum6 = activation_afp(sum6, activation_type, activation_param_0, activation_param_1); | |
| sum7 = activation_afp(sum7, activation_type, activation_param_0, activation_param_1); | |
| image3d_st1(top_blob, ivec3(gx2.x, gy2.x, gz2.x), sum0); | |
| image3d_st1(top_blob, ivec3(gx2.y, gy2.x, gz2.x), sum1); | |
| image3d_st1(top_blob, ivec3(gx2.x, gy2.y, gz2.x), sum2); | |
| image3d_st1(top_blob, ivec3(gx2.y, gy2.y, gz2.x), sum3); | |
| image3d_st1(top_blob, ivec3(gx2.x, gy2.x, gz2.y), sum4); | |
| image3d_st1(top_blob, ivec3(gx2.y, gy2.x, gz2.y), sum5); | |
| image3d_st1(top_blob, ivec3(gx2.x, gy2.y, gz2.y), sum6); | |
| image3d_st1(top_blob, ivec3(gx2.y, gy2.y, gz2.y), sum7); | |
| const ivec2 gi = gz2 * psc(outcstep) + gy * psc(outw) + gx; | |
| buffer_st1(top_blob_data, gi.x, sum0); | |
| if (gx + 1 < psc(outw)) buffer_st1(top_blob_data, gi.x + 1, sum1); | |
| if (gy + 1 < psc(outh)) buffer_st1(top_blob_data, gi.x + psc(outw), sum2); | |
| if (gy + 1 < psc(outh) && gx + 1 < psc(outw)) buffer_st1(top_blob_data, gi.x + psc(outw) + 1, sum3); | |
| if (gz + 1 < psc(outc)) | |
| { | |
| buffer_st1(top_blob_data, gi.y, sum4); | |
| if (gx + 1 < psc(outw)) buffer_st1(top_blob_data, gi.y + 1, sum5); | |
| if (gy + 1 < psc(outh)) buffer_st1(top_blob_data, gi.y + psc(outw), sum6); | |
| if (gy + 1 < psc(outh) && gx + 1 < psc(outw)) buffer_st1(top_blob_data, gi.y + psc(outw) + 1, sum7); | |
| } | |
| } | |