Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

63 linhas
1.5KB

  1. #include <cuda_runtime.h>
  2. #include <math.h>
  3. extern "C" __global__ void gpud_freq_shift_kernel(
  4. const float2* __restrict__ in,
  5. float2* __restrict__ out,
  6. int n,
  7. double phase_inc,
  8. double phase_start
  9. ) {
  10. int idx = blockIdx.x * blockDim.x + threadIdx.x;
  11. if (idx >= n) return;
  12. double phase = phase_start + phase_inc * (double)idx;
  13. float si, co;
  14. sincosf((float)phase, &si, &co);
  15. float2 v = in[idx];
  16. out[idx].x = v.x * co - v.y * si;
  17. out[idx].y = v.x * si + v.y * co;
  18. }
  19. extern "C" int gpud_launch_freq_shift_cuda(
  20. const float2* in,
  21. float2* out,
  22. int n,
  23. double phase_inc,
  24. double phase_start
  25. ) {
  26. if (n <= 0) return 0;
  27. const int block = 256;
  28. const int grid = (n + block - 1) / block;
  29. gpud_freq_shift_kernel<<<grid, block>>>(in, out, n, phase_inc, phase_start);
  30. return (int)cudaGetLastError();
  31. }
  32. extern "C" __global__ void gpud_fm_discrim_kernel(
  33. const float2* __restrict__ in,
  34. float* __restrict__ out,
  35. int n
  36. ) {
  37. int idx = blockIdx.x * blockDim.x + threadIdx.x;
  38. if (idx >= n - 1) return;
  39. float2 prev = in[idx];
  40. float2 curr = in[idx + 1];
  41. float re = prev.x * curr.x + prev.y * curr.y;
  42. float im = prev.x * curr.y - prev.y * curr.x;
  43. out[idx] = atan2f(im, re);
  44. }
  45. extern "C" int gpud_launch_fm_discrim_cuda(
  46. const float2* in,
  47. float* out,
  48. int n
  49. ) {
  50. if (n <= 1) return 0;
  51. const int block = 256;
  52. const int grid = (n + block - 1) / block;
  53. gpud_fm_discrim_kernel<<<grid, block>>>(in, out, n);
  54. return (int)cudaGetLastError();
  55. }