Copying data to cufftComplex data structure?

I have data stored as arrays of floats (single precision). I have one array for my real data and one array for my complex data, which I use as input to the FFT. I need to copy this data into the cufftComplex data type if I want to use the CUDA cufft library. From nVidia: " cufftComplex is a single-precision, complex, floating-point data type consisting of alternating real and imaginary components." The data that cufft will use is stored in cufftComplex arrays.

How to quickly copy data from a regular C array to a cufftComplex array? I do not want to use a for loop because this is probably the slowest option. I do not know how to use memcpy for arrays of data of this type, because I do not know how it is stored in memory. Thanks!

+4
source share
1 answer

You can do this as part of a copy of the host-> device. Each copy takes one of the adjacent input arrays on the host and copies them to the device. The layout of the storage of complex data types in CUDA is compatible with the layout defined for complex types in Fortran and C ++, i.e. As a structure with a real part, followed by an imaginary part.

 float * real_vec; // host vector, real part float * imag_vec; // host vector, imaginary part float2 * complex_vec_d; // device vector, single-precision complex float * tmp_d = (float *) complex_vec_d; cudaStat = cudaMemcpy2D (tmp_d, 2 * sizeof(tmp_d[0]), real_vec, 1 * sizeof(real_vec[0]), sizeof(real_vec[0]), n, cudaMemcpyHostToDevice); cudaStat = cudaMemcpy2D (tmp_d + 1, 2 * sizeof(tmp_d[0]), imag_vec, 1 * sizeof(imag_vec[0]), sizeof(imag_vec[0]), n, cudaMemcpyHostToDevice); 
+5
source

Source: https://habr.com/ru/post/1448022/


All Articles