In my CUDA Kernel:
// declaring data
float * data = new float[size];
[...]
[fill data]
[...]
// sorting
thrust::sort(data, data + size, thrust::greater<float>());
// unique
thrust::unique(thrust::device, data, data + size);
Output:
data =
0.1000
0.1000
0.1000
0
-0.3000
-0.2000
-0.1000
-Inf
-Inf
-Inf
NaN
Inf
Inf
Inf
-Inf
-Inf
NaN
Inf
Inf
Inf
Inf
My output, which you can here see in MATLAB is not sorted and the duplicates are not removed. UNIQUE and SORT isn't working at all. Is an pointer to array not supported for Thrust?
No comparison based algorithm can work correctly with data containing
NaN
values, becauseNaN
is uncomparable.Inf
and-Inf
are comparable, and will work with thrust or C++ standard library algorithms which perform comparison.The only solution here is to firstly remove the
NaN
values (thrust::remove_if
can be used for this with a functor or lambda expression which usesisnan
), then run comparison based algorithms on the data. So something like this:which does the following:
is perfectly capable of sorting and extracting unique values, include
Inf
and-Inf
on the input data once theNaN
entries are removed.