gpt4 book ai didi

cuda - 通过推力执行傅立叶变换

转载 作者:行者123 更新时间:2023-12-04 04:06:38 26 4
gpt4 key购买 nike

对于启动CUDA编程,Thrust是一个了不起的包装器。
我想知道是否可以用推力封装NVIDIA CUFFT,还是我们需要实现自己?

最佳答案

这是一个很晚的答案,只是从未答复的列表中删除此问题。

对推力使用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();
}

关于cuda - 通过推力执行傅立叶变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13669019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com