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?
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.