7

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 the input to FFTs. 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, floating‐point complex data type that consists of interleaved real and imaginary components." Data to be operated on by cufft is stored in arrays of cufftComplex.

How do I quickly copy my data from a normal C array into an array of cufftComplex ? I don't want to use a for loop because it's probably the slowest possible option. I don't know how to use memcpy on arrays data of this type, because I do not know how it is stored in memory. Thanks!

4

1 に答える 1

10

これは、ホストからデバイスへのコピーの一部として実行できます。各コピーは、ホスト上の連続する入力配列の 1 つを取得し、ストライド方式でデバイスにコピーします。CUDA の複雑なデータ型のストレージ レイアウトは、Fortran および C++ で定義された複雑な型のレイアウトと互換性があります。つまり、実部の後に虚部が続く構造体です。

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);
于 2012-11-23T22:32:45.987 に答える