perf(sort): packed-key fast path for sort(A; dims=1) - #121
Draft
shreyas-omkar wants to merge 2 commits into
Draft
Conversation
Sort or permute each 1D slice along an integer `dims` independently, matching Base. The default `dims=:` keeps the existing flat behaviour. There is no batched sort kernel, so each element is tagged with its slice and the whole array is sorted once by (slice, value), then scattered back into place. sortperm carries the original index as the payload and uses it to break ties, keeping the permutation stable. This reuses the backend's tuned sort and runs unchanged on CPU and every GPU backend.
shreyas-omkar
marked this pull request as draft
September 8, 2026 15:26
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.
Follow-up to #117.
Packs
(slice_id, value key)into a singleUInt64and sorts that, instead of the comparator merge over(slice, value)tuples, forsort(A; dims=1)with a 32-bit eltype under the default ordering. Everything else falls back to the #117 path unchanged.sort(A; dims=1),Float32, 1M elements, min of 30 runs:Vendor is CUDA.jl / AMDGPU.jl native
sort(A; dims). AMDGPU.jl has no GPUdimssort (it hits a scalar-indexing fallback), so AK is the only GPU path there. CUDA.jl uses a dedicated segmented sorter and stays ahead; closing that gap is tracked in #120.