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
NaNvalues, becauseNaNis uncomparable.Infand-Infare comparable, and will work with thrust or C++ standard library algorithms which perform comparison.The only solution here is to firstly remove the
NaNvalues (thrust::remove_ifcan 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
Infand-Infon the input data once theNaNentries are removed.