1

我必须从文件中加载数据。每个样本都是 20 维的。

所以我使用这个数据结构来帮助我解决这个问题:

class DataType
{
    vector<float> d;
}

但是当我使用这个变量定义时,它不能工作。

thrust::host_vector<DataType> host_input;
// after initializing the host input;
thrust::device_vector<DataType> device_input = host_input;
for(unsigned int i = 0; i < device_input.size(); i++)
    for(unsigned int j = 0; j < dim; j++)
        cout<<device_input[i].d[j]<<end;

这没用。编译器告诉我,我不能在 device_input 中使用向量(主机)。因为 device_input 将在设备(gpu)上实现,而 vector 将在 CPU 上实现。那么,我给出正确定义 DataType 的合适方法是什么?

4

1 回答 1

2

std::vector需要主机端动态分配内存,所以不能在设备端使用。

这应该有效。

class DataType
{
    float d[20];
}
于 2013-07-13T07:37:20.980 回答