Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1442 from senior-zero/main-feature/github/thrust_…
Browse files Browse the repository at this point in the history
…merge_sort_comparisons_count_reduction/1436

Reduce comparisons count in merge sort
  • Loading branch information
alliepiper authored Jun 8, 2021
2 parents 6cf65fc + 403829e commit 1865104
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions thrust/system/cuda/detail/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ namespace __merge_sort {
// Parallel thread block merge sort
//---------------------------------------------------------------------

template <bool IS_LAST_TILE>
THRUST_DEVICE_FUNCTION void
block_mergesort(int tid,
int count,
Expand All @@ -343,9 +344,12 @@ namespace __merge_sort {
using core::uninitialized_array;
using core::sync_threadblock;

// stable sort items in a single thread
// if first element of thread is in input range, stable sort items
//
stable_odd_even_sort(keys_loc,items_loc);
if (!IS_LAST_TILE || ITEMS_PER_THREAD * tid < count)
{
stable_odd_even_sort(keys_loc, items_loc);
}

// each thread has sorted keys_loc
// merge sort keys_loc in shared memory
Expand Down Expand Up @@ -499,17 +503,17 @@ namespace __merge_sort {

if (IS_LAST_TILE)
{
block_mergesort(tid,
num_remaining,
keys_loc,
items_loc);
block_mergesort<IS_LAST_TILE>(tid,
num_remaining,
keys_loc,
items_loc);
}
else
{
block_mergesort(tid,
ITEMS_PER_TILE,
keys_loc,
items_loc);
block_mergesort<IS_LAST_TILE>(tid,
ITEMS_PER_TILE,
keys_loc,
items_loc);
}

sync_threadblock();
Expand Down

0 comments on commit 1865104

Please sign in to comment.