-
Notifications
You must be signed in to change notification settings - Fork 153
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
Improve BitonicSort performance for sorting floats #952
base: master
Are you sure you want to change the base?
Conversation
Additional changes to sort.jl: - Put sort.jl into a module to avoid polluting StaticArrays namespace. - Add docstring. - Extend tests. - Add benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transformation by wrapping -NaN
around is indeed a nice idea! I've added some quick comments on your implementation.
The separate benchmark seems quite extensive, but I haven't looked at it in detail.
@stev47 Thank you for the review. I've made some changes based on your feedback. |
Instead of using generated functions to unroll tuples, use `ntuple(f, Val(N))` where `f` has an inline hint.
It is a bit regrettable that we now have a different |
Could a maintainer approve the pending workflows? This is ready for merging. |
Also: add docstring, extend tests, and add benchmarks.
The speedup (for sorting
isbits
floats underisless
) is based on @stev47's improvement toisless
in Julia 1.7 (stev47 also authored the BitonicSort implementation!), but instead of NaN-checking we subtract an offset to wrap the NaNs with negative sign to the greatest integers (see code for details), giving branchless code. We apply this transformation only once at the start of each sort to sort them as integers, then apply the inverse transformation at the end to get back the floats. (This technique cannot be used forisless
in Julia Base becauseisless(NaN, NaN)
returns false regardless of payload and sign.)Comparative benchmark results on Julia 1.7.0-beta3:
(The couple of timing fluctuations that show up for integer sorting are just noise.)
I have a vectorized implementation that I hope to contribute later after cleaning it up. (SIMD performance is of course heavily dependent on CPU capabilities and compiler support, which is why I'm benchmarking on three machines. Didn't matter for this PR, though.)