使用推力库操作时使用袖口
Using cufft when operating with the thrust library
本文关键字:操作 更新时间:2023-10-16
我想在我的项目中合并thrust
库和cufft
。因此,为了测试,我写了
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;
不幸的是,cufft
只接受像cuDoubleComplex *a
这样的数组,而thrust::sequence
只能用thrust::complex<double>
向量正常工作。编译上面的代码时,我得到两个错误:
error : no operator "=" matches these operands
error : no operator "<<" matches these operands
第一个指的是thrust::sequence(V2.begin(), V2.end(), 2);
,而第二个指的是std::cout << V1[i] << ' ' << V2[i] << ' ' << V3[i] << 'n';
。如果我V2
评论,一切正常。thrust::device_vector<thrust::complex<double>>
和cuDoubleComplex *
之间有转换吗?如果没有,我该如何组合它们?
thrust::complex<double>
和std::complex<double>
与cuDoubleComplex
共享相同的数据布局。因此,使上述示例正常工作所需的只是将device_vector
中的数据转换为原始指针并将它们传递给 cuFFT。推力本身不能在大多数操作中与cuDoubleComplex
一起使用,因为该类型是一个简单的容器,它没有定义任何需要执行推力期望的POD类型的任何操作的运算符。
这应该有效:
#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;
}
相关文章:
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 重载操作程序时出错>>用于类中的字符串 memebr
- 对字符串进行位操作
- 我可以在 C++ 中的函数体之外进行操作吗?
- MPI突然停止了对多个核心的操作
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- 对字符数组中的元素执行逐位操作
- 如何在directx/c++中进行平移/缩放操作
- 逐位操作的隐式类型转换
- 为什么一个向量上的多线程操作很慢
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 位移操作和位掩码未检测到重复字符
- 如何进行特定的位操作?
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 字符串操作 - 字符计数
- 此代码中的操作流程是什么?C/C++.
- 复制和交换习惯用法与移动操作之间的交互
- 像union_这样的 Boost.Geometry 操作如何处理浮点类型的基本不精确性?
- 为什么 std::lerp 不适用于任何已实现所需操作的类型?
- 无法合并生成操作.. 先决条件不同