我正在尝试制作一个 cusp::coo_matrix
的 vector ,但似乎不能以这种方式使用 thrust::host_vector
。考虑这段代码:
int main(void)
{
typedef typename cusp::coo_matrix<int, float, cusp::device_memory> maintype;
maintype B;
thrust::host_vector<maintype> h_vec(2,B);
return 0;
}
我从 nvcc
得到这个错误信息:
Warning: calling a __host__ function("thrust::detail::vector_base<int, thrust::device_malloc_allocator<int> > ::vector_base") from a __host__ __device__ function("thrust::detail::vector_base<int, thrust::device_malloc_allocator<int> > ::vector_base [subobject]") is not allowed
Warning: calling a __host__ function("thrust::detail::vector_base<float, thrust::device_malloc_allocator<float> > ::vector_base") from a __host__ __device__ function("thrust::detail::vector_base<float, thrust::device_malloc_allocator<float> > ::vector_base [subobject]") is not allowed
有趣的是,我用 cusp::host_memory
得到了完全相同的错误(嗯,几乎相同):
Warning: calling a __host__ function("thrust::detail::vector_base<int, std::allocator<int> > ::vector_base") from a __host__ __device__ function("thrust::detail::vector_base<int, std::allocator<int> > ::vector_base [subobject]") is not allowed
Warning: calling a __host__ function("thrust::detail::vector_base<float, std::allocator<float> > ::vector_base") from a __host__ __device__ function("thrust::detail::vector_base<float, std::allocator<float> > ::vector_base [subobject]") is not allowed
所以,我的问题是,这真的是缺点还是我做错了什么?非常感谢任何帮助。
此外,我测试了 std::vector
而不是 thrust::host_vector
并且它工作正常。并不是说我是 Thrust 库的忠实粉丝,而是我只是好奇。此外,我将需要重写一些代码,以防 thrust::host_vector
不合适(使用了 thrust::find
和其他一些函数)。
此外,还有其他方法可以制作尖点矩阵数组吗?我不认为原始指针和 new/delete
无论如何都比 std::vector
好,对吗?
最佳答案
如评论中所述,编译器警告是良性的。在推力主 vector 中使用非 POD 类型是安全的。用推力装置 vector 做同样的事情是不安全的。
此答案已添加为来自评论的社区 Wiki,以将其从未答复列表中移除
关于c++ - 无法在 device_memory 中创建 cusp::coo_matrix 的 thrust::host_vector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965731/