rope_norm.comp 901 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #version 450
  2. #include "rope_head.comp"
  3. void main() {
  4. const uint col = gl_GlobalInvocationID.y * 2;
  5. const uint row = gl_GlobalInvocationID.x;
  6. if (col >= p.ncols) {
  7. return;
  8. }
  9. if (col >= p.n_dims) {
  10. const uint i = row*p.ncols + col;
  11. data_d[i + 0] = data_a[i + 0];
  12. data_d[i + 1] = data_a[i + 1];
  13. return;
  14. }
  15. const uint i = row*p.ncols + col;
  16. const uint i2 = row/p.p_delta_rows;
  17. const float theta_base = data_pos[i2] * pow(p.theta_scale, col/2.0f);
  18. const float freq_factor = p.has_ff != 0 ? data_ff[col/2] : 1.0f;
  19. float cos_theta, sin_theta;
  20. rope_yarn(theta_base / freq_factor, col, cos_theta, sin_theta);
  21. const float x0 = float(data_a[i + 0]);
  22. const float x1 = float(data_a[i + 1]);
  23. data_d[i + 0] = D_TYPE(x0*cos_theta - x1*sin_theta);
  24. data_d[i + 1] = D_TYPE(x0*sin_theta + x1*cos_theta);
  25. }