使用Thrust执行傅里叶变换

10

Thrust是一个很棒的CUDA编程封装库。我想知道是否有任何东西可以将NVIDIA CUFFT与thrust封装在一起,还是我们需要自己实现?


2
为什么不使用ArrayFire,它拥有一个库中的所有内容? - Ben Stewart
另一篇帖子是关于如何使用Thrust计算外积的。我期待下一篇会是如何在Thrust中实现Dijkstra算法)) 为什么人们一直在问这个问题? - user1545642
我也想使用ArrayFire,实际上我必须使用它来与其他库进行比较。有什么方法吗? - Quan Tran Minh
1
你还可以使用cudafft,并直接访问它来进行代码中的FFT部分,然后在Thrust中完成其他所有操作。或者为其编写一个简单的迭代器/容器封装器。 - Ade Miller
1个回答

10

这是一个很晚的回答,只是为了将这个问题从未答复列表中移除。

使用cuFFT和thrust应该非常简单,唯一要做的就是将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();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接