Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cuda 具有自定义数据类型的推力矢量_Cuda_Copy_Thrust - Fatal编程技术网

Cuda 具有自定义数据类型的推力矢量

Cuda 具有自定义数据类型的推力矢量,cuda,copy,thrust,Cuda,Copy,Thrust,我在项目中使用推力库时遇到以下问题: 我有一个名为box的结构,定义为 typedef struct { int coord[4]; float h; } box; 我现在正试图将数据从一个盒子的设备向量复制到一个盒子的主机向量: thrust::device_vector<box> d_boxes(100); thrust::host_vector<box> h_boxes; thrust::copy(d_boxes.begin(), d_boxes.

我在项目中使用推力库时遇到以下问题:

我有一个名为box的结构,定义为

typedef struct {
    int coord[4];
    float h;
} box;
我现在正试图将数据从一个盒子的设备向量复制到一个盒子的主机向量:

thrust::device_vector<box> d_boxes(100);
thrust::host_vector<box> h_boxes;
thrust::copy(d_boxes.begin(), d_boxes.end(), h_boxes.begin());
推力::设备向量d_盒(100);
推力:主机向量h_盒;
推力::复制(d_-box.begin(),d_-box.end(),h_-box.begin());
但这就产生了错误

在抛出“推力::系统::系统_错误”的实例后调用terminate what():无效参数

如果我对int而不是box做同样的操作,它就可以正常工作。 不幸的是,文档中似乎没有任何自定义数据类型的向量示例


我错过了什么?

推力::复制不会自动为您调整向量大小(实际上没有推力算法)

这是一个空向量,不足以容纳100个对象:

thrust::host_vector<box> h_boxes;
推力::主机向量h_盒;
请尝试以下方法:

thrust::host_vector<box> h_boxes(100);
推力::主机向量h_盒(100);
正如@JaredHoberock所指出的,另一种实现方式可能是:

thrust::device_vector<box> d_boxes(100);
thrust::host_vector<box> h_boxes = d_boxes;
推力::设备向量d_盒(100);
推力::主机向量h_盒=d_盒;

在这种情况下,
h_盒
的构造函数创建它时,其大小适合容纳
d_盒
中的元素数量(以及执行设备->主机数据复制)。

Ha。我不知道。谢谢:)您不需要调用
推力::复制
,只需在初始化时将
d_框
分配给
h_框