Guest User

Untitled

a guest
Jul 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // Enable double-precision floating point numbers support.
  2. // Not all platforms / devices support this, so you may have to switch to floats.
  3. #pragma OPENCL EXTENSION cl_khr_fp64 : enable
  4.  
  5. __kernel void dft(
  6. __global const double2 *in, // complex values input
  7. __global double2 *out, // complex values output
  8. int length, // number of input and output values
  9. int sign) // sign modifier in the exponential :
  10. // 1 for forward transform, -1 for backward.
  11. {
  12. // Get the varying parameter of the parallel execution :
  13. int i = get_global_id(0);
  14.  
  15. // In case we're executed "too much", check bounds :
  16. if (i >= length)
  17. return;
  18.  
  19. // Initialize sum and inner arguments
  20. double2 tot = 0;
  21. double param = (-2 * sign * i) * M_PI / (double)length;
  22.  
  23. for (int k = 0; k < length; k++) {
  24. double2 value = in[k];
  25.  
  26. // Compute sin and cos in a single call :
  27. double c;
  28. double s = sincos(k * param, &c);
  29.  
  30. // This adds (value.x * c - value.y * s, value.x * s + value.y * c) to the sum :
  31. tot += (double2)(
  32. dot(value, (double2)(c, -s)),
  33. dot(value, (double2)(s, c))
  34. );
  35. }
  36.  
  37. if (sign == 1) {
  38. // forward transform (space -> frequential)
  39. out[i] = tot;
  40. } else {
  41. // backward transform (frequential -> space)
  42. out[i] = tot / (double)length;
  43. }
  44. }
Add Comment
Please, Sign In to add comment