30
30
#include <thrust/sequence.h>
31
31
#include <thrust/iterator/iterator_traits.h>
32
32
#include <thrust/detail/uninitialized_array.h>
33
#include <thrust/detail/trivial_sequence.h>
35
36
* This file implements the following dispatch procedure for cuda::stable_sort()
269
270
StrictWeakOrdering comp,
270
271
thrust::detail::true_type)
272
// CUDA path for thrust::stable_sort with primitive keys
273
// (e.g. int, float, short, etc.) and a less<T> or greater<T> comparison
274
// method is implemented with stable_radix_sort
275
thrust::detail::backend::cuda::detail::stable_radix_sort(first, last);
273
// ensure sequence has trivial iterators
274
thrust::detail::trivial_sequence<RandomAccessIterator> keys(first, last);
276
// CUDA path for thrust::stable_sort with primitive keys
277
// (e.g. int, float, short, etc.) and a less<T> or greater<T> comparison
278
// method is implemented with stable_radix_sort
279
thrust::detail::backend::cuda::detail::stable_radix_sort(keys.begin(), keys.end());
281
// copy results back, if necessary
282
if(!thrust::detail::is_trivial_iterator<RandomAccessIterator>::value)
283
thrust::copy(keys.begin(), keys.end(), first);
277
// if comp is greater<T> then reverse the keys
278
typedef typename thrust::iterator_traits<RandomAccessIterator>::value_type KeyType;
279
const static bool reverse = thrust::detail::is_same<StrictWeakOrdering, typename thrust::greater<KeyType> >::value;
285
// if comp is greater<T> then reverse the keys
286
typedef typename thrust::iterator_traits<RandomAccessIterator>::value_type KeyType;
287
const static bool reverse = thrust::detail::is_same<StrictWeakOrdering, typename thrust::greater<KeyType> >::value;
282
thrust::reverse(first, last);
290
thrust::reverse(first, last);
285
293
template<typename RandomAccessIterator,
330
338
thrust::reverse(values_first, values_first + (keys_last - keys_first));
333
thrust::detail::backend::cuda::detail::stable_radix_sort_by_key(keys_first, keys_last, values_first);
341
// ensure sequences have trivial iterators
342
thrust::detail::trivial_sequence<RandomAccessIterator1> keys(keys_first, keys_last);
343
thrust::detail::trivial_sequence<RandomAccessIterator2> values(values_first, values_first + (keys_last - keys_first));
345
thrust::detail::backend::cuda::detail::stable_radix_sort_by_key(keys.begin(), keys.end(), values.begin());
347
// copy results back, if necessary
348
if(!thrust::detail::is_trivial_iterator<RandomAccessIterator1>::value)
349
thrust::copy(keys.begin(), keys.end(), keys_first);
350
if(!thrust::detail::is_trivial_iterator<RandomAccessIterator2>::value)
351
thrust::copy(values.begin(), values.end(), values_first);