Copying data to “cufftComplex” data struct?

岁酱吖の 提交于 2019-11-27 09:31:14

You could do this as part of a host-> device copy. Each copy would take one of the contiguous input arrays on the host and copy it in strided fashion to the device. The storage layout 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 the real part followed by 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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!