OpenCLFFT.h 2.84 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 103 104 105 106 107 108 109 110 111 112 113
/*

  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"

class OpenCLFFT : public DKSFFT {

private:

  OpenCLBase *m_oclbase;

  /*
    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);

public:

  /* constructor - currently does nothing*/
  OpenCLFFT(OpenCLBase *base) {
    m_oclbase = base;
  }
	
  /* destructor - currently does nothing*/
  ~OpenCLFFT() { }
	
  /*
    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
  */
  int setupFFT(int ndim, int N[3]) { return DKS_SUCCESS; }

  int setupFFTRC(int ndim, int N[3], double scale = 1.0) { return DKS_SUCCESS; }

  int setupFFTCR(int ndim, int N[3], double scale = 1.0) { return DKS_SUCCESS; }

  int destroyFFT() { return DKS_SUCCESS; }
	
  int executeRCFFT(void * real_ptr, void * comp_ptr, int ndim, int N[3], 
				int streamId = -1)
    {
      return DKS_ERROR;
    }
  int executeCRFFT(void * real_ptr, void * comp_ptr, int ndim, int N[3], 
				int streamId = -1)
    {
      return DKS_ERROR;
    }
  int normalizeCRFFT(void *real_ptr, int ndim, int N[3], int streamId = -1)
    {
      return DKS_ERROR;
    }

  int ocl_executeFFTStockham(void* &src, int ndim, int N, bool forward = true);

  int ocl_executeFFTStockham2(void* &src, int ndim, int N, bool forward = true);

  int ocl_executeTranspose(void *src, int N[3], int ndim, int dim);
	
  //void printData3DN4(cl_double2* &data, int N);

};

#endif