op_gelu.comp 604 B

12345678910111213141516171819202122
  1. #version 450
  2. #include "common.comp"
  3. layout(local_size_x = 1) in;
  4. layout(binding = 0) buffer restrict readonly tensorIn { float in_[]; };
  5. layout(binding = 1) buffer restrict writeonly tensorOut { float out_[]; };
  6. layout(push_constant) uniform PushConstants {
  7. uint inOff;
  8. uint outOff;
  9. } pcs;
  10. void main() {
  11. const uint baseIndex = gl_WorkGroupID.x * 8;
  12. for (uint x = 0; x < 8; x++) {
  13. const uint i = baseIndex + x;
  14. const float y = in_[i + pcs.inOff];
  15. out_[i + pcs.outOff] = 0.5*y*(1.0 + tanh(clamp(SQRT_2_OVER_PI*y*(1.0 + GELU_COEF_A*y*y), -15.0, 15.0)));
  16. }
  17. }