Using cufft when working with traction library

I want to combine the library thrustand cufftin my project. So for testing, I wrote

    int length = 5;
    thrust::device_vector<thrust::complex<double> > V1(length);
    thrust::device_vector<cuDoubleComplex> V2(length);
    thrust::device_vector<thrust::complex<double> > V3(length);
    thrust::sequence(V1.begin(), V1.end(), 1);
    thrust::sequence(V2.begin(), V2.end(), 2);
    thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), thrust::multiplies<thrust::complex<double> >());
    cufftHandle plan;
    cufftPlan1d(&plan, length, thrust::complex<double>, 1);
    cufftExecZ2Z(plan, &V1, &V2, CUFFT_FORWARD);
    for (int i = 0; i < length; i++)
        std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';
    std::cout << '\n';
    return  EXIT_SUCCESS;

Unfortunately, cufftit only accepts arrays, such as cuDoubleComplex *a, but thrust::sequenceonly works with thrust::complex<double>-vectors. When compiling the code above, I get two errors:

error : no operator "=" matches these operands
error : no operator "<<" matches these operands

The first refers to thrust::sequence(V2.begin(), V2.end(), 2);, and the second relates to std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';. If I comment V2, everything will be fine. Is there a conversion between thrust::device_vector<thrust::complex<double>>and cuDoubleComplex *? If not, how can I combine them?

+3
source share
1 answer

thrust::complex<double> std::complex<double> cuDoubleComplex. , , , - device_vector cuFFT. cuDoubleComplex , , , , Thrust POD.

:

#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/sequence.h>
#include <thrust/complex.h>
#include <iostream>
#include <cufft.h>

int main()
{
    int length = 5;
    thrust::device_vector<thrust::complex<double> > V1(length);
    thrust::device_vector<thrust::complex<double> > V2(length);
    thrust::device_vector<thrust::complex<double> > V3(length);
    thrust::sequence(V1.begin(), V1.end(), 1);
    thrust::sequence(V2.begin(), V2.end(), 2);
    thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), 
                         thrust::multiplies<thrust::complex<double> >());
    cufftHandle plan;
    cufftPlan1d(&plan, length, CUFFT_Z2Z, 1);
    cuDoubleComplex* _V1 = (cuDoubleComplex*)thrust::raw_pointer_cast(V1.data());
    cuDoubleComplex* _V2 = (cuDoubleComplex*)thrust::raw_pointer_cast(V2.data());

    cufftExecZ2Z(plan, _V1, _V2, CUFFT_FORWARD);
    for (int i = 0; i < length; i++)
        std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';
    std::cout << '\n';
    return  EXIT_SUCCESS;
}
+4

All Articles