2012-12-02 117 views
7

Thrust是開始編程CUDA的驚人包裝。 我想知道是否有什麼東西要封裝NVIDIA CUFFT或者我們需要實現自己?使用Thrust進行傅里葉變換

+2

爲什麼不使用ArrayFire它擁有一個庫中的所有東西? –

+0

另一篇文章是關於如何使用推力來計算外層產品..我期望下一篇文章是如何實現Dijkstra算法的推力)爲什麼人們不斷問這個問題? – 2012-12-03 12:08:42

+0

我也想使用ArrayFire,實際上我必須使用它才能與其他庫進行比較。有什麼辦法嗎? –

回答

6

這是一個非常晚的答案,只是爲了從無人答覆的清單中刪除這個問題。

使用帶推力的cuFFT應該非常簡單,唯一要做的就是將thrust::device_vector轉換爲原始指針。一個非常簡單的例子如下:

#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(); 
}