CUDA Thrust library: How can I create a host_vector of host_vectors of integers?

限于喜欢 提交于 2019-12-07 16:49:55

问题


In C++ in order to create a vector that has 10 vectors of integers I would do the following:

  std::vector< std::vector<int> > test(10);

Since I thought Thrust was using the same logic with the STL I tried doing the same:

  thrust::host_vector< thrust::host_vector<int> > test(10);

However I got too many confusing errors. I tried doing:

  thrust::host_vector< thrust::host_vector<int> > test;

and it worked, however I can't add anything to this vector. Doing

  thrust::host_vector<int> temp(3);
  test.push_back(temp);

would give me the same errors(too many to paste them here).

Also generally speaking when using Thrust, does it make a difference between using host_vector and the STL's vector?

Thank you in advance


回答1:


Thrust's containers are only designed for POD (plain old data) types. It isn't possible to create multidimensional vectors by instantiating "vectors of vectors" in thrust, mostly because of the limitations on the GPU side which make it impossible to pass and use in the device code path.

There is some level of compatibility between C++ standard library types and algorithms and the thrust host implementation of those STL derived models, but you should really stick with host vectors when you want to work both with the host and device library back ends.



来源:https://stackoverflow.com/questions/15869049/cuda-thrust-library-how-can-i-create-a-host-vector-of-host-vectors-of-integers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!