无法在device_memory中创建Cusp :: COO_MATRIX的TOLLUST :: HOST_VECTOR

Impossible to create thrust::host_vector of cusp::coo_matrix within device_memory?

本文关键字:MATRIX COO TOLLUST VECTOR HOST 创建 device memory Cusp      更新时间:2023-10-16

我正在尝试制作一个 cusp::coo_matrix的向量,并且似乎不能以这种方式使用 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::host_vector不合适,我将需要重写一些代码(使用thrust::find和其他一些功能)。

另外,还有其他方法可以制作一系列尖端矩阵吗?我不认为原始指针和new/deletestd::vector更好,我是对的吗?

如注释中所述,编译器警告是良性的。在推力主机向量中不使用POD类型是安全的。使用推力设备向量做同样的事情是不安全的。

此答案是从评论中添加为一个社区Wiki,以将其从未解决的列表中获取