Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid extra loops on sorted data in the __subgroup_bubble_sorter::sort #1874

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SergeyKopienko
Copy link
Contributor

@SergeyKopienko SergeyKopienko commented Sep 24, 2024

In this PR we avoid extra loops on sorted data in the __subgroup_bubble_sorter::sort,
which calls in sort algorithms on the device for every work item.

This is beneficial when the data is already sorted, which according to https://en.wikipedia.org/wiki/Sorting_algorithm is a common real-world case.

….h - fix corner case performance issue in the __subgroup_bubble_sorter::sort

Signed-off-by: Sergey Kopienko <[email protected]>
….h - avoid loops and condition checks for small data sizes in __subgroup_bubble_sorter::sort

Signed-off-by: Sergey Kopienko <[email protected]>
case 0:
case 1:
break;
case 2:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to ignore clang format at this place.


_IndexType __n = __end - __start;

switch (__n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no other occurrences of switch in the library. What about using if-else? I guess switch is not necessary here due to having only 4 options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe switch / case should works faster.

if (__comp(__second_item, __first_item))
std::swap(__first_item, __second_item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you allow ADL as it was originally?

using std::swap;
swap(__first_item, __second_item);

Comment on lines +43 to +45
using _IndexType = std::make_signed_t<decltype(__end)>;

_IndexType __n = __end - __start;
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overflow is handled in the caller side, so it does not make sense to make a signed type. Also, it makes the positive range of data smaller, which may result in warnings (I do not expect it overflow, though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants