在C++中,为了创建一个包含10个整数向量的向量,我将执行以下操作:
std::vector< std::vector<int> > test(10);
Run Code Online (Sandbox Code Playgroud)
由于我认为Thrust使用与STL相同的逻辑,我尝试做同样的事情:
thrust::host_vector< thrust::host_vector<int> > test(10);
Run Code Online (Sandbox Code Playgroud)
但是我遇到了太多令人困惑的错误.我试过做:
thrust::host_vector< thrust::host_vector<int> > test;
Run Code Online (Sandbox Code Playgroud)
它工作,但我不能添加任何东西到这个向量.干
thrust::host_vector<int> temp(3);
test.push_back(temp);
Run Code Online (Sandbox Code Playgroud)
会给我同样的错误(太多了,不能粘贴在这里).
一般来说,使用Thrust时,它是否会影响使用host_vector和STL 之间的区别vector?
先感谢您
Thrust的容器仅适用于POD(普通旧数据)类型.通过在推力中实例化"向量矢量"来创建多维向量是不可能的,主要是因为GPU侧的限制使得无法在设备代码路径中传递和使用.
C++标准库类型和算法与那些STL派生模型的推力主机实现之间存在一定程度的兼容性,但是当您希望同时使用主机和设备库后端时,您应该坚持使用主机向量.