Take the 2-minute tour ×

Thrust is an amazing wrapper for starting programming CUDA. I wonder there is any thing to encapsulate NVIDIA CUFFT with thrust or we need to implement ourselves?

share|improve this question
Why not use ArrayFire which has everything in one library? –  Ben Stewart Dec 3 '12 at 2:22
Another post was about how to compute the outer product using thrust.. I expect the next one would be how implement Dijkstra algorithm in thrust )) why people keep on asking that ? –  asm Dec 3 '12 at 12:08
I also want to use ArrayFire and actually I have to use in order to compare with other libraries. Is there any approach? –  Quan Tran Minh Dec 5 '12 at 8:03
You could also use cudafft and just access that directly for the FFT portion of your code and do everything else in Thrust. Or write a simple iterator/container based wrapper for it. –  Ade Miller Apr 2 '13 at 16:59
add comment

1 Answer

This is a very late answer, just to remove this question from the unanswered list.

Using cuFFT with thrust should be very simple and the only thing to do should be to cast the thrust::device_vector to a raw pointer. A very simple example is reported below:

#include <iostream>
#include <cufft.h>
#include <stdlib.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/transform.h>

int main(void){

    int N=4;

    // --- Setting up input device vector    
    thrust::device_vector<cuFloatComplex> d_in(N,make_cuComplex(1.f,2.f)), d_out(N);

    cufftHandle plan;
    cufftPlan1d(&plan, N, CUFFT_C2C, 1);

    cufftExecC2C(plan, thrust::raw_pointer_cast(d_in.data()), thrust::raw_pointer_cast(d_out.data()), CUFFT_FORWARD);

    // --- Setting up output host vector    
    thrust::host_vector<cuFloatComplex> h_out(d_out);

    for (int i=0; i<N; i++) printf("Element #%i; Real part = %f; Imaginary part: %f\n",i,h_out[i].x,h_out[i].y);

share|improve this answer
add comment

Your Answer


