C++ 使用推力库操作时使用cufft
我想在我的项目中结合C++ 使用推力库操作时使用cufft,c++,cuda,thrust,C++,Cuda,Thrust,我想在我的项目中结合推力库和袖口。因此,为了测试,我写了 int length = 5; thrust::device_vector<thrust::complex<double> > V1(length); thrust::device_vector<cuDoubleComplex> V2(length); thrust::device_vector<thrust::complex<double> >
推力
库和袖口
。因此,为了测试,我写了
int length = 5;
thrust::device_vector<thrust::complex<double> > V1(length);
thrust::device_vector<cuDoubleComplex> V2(length);
thrust::device_vector<thrust::complex<double> > V3(length);
thrust::sequence(V1.begin(), V1.end(), 1);
thrust::sequence(V2.begin(), V2.end(), 2);
thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), thrust::multiplies<thrust::complex<double> >());
cufftHandle plan;
cufftPlan1d(&plan, length, thrust::complex<double>, 1);
cufftExecZ2Z(plan, &V1, &V2, CUFFT_FORWARD);
for (int i = 0; i < length; i++)
std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';
std::cout << '\n';
return EXIT_SUCCESS;
第一个是指推力序列(V2.begin(),V2.end(),2)代码>,而第二个是指std::cout推力::complex
和std::complex
与cuDoubleComplex
共享相同的数据布局。因此,使上述示例起作用所需的全部工作就是将device\u vector
中的数据转换为原始指针,并将其传递给cuFFT。在大多数操作中,推力本身不能与cuDoubleComplex
一起工作,因为该类型是一个简单的容器,它没有定义执行推力预期的任何操作所需的任何运算符
这应该起作用:
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/sequence.h>
#include <thrust/complex.h>
#include <iostream>
#include <cufft.h>
int main()
{
int length = 5;
thrust::device_vector<thrust::complex<double> > V1(length);
thrust::device_vector<thrust::complex<double> > V2(length);
thrust::device_vector<thrust::complex<double> > V3(length);
thrust::sequence(V1.begin(), V1.end(), 1);
thrust::sequence(V2.begin(), V2.end(), 2);
thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(),
thrust::multiplies<thrust::complex<double> >());
cufftHandle plan;
cufftPlan1d(&plan, length, CUFFT_Z2Z, 1);
cuDoubleComplex* _V1 = (cuDoubleComplex*)thrust::raw_pointer_cast(V1.data());
cuDoubleComplex* _V2 = (cuDoubleComplex*)thrust::raw_pointer_cast(V2.data());
cufftExecZ2Z(plan, _V1, _V2, CUFFT_FORWARD);
for (int i = 0; i < length; i++)
std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';
std::cout << '\n';
return EXIT_SUCCESS;
}
#包括
#包括
#包括
#包括
#包括
#包括
int main()
{
整数长度=5;
推力:装置_矢量V1(长度);
推力:装置_矢量V2(长度);
推力:设备_矢量V3(长度);
推力::序列(V1.begin(),V1.end(),1);
推力::序列(V2.begin(),V2.end(),2);
推力::变换(V1.begin(),V1.end(),V2.begin(),V3.begin(),
推力::乘法();
卡夫坦德尔计划;
袖口平面图(和平面图、长度、袖口Z、1);
cuDoubleComplex*V1=(cuDoubleComplex*)推力::原始指针转换(V1.data());
cuDoubleComplex*V2=(cuDoubleComplex*)推力::原始指针转换(V2.data());
cufftExecZ2Z(平面图,V 1,V 2,CUFFT向前);
for(int i=0;i std::cout使用带有自定义单操作的推力::制表
而不是推力::序列
?CUFFT_C2C->CUFFT_Z2Z怎么样
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/sequence.h>
#include <thrust/complex.h>
#include <iostream>
#include <cufft.h>
int main()
{
int length = 5;
thrust::device_vector<thrust::complex<double> > V1(length);
thrust::device_vector<thrust::complex<double> > V2(length);
thrust::device_vector<thrust::complex<double> > V3(length);
thrust::sequence(V1.begin(), V1.end(), 1);
thrust::sequence(V2.begin(), V2.end(), 2);
thrust::transform(V1.begin(), V1.end(), V2.begin(), V3.begin(),
thrust::multiplies<thrust::complex<double> >());
cufftHandle plan;
cufftPlan1d(&plan, length, CUFFT_Z2Z, 1);
cuDoubleComplex* _V1 = (cuDoubleComplex*)thrust::raw_pointer_cast(V1.data());
cuDoubleComplex* _V2 = (cuDoubleComplex*)thrust::raw_pointer_cast(V2.data());
cufftExecZ2Z(plan, _V1, _V2, CUFFT_FORWARD);
for (int i = 0; i < length; i++)
std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << '\n';
std::cout << '\n';
return EXIT_SUCCESS;
}