Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is that possible to use the push_back method on kernel of CUDA?

Tags:

cuda

thrust

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?

like image 784
Hanson Avatar asked Feb 04 '26 02:02

Hanson


1 Answers

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.

like image 116
talonmies Avatar answered Feb 05 '26 17:02

talonmies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!