You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

convolution_pack1to4.comp 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  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
  7. //
  8. // https://opensource.org/licenses/BSD-3-Clause
  9. //
  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.
  14. #version 450
  15. layout (constant_id = 0) const int kernel_w = 1;
  16. layout (constant_id = 1) const int kernel_h = 1;
  17. layout (constant_id = 2) const int dilation_w = 1;
  18. layout (constant_id = 3) const int dilation_h = 1;
  19. layout (constant_id = 4) const int stride_w = 1;
  20. layout (constant_id = 5) const int stride_h = 1;
  21. layout (constant_id = 6) const int bias_term = 0;
  22. layout (local_size_x_id = 233) in;
  23. layout (local_size_y_id = 234) in;
  24. layout (local_size_z_id = 235) in;
  25. layout (binding = 0) readonly buffer bottom_blob { float bottom_blob_data[]; };
  26. layout (binding = 1) writeonly buffer top_blob { vec4 top_blob_data[]; };
  27. layout (binding = 2) readonly buffer weight_blob { vec4 weight_data[]; };
  28. layout (binding = 3) readonly buffer bias_blob { vec4 bias_data[]; };
  29. layout (push_constant) uniform parameter
  30. {
  31. int dims;
  32. int w;
  33. int h;
  34. int c;
  35. int cstep;
  36. int outdims;
  37. int outw;
  38. int outh;
  39. int outc;
  40. int outcstep;
  41. } p;
  42. void main()
  43. {
  44. int gx = int(gl_GlobalInvocationID.x);
  45. int gy = int(gl_GlobalInvocationID.y);
  46. int gz = int(gl_GlobalInvocationID.z);
  47. if (gx >= p.outw || gy >= p.outh || gz >= p.outc)
  48. return;
  49. vec4 sum;
  50. if (bias_term == 1)
  51. {
  52. sum = bias_data[gz];
  53. }
  54. else
  55. {
  56. sum = vec4(0.0);
  57. }
  58. int w_offset = gz * p.c * kernel_w * kernel_h;
  59. for (int z = 0; z < p.c; z++)
  60. {
  61. int v_offset = z * p.cstep + gy * stride_h * p.w + gx * stride_w;
  62. for (int y = 0; y < kernel_h; y++)
  63. {
  64. for (int x = 0; x < kernel_w; x++)
  65. {
  66. float v = bottom_blob_data[v_offset + x * dilation_w];
  67. vec4 k = weight_data[w_offset + x];
  68. sum += v * k;
  69. }
  70. v_offset += dilation_h * p.w;
  71. w_offset += kernel_w;
  72. }
  73. }
  74. top_blob_data[gz * p.outcstep + gy * p.outw + gx] = sum;
  75. }