3

In my code, I want to push_back my date on the __global__ function,and it is hard to use array here. So I want to know is that possible to use the push_back method on kernel of CUDA? Can I use the std::vector on the __global__ function through some other way,or how to use the thrust::vector on __global__ function.

Can somebody give me an example code?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Hanson
  • 35
  • 5
  • [here's](http://stackoverflow.com/questions/21786495/cuda-kernel-returning-vectors/21788662#21788662) an example of something like push_back – Robert Crovella Apr 16 '14 at 13:58
  • Thank you very much and can you help me with my code? I still do not know how to do with it. May I have your email address? – Hanson Apr 17 '14 at 03:05
  • You can find an appropriate answer in [here][1] [1]: https://stackoverflow.com/questions/11534700/multiple-threads-writing-to-sequential-array-in-cuda-kernel –  Jun 11 '15 at 19:04

1 Answers1

3

It is not possible either std::vector or thrust::vector in CUDA kernel code. Thrust is a host side abstraction for GPU arrays and algorithms which cannot be used inside CUDA kernels.

You should rethink approach. push_back style appending of data is an fundamentally serial operation which requires some sort of locking or atomic operation in data parallel execution models. This almost always has negative performance impact on GPU code.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • I will appreciate if you can help me to review my code and find some way to solve my problem.May I have your email address and send my code to you? – Hanson Apr 16 '14 at 09:51