OpenCLFFT.h 3.22 KB
Newer Older
Uldis Locans's avatar
Uldis Locans committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*

  Name: OpenCLFFT

  Author: Uldis Locans

  Info:Extend OpenCLBase class to implement fft and ifft functions using OpenCL

  Data: 19.09.2014

*/
#ifndef H_OPENCL_FFT
#define H_OPENCL_FFT


#include <iostream>
#include <math.h>
#include <complex>

#include "../Algorithms/FFT.h"
#include "OpenCLBase.h"

23 24
#include "clFFT.h"

Uldis Locans's avatar
Uldis Locans committed
25 26 27 28 29 30
class OpenCLFFT : public DKSFFT {

private:

  OpenCLBase *m_oclbase;

31 32 33 34 35
  clfftSetupData fftSetup;
  clfftPlanHandle planHandleZ2Z;
  clfftPlanHandle planHandleD2Z;
  clfftPlanHandle planHandleZ2D;

Uldis Locans's avatar
Uldis Locans committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  /*
    Info: call fft kernels to execute FFT of the given domain,
    data - devevice memory ptr, cdim - current dim to transform, 
    ndim - totla number of dimmensions, N - size of dimension
    Return: success or error code
  */
  int ocl_callFFTKernel(cl_mem &data, int cdim, int ndim, int N, bool forward = true);
	
  /*
    Info: call ifft kernel to execute the bit reverse sort
    data - devevice memory ptr, cdim - current dim to transform, 
    ndim - totla number of dimmensions, N - size of dimension
    Return: success or error code
  */
  int ocl_callBitReverseKernel(cl_mem &data, int cdim, int ndim, int N);

52 53 54 55 56 57 58 59
  /** Get clfftStatus and print the corresponding error message.
   *  clfftStatus is returned from all clFFT library functions, print error displays the
   *  corresponding error message. If "other" is printed then error code corresponds to 
   *  OpenCL error code and not specifically to clFFT library, then OpenCL error codes should
   *  be checked to determine the reason for the error.
   */
  void printError(clfftStatus err);
  
Uldis Locans's avatar
Uldis Locans committed
60 61 62 63 64
public:

  /* constructor - currently does nothing*/
  OpenCLFFT(OpenCLBase *base) {
    m_oclbase = base;
65 66 67 68 69 70 71 72

    /* Set up fft */
    cl_int err;
    err = clfftInitSetupData(&fftSetup);
    err = clfftSetup(&fftSetup);
    
    if (err != CL_SUCCESS)
      DEBUG_MSG("Error seting up clFFT");
Uldis Locans's avatar
Uldis Locans committed
73 74 75
  }
	
  /* destructor - currently does nothing*/
76
  ~OpenCLFFT() { destroyFFT(); }
Uldis Locans's avatar
Uldis Locans committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	
  /*
    Info: execute forward fft function with data set on device
    Return: success or error code
  */
  //int ocl_executeFFT(cl_mem &data, int ndim, int N, bool forward = true);
  int executeFFT(void *data, int ndim, int N[3], int streamId = -1, bool forward = true);
	
  /*
    Info: execute inverse fft with data set on device
    Return: success or error code
  */
  //int ocl_executeIFFT(cl_mem &data, int ndim, int N);
  int executeIFFT(void *data, int ndim, int N[3], int streamId = -1);
	
  /*
    Info: execute normalize kernel
    Return: success or error code
  */
  //int ocl_normalizeFFT(cl_mem &data, int ndim, int N);
  int normalizeFFT(void *data, int ndim, int N[3], int streamId = -1);
	
  /*
    Info: set FFT size
    Return: success or error code
  */
103
  int setupFFT(int ndim, int N[3]);
Uldis Locans's avatar
Uldis Locans committed
104

105
  int setupFFTRC(int ndim, int N[3], double scale = 1.0);
Uldis Locans's avatar
Uldis Locans committed
106

107
  int setupFFTCR(int ndim, int N[3], double scale = 1.0);
Uldis Locans's avatar
Uldis Locans committed
108

109
  int destroyFFT();
Uldis Locans's avatar
Uldis Locans committed
110 111
	
  int executeRCFFT(void * real_ptr, void * comp_ptr, int ndim, int N[3], 
112
		   int streamId = -1);
Uldis Locans's avatar
Uldis Locans committed
113
  int executeCRFFT(void * real_ptr, void * comp_ptr, int ndim, int N[3], 
114
		   int streamId = -1);
Uldis Locans's avatar
Uldis Locans committed
115 116 117 118 119 120 121 122 123 124
  int normalizeCRFFT(void *real_ptr, int ndim, int N[3], int streamId = -1)
    {
      return DKS_ERROR;
    }

  //void printData3DN4(cl_double2* &data, int N);

};

#endif