Dynamic Array Creating Dynamic array in cuda


I am working on detecting all distinct values in an array and I need to store the distinct values in new array. the problem is that I don’t know the number of the distinct values.
for example if I have the input array = [1,2,3,5,1,2,4,7,3,5,6] then the expected output will be [1,2,3,4,5,6,7]

I wrote the code sequentially using vector. I was wondering is their any solution to have an array with the same behavior of the vector where every time I find a new element, the element is inserted .

Thank you and best Regards,

This would be a decent way to do this:

  1. use thrust::sort the list

  2. use thrust::unique on the list

If you want to write it yourself I would use that same algorithm. basically you sort and then collapse numbers that are next to each other which are the same. You could easily do this inplace using your existing array and would not have to worry about allocating new memory.