c++ - Is there any way to use thrust with cufftComplex data type when the data is in device? -


i'm making program have 4d data. in loop iterate through 4th dimension, , take 3d data float, convert data cufftcomplex , copy device , several device operations fourier transform(from cufft library), image denoising(my own cuda kernel). while being in loop in between these operations after fourier transform want find median of 3d data in particular iteration.

i know thrust allows me sorting can find median value in following example normal float data type do

int row, column, slice; row = 5; column = 5; slice = 5; int alloc_size = row*column*slice; float * themaindata = new float[alloc_size]; srand(time(null)); for(int k=0; k<slice; k++) {     for(int j=0; j<column; j++)     {        for(int i=0; i<row; i++)        {           themaindata[i+(j*column)+(k*row*column)] = rand()%1000;;        }     } } thrust::sort(themaindata, themaindata + alloc_size); float median = themaindata[(alloc_size/2)]; cout<<endl<<"the median value "<<median<<endl; 

so, question is, there way make thrust::sort() function work cufftcomplex when data copied device? or there other function similar thrust can deal cufftcomplex data type when data copied device?

so, question is, there way make thrust::sort() function work cufftcomplex when data copied device?

yes.

thrust provides versions of sort operation accept user defined comparison operators, order data way wish.

an example usage custom functor given in thrust sorting example (using evens_before_odds functor).

so you'll need comparison functor. don't know how sort complex values, example if wanted sort them based on magnitude do:

#include <cucomplex.h> #include <cufft.h>   struct my_complex_sort {   __host__ __device__   bool operator()(cufftcomplex x, cufftcomplex y)   {     return (cucabs(x) > cucabs(y));   } }; 

if have cufftcomplex data on device, create thrust pointer it. let's suppose pointer device data d_data , data size n:

thrust::device_ptr<cufftcomplex> dp_data = thrust::device_pointer_cast(d_data); 

then sort data with:

thrust::sort(dp_data, dp_data+n, my_complex_sort()); 

(disclaimer: coded in browser, not tested)


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -