10

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 2
    Why not use ArrayFire which has everything in one library? – Ben Stewart Dec 03 '12 at 02: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 ? –  Dec 03 '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 05 '12 at 08:03
  • 1
    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 02 '13 at 16:59

1 Answers1

10

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);

    getchar();
}
Vitality
  • 20,705
  • 4
  • 108
  • 146