Skip to content

Commit

Permalink
Merge pull request boostorg#803 from rosenrodt/fix-dupe-with-custom-c…
Browse files Browse the repository at this point in the history
…ompare-bitonic-block-sort

Fix duplicates using custom compare with bitonic block sort
  • Loading branch information
jszuppe authored Dec 20, 2018
2 parents 2c16bbc + 3cba294 commit 2a12dee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/boost/compute/algorithm/detail/merge_sort_on_gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ inline size_t bitonic_block_sort(KeyIterator keys_first,
k.decl<bool>("compare") << " = " <<
compare(k.var<key_type>("sibling_key"),
k.var<key_type>("my_key")) << ";\n" <<
k.decl<bool>("equal") << " = !(compare || " <<
compare(k.var<key_type>("my_key"),
k.var<key_type>("sibling_key")) << ");\n" <<
k.decl<bool>("swap") <<
" = compare ^ (sibling_idx < lid) ^ direction;\n" <<
"swap = equal ? false : swap;\n" <<
"my_key = swap ? sibling_key : my_key;\n";
if(sort_by_key)
{
Expand Down Expand Up @@ -220,8 +224,12 @@ inline size_t bitonic_block_sort(KeyIterator keys_first,
k.decl<bool>("compare") << " = " <<
compare(k.var<key_type>("sibling_key"),
k.var<key_type>("my_key")) << ";\n" <<
k.decl<bool>("equal") << " = !(compare || " <<
compare(k.var<key_type>("my_key"),
k.var<key_type>("sibling_key")) << ");\n" <<
k.decl<bool>("swap") <<
" = compare ^ (sibling_idx < lid);\n" <<
"swap = equal ? false : swap;\n" <<
"my_key = swap ? sibling_key : my_key;\n";
if(sort_by_key)
{
Expand Down
3 changes: 3 additions & 0 deletions test/test_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ BOOST_AUTO_TEST_CASE(sort_int2)
host[size/4] = int2_(20.f, 0.f);
host[(size*3)/4] = int2_(9.f, 0.f);
host[size-3] = int2_(-10.0f, 0.f);
host[size/2+1] = int2_(-10.0f, -1.f);

boost::compute::vector<int2_> vector(size, context);
boost::compute::copy(host.begin(), host.end(), vector.begin(), queue);
Expand All @@ -356,9 +357,11 @@ BOOST_AUTO_TEST_CASE(sort_int2)
);
boost::compute::copy(vector.begin(), vector.end(), host.begin(), queue);
BOOST_CHECK_CLOSE(host[0][0], -10.f, 0.1);
BOOST_CHECK_CLOSE(host[1][0], -10.f, 0.1);
BOOST_CHECK_CLOSE(host[(size - 3)][0], 9.f, 0.1);
BOOST_CHECK_CLOSE(host[(size - 2)][0], 20.f, 0.1);
BOOST_CHECK_CLOSE(host[(size - 1)][0], 100.f, 0.1);
BOOST_CHECK_NE(host[0], host[1]);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 2a12dee

Please sign in to comment.