sum_rows.comp 887 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #version 450
  2. #include "generic_head.comp"
  3. #include "types.comp"
  4. #extension GL_EXT_control_flow_attributes : enable
  5. layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in;
  6. layout (binding = 0) readonly buffer A {A_TYPE data_a[];};
  7. layout (binding = 1) writeonly buffer D {D_TYPE data_d[];};
  8. layout (constant_id = 0) const uint BLOCK_SIZE = 32;
  9. shared FLOAT_TYPE tmp[BLOCK_SIZE];
  10. void main() {
  11. const uint row = gl_WorkGroupID.x;
  12. const uint col = gl_LocalInvocationID.x;
  13. tmp[col] = FLOAT_TYPE(0.0f);
  14. for (uint i = col; i < p.KX; i += BLOCK_SIZE) {
  15. tmp[col] += FLOAT_TYPE(data_a[row*p.KX + i]);
  16. }
  17. barrier();
  18. [[unroll]] for (int s = int(BLOCK_SIZE) / 2; s > 0; s >>= 1) {
  19. if (col < s) {
  20. tmp[col] += tmp[col + s];
  21. }
  22. barrier();
  23. }
  24. if (col == 0) {
  25. data_d[row] = D_TYPE(tmp[0]);
  26. }
  27. }