Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing Fourier Transform with Thrust

Tags:

cuda

fft

thrust

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?

like image 586
Quan Tran Minh Avatar asked Dec 02 '12 11:12

Quan Tran Minh


1 Answers

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();
}
like image 120
Vitality Avatar answered Nov 12 '22 17:11

Vitality