user1805103
user1805103

Reputation: 129

CUDA array/vector delete

I am new to CUDA and am trying to write my own kernel.

On the CPU side, I have a series of vectors containing ints (one vector/GPU thread).

I want each of the GPU threads to remove some of the elements from its vector that I will then copy back to the host. On the CPU side the comparable operation would be:

vector.erase(element_number);

My understanding is that stl type vectors are not supported on the GPU and I really can't use Thrust (because I am using my own kernel).

However, I could convert the CPU vectors to arrays (including data on the number of elements) and then copy the arrays to the GPU. Then, If I identified an element to be deleted, I could shift all the elements below up and decrement the total number of elements.

Before I recreate the wheel and write that, my question is: is there some CUDA supported operation that already does this?

Upvotes: 1

Views: 584

Answers (1)

user673679
user673679

Reputation: 1366

Not really. You'd have to write your own vector class in the way you describe.

If you don't care about the order of the elements in the vector, you can implement the erase operation by swapping the element to be erased with the last element in the vector, and then decrementing the size, instead of moving everything.

Upvotes: 1

Related Questions