无法在device_memory中创建cusp :: coo_matrix的thrust :: host_vector?

时间:2012-10-19 00:29:02

标签: c++ cuda thrust nvcc cusp-library

我正在尝试制作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图书馆的忠实粉丝,但我只是好奇。此外,我需要重写一些代码,以防thrust::host_vector不合适(thrust::find并使用其他一些函数)。

另外,还有其他方法可以制作尖点矩阵数组吗?我认为原始指针和new/delete无论如何都比std::vector更好,我是对的吗?

1 个答案:

答案 0 :(得分:1)

正如评论中所指出的,编译器警告是良性的。在推力宿主矢量中使用非POD类型是安全的。使用推力装置矢量做同样的事情是不安全的。

这个答案是作为社区维基从评论中添加到未答复的列表中