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

标签 c++ cuda thrust nvcc cusp-library

我正在尝试制作一个 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/

相关文章:

cudaEventSynchronize 与 cudaDeviceSynchronize

cuda - 在 opencl 中 CPU 作为主机,intel HD 4000 作为设备 1,离散 GPU 作为设备 2

c++ - thrust::device_vector 使用 thrust::replace 或 thrust::transform 自定义仿函数/谓词

c++ - 什么是 C++ forwarditerator 的例子?

c++ - 这种类型的双关语定义明确吗?

c++ - FFTW 性能变化

macos - OSX 10.10 为什么 CUDA 7.5 认为我的驱动程序不足?

c++ - Boost库文件生成

c++ - 如何在设备上运行 thrust::count_if? (库达)

memory-management - 静态推力自定义分配器?