Improve BitonicSort performance for sorting floats#952
Open
vyu wants to merge 7 commits intoJuliaArrays:masterfrom
Open
Improve BitonicSort performance for sorting floats#952vyu wants to merge 7 commits intoJuliaArrays:masterfrom
vyu wants to merge 7 commits intoJuliaArrays:masterfrom
Conversation
Additional changes to sort.jl: - Put sort.jl into a module to avoid polluting StaticArrays namespace. - Add docstring. - Extend tests. - Add benchmarks.
stev47
reviewed
Aug 21, 2021
Contributor
stev47
left a comment
There was a problem hiding this comment.
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.
Contributor
Author
|
@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.
Contributor
|
It is a bit regrettable that we now have a different |
Contributor
Author
|
Could a maintainer approve the pending workflows? This is ready for merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also: add docstring, extend tests, and add benchmarks.
The speedup (for sorting
isbitsfloats underisless) is based on @stev47's improvement toislessin 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 forislessin 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.)