Skip to content

Commit

Permalink
Changed precondition for edge case in serial_merge to prevent asserti…
Browse files Browse the repository at this point in the history
…on error (#622)

* added std::min to ensure no out of bound acess

* fixed typo keys->keys1

* updated changelog

* reverted std::min

* implemented suggested logic
  • Loading branch information
NguyenNhuDi authored Oct 11, 2024
1 parent 95f09a2 commit b9a2da9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Documentation for rocPRIM is available at
* device merge,
* device partial sort, and/or
* device sort (merge sort).
* Fixed an issue where on certain inputs to block_sort_merge, device_merge_sort_merge_path, device_merge, and warp_sort_stable would cause an assertion error during its call to serial_merge

### Deprecations

Expand Down
4 changes: 2 additions & 2 deletions rocprim/include/rocprim/detail/merge_path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ void serial_merge(KeyType* keys_shared,
OutputFunction output_function)
{
// Pre condition, we're including some edge cases too.
assert(range.begin1 <= range.end1);
assert(range.begin2 <= range.end2);
if (!AllowUnsafe && range.begin1 > range.end1 && range.begin2 > range.end2)
return; // don't do anything, we have invalid inputs

// More descriptive names for ranges:
auto idx_a = range.begin1;
Expand Down

0 comments on commit b9a2da9

Please sign in to comment.